:root {
  --bg: #f4f6fa; --surface: #fff; --text: #1d2433; --muted: #6b7385; --border: #e2e6ee;
  --primary: #0f62fe; --primary-ink: #fff; --danger: #d92d20; --ok: #16a34a; --warn: #b54708;
  --chip: #eef2f9;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1218; --surface: #181c25; --text: #e6e9ef; --muted: #98a0b3; --border: #2a3040; --chip: #232a38; --primary: #4589ff; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.error { color: var(--danger); }
[hidden] { display: none !important; }

#app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
#nav { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
#nav .brand { font-weight: 800; font-size: 18px; padding: 6px 10px 16px; }
#nav a { padding: 9px 10px; border-radius: 8px; text-decoration: none; color: var(--text); }
#nav a.active, #nav a:hover { background: var(--chip); }
#nav #logout { margin-top: auto; }
#view { padding: 24px; max-width: 1200px; width: 100%; }
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); }
  #nav .brand { width: 100%; padding-bottom: 6px; }
  #nav #logout { margin-top: 0; }
  #view { padding: 16px; }
}

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.grid { display: grid; gap: 14px; }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.kpi .v { font-size: 28px; font-weight: 800; }
.kpi .l { color: var(--muted); }

button, .btn { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
button.danger { color: var(--danger); }
button.small, .btn.small { padding: 4px 9px; font-size: 13px; }
button.link { border: 0; background: none; color: var(--muted); text-align: left; padding: 9px 10px; }
button:disabled { opacity: .5; cursor: default; }

label { display: block; font-weight: 600; font-size: 13px; }
input, select, textarea { font: inherit; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
input[type=checkbox] { width: auto; margin: 0 6px 0 0; }
input[type=color] { padding: 2px; height: 38px; }
.form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; font-weight: 500; }
.days { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.days label { font-weight: 500; background: var(--chip); padding: 5px 9px; border-radius: 6px; display: flex; align-items: center; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }

.chip { display: inline-block; background: var(--chip); border-radius: 999px; padding: 2px 9px; font-size: 12px; }
.chip.on { background: #dcfce7; color: #14532d; }
.chip.off { background: #fee4e2; color: #7a271a; }
code { background: var(--chip); padding: 2px 6px; border-radius: 6px; font-size: 12px; word-break: break-all; }

.media-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.media-card { overflow: hidden; padding: 0; }
.media-card .thumb { aspect-ratio: 16/9; background: #000; display: grid; place-items: center; }
.media-card .thumb img, .media-card .thumb video { width: 100%; height: 100%; object-fit: contain; }
.media-card .meta { padding: 10px; display: grid; gap: 6px; }
.media-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drop { border: 2px dashed var(--border); border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--primary); color: var(--primary); }

.items { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.items li { display: flex; align-items: center; gap: 8px; background: var(--chip); padding: 6px 8px; border-radius: 8px; }
.items li img, .items li video { width: 64px; height: 36px; object-fit: cover; background: #000; border-radius: 4px; }
.items li .n { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.items li input { width: 74px; margin: 0; }
.picker { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); max-height: 260px; overflow: auto; }
.picker button { padding: 0; overflow: hidden; text-align: left; }
.picker button img, .picker button video { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: #000; display: block; }
.picker button span { display: block; padding: 4px 6px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; }
.bars div { flex: 1; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars div span { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; }

.phone { width: 300px; height: 600px; border: 10px solid #111; border-radius: 34px; overflow: hidden; background: #000; flex-shrink: 0; }
.phone iframe { width: 100%; height: 100%; border: 0; }
.ticker-demo { height: 40px; line-height: 40px; overflow: hidden; border-radius: 8px; white-space: nowrap; font-weight: 600; padding: 0 12px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(760px, 94vw); max-height: 90vh; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(10, 14, 22, .55); }
#modal-body { padding: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

#toast { position: fixed; right: 20px; bottom: 20px; background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 10; }
#toast.err { background: var(--danger); }

#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; }

/* Tableau de bord : filtres, recherche avec suggestions, tableaux chiffrés */
.subtitle { margin: -6px 0 16px; }
.filters { display: grid; gap: 12px; grid-template-columns: 170px repeat(2, minmax(200px, 1fr)) auto; align-items: end; }
@media (max-width: 900px) { .filters { grid-template-columns: 1fr; } }
.combo { position: relative; }
.combo-list { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  max-height: 320px; overflow: auto; font-weight: 500; }
.combo-list li { padding: 7px 9px; border-radius: 6px; cursor: pointer; }
.combo-list li.active, .combo-list li[role=option]:hover { background: var(--chip); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pager { margin-top: 10px; }
.inline-search { max-width: 240px; margin: 0; }
a.chip { text-decoration: none; color: var(--text); }
.cols-tables { grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); }
@media (max-width: 520px) { .cols-tables { grid-template-columns: 1fr; } }

/* Paramètres : onglets, aides, compte connecté */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs a:hover { color: var(--text); }
.help { display: block; font-weight: 400; color: var(--muted); margin-top: 4px; }
#whoami { margin-top: auto; padding: 6px 10px; font-size: 12px; }
#nav #whoami + #logout { margin-top: 0; }
a.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }

/* Compte en lecture seule : actions de modification masquées */
body.readonly #view button.primary:not(.self), body.readonly #view button.danger:not(.self),
body.readonly #modal .modal-actions button.primary { display: none; }
body.readonly #view a.chip.off { pointer-events: none; }
