:root {
    --color-ink: #1b2430;
    --color-teal: #1f6f78;
    --color-teal-dark: #144e55;
    --color-muted: #59616c;
    --color-border: #dde2e6;
    --color-bg: #f6f7f9;
    --color-error: #b3261e;
    --color-success: #2e7d32;
    font-family: "IBM Plex Sans", -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-ink);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--color-ink);
    color: white;
}

.topbar__row { display: none; }
.topbar__toggle { display: none; }
.topbar__toggle-input { display: none; }
.topbar__collapsible { display: contents; }

.topbar__brand { font-weight: 600; }
.topbar__brand-short { display: none; }

.topbar__nav a {
    color: white;
    text-decoration: none;
    margin-right: 0.95rem;
    opacity: 0.85;
}
.topbar__nav a:hover { opacity: 1; text-decoration: underline; }

.topbar__user { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }

.content { max-width: 1600px; margin: 0 auto; padding: 2rem 1.5rem; }

.page-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.card {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}

.modal {
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 1.5rem;
    max-width: 600px;
    width: 90vw;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
}
.modal::backdrop { background: rgba(0,0,0,0.4); }

.table-wrapper { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; background: white; }
.table th, .table td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
.table th { font-size: 0.8rem; text-transform: uppercase; color: #4f5761; }
.table--compact td, .table--compact th { padding: 0.4rem 0.6rem; }

.totals-card {
    font-size: 0.95rem;
    padding: 0.75rem 1rem;
    background: #f4f7f6;
    border: 1px solid var(--color-border);
}
.totals-card strong { color: var(--color-ink); }

.table tr.row--taxe { background: #fdecea; }
.table tr.row--taxe:hover { background: #fbd9d5; }
.table tr.row--abandonne { background: #e9e9e9; color: var(--color-muted); }
.table tr.row--abandonne:hover { background: #dedede; }

.inline-select-form select {
    padding: 0.3rem 0.4rem;
    font-size: 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
}

.text-right { text-align: right; }
.text-muted { color: var(--color-muted); }

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: white;
    color: var(--color-ink);
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
}
.btn--primary { background: var(--color-teal); border-color: var(--color-teal); color: white; }
.btn--primary:hover { background: var(--color-teal-dark); }
.btn--link { border: none; background: none; text-decoration: underline; padding: 0; color: inherit; }

.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; }
.badge--muted { background: var(--color-border); color: var(--color-muted); }
.badge--active { background: #e3f1ec; color: var(--color-success); }

.alert { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.alert--error { background: #fdecea; color: var(--color-error); border-left: 4px solid var(--color-error); }
.alert--success { background: #e8f5e9; color: var(--color-success); border-left: 4px solid var(--color-success); }
.alert--info { background: #e8f1f2; color: var(--color-ink); border-left: 4px solid var(--color-teal); }

.form-grid { display: flex; flex-direction: column; gap: 0.6rem; max-width: 420px; }
.form-grid--inline { flex-direction: row; gap: 1rem; max-width: none; }
.form-grid label { font-size: 0.85rem; color: var(--color-muted); }
.form-grid input, .form-grid textarea, input, textarea, select {
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.95rem;
}

.form-grid--wide {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.6rem 1rem;
    max-width: 900px;
}
.form-grid--wide .field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.form-grid--wide .field--full { grid-column: 1 / -1; }
.form-grid--wide label { font-size: 0.85rem; color: var(--color-muted); }
.form-grid--wide input, .form-grid--wide select, .form-grid--wide textarea {
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.95rem;
    width: 100%;
}
.form-grid--wide button { grid-column: 1 / -1; justify-self: start; }

.login-page { display: flex; justify-content: center; padding-top: 3rem; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 0.6rem; }

.reconciliation-group fieldset { border: none; padding: 0; margin: 0.75rem 0; display: flex; gap: 1rem; flex-wrap: wrap; }
.reconciliation-group legend { font-size: 0.85rem; color: var(--color-muted); margin-bottom: 0.35rem; }

.definition-list { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0; }
.definition-list dt { color: var(--color-muted); }

.search-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.toggle-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}
.toggle-switch input { display: none; }
.toggle-switch .track {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--color-border);
    border-radius: 999px;
    transition: background 0.15s ease;
    flex-shrink: 0;
}
.toggle-switch .track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.15s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle-switch input:checked ~ .track { background: var(--color-teal); }
.toggle-switch input:checked ~ .track::after { transform: translateX(18px); }

/* --- Responsive: tablets and phones --- */
@media (max-width: 768px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
        padding: 0.75rem 1rem;
    }
    .topbar__row {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .topbar__brand-full { display: none; }
    .topbar__brand-short { display: inline; font-size: 1rem; }
    .topbar__toggle {
        display: block;
        font-size: 1.4rem;
        line-height: 1;
        cursor: pointer;
        padding: 0.25rem 0.5rem;
    }
    .topbar__collapsible {
        display: block;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.2s ease;
    }
    .topbar__toggle-input:checked ~ .topbar__collapsible {
        max-height: 640px;
    }
    .topbar__nav {
        display: flex;
        flex-direction: column;
        padding-top: 0.5rem;
    }
    .topbar__nav a {
        margin-right: 0;
        padding: 0.6rem 0;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
    }
    .topbar__user {
        flex-direction: row;
        justify-content: space-between;
        padding: 0.6rem 0;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
    }

    .content { padding: 1.25rem 1rem; }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }
    .page-header > div { display: flex; flex-wrap: wrap; gap: 0.5rem; }

    .card { padding: 1rem; }

    .form-grid--wide { grid-template-columns: 1fr 1fr; max-width: 100%; }

    .col-hide-mobile { display: none; }

    .search-form { width: 100%; }
    .search-form input[type="search"] { flex: 1 1 auto; min-width: 0; }
}

@media (max-width: 480px) {
    .form-grid--wide { grid-template-columns: 1fr; }
    .form-grid { max-width: 100%; }
    .login-card { max-width: 100%; margin: 0 1rem; }
    .btn { padding: 0.5rem 0.75rem; font-size: 0.85rem; }
    h1 { font-size: 1.3rem; }
}

/* --- Fiche dossier : chiffres clés, boutons d'ajout (29/10) --- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.stat { background: white; border: 1px solid var(--color-border); border-radius: 6px; padding: 0.75rem 1rem; display: flex; flex-direction: column; gap: 0.15rem; }
.stat__label { font-size: 0.8rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.stat__value { font-size: 1.35rem; font-weight: 600; white-space: nowrap; }
.stat__hint { font-size: 0.8rem; color: var(--color-muted); }
.stat--due { border-color: var(--color-error); }
.stat--due .stat__value { color: var(--color-error); }
.badge--error { background: #fdecea; color: var(--color-error); }
.details-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-start; margin-top: 0.75rem; }
.details-row details { flex: 1 1 100%; }
.details-row details:not([open]) { flex: 0 0 auto; }
.details-row summary { list-style: none; cursor: pointer; display: inline-block; }
.details-row summary::-webkit-details-marker { display: none; }
.form-grid--wide .field--span2 { grid-column: span 2; }
#repartition-table { width: 100%; }
#repartition-table td, #repartition-table th { white-space: nowrap; }
#repartition-table td.rep-client { white-space: normal; }
@media (max-width: 600px) { .form-grid--wide .field--span2 { grid-column: 1 / -1; } }

/* --- Utilitaires (remplacent les styles écrits dans les pages, 29/10) --- */
[hidden] { display: none !important; }
.form-grid--wide input[type=checkbox], .form-grid--wide input[type=radio],
.inline-check input, .card input[type=checkbox], .card input[type=radio] { width: auto; }
.inline-check { display: flex; align-items: center; gap: 0.4rem; font-weight: normal; }
.toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.toolbar--tight { gap: 0.4rem; }
.toolbar--wide { gap: 1rem; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0.5rem; }
.inline { display: inline; }
.nowrap { white-space: nowrap; }
.pre-wrap { white-space: pre-wrap; }
.fw-normal { font-weight: normal; }
.text-error { color: var(--color-error); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.8rem; }
.text-center { text-align: center; }
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-tiny { margin-top: 0.2rem; }
.mt-third { margin-top: 0.3rem; }
.mt-half { margin-top: 0.5rem; }
.mt-1 { margin-top: 1rem; }
.mt-2 { margin-top: 2rem; }
.mb-0 { margin-bottom: 0; }
.mb-third { margin-bottom: 0.3rem; }
.mb-half { margin-bottom: 0.5rem; }
.pl-0 { padding-left: 0; }
.lead-in { margin-top: -0.5rem; }
.input-xs { width: 5rem; }
.input-sm { width: 7rem; }
.select-md { max-width: 420px; }
.btn--danger { border-color: var(--color-error); color: var(--color-error); }
.danger-zone { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--color-border); }

/* --- Règlement ventilé (29/10) --- */
details.reglement > summary { cursor: pointer; list-style: none; }
details.reglement > summary::-webkit-details-marker { display: none; }
details.reglement > summary h3::before { content: "▸ "; color: var(--color-muted); }
details.reglement[open] > summary h3::before { content: "▾ "; }
.reglement-table input { width: 7rem; }
.reglement-table tr.is-paid td { background: #f1f8f3; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* --- Lisibilité, menu, messages (29/10) --- */
.btn--sm { padding: 0.25rem 0.6rem; font-size: 0.82rem; }
.btn--sm + form, form + form .btn--sm { margin-left: 0.25rem; }
.topbar__nav a.is-active { opacity: 1; font-weight: 600; text-decoration: underline; text-underline-offset: 0.35em; }
.topbar__sep { display: inline-block; width: 1px; height: 1.1em; background: rgba(255,255,255,0.35); margin: 0 0.95rem 0 0; vertical-align: middle; }
.flash { margin-bottom: 1rem; }
:focus-visible { outline: 2px solid var(--color-teal); outline-offset: 2px; }
details > summary { cursor: pointer; }
@media (max-width: 768px) { .topbar__sep { display: block; width: 100%; height: 0; margin: 0.3rem 0; background: none; } }
.table td.pre-wrap { overflow-wrap: anywhere; min-width: 10rem; }
.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }
.search-wide { min-width: 18rem; }
@media (max-width: 480px) { .search-wide { min-width: 0; width: 100%; } }
.topbar__search { margin-left: auto; margin-right: 1rem; }
.topbar__search input { padding: 0.35rem 0.6rem; border-radius: 6px; border: 1px solid rgba(255,255,255,0.25); background: rgba(255,255,255,0.1); color: white; width: 10.5rem; font-size: 0.9rem; }
.topbar__search input::placeholder { color: rgba(255,255,255,0.65); }
.topbar__search input:focus { background: white; color: var(--color-ink); outline: none; }
@media (max-width: 768px) { .topbar__search { margin: 0.5rem 0; } .topbar__search input { width: 100%; } }
.btn.is-current { background: var(--color-teal); border-color: var(--color-teal); color: white; }
.badge--warn { background: #fff4e0; color: #8a5300; }
.table tr.row--group td { background: #eef2f4; font-weight: 600; padding-top: 0.5rem; padding-bottom: 0.5rem; }
.table tr.row--future td { background: #fffaf0; }
.table tr.row--late td:first-child { box-shadow: inset 3px 0 0 var(--color-error); }
.table .col-tech { display: none; }
.table.show-tech .col-tech { display: table-cell; }
@media (max-width: 768px) { .table.show-tech .col-tech.col-hide-mobile { display: none; } }

/* menu sur une ligne avec la recherche ; recherche en tête du menu mobile */
.topbar__nav { white-space: nowrap; }
@media (max-width: 1280px) { .topbar__nav a, .topbar__sep { margin-right: 0.7rem; } .topbar__nav a { font-size: 0.92rem; } .topbar__search input { width: 8.5rem; } }
@media (max-width: 768px) {
    .topbar__nav { white-space: normal; }
    .topbar__toggle-input:checked ~ .topbar__collapsible { display: flex; flex-direction: column; }
    .topbar__search { order: -1; margin: 0.6rem 0 0.2rem; }
    .topbar__search input { width: 100%; font-size: 1rem; padding: 0.5rem 0.7rem; }
}
@media (min-width: 769px) and (max-width: 1240px) { .topbar__nav { white-space: normal; flex: 1 1 auto; } .topbar { gap: 0.75rem; } }

/* --- Champ dossier avec recherche (pages facture) --- */
.dossier-picker { position: relative; }
.dossier-picker__box { display: flex; gap: 0.35rem; }
.dossier-picker__box input { flex: 1; }
.dossier-picker__results { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; margin: 0.2rem 0 0; padding: 0.25rem 0;
    list-style: none; background: white; border: 1px solid var(--color-border); border-radius: 6px;
    box-shadow: 0 6px 18px rgba(27, 36, 48, 0.12); max-height: 18rem; overflow-y: auto; }
.dossier-picker__results li { padding: 0.45rem 0.7rem; cursor: pointer; display: flex; justify-content: space-between; gap: 0.75rem; }
.dossier-picker__results li small { color: var(--color-muted); text-align: right; }
.dossier-picker__results li[aria-selected="true"], .dossier-picker__results li:hover { background: #e8f1f2; }
.dossier-picker__results li.is-empty { color: var(--color-muted); cursor: default; }
