:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --panel-soft: #f9fbfc;
    --text: #17202a;
    --muted: #627084;
    --line: #dfe5eb;
    --line-soft: #edf1f4;
    --primary: #007aff;
    --primary-dark: #005ecb;
    --blue: #2563eb;
    --green: #15803d;
    --amber: #b45309;
    --red: #b91c1c;
    --purple: #7c3aed;
    --shadow: 0 12px 28px rgba(23, 32, 42, .08);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

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

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

button,
input,
select,
textarea {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: center;
    min-height: 72px;
    padding: 12px 28px;
    border-bottom: 1px solid rgba(255, 255, 255, .12);
    background: #0f172a;
    color: #eaf3ff;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    flex: 0 0 auto;
    padding: 4px 0;
    color: #ffffff;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    font-weight: 900;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    margin-top: 2px;
    color: #b9d8ff;
    font-size: .78rem;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #d8e8ff;
    font-weight: 650;
}

.nav a span {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: rgba(255, 255, 255, .08);
    color: #ffffff;
    font-weight: 800;
}

.nav a:hover,
.nav a.active {
    background: rgba(0, 122, 255, .22);
    color: #ffffff;
}

.content-shell {
    min-width: 0;
    padding: 28px;
}

.page {
    width: min(1440px, 100%);
    margin: 0 auto 48px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    line-height: 1.16;
}

h1 {
    font-size: 1.9rem;
}

h2 {
    font-size: 1.05rem;
}

.header-actions,
.filter-actions,
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 9px 13px;
    border: 1px solid var(--primary);
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    cursor: pointer;
    font-weight: 750;
    white-space: nowrap;
}

.btn:hover {
    background: var(--primary-dark);
    color: #ffffff;
}

.btn.secondary,
.btn.ghost {
    background: #ffffff;
    color: var(--primary-dark);
}

.btn.ghost {
    border-color: var(--line);
    color: var(--muted);
}

.compact-btn {
    min-height: 34px;
    padding: 7px 10px;
}

.summary-band {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1px;
    overflow: hidden;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--line);
    box-shadow: var(--shadow);
}

.summary-band div {
    padding: 18px;
    background: var(--panel);
}

.summary-band span,
.metric span,
.detail-grid span,
.notice-panel span,
.page-count,
.panel-header span {
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
}

.summary-band strong {
    display: block;
    margin-top: 4px;
    font-size: 1.15rem;
}

.stats-grid,
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
}

.metric,
.detail-grid div,
.panel,
.notice-panel,
.filter-panel,
.table-card,
.record-hero,
.flash {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.metric {
    position: relative;
    min-height: 132px;
    padding: 18px;
    overflow: hidden;
}

.metric::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--primary);
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: 2rem;
}

.metric small {
    display: block;
    margin-top: 10px;
    color: var(--muted);
}

.accent-green::before { background: var(--green); }
.accent-blue::before { background: var(--blue); }
.accent-amber::before { background: var(--amber); }
.accent-red::before { background: var(--red); }
.accent-purple::before { background: var(--purple); }
.accent-slate::before { background: #475569; }
.accent-teal::before { background: var(--primary); }

.filter-panel {
    display: grid;
    grid-template-columns: minmax(240px, 2fr) repeat(4, minmax(130px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
    padding: 16px;
}

.filter-row,
.form-grid label,
.full-field {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: .8rem;
    font-weight: 700;
}

.filter-row.wide {
    grid-column: span 2;
}

input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid #cbd5df;
    border-radius: 8px;
    padding: 8px 10px;
    background: #ffffff;
    color: var(--text);
}

textarea {
    min-height: 104px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(0, 122, 255, .2);
    border-color: var(--primary);
}

.check-row {
    display: flex;
    gap: 8px;
    align-items: center;
    color: var(--text);
    font-weight: 650;
}

.check-row input {
    width: 16px;
    min-height: 16px;
}

.table-card {
    overflow: auto;
}

.data-table {
    width: 100%;
    min-width: 980px;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--line-soft);
    text-align: left;
    vertical-align: top;
}

.data-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: .72rem;
    font-weight: 850;
    text-transform: uppercase;
}

.data-table tbody tr:hover {
    background: #fbfcfd;
}

.numeric {
    text-align: right;
}

