/*
 * @file app.css
 * @description Styles du Backoffice interne (spec 025), repris du hi-fi design/wireframes/backoffice/bo-hifi.html.
 *              Tokens de app/lib/core/theme/ (mêmes valeurs que la page de reprise). Thème : préférence du système, ou
 *              choix mémorisé posé par app.js sur <html data-theme>.
 */

:root {
  --surface-primary: #FFFFFF; --surface-secondary: #FFF9F5; --surface-card: #FFFFFF; --surface-elevated: #FFFFFF;
  --text-primary: #2D1B2E; --text-secondary: #6B5B63; --text-muted: #9C8B92; --text-inverse: #FFFFFF;
  --border-primary: #EADFD7; --border-secondary: #F3EBE5;
  --action-primary: #FF8A6B; --action-primary-strong: #C4452A; --action-secondary: #FFF3EE;
  --status-danger-text: #C0392F; --status-danger-surface: #FFF0EF;
  --status-warning-text: #8A5A00; --status-warning-surface: #FFF6E6;
  --status-success-text: #1F7A4C; --status-success-surface: #EDF9F2;
  --status-info-text: #1F5FA8; --status-info-surface: #EFF6FF;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px; --space-6: 24px;
  --radius-sm: 12px; --radius-md: 16px; --radius-lg: 20px; --radius-pill: 999px;
  --motion-tap: 120ms; --motion-page: 250ms;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color-scheme: light;
}

