/* ============================================================================
   CIA autonome — feuille unique.
   Les couleurs sont des VARIABLES : le mode sombre ne redefinit qu'elles, jamais
   une regle de mise en page. Trois etats : clair, sombre, et "systeme" par defaut.
   ========================================================================== */

:root {
    color-scheme: light dark;

    --ink:        #17202a;
    --ink-soft:   #5b6a7a;
    --line:       #dde3ea;
    --line-soft:  #edf1f5;
    --bg:         #f4f6f9;
    --surface:    #ffffff;
    --surface-2:  #f8fafc;
    --accent:     #1f6feb;
    --accent-ink: #ffffff;
    --accent-soft:#e8f0fe;

    --ok:      #15803d;
    --ok-bg:   #e7f6ec;
    --warn:    #a35b00;
    --warn-bg: #fdf1e0;
    --bad:     #b42318;
    --bad-bg:  #fdeceb;
    --info:    #1e5fa8;
    --info-bg: #e7f0fa;
    --muted-bg:#eef1f5;

    --radius:   10px;
    --radius-s: 7px;
    --shadow:   0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
    --gap:      16px;
    --font:     system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --mono:     ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* Le mode sombre suit le systeme, sauf si l'utilisateur a choisi. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --ink:        #e6edf3;
        --ink-soft:   #9aa7b4;
        --line:       #2b333d;
        --line-soft:  #222a33;
        --bg:         #12171d;
        --surface:    #1a2027;
        --surface-2:  #202831;
        --accent:     #4f9cf9;
        --accent-ink: #0b1218;
        --accent-soft:#1b2c42;

        --ok:      #5ed08a;
        --ok-bg:   #15301f;
        --warn:    #f0b357;
        --warn-bg: #352713;
        --bad:     #ff8781;
        --bad-bg:  #3a1d1b;
        --info:    #7ab6f5;
        --info-bg: #17293d;
        --muted-bg:#242c35;

        --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    }
}

:root[data-theme="dark"] {
    --ink:        #e6edf3;
    --ink-soft:   #9aa7b4;
    --line:       #2b333d;
    --line-soft:  #222a33;
    --bg:         #12171d;
    --surface:    #1a2027;
    --surface-2:  #202831;
    --accent:     #4f9cf9;
    --accent-ink: #0b1218;
    --accent-soft:#1b2c42;

    --ok:      #5ed08a;
    --ok-bg:   #15301f;
    --warn:    #f0b357;
    --warn-bg: #352713;
    --bad:     #ff8781;
    --bad-bg:  #3a1d1b;
    --info:    #7ab6f5;
    --info-bg: #17293d;
    --muted-bg:#242c35;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font: 15px/1.55 var(--font);
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: .92em; background: var(--muted-bg); padding: 1px 5px; border-radius: 4px; }

/* ---------------------------------------------------------------- en-tete */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 18px;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; letter-spacing: -.01em; padding: 12px 0; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
.brand img { width: 22px; height: 22px; }
.login-logo { display: block; width: 56px; height: 56px; margin: 0 auto 10px; }
/* Menu par métier : des liens et des groupes <details> qui s'ouvrent sans JavaScript.
   Pas d'overflow sur la barre : il couperait les panneaux qui débordent dessous. */
.topbar nav.menu { display: flex; align-items: stretch; gap: 2px; flex: 1; flex-wrap: wrap; }
.menu > a, .menu summary {
    display: block; color: var(--ink-soft); padding: 12px 10px; border-bottom: 2px solid transparent;
    white-space: nowrap; font-size: 14.5px; text-decoration: none; cursor: pointer;
}
.menu summary { list-style: none; user-select: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: "▾"; font-size: 11px; margin-left: 6px; opacity: .65; }
.menu > a:hover, .menu summary:hover, .menu details[open] > summary { color: var(--ink); background: var(--surface-2); text-decoration: none; }
.menu > a[aria-current="page"], .menu details.current > summary { color: var(--accent); border-bottom-color: var(--accent); font-weight: 550; }
.menu details { position: relative; }
.menu-panel {
    position: absolute; top: 100%; left: 0; z-index: 30; min-width: 220px;
    display: flex; flex-direction: column; padding: 6px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); box-shadow: var(--shadow);
}
.menu-panel a { padding: 8px 10px; border-radius: 5px; color: var(--ink); white-space: nowrap; font-size: 14.5px; }
.menu-panel a:hover { background: var(--surface-2); text-decoration: none; }
.menu-panel a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); font-weight: 550; }
/* Administration à droite, son panneau ouvert vers la gauche pour rester dans l'écran. */
.menu .menu-admin { margin-left: auto; }
.menu details.menu-admin .menu-panel { left: auto; right: 0; }
.topbar .tools { display: flex; align-items: center; gap: 10px; }
.who { color: var(--ink-soft); font-size: 14px; }

