/* ============================================================
   Apotekku Smart Eye — Operations Console
   Dark control-room theme: apothecary emerald + monospace telemetry.
   Display: Bricolage Grotesque · UI: Hanken Grotesk · Data: JetBrains Mono
   ============================================================ */

:root {
  --bg: #0a0d0c;
  --bg-2: #0d1210;
  --surface: #121815;
  --surface-2: #0f1512;
  --surface-hi: #18201c;
  --ink: #e9f0ea;
  --ink-dim: #b8c4bc;
  --muted: #7c8a81;
  --faint: #56635b;
  --line: rgba(120, 170, 140, 0.12);
  --line-hi: rgba(120, 170, 140, 0.22);
  --accent: #27e29c;
  --accent-deep: #12b07a;
  --accent-glow: rgba(39, 226, 156, 0.16);
  --amber: #ffb74d;
  --danger: #ff6b6b;
  --sky: #5cc8ff;

  --r-lg: 18px;
  --r-md: 13px;
  --r-sm: 9px;

  --display: "Bricolage Grotesque", "Hanken Grotesk", sans-serif;
  --ui: "Hanken Grotesk", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;

  --shadow: 0 24px 60px -22px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--ui);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 600px at 12% -8%, rgba(39, 226, 156, 0.10), transparent 60%),
    radial-gradient(800px 520px at 100% 0%, rgba(92, 200, 255, 0.06), transparent 55%),
    radial-gradient(700px 700px at 85% 110%, rgba(255, 183, 77, 0.05), transparent 60%);
  background-attachment: fixed;
}

/* faint dot-grid + grain atmosphere */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(circle at 50% 30%, #000 30%, transparent 90%);
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1280px, 94vw);
  margin: 0 auto;
  padding: 26px 0 64px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 18px;
  margin-bottom: 26px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.12)),
    var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.18rem;
  letter-spacing: -0.01em;
}

.brand .mark {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 50%, var(--accent) 0 22%, transparent 24%),
    conic-gradient(from 210deg, var(--accent-deep), #0a3b2b 60%, var(--accent-deep));
  box-shadow: 0 0 0 1px var(--line-hi), 0 0 18px -2px var(--accent-glow);
  position: relative;
}
.brand .mark::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.35);
}
.brand b { color: var(--ink); }
.brand .sub {
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.62rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  align-self: center;
  padding-left: 2px;
}

.tabs { display: flex; gap: 6px; }
.tabs a {
  text-decoration: none;
  color: var(--ink-dim);
  border: 1px solid transparent;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.18s ease;
}
.tabs a:hover { color: var(--ink); background: var(--surface-hi); }
.tabs a.active {
  color: var(--accent);
  border-color: var(--line-hi);
  background: var(--accent-dim, var(--accent-glow));
  box-shadow: inset 0 0 0 1px rgba(39, 226, 156, 0.12);
}

.bar-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.bar-cluster .meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* ---------- Layout ---------- */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 2.05fr) minmax(280px, 1fr);
  gap: 18px;
}
.stack { display: grid; gap: 18px; align-content: start; }

.card {
  position: relative;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent 40%),
    var(--surface);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow);
}

.title {
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
}
.title::before {
  content: "";
  width: 6px; height: 16px;
  border-radius: 2px;
  background: linear-gradient(var(--accent), var(--accent-deep));
  box-shadow: 0 0 12px -2px var(--accent-glow);
}
.title .tag {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 500;
}

/* ---------- Monitor (live video) ---------- */
.monitor {
  position: relative;
  padding: 0;
  overflow: hidden;
  border-color: var(--line-hi);
  background: #06100c;
}
.monitor .hero {
  display: block;
  width: 100%;
  height: auto;
  min-height: 220px;
  /* follow the camera's native ratio; never crop */
  object-fit: contain;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.012) 0 2px, transparent 2px 4px),
    radial-gradient(circle at 50% 45%, #0c1814, #050a08);
}
.monitor::after { /* vignette + scanline veil */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 50%, transparent 62%, rgba(0, 0, 0, 0.45)),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}
.monitor .chrome {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.monitor .chrome .row { display: flex; justify-content: space-between; align-items: flex-start; }
/* corner brackets */
.bracket {
  width: 22px; height: 22px;
  border: 2px solid rgba(39, 226, 156, 0.55);
}
.bracket.tl { border-right: 0; border-bottom: 0; }
.bracket.tr { border-left: 0; border-bottom: 0; }
.bracket.bl { border-right: 0; border-top: 0; }
.bracket.br { border-left: 0; border-top: 0; }

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  font-weight: 600;
  color: #ffd9d9;
  background: rgba(40, 8, 8, 0.6);
  border: 1px solid rgba(255, 107, 107, 0.4);
  padding: 5px 11px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}
.live-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.7);
  animation: pulse 1.8s infinite;
}
.cam-clock {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  color: rgba(233, 240, 234, 0.78);
  background: rgba(0, 0, 0, 0.45);
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.6); }
  70% { box-shadow: 0 0 0 7px rgba(255, 107, 107, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0); }
}

/* ---------- KPI ---------- */
.kpi {
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(39, 226, 156, 0.10), transparent 55%),
    var(--surface);
}
.kpi .kpi-label {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}
.kpi .kpi-value {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(3.2rem, 8vw, 4.6rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
  margin: 8px 0 4px;
  color: var(--ink);
  text-shadow: 0 0 28px var(--accent-glow);
  font-variant-numeric: tabular-nums;
}
.kpi .kpi-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}
.kpi .kpi-foot b { color: var(--accent); font-family: var(--mono); }