@font-face { font-family: 'Nunito'; src: url('/bo/fonts/nunito-variable.woff2') format('woff2'); font-weight: 200 1000; font-display: swap; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-primary: #0E090B; --surface-secondary: #1A1316; --surface-card: #241B1F; --surface-elevated: #2D2328;
    --text-primary: #F5EBE0; --text-secondary: #D7C2B0; --text-muted: #A7919C; --text-inverse: #0E090B;
    --border-primary: #3A2D33; --border-secondary: #2B2025;
    --action-primary-strong: #FF8A6B; --action-secondary: #2D2328;
    --status-danger-text: #FFA1A1; --status-danger-surface: #3A2024;
    --status-warning-text: #FFD79A; --status-warning-surface: #3A2E1C;
    --status-success-text: #8AE3B7; --status-success-surface: #16301F;
    --status-info-text: #A9D3FF; --status-info-surface: #16263A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --surface-primary: #0E090B; --surface-secondary: #1A1316; --surface-card: #241B1F; --surface-elevated: #2D2328;
  --text-primary: #F5EBE0; --text-secondary: #D7C2B0; --text-muted: #A7919C; --text-inverse: #0E090B;
  --border-primary: #3A2D33; --border-secondary: #2B2025;
  --action-primary-strong: #FF8A6B; --action-secondary: #2D2328;
  --status-danger-text: #FFA1A1; --status-danger-surface: #3A2024;
  --status-warning-text: #FFD79A; --status-warning-surface: #3A2E1C;
  --status-success-text: #8AE3B7; --status-success-surface: #16301F;
  --status-info-text: #A9D3FF; --status-info-surface: #16263A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100vh; font-family: var(--font); background: var(--surface-primary); color: var(--text-primary); transition: background var(--motion-page), color var(--motion-page); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.bo-loading { padding: 48px 24px; text-align: center; color: var(--text-secondary); font-weight: 600; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Icônes Phosphor (bold) servies en local, teintées par la couleur du texte (masque CSS) */
.ic { display: inline-block; width: 1.15em; height: 1.15em; flex-shrink: 0; background: currentColor;
  -webkit-mask: var(--ic) center / contain no-repeat; mask: var(--ic) center / contain no-repeat; vertical-align: -0.2em; }
.ic-arrow-down { --ic: url('/bo/icons/arrow-down.svg'); }
.ic-camera { --ic: url('/bo/icons/camera.svg'); }
.ic-caret-down { --ic: url('/bo/icons/caret-down.svg'); }
.ic-caret-left { --ic: url('/bo/icons/caret-left.svg'); }
.ic-caret-right { --ic: url('/bo/icons/caret-right.svg'); }
.ic-chart-bar { --ic: url('/bo/icons/chart-bar.svg'); }
.ic-check { --ic: url('/bo/icons/check.svg'); }
.ic-check-square { --ic: url('/bo/icons/check-square.svg'); }
.ic-clock-counter-clockwise { --ic: url('/bo/icons/clock-counter-clockwise.svg'); }
.ic-envelope-simple { --ic: url('/bo/icons/envelope-simple.svg'); }
.ic-first-aid-kit { --ic: url('/bo/icons/first-aid-kit.svg'); }
.ic-hourglass { --ic: url('/bo/icons/hourglass.svg'); }
.ic-list-checks { --ic: url('/bo/icons/list-checks.svg'); }
.ic-lock-key { --ic: url('/bo/icons/lock-key.svg'); }
.ic-magnifying-glass { --ic: url('/bo/icons/magnifying-glass.svg'); }
.ic-minus-circle { --ic: url('/bo/icons/minus-circle.svg'); }
.ic-moon { --ic: url('/bo/icons/moon.svg'); }
.ic-note-pencil { --ic: url('/bo/icons/note-pencil.svg'); }
.ic-sign-in { --ic: url('/bo/icons/sign-in.svg'); }
.ic-sign-out { --ic: url('/bo/icons/sign-out.svg'); }
.ic-storefront { --ic: url('/bo/icons/storefront.svg'); }
.ic-sun { --ic: url('/bo/icons/sun.svg'); }
.ic-tray-arrow-down { --ic: url('/bo/icons/tray-arrow-down.svg'); }
.ic-user { --ic: url('/bo/icons/user.svg'); }
.ic-user-circle { --ic: url('/bo/icons/user-circle.svg'); }
.ic-warning-circle { --ic: url('/bo/icons/warning-circle.svg'); }
.ic-warning-octagon { --ic: url('/bo/icons/warning-octagon.svg'); }
.ic-x { --ic: url('/bo/icons/x.svg'); }


/* ── Coque : menu général à gauche, navigation contextuelle en haut ── */
.bo { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.bo-side { position: sticky; top: 0; height: 100vh; background: var(--surface-secondary); border-right: 1px solid var(--border-secondary); padding: var(--space-4) var(--space-3); display: flex; flex-direction: column; gap: 2px; }
.bo-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 15px; padding: 4px 8px 20px; }
.bo-brand svg { width: 30px; height: 30px; flex: none; }
.bo-brand small { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); }
.bo-nav { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 700; color: var(--text-secondary); text-decoration: none; cursor: pointer; border: 1px solid transparent; }
.bo-nav .ic { font-size: 20px; }
.bo-nav:hover { background: var(--surface-card); }
.bo-nav[aria-current="page"] { background: var(--surface-card); color: var(--text-primary); border-color: var(--border-primary); box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.bo-nav[aria-current="page"] .ic { color: var(--action-primary-strong); }
.bo-me { margin-top: auto; border-top: 1px solid var(--border-secondary); padding: var(--space-3) 8px 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.bo-me .who { display: flex; gap: 8px; align-items: center; font-weight: 700; color: var(--text-secondary); overflow-wrap: anywhere; }
.bo-me .who .ic { font-size: 20px; }
.bo-out { display: inline-flex; gap: 6px; align-items: center; min-height: 44px; font: 700 13px var(--font); color: var(--text-secondary); background: none; border: none; padding: 0; cursor: pointer; }
.bo-main { display: flex; flex-direction: column; min-width: 0; }
.bo-ctx { padding: var(--space-4) var(--space-6) 0; border-bottom: 1px solid var(--border-secondary); display: flex; flex-direction: column; gap: var(--space-3); }
.bo-ctx.flat { padding-bottom: var(--space-4); }
.crumbs { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.crumb-back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; font: 700 14px var(--font); color: var(--text-secondary); background: none; border: none; padding: 0; cursor: pointer; }
.crumbs .sep { color: var(--text-muted); }
.crumbs h1 { margin: 0; font-size: 22px; font-weight: 800; }
.reason { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 700; color: var(--text-secondary); background: var(--surface-secondary); border: 1px solid var(--border-secondary); border-radius: var(--radius-pill); padding: 6px 12px; }
.tabs { display: flex; gap: var(--space-1); overflow-x: auto; }
.tab { border: none; background: none; font: 700 14px var(--font); color: var(--text-secondary); padding: 12px 12px 10px; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; min-height: 44px; }
.tab[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--action-primary); }
.bo-body { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }

.card { background: var(--surface-card); border: 1px solid var(--border-primary); border-radius: var(--radius-lg); padding: var(--space-5); }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.eyebrow { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: var(--space-3); }
.eyebrow .ic { font-size: 16px; }
.kv { display: flex; justify-content: space-between; gap: var(--space-3); padding: 6px 0; font-size: 14px; font-weight: 600; color: var(--text-secondary); border-top: 1px solid var(--border-secondary); }
.kv:first-of-type { border-top: none; }
.kv b { color: var(--text-primary); font-weight: 800; text-align: right; }
.big { font-size: 32px; font-weight: 800; line-height: 1.1; }
.big small { font-size: 13px; font-weight: 700; color: var(--text-muted); margin-left: 6px; }
.link { color: var(--action-primary-strong); font-weight: 800; text-decoration: none; cursor: pointer; display: inline-flex; align-items: center; gap: 2px; }
.pill { display: inline-flex; gap: 4px; align-items: center; border-radius: var(--radius-pill); padding: 4px 10px; font-size: 12px; font-weight: 800; white-space: nowrap; background: var(--surface-secondary); color: var(--text-secondary); }
.pill.warn { background: var(--status-warning-surface); color: var(--status-warning-text); }
.pill.danger { background: var(--status-danger-surface); color: var(--status-danger-text); }
.pill.ok { background: var(--status-success-surface); color: var(--status-success-text); }
.pill.info { background: var(--status-info-surface); color: var(--status-info-text); }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--text-muted); }