main { max-width: 1240px; margin: 22px auto 60px; padding: 0 20px; }
footer { max-width: 1240px; margin: 0 auto 30px; padding: 0 20px; color: var(--ink-soft); font-size: 13px; }

h1 { font-size: 21px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 26px 0 10px; letter-spacing: -.005em; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ------------------------------------------------------------------ cartes */
.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card label { display: block; margin-bottom: 13px; font-size: 13.5px; color: var(--ink-soft); }
.card.inline { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.card.inline label { margin-bottom: 0; }

input, select, textarea {
    display: block; width: 100%; padding: 8px 10px; margin-top: 4px;
    border: 1px solid var(--line); border-radius: var(--radius-s);
    font: inherit; color: var(--ink); background: var(--surface-2);
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent-soft); border-color: var(--accent); background: var(--surface);
}
.card.inline input, .card.inline select { width: auto; min-width: 150px; }
input[type="checkbox"] { width: auto; display: inline-block; margin-right: 6px; }

button, .button {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border: 1px solid var(--accent); border-radius: var(--radius-s);
    background: var(--accent); color: var(--accent-ink);
    font: inherit; font-size: 14px; cursor: pointer; text-decoration: none;
}
button:hover, .button:hover { filter: brightness(1.07); text-decoration: none; }
button.secondary, .button.secondary { background: var(--surface); color: var(--accent); }
button.ghost, .button.ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
button.ghost:hover { color: var(--ink); }

/* ------------------------------------------------------------------ tables */
table.grid {
    width: 100%; border-collapse: collapse; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
    box-shadow: var(--shadow); font-size: 14px;
}
table.grid th, table.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
table.grid thead th {
    position: sticky; top: 49px; z-index: 5;
    background: var(--surface-2); color: var(--ink-soft);
    font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em;
}
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid tr.muted td { color: var(--ink-soft); }
/* A row that will be refused (a statement line dated in a closed month). */
table.grid tr.bad td { color: var(--bad); }
/* Several small forms side by side in the last column of a list. */
table.grid td.actions form { display: inline-block; margin-right: .4rem; }
table.grid tfoot th { background: var(--surface-2); font-size: 13px; }
.num, table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- badges */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.badge-ok   { background: var(--ok-bg);   color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad  { background: var(--bad-bg);  color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted{ background: var(--muted-bg);color: var(--ink-soft); }

/* Barre coloree en tete de ligne : l'etat se voit avant d'etre lu. */
tr.state-ok   td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
tr.state-warn td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
tr.state-bad  td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
tr.state-info td:first-child { box-shadow: inset 3px 0 0 var(--info); }

/* --------------------------------------------------------------- messages */
.flash { padding: 11px 14px; border-radius: var(--radius-s); margin: 0 0 14px; border: 1px solid transparent; font-size: 14px; }
.flash-ok    { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok); }
.flash-error { background: var(--bad-bg);  color: var(--bad);  border-color: var(--bad); }
.flash-warn  { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }

/* --------------------------------------------------------------- vignettes */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--gap); margin-bottom: 22px; }
.tile {
    background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent);
    border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.tile-value { display: block; font-size: 24px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--ink-soft); font-size: 13px; }
.tile-sub { display: block; margin-top: 3px; font-size: 12.5px; }
.tile.ok   { border-left-color: var(--ok); }
.tile.warn { border-left-color: var(--warn); }
.tile.bad  { border-left-color: var(--bad); }

