/* Colours, type and radii follow the CureBay Figma design (light). */
@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Geist";
  src: url("/static/fonts/geist.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #f9f9f9;          /* Black/2 */
  --panel: #ffffff;       /* Black/1 */
  --panel-2: #f9f9f9;
  --line: #e5e5e5;        /* Black/3 */
  --line-soft: #ebebeb;
  --text: #000000;        /* Black/12 */
  --text-2: #4d4d4d;      /* Black/9 */
  --muted: #808080;       /* Black/7 */
  --placeholder: #cccccc; /* Black/4 */
  --accent: #004172;      /* Blue Primary/Brand */
  --ok: #00b82e;          /* Success/Dark */
  --ok-bg: #e8fff1;       /* Success/light */
  --warn: #d29300;        /* Warning/Dark */
  --warn-bg: #fff3d7;
  --bad: #d82525;         /* Error/Dark */
  --bad-bg: #ffdbdb;
  --shadow-card: 0 2px 20px rgb(0 65 114 / .08), inset 0 0 2px rgb(0 65 114 / .12);  /* Outer/6 */
  --shadow-btn: 0 2px 4px rgb(0 65 114 / .08), inset 0 0 2px rgb(0 65 114 / .08);    /* Outer/2 */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-ui: "Geist", var(--font);
  --topbar: 64px;
  --pager: 52px;
  --side: 250px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 500 14px/1.4 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; font: 600 15px var(--font-ui); white-space: nowrap; }