.table-wrap { overflow-x: auto; }
table.bo-table { width: 100%; border-collapse: collapse; min-width: 640px; font-size: 14px; }
.bo-table th { text-align: left; font-size: 12px; font-weight: 800; color: var(--text-muted); padding: 8px 12px; }
.bo-table td { padding: 12px; border-top: 1px solid var(--border-secondary); font-weight: 600; vertical-align: middle; }
.bo-table tr.row-link { cursor: pointer; }
.bo-table tr.row-link:hover td, .bo-table tr.row-link:focus-visible td { background: var(--action-secondary); outline: none; }
.bo-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

.search { display: flex; gap: 10px; align-items: center; border: 1px solid var(--border-primary); border-radius: var(--radius-pill); padding: 0 18px; min-height: 52px; background: var(--surface-card); }
.search .ic { font-size: 20px; color: var(--text-muted); }
.search input { flex: 1; border: none; background: transparent; font: 600 16px var(--font); color: var(--text-primary); outline: none; }
.hint { font-size: 13px; font-weight: 600; color: var(--text-muted); margin: -6px 0 0 18px; }
.filters { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.select { min-height: 44px; border: 1px solid var(--border-primary); border-radius: var(--radius-pill); padding: 0 14px; font: 700 13px var(--font); background: var(--surface-card); color: var(--text-secondary); display: inline-flex; align-items: center; gap: 6px; }
.select.on { border-color: var(--action-primary); color: var(--text-primary); }

.btn { display: inline-flex; gap: 8px; align-items: center; justify-content: center; min-height: 48px; padding: 0 20px; border-radius: var(--radius-pill); border: 1px solid var(--border-primary); background: var(--surface-card); color: var(--text-primary); font: 800 15px var(--font); cursor: pointer; transition: transform var(--motion-tap); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--action-primary-strong); border-color: var(--action-primary-strong); color: var(--text-inverse); }
.btn.ghost { border-color: var(--border-primary); background: transparent; color: var(--text-secondary); min-height: 44px; }
.btn:focus-visible, .tab:focus-visible, .bo-nav:focus-visible, .crumb-back:focus-visible, input:focus-visible { outline: 3px solid var(--action-primary); outline-offset: 2px; }
.banner { display: flex; gap: var(--space-3); align-items: center; border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); font-size: 14px; font-weight: 700; }
.banner.danger { background: var(--status-danger-surface); color: var(--status-danger-text); }
.banner.warn { background: var(--status-warning-surface); color: var(--status-warning-text); }