/* ------------------------------------------------- barre d'outils de page */
.toolbar {
    position: sticky; top: 49px; z-index: 10;
    display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
    padding: 10px 0; margin-bottom: 14px;
    background: var(--bg); border-bottom: 1px solid var(--line);
}
.toolbar input[type="search"] { width: 260px; margin: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px;
    background: var(--surface); color: var(--ink-soft); font-size: 13px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.jump { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; }
.jump a { color: var(--ink-soft); }
.jump a:hover { color: var(--accent); }
.count-hint { color: var(--ink-soft); font-size: 13px; margin-left: auto; }

/* La ligne masquee par la recherche de page. */
tr[hidden], .hidden { display: none !important; }
mark { background: var(--warn-bg); color: inherit; padding: 0 2px; border-radius: 3px; }

/* ---------------------------------------------------------------- sections */
.section { margin-bottom: 30px; scroll-margin-top: 110px; }
.section > header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.section > header h2 { margin: 0; }
.section-note { color: var(--ink-soft); font-size: 13px; }

/* ---------------------------------------------------------------- planning */
.planning-scroll { overflow-x: auto; border-radius: var(--radius); }
table.planning { font-size: 12px; }
table.planning th, table.planning td { padding: 3px; text-align: center; border-bottom: 1px solid var(--line-soft); }
table.planning th.weekend { background: var(--muted-bg); }
table.planning td.day { min-width: 22px; height: 26px; padding: 0; }
table.planning td.day a { display: block; width: 100%; height: 26px; }
table.planning td.nowrap { text-align: left; white-space: nowrap; font-size: 13px; }
/* Les couleurs de statut sont des CLASSES : aucun style en ligne, la politique de
   securite du navigateur les refuserait. */
td.st-option    { background: var(--warn-bg); }
td.st-confirmed { background: var(--ok-bg); }
td.st-in_stay   { background: var(--info-bg); }
td.st-done      { background: var(--muted-bg); }
.legend { display: inline-block; width: 13px; height: 13px; border: 1px solid var(--line); border-radius: 3px; vertical-align: middle; margin: 0 5px 0 14px; }
.legend.st-option { background: var(--warn-bg); }
.legend.st-confirmed { background: var(--ok-bg); }
.legend.st-in_stay { background: var(--info-bg); }
.legend.st-done { background: var(--muted-bg); }
/* An external event (Airbnb, Booking.com) nobody has turned into a booking yet: hatched. */
td.st-external, .legend.st-external {
    background: repeating-linear-gradient(45deg, var(--muted-bg), var(--muted-bg) 3px, var(--bad-bg) 3px, var(--bad-bg) 6px);
}

/* ------------------------------------------------------------ connexion */
body.bare { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.centered { width: 100%; max-width: 390px; padding: 20px; }
.login h1 { text-align: center; margin-bottom: 18px; }
.login button { width: 100%; justify-content: center; margin-top: 6px; }

.pager { margin-top: 14px; display: flex; gap: 14px; align-items: center; color: var(--ink-soft); font-size: 14px; }

/* Aide clavier, repliee par defaut. */
details.help { margin: 10px 0 0; font-size: 13px; color: var(--ink-soft); }
details.help summary { cursor: pointer; }
details.help kbd {
    font-family: var(--mono); font-size: 12px; background: var(--muted-bg);
    border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px;
}

/* Lien d'evitement, visible seulement au clavier. */
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 10px; z-index: 50; background: var(--surface); padding: 8px 12px; border-radius: var(--radius-s); }

@media (max-width: 800px) {
    .topbar { flex-wrap: wrap; gap: 8px; }
    /* On a phone the groups wrap on several lines: a panel opened from the middle of a line
       would leave the screen. Every panel spans the whole menu, under it. */
    .topbar nav.menu { order: 3; flex-basis: 100%; position: relative; }
    .menu .menu-admin { margin-left: 0; }
    .menu details { position: static; }
    .menu .menu-panel, .menu details.menu-admin .menu-panel { left: 0; right: 0; min-width: 0; }
    .toolbar { position: static; }
    table.grid thead th { position: static; }
    .toolbar input[type="search"] { width: 100%; }
}

@media print {
    .topbar, .toolbar, footer, button, .button { display: none !important; }
    body { background: #fff; }
}

/* The document preview, framed by the settings page: an A4 sheet needs height. */
.preview-frame { width: 100%; height: 82vh; border: 1px solid var(--line); border-radius: 6px; background: #fff; }

/* Two tables side by side (failed logins by account and by address), stacked on a phone. */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

/* Journal d'activite : filtres en grille, lignes refusees ou en erreur teintees, JSON repliable. */
.journal-filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 14px; align-items: end; }
.journal-filters label { margin: 0; }
.journal-buttons { display: flex; gap: 8px; flex-wrap: wrap; grid-column: 1 / -1; }
.journal-scope { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
table.journal td { font-size: 14px; }
table.journal tr.journal-refused td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.journal tr.journal-error td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.journal-json summary { cursor: pointer; color: var(--accent); }
.journal-json pre { max-width: 420px; max-height: 260px; overflow: auto; font-size: 12px; margin: 6px 0;
                    background: var(--muted-bg); padding: 6px 8px; border-radius: 5px; white-space: pre-wrap; word-break: break-word; }
