:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-border: #d9dce1;
    --color-text: #1f2430;
    --color-text-muted: #5a6270;
    --color-primary: #1f5c8b;
    --color-primary-dark: #164567;
    --color-danger: #b3261e;
    --color-danger-bg: #fbeaea;
    --color-success: #1b7a43;
    --color-success-bg: #e9f7ee;
    --radius: 6px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.45;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 1.5rem;
    position: relative;
    z-index: 1;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--color-text);
    font-weight: 600;
}
.brand:hover { text-decoration: none; }
.brand-logo { height: 40px; width: auto; object-fit: contain; }
.brand-logo-right { height: 34px; width: auto; object-fit: contain; margin-left: 0.25rem; }

.app-nav { display: flex; align-items: center; gap: 1rem; }
.app-user { color: var(--color-text-muted); font-size: 0.9rem; }

.app-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.75rem 1.5rem 3rem;
    position: relative;
    z-index: 1;
}

.page-bg-logo {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.06;
    z-index: 0;
    pointer-events: none;
}
.page-bg-logo img { width: 35%; max-width: 380px; }

.corner-logo {
    position: fixed;
    top: 1rem;
    height: 50px;
    width: auto;
    z-index: 2;
}
.corner-logo-left { left: 1.5rem; }
.corner-logo-right { right: 1.5rem; }

h1 { font-size: 1.5rem; margin: 0 0 1.25rem; }
h2 { font-size: 1.15rem; margin: 0 0 1rem; }

