:root {
  --bg: #0a0b0d;
  --surface: #131519;
  --surface-2: #1a1d22;
  --line: #24282f;
  --text: #e9eaec;
  --muted: #8a9099;
  --accent: #ff3b4e;
  --accent-soft: rgba(255, 59, 78, 0.14);
  --ok: #34d17a;
  --warn: #f5b94a;
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2 { margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 22px; margin-bottom: 16px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .fill { fill: currentColor; stroke: none; }

/* ---------- boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); text-decoration: none; font-weight: 600; transition: background .15s, border-color .15s;
}
.btn:hover { background: #20242a; }
.btn.primary { background: var(--text); color: #0a0b0d; border-color: transparent; }
.btn.primary:hover { background: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--accent); border-color: rgba(255, 59, 78, .35); background: transparent; }
.btn.danger:hover { background: var(--accent-soft); }
.btn.small { height: 36px; padding: 0 14px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, .08); background: rgba(10, 11, 13, .55); backdrop-filter: blur(8px);
}

/* ---------- connexion ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center;
  padding: 32px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
}
.login-logo { width: 56px; height: 56px; margin: 0 auto 4px; }
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0 0 8px; }
.login-card input {
  height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); outline: none; text-align: center; font-size: 16px;
}
.login-card input:focus { border-color: #4a515c; }
.error { color: var(--accent); min-height: 1.4em; margin: 0; font-size: 14px; }

/* ---------- structure ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(10, 11, 13, .96); border-bottom: 1px solid var(--line);
}
/* pas de backdrop-filter sur mobile : il casserait le position:fixed de la barre d'onglets */
@media (min-width: 900px) { .top { background: rgba(10, 11, 13, .86); backdrop-filter: blur(14px); } }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cam-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam-sub { font-size: 12.5px; color: var(--muted); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; transition: background .3s, box-shadow .3s; }
.status-dot.on { background: var(--ok); box-shadow: 0 0 0 4px rgba(52, 209, 122, .15); }
.status-dot.off { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

main { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 16px; padding-bottom: calc(var(--nav-h) + var(--safe-b) + 20px); }
.view { display: none; animation: fade .2s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* onglets : barre du bas sur mobile, en haut sur grand ecran */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(13, 14, 17, .94); backdrop-filter: blur(14px); border-top: 1px solid var(--line);
}
.tabs button {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--muted); font-size: 11.5px; font-weight: 600;
}
.tabs button.active { color: var(--text); }
.tabs button svg { width: 22px; height: 22px; }
.tab-badge {
  position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

@media (min-width: 900px) {
  .tabs { position: static; height: auto; padding: 4px; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
  .tabs button { flex-direction: row; gap: 8px; padding: 8px 14px; border-radius: 9px; font-size: 14px; }
  .tabs button.active { background: var(--surface-2); }
  .tabs button svg { width: 18px; height: 18px; }
  .tab-badge { position: static; }
  main { padding: 24px; padding-bottom: 32px; }
}

/* ---------- direct ---------- */
.live-grid { display: grid; gap: 16px; }
@media (min-width: 900px) { .live-grid { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; } }

.stage {
  position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line);
}
.stage canvas { width: 100%; height: 100%; display: block; object-fit: contain; }
.stage:fullscreen { border-radius: 0; border: 0; aspect-ratio: auto; }
.stage-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  color: var(--muted); font-size: 14px; background: radial-gradient(circle at 50% 40%, #15181c, #050506);
}
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #2a2f36; border-top-color: var(--text); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hud { position: absolute; z-index: 2; }
.hud-tl { top: 12px; left: 12px; }
.hud-tr { top: 12px; right: 12px; }
.hud-bl { bottom: 16px; left: 12px; font-size: 12.5px; font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, .85); text-shadow: 0 1px 3px #000; }
.hud-br { bottom: 12px; right: 12px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border-radius: 15px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600;
}
.chip svg { width: 15px; height: 15px; }
.chip.active { color: var(--text); border-color: #3a4049; background: var(--surface-2); }
.motion-chip { background: rgba(10, 11, 13, .6); border-color: rgba(255, 255, 255, .08); backdrop-filter: blur(8px); }
.motion-chip.on { color: #fff; background: rgba(245, 185, 74, .22); border-color: rgba(245, 185, 74, .5); }

.rec-badge {
  display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 11px; border-radius: 15px;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; letter-spacing: .04em; font-variant-numeric: tabular-nums;
}
.rec-badge i { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.meter { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .06); }
.meter i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--warn); transition: width .2s; }
.meter b { position: absolute; top: -3px; bottom: 0; width: 2px; background: rgba(255, 255, 255, .5); }

.side { display: flex; flex-direction: column; gap: 16px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; height: 84px;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 600;
  transition: background .15s, border-color .15s, transform .1s;
}
.action:hover { background: var(--surface-2); }
.action:active { transform: scale(.97); }
.action svg { width: 24px; height: 24px; }
.action.rec svg { color: var(--accent); }
.action.rec.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.action.rec.on svg { color: #fff; }
.action.sleep-on { border-color: #3a4049; background: var(--surface-2); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 12px; }
.link { color: var(--text); text-decoration: none; text-transform: none; letter-spacing: 0; font-weight: 600; }

.ptz { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); gap: 6px; justify-content: center; }
.ptz button {
  display: grid; place-items: center; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2);
  touch-action: none; user-select: none; transition: background .1s;
}
.ptz button:active, .ptz button.held { background: #2a2f36; }
.ptz button.home { border-radius: 50%; }
.ptz svg { width: 22px; height: 22px; }

.recent { display: flex; flex-direction: column; gap: 8px; }
.recent-item { display: flex; align-items: center; gap: 12px; padding: 6px; margin: -6px; border-radius: 10px; cursor: pointer; }
.recent-item:hover { background: var(--surface-2); }
.recent-item img, .recent-item .ph { width: 72px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; background: #000; flex: none; }
.recent-item b { display: block; font-size: 14px; }
.recent-item small { color: var(--muted); font-size: 12.5px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* ---------- clips ---------- */
.clips-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.clips-head h2 { margin: 0; }
.chips { display: flex; gap: 8px; }
.day { margin: 20px 0 10px; font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.day:first-child { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: border-color .15s, transform .15s; }
.card:hover { border-color: #3a4049; transform: translateY(-2px); }
.thumb { position: relative; aspect-ratio: 16 / 9; background: #000; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .dur { position: absolute; right: 8px; bottom: 8px; padding: 2px 7px; border-radius: 6px; background: rgba(0, 0, 0, .7); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.thumb .tag { position: absolute; left: 8px; top: 8px; padding: 2px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 700; background: rgba(0, 0, 0, .7); }
.tag.motion { color: var(--warn); }
.tag.manual { color: var(--accent); }
.card-body { padding: 10px 12px; display: flex; justify-content: space-between; font-size: 14px; }
.card-body span { color: var(--muted); font-size: 13px; }
#cloudDir { word-break: break-all; }
.slot { padding: 12px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.slot-days { display: flex; gap: 6px; }
.day-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 13px; }
.day-btn.on { background: var(--text); color: #0a0b0d; border-color: transparent; }
.slot-time { display: flex; align-items: center; gap: 8px; }
.slot-time input[type=time] { height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.slot-time .slot-del { margin-left: auto; color: var(--accent); }
#btnAddSlot { margin-top: 12px; }
.card-body .cloud-ok, small.cloud-ok { color: var(--ok); }
.card-body .cloud-wait, small.cloud-wait { color: var(--warn); }
@media (max-width: 520px) { .grid { grid-template-columns: 1fr 1fr; gap: 8px; } .card-body { padding: 8px 10px; flex-direction: column; } }

/* ---------- reglages ---------- */
.settings { display: grid; gap: 16px; max-width: 680px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.panel-title + .row { border-top: 0; padding-top: 0; }
.row span { display: flex; flex-direction: column; font-weight: 550; }
.row small { color: var(--muted); font-weight: 400; font-size: 13px; }
.row.col { flex-direction: column; align-items: stretch; gap: 10px; }
.row.col span { flex-direction: row; justify-content: space-between; }
.row input[type=number] { width: 76px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); text-align: center; }
input[type=range] { width: 100%; accent-color: var(--text); }
.switch { appearance: none; width: 46px; height: 28px; border-radius: 14px; background: #2a2f36; position: relative; cursor: pointer; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(18px); }

/* ---------- lecteur ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .75); backdrop-filter: blur(6px); animation: fade .15s; }
.modal-card { width: min(960px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; }
.modal-head .icon-btn { background: var(--surface-2); }
.modal video { width: 100%; max-height: 70vh; background: #000; display: block; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translateX(-50%); z-index: 60;
  padding: 10px 16px; border-radius: 12px; background: var(--text); color: #0a0b0d; font-weight: 600; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); animation: fade .2s; max-width: calc(100% - 32px);
}
@media (min-width: 900px) { .toast { bottom: 24px; } }