.brand-logo { display: block; height: 24px; width: auto; }
.stats { display: flex; gap: 8px; margin-left: 12px; }
.pill {
  padding: 6px 12px; border-radius: 8px;
  background: var(--panel-2); color: var(--muted);
  font-size: 12px; letter-spacing: .03em; white-space: nowrap;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.spacer { flex: 1; }
.search {
  width: 280px; height: 40px; padding: 0 14px;
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: 12px; outline: none;
  letter-spacing: .02em;
}
.search::placeholder { color: var(--placeholder); }
.search:focus { border-color: var(--accent); }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; white-space: nowrap; cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.seg {
  display: flex; gap: 2px; padding: 3px;
  background: rgb(255 255 255 / .48); border-radius: 12px;
  box-shadow: inset 0 0 5px rgb(0 65 114 / .2);   /* Inner/5 */
}
.seg button { background: none; border: 0; border-radius: 9px; padding: 5px 11px; color: var(--text-2); }
.seg button.active { background: var(--accent); color: #fff; }
.icon-btn {
  display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 8px;
  background: var(--panel); border: 0; border-radius: 12px; box-shadow: var(--shadow-btn);
  color: var(--accent); text-decoration: none; font-size: 15px;
}
.icon-btn:hover { background: var(--panel-2); }
.seg button:hover:not(.active) { color: var(--accent); }
.icon-btn.active { background: var(--accent); color: #fff; }
#menuBtn { display: none; }

/* ---------- layout ---------- */
.layout { display: flex; height: calc(100% - var(--topbar)); }
.sidebar {
  width: var(--side); flex: none; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line);
  font-family: var(--font-ui);
}
.side-head { padding: 20px 24px 8px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
.sidebar ul { list-style: none; margin: 0; padding: 0 16px 16px; display: flex; flex-direction: column; gap: 2px; }
.site {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  background: none; border: 1px solid transparent; border-radius: 6px; text-align: left;
  color: var(--muted); font-size: 13px; font-weight: 400;
}
.site:hover { background: var(--panel-2); color: var(--text); }
.site.active { background: var(--panel-2); border-color: var(--line); color: var(--text); font-weight: 500; }
.site.active .count { color: var(--text); font-weight: 600; }
.site.offline .site-name { color: var(--muted); }
.site-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.dot { width: 6px; height: 6px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.banner {
  margin: 12px 12px 0; padding: 12px 16px;
  background: var(--warn-bg); color: #7a5600;
  border: 1px solid rgb(210 147 0 / .3); border-radius: 12px; font-size: 13px;
}

/* ---------- camera grid ---------- */
.grid {
  flex: 1; min-height: 0; padding: 12px; gap: 10px;
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 4), minmax(0, 1fr));
}
.tile {
  position: relative; overflow: hidden; min-height: 0;
  background: #000; border: 1px solid var(--line); border-radius: 16px; cursor: pointer;
  box-shadow: 0 4px 6px rgb(0 65 114 / .08);
}
.tile:hover, .tile:focus-visible { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px rgb(0 65 114 / .25); }
.tile cam-player, .tile video { display: block; width: 100%; height: 100%; }
.tile video { object-fit: contain; background: #000; }
.label {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 6px; padding: 8px 12px;
  background: linear-gradient(rgb(0 0 0 / .65), transparent);
  color: #fff; font-size: 12px; pointer-events: none;
}
.label .dot { width: 7px; height: 7px; }
.cam-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam-site { color: #d9d9d9; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #999; font-size: 13px; pointer-events: none; text-align: center; padding: 0 10px;
}
.tile[data-state="live"] .status { display: none; }
.tile[data-state="error"] .status { color: #ff9a9a; }
.tile.is-offline {
  cursor: default; box-shadow: none;
  background: repeating-linear-gradient(45deg, #f2f2f2, #f2f2f2 10px, #ededed 10px, #ededed 20px);
}
.tile.is-offline .label { background: none; color: var(--text-2); }
.tile.is-offline .cam-site { color: var(--muted); }
.tile.is-offline .status { color: var(--bad); }
.tile.is-offline:hover { border-color: var(--line); box-shadow: none; }
.empty { grid-column: 1 / -1; grid-row: 1 / -1; display: grid; place-items: center; color: var(--muted); }

.pager {
  height: var(--pager); flex: none; display: flex; align-items: center; justify-content: center; gap: 16px;
  border-top: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 12px;
}
.pager button {
  background: var(--panel); border: 0; border-radius: 12px; box-shadow: var(--shadow-btn);
  padding: 7px 14px; color: var(--accent); font-weight: 600; font-size: 13px;
}
.pager button:hover:not(:disabled) { background: var(--panel-2); }
.pager button:disabled { opacity: .35; cursor: default; }
.pager.single button { visibility: hidden; }

/* ---------- HD modal ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgb(0 0 0 / .6); }
.modal-inner {
  width: min(1400px, 100%); display: flex; flex-direction: column; overflow: hidden;
  background: var(--panel); border-radius: 24px; box-shadow: var(--shadow-card);
}
.modal-bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 20px; font-weight: 700; font-size: 16px; }
.badge { font-size: 12px; font-weight: 500; padding: 5px 10px; border-radius: 8px; background: var(--accent); color: #fff; }
.modal-video { aspect-ratio: 16 / 9; max-height: calc(100vh - 110px); }
.modal-video .tile { height: 100%; border: 0; border-radius: 0; box-shadow: none; cursor: default; }
.modal-video .tile:hover { box-shadow: none; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; padding: 16px; overflow: auto; }
.login-card {
  width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 32px;
  background: var(--panel); border-radius: 24px; box-shadow: var(--shadow-card);
}
.login-card .brand-logo { height: 32px; align-self: flex-start; }
.login-title { margin: 8px 0 0; font-size: 24px; font-weight: 700; letter-spacing: .01em; }
.login-sub { margin: -8px 0 4px; color: var(--muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--text-2); font-size: 13px; }
.login-card input {
  height: 44px; padding: 0 14px; background: var(--panel);
  border: 1px solid var(--line-soft); border-radius: 12px; outline: none; font-size: 15px;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  height: 48px; margin-top: 6px; background: var(--accent); border: 0; border-radius: 16px;
  color: #fff; font-weight: 500; font-size: 16px; box-shadow: 0 2px 2px rgb(0 65 114 / .08);
}
.login-card button:hover { background: #00355d; }
.login-error { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--bad-bg); color: var(--bad); font-size: 13px; }

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  .stats, .toggle, #title { display: none; }
  .search { width: 180px; }
}
@media (max-width: 760px) {
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; row-gap: 10px; }
  .search { order: 10; flex: 1 1 100%; width: auto; }
  #menuBtn { display: inline-grid; }
  .seg button[data-n="16"], .seg button[data-n="25"], #fsBtn { display: none; }
  .layout { height: auto; min-height: calc(100% - var(--topbar)); }
  .sidebar {
    position: fixed; z-index: 10; top: 0; bottom: 0; left: 0; width: min(80vw, 300px);
    transform: translateX(-100%); transition: transform .2s;
  }
  body.side-open .sidebar { transform: none; box-shadow: 0 0 40px rgb(0 65 114 / .2); }
  .grid { display: flex; flex-direction: column; padding: 12px 16px; gap: 10px; }
  .tile { aspect-ratio: 16 / 9; flex: none; }
  .pager { position: sticky; bottom: 0; }
}