.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: 0.95rem;
}
.flash-success { background: var(--color-success-bg); color: var(--color-success); border: 1px solid #bfe6cc; }
.flash-error { background: var(--color-danger-bg); color: var(--color-danger); border: 1px solid #f0c4c1; }

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.form-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 480px;
}

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-weight: 600; font-size: 0.9rem; }
.field input[readonly] { background: #eef0f3; color: var(--color-text-muted); }

input[type="text"], input[type="date"], input[type="password"], input[type="search"] {
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
}
input:focus { outline: 2px solid var(--color-primary); outline-offset: 1px; }

.form-actions { display: flex; gap: 0.75rem; margin-top: 0.5rem; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); text-decoration: none; }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: #eef0f3; text-decoration: none; }
.btn-danger { background: var(--color-danger-bg); color: var(--color-danger); border-color: #f0c4c1; }
.btn-danger:hover { background: #f6d9d7; text-decoration: none; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.85rem; }

.nav-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}
.nav-tile {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--color-text);
    font-weight: 600;
}
.nav-tile:hover { border-color: var(--color-primary); text-decoration: none; background: #f6faff; }
.nav-tile .icon { font-size: 1.8rem; display: block; margin-bottom: 0.5rem; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}
th, td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}
th { background: #eef1f5; font-weight: 600; }
tbody tr:hover { background: #f6faff; }
tbody tr.row-link { cursor: pointer; }
tbody tr.table-group-row, tbody tr.table-group-row:hover { background: #eef1f5; }
tbody tr.table-group-row td { font-weight: 700; border-top: 2px solid var(--color-border); }
.table-wrap { overflow-x: auto; }
.actions-cell { white-space: nowrap; display: flex; gap: 0.5rem; }

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-complete { background: var(--color-success-bg); color: var(--color-success); }
.badge-pending { background: #fdf3e3; color: #9a6a12; }

.search-box { max-width: 420px; }
.search-input { width: 100%; }
#search-results { margin-top: 1.25rem; }
.search-hint { color: var(--color-text-muted); font-size: 0.85rem; margin-top: 0.4rem; }

.fiche {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 640px;
    margin: 0 auto;
    position: relative;
    text-align: center;
}
.fiche-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1rem; }
.fiche-logo, .fiche-logo-left { height: 60px; width: auto; object-fit: contain; }
.fiche-logo-group { display: flex; flex-direction: column; align-items: center; }
.fiche-logo-caption { margin-top: 0.3rem; font-size: 0.65rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; text-align: center; white-space: nowrap; }
.fiche h1 { margin-bottom: 1.5rem; }
.fiche dl { display: inline-grid; grid-template-columns: 220px 1fr; row-gap: 0.75rem; column-gap: 1rem; margin: 0 auto; text-align: left; }
.fiche dt { color: var(--color-text-muted); font-weight: 600; }
.fiche dd { margin: 0; }
.fiche-actions { margin-top: 2rem; display: flex; gap: 0.75rem; }
.fiche-footer { margin-top: 2rem; text-align: center; }
.fiche-footer img { width: 60%; max-width: 280px; }

.fiche-signature { margin-top: 2.5rem; text-align: right; }
.fiche-signature-line { border-top: 1px solid var(--color-text); width: 220px; margin: 0 0 0.4rem auto; }
.fiche-signature-img { max-width: 200px; max-height: 70px; display: inline-block; margin-bottom: 0.3rem; }
.fiche-signature-name { font-weight: 600; }

.signature-preview { max-width: 220px; max-height: 90px; display: block; border: 1px solid var(--color-border); padding: 0.5rem; background: #fff; }

.rapport-page { background: #fce300; padding: 1.5rem; border-radius: var(--radius); }
@media print {
    .rapport-page { background: none; padding: 0; }
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        linear-gradient(rgba(20,30,45,0.72), rgba(20,30,45,0.72)),
        var(--color-bg);
    position: relative;
}
.login-bg-logo {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.08;
    z-index: 0;
    pointer-events: none;
}
.login-bg-logo img { width: 60%; max-width: 480px; }
.login-card {
    position: relative;
    z-index: 1;
    background: var(--color-surface);
    border-radius: 10px;
    padding: 2.25rem 2rem;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.25);
}
.login-card h1 { text-align: center; font-size: 1.25rem; margin-bottom: 1.5rem; }
.login-card .btn-primary { width: 100%; justify-content: center; margin-top: 0.5rem; }
.login-card .landing-back { text-align: center; margin: 1.25rem 0 0; font-size: 0.85rem; }

.landing-card { max-width: 400px; text-align: center; }
.landing-sub { color: var(--color-text-muted); font-size: 0.9rem; margin: -0.5rem 0 1.5rem; }
.landing-actions { display: flex; flex-direction: column; gap: 0.75rem; }
.landing-actions .btn { width: 100%; justify-content: center; }

.home-hero {
    text-align: center;
    padding: 2rem 1rem 2.5rem;
}
.home-hero h1 { font-size: 1.9rem; margin-bottom: 0.75rem; }
.home-hero-sub { font-size: 1rem; max-width: 640px; margin: 0 auto 1.5rem; }
.cta-row { display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap; }

.home-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.75rem 2rem;
    margin-bottom: 1.5rem;
}
.home-cta-section { text-align: center; }
.home-cta-section .btn { margin-top: 0.5rem; }

.steps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
}
.step-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem 1rem;
    position: relative;
}
.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 0.6rem;
}
.step-card h3 { font-size: 1rem; margin: 0 0 0.4rem; }
.step-card p { margin: 0; color: var(--color-text-muted); font-size: 0.9rem; }

.suivi-card { max-width: 480px; margin-top: 1.25rem; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem 1rem;
    text-align: center;
}
.stat-card-primary { border-color: var(--color-primary); background: #f6faff; }
.stat-card-success { border-color: var(--color-success); background: var(--color-success-bg); }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stat-label { margin-top: 0.35rem; color: var(--color-text-muted); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }

.dl-grid {
    display: inline-grid;
    grid-template-columns: 260px 1fr;
    row-gap: 0.6rem;
    column-gap: 1rem;
    margin: 0;
}
.dl-grid dt { color: var(--color-text-muted); font-weight: 600; }
.dl-grid dd { margin: 0; font-weight: 600; }

@media print {
    .app-header, .no-print { display: none !important; }
    body { background: #fff; }
    .app-main { padding: 0; max-width: none; }
    .fiche { border: none; box-shadow: none; padding: 0; }
}