/* ---------- Telemetry readouts ---------- */
.readouts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--line);
}
.readout {
  background: var(--surface-2);
  padding: 12px 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.readout .k {
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  color: var(--muted);
  text-transform: uppercase;
  white-space: nowrap;
}
.readout .v {
  font-family: var(--mono);
  font-size: 1.06rem;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}
.readout.span-2 { grid-column: 1 / -1; }
.readout .v.warning { color: var(--amber); font-size: 0.86rem; }

/* ---------- Status pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-hi);
  color: var(--ink-dim);
  text-transform: uppercase;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill--ok { color: var(--accent); border-color: rgba(39, 226, 156, 0.3); background: rgba(39, 226, 156, 0.08); }
.pill--warn { color: var(--amber); border-color: rgba(255, 183, 77, 0.3); background: rgba(255, 183, 77, 0.08); }
.pill--danger { color: var(--danger); border-color: rgba(255, 107, 107, 0.3); background: rgba(255, 107, 107, 0.08); }
.pill--idle { color: var(--muted); }
.pill--sky { color: var(--sky); border-color: rgba(92, 200, 255, 0.3); background: rgba(92, 200, 255, 0.08); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--r-md); }
table { width: 100%; border-collapse: collapse; }
thead th {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-hi);
  white-space: nowrap;
}
tbody td {
  padding: 11px 12px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--line);
  color: var(--ink-dim);
  vertical-align: middle;
}
tbody tr { transition: background 0.14s ease; }
tbody tr:hover { background: rgba(39, 226, 156, 0.04); }
tbody tr:last-child td { border-bottom: 0; }
td.mono, .mono-num { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); }
td a { color: var(--accent); text-decoration: none; border-bottom: 1px dotted rgba(39, 226, 156, 0.4); }
td a:hover { border-bottom-style: solid; }
.empty-row td { color: var(--faint); text-align: center; padding: 26px; font-style: italic; }

/* ---------- Visitor tag ---------- */
.vtag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--accent);
}
.vtag::before {
  content: "";
  width: 14px; height: 14px;
  background: var(--accent);
  -webkit-mask: var(--person-mask) center / contain no-repeat;
  mask: var(--person-mask) center / contain no-repeat;
  --person-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='7' r='4'/><path d='M4 21c0-4.4 3.6-8 8-8s8 3.6 8 8'/></svg>");
}

/* ---------- Inputs / buttons ---------- */
input, button, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface-hi);
  border: 1px solid var(--line-hi);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  transition: border-color 0.16s, box-shadow 0.16s;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-deep);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input[type="date"] { color-scheme: dark; }
select { cursor: pointer; }

button {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #04140d;
  font-weight: 700;
  border: 0;
  cursor: pointer;
  letter-spacing: 0.01em;
}
button:hover { filter: brightness(1.08); box-shadow: 0 8px 20px -8px var(--accent-glow); }
button:active { transform: translateY(1px); }
button.secondary {
  background: var(--surface-hi);
  color: var(--ink-dim);
  border: 1px solid var(--line-hi);
}
button.secondary:hover { color: var(--ink); border-color: var(--accent-deep); box-shadow: none; }

label { color: var(--ink-dim); }

/* ---------- Segmented control ---------- */
.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.segmented button {
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 7px 16px;
  border-radius: 999px;
  box-shadow: none;
  letter-spacing: 0.01em;
}
.segmented button:hover { color: var(--ink); filter: none; }
.segmented button.active {
  background: linear-gradient(180deg, rgba(39, 226, 156, 0.16), rgba(39, 226, 156, 0.06));
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--line-hi);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar .spacer { flex: 1; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  color: var(--ink-dim);
  cursor: pointer;
  user-select: none;
}
.check input { width: 15px; height: 15px; padding: 0; accent-color: var(--accent); }

.muted { color: var(--muted); }
.warning { color: var(--amber); }
.hidden { display: none !important; }

/* ---------- Setup canvas ---------- */
.canvas-wrap { position: relative; border-radius: var(--r-md); overflow: hidden; }
canvas.overlay {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
}
.field-grid { display: grid; gap: 12px; }
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
}
.field:last-child { border-bottom: 0; }
.field span { color: var(--ink-dim); font-size: 0.9rem; }
.field input, .field select { width: 130px; }

/* ---------- Login ---------- */
.login-wrap { width: min(400px, 92vw); margin: 13vh auto 0; position: relative; z-index: 1; }
.login-card { padding: 34px 30px; }
.login-card h1 { font-family: var(--display); font-size: 1.5rem; margin: 14px 0 4px; letter-spacing: -0.01em; }
.login-card .muted { margin: 0 0 22px; font-size: 0.9rem; }
.login-card label { display: block; font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 16px 0 6px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 24px; padding: 12px; }
.login-error { color: var(--danger); font-size: 0.85rem; margin-top: 14px; min-height: 18px; }

/* ---------- Load reveal ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.reveal { opacity: 0; animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) forwards; }
.reveal:nth-child(1) { animation-delay: 0.04s; }
.reveal:nth-child(2) { animation-delay: 0.12s; }
.reveal:nth-child(3) { animation-delay: 0.2s; }
.reveal:nth-child(4) { animation-delay: 0.28s; }

@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none; opacity: 1; }
  .live-pill .dot { animation: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 940px) {
  .grid { grid-template-columns: 1fr; }
  .topbar { gap: 12px; }
}
@media (max-width: 560px) {
  .readouts { grid-template-columns: 1fr; }
  .brand .sub { display: none; }
  .field input, .field select { width: 108px; }
}

/* ---- Frame archive grid (history page) ---- */
.frame-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.frame-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  border-radius: var(--r-md);
  overflow: hidden;
}
.frame-cell img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--r-md);
  display: block;
}
.frame-cell span {
  font-size: 0.7rem;
  text-align: center;
  opacity: 0.7;
}