.auth { display: grid; place-items: center; padding: 56px 24px; min-height: 100vh; background: var(--surface-secondary); }
.auth .card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: var(--space-4); }
.auth .logo { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.auth .logo svg { width: 36px; height: 36px; }
.auth h1 { margin: 0; font-size: 24px; font-weight: 800; }
.auth p { margin: 0; color: var(--text-secondary); font-weight: 600; font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 800; }
.input { width: 100%; min-height: 48px; border: 1px solid var(--border-primary); border-radius: var(--radius-sm); padding: 0 14px; font: 600 15px var(--font); background: var(--surface-card); color: var(--text-primary); }
.input.code { font: 700 26px var(--mono); letter-spacing: 10px; text-align: center; }
.qr { width: 184px; height: 184px; margin: 0 auto; border-radius: var(--radius-sm); border: 1px solid var(--border-primary); background: #FFFFFF; padding: 8px; display: block; }
.secret { font: 700 15px var(--mono); letter-spacing: 1px; background: var(--surface-secondary); border-radius: var(--radius-sm); padding: 12px; text-align: center; overflow-wrap: anywhere; }

.scrim { position: fixed; inset: 0; z-index: 10; background: rgba(14, 9, 11, .45); display: grid; place-items: center; }
.dialog { width: 440px; max-width: calc(100% - 32px); background: var(--surface-elevated); border-radius: var(--radius-lg); padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); box-shadow: 0 24px 64px rgba(0,0,0,.25); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); }
.dialog-head h2 { margin: 0; font-size: 18px; font-weight: 800; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: none; background: var(--surface-secondary); color: var(--text-secondary); font-size: 18px; cursor: pointer; }
.dim { opacity: .4; }
.states { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.empty { display: flex; gap: var(--space-3); align-items: center; color: var(--text-secondary); font-weight: 700; font-size: 14px; }
.empty .ic { font-size: 24px; color: var(--text-muted); }
.skeleton { height: 14px; border-radius: 7px; background: var(--border-secondary); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; } }
@media (max-width: 960px) { .bo { grid-template-columns: 1fr; } .bo-side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; } .bo-brand { padding-bottom: 4px; } .bo-me { margin-top: 0; border-top: none; flex-direction: row; } .grid3, .states { grid-template-columns: 1fr; } .reason { margin-left: 0; } }

/* Compléments de la page servie */
.select select { border: none; background: transparent; font: 700 13px var(--font); color: inherit; min-height: 40px; cursor: pointer; }
.select input[type="date"] { border: none; background: transparent; font: 700 13px var(--font); color: inherit; min-height: 40px; }
.select button { border: none; background: none; cursor: pointer; color: inherit; display: inline-flex; padding: 0; }
.field-error { color: var(--status-danger-text); font-size: 13px; font-weight: 700; margin: 0; }
.bo-table caption { text-align: left; }
.theme-btn { display: inline-flex; gap: 6px; align-items: center; min-height: 44px; font: 700 13px var(--font); color: var(--text-secondary); background: none; border: none; padding: 0; cursor: pointer; }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.row-between { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.inline { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.sub { font-size: 14px; font-weight: 700; color: var(--text-muted); margin: 0; }
.spacer-8 { height: 8px; }
.search:focus-within { outline: 3px solid var(--action-primary); outline-offset: 2px; }
.search input:focus-visible { outline: none; }
a.crumb-back, a.tab, a.bo-nav, a.link { text-decoration: none; }
a.link:hover, a.crumb-back:hover { text-decoration: underline; }
h1[tabindex="-1"]:focus { outline: none; }
.bo-table td:first-child { white-space: nowrap; }