.reference-link {
    font-weight: 800;
}

.project-chip,
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f8fafc;
    color: #334155;
    font-size: .75rem;
    font-weight: 800;
    white-space: nowrap;
}

.subject-cell {
    max-width: 520px;
    color: #334155;
}

.subject-cell strong,
.subject-cell small,
.amount-cell small {
    display: block;
}

.subject-cell small {
    margin-top: 6px;
    color: var(--muted);
    font-weight: 500;
}

.amount-cell strong {
    font-variant-numeric: tabular-nums;
}

.amount-cell small {
    color: var(--muted);
}

.muted,
.empty-state {
    color: var(--muted);
}

.empty-state {
    padding: 32px;
    text-align: center;
}

.status-reponse-recue,
.decision-non-objection {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.status-en-attente {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
}

.status-a-verifier,
.status-to-verify,
.decision-commentaires,
.decision-non-determinee {
    border-color: #fde68a;
    background: #fffbeb;
    color: #92400e;
}

.decision-refus-non-objection {
    border-color: #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.status-unmatched,
.status-ignored {
    border-color: #e2e8f0;
    background: #f8fafc;
    color: #475569;
}

.record-hero {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 14px;
    padding: 20px;
}

.record-hero h2 {
    margin-top: 12px;
    max-width: 920px;
}

.record-hero p {
    margin: 8px 0 0;
    color: var(--muted);
}

.record-status {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-content: flex-start;
    justify-content: flex-end;
}

.detail-grid {
    margin-bottom: 14px;
}

.detail-grid div {
    min-height: 94px;
    padding: 16px;
}

.detail-grid strong {
    display: block;
    margin-top: 6px;
    font-size: 1.05rem;
}

.notice-panel {
    margin-bottom: 14px;
    padding: 16px;
}

.notice-panel p {
    margin: 6px 0 0;
    white-space: pre-wrap;
}

.panel {
    margin-bottom: 14px;
    padding: 16px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.full-field {
    margin-bottom: 12px;
}

.timeline-item {
    position: relative;
    padding: 16px 0 16px 20px;
    border-top: 1px solid var(--line-soft);
}

.timeline-item::before {
    content: "";
    position: absolute;
    top: 22px;
    left: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
}

.timeline-item:first-of-type {
    border-top: 0;
}

.timeline-item.received::before {
    background: var(--blue);
}

.timeline-item.sent::before {
    background: var(--green);
}

.timeline-item.compact {
    padding-bottom: 10px;
}

.timeline-meta {
    display: grid;
    gap: 6px;
}

.timeline-meta strong {
    color: #263241;
}

.timeline-meta small,
.timeline-item small {
    color: var(--muted);
}

.timeline-item p {
    margin: 10px 0;
    color: #334155;
    white-space: pre-wrap;
}

.attachment-list {
    margin: 10px 0 0;
    padding-left: 18px;
    color: var(--muted);
}

.inline-form {
    display: grid;
    grid-template-columns: minmax(210px, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.pagination {
    justify-content: flex-end;
    margin-top: 16px;
}

.flash {
    width: min(1440px, 100%);
    margin: 0 auto 14px;
    padding: 12px 14px;
}

.flash-success {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.flash-error,
.flash-danger {
    border-color: #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.auth-page {
    display: grid;
    min-height: calc(100vh - 56px);
    place-items: center;
}

.auth-card {
    display: grid;
    gap: 18px;
    width: min(460px, 100%);
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.auth-card h1 {
    font-size: 1.55rem;
}

.auth-intro {
    margin: 8px 0 0;
    color: var(--muted);
}

.auth-form {
    display: grid;
    gap: 14px;
}

.auth-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: .84rem;
    font-weight: 800;
}

@media (max-width: 960px) {
    .topbar {
        position: static;
        display: grid;
        gap: 12px;
        padding: 12px;
    }

    .nav {
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .nav a {
        flex: 0 0 auto;
    }

    .content-shell {
        padding: 18px 12px;
    }

    .page-header,
    .record-hero {
        display: grid;
    }

    .summary-band,
    .filter-panel,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .filter-row.wide {
        grid-column: auto;
    }

    .header-actions,
    .filter-actions,
    .pagination,
    .record-status {
        justify-content: flex-start;
    }
}
