/*
 * Sentinel web console.
 *
 * The palette is lifted verbatim from the Android app's theme (ui/theme/Color.kt) so the two clients
 * read as one product: the same deep teal used sparingly for actions and selection, over cool
 * neutrals that carry hierarchy through borders and spacing rather than heavy fills.
 */

:root {
  color-scheme: light dark;

  --teal: #1F6E5C;
  --teal-hover: #1a5c4d;
  --on-teal: #ffffff;

  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --surface-2: #F1F3F6;
  --surface-3: #E8EBEF;
  --outline: #C9D0D8;
  --outline-subtle: #E4E8ED;
  --text: #11181D;
  --text-dim: #56636E;

  --danger: #B3261E;
  --danger-bg: #FCEEEE;
  --warn: #8A5300;
  --warn-bg: #FDF3E2;
  --ok: #1F6E5C;
  --ok-bg: #E6F1ED;
  --info: #3F6377;
  --info-bg: #EAF0F4;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(17 24 29 / .06), 0 4px 16px rgb(17 24 29 / .06);
  --sidenav-w: 232px;
  --topbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --teal: #5FCFB4;
    --teal-hover: #7ad9c3;
    --on-teal: #06231C;

    --bg: #0D1214;
    --surface: #141B1E;
    --surface-2: #1A2226;
    --surface-3: #212B2F;
    --outline: #3C484E;
    --outline-subtle: #232D32;
    --text: #E3E8EB;
    --text-dim: #9BA8B1;

    --danger: #F2B8B5;
    --danger-bg: #2A1614;
    --warn: #F5C77E;
    --warn-bg: #2A1F0E;
    --ok: #5FCFB4;
    --ok-bg: #0F2A24;
    --info: #A8C7DA;
    --info-bg: #14242C;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--teal); }

.muted { color: var(--text-dim); }
.error { color: var(--danger); }
[hidden] { display: none !important; }

/* ---- Sign-in ------------------------------------------------------------ */

.signin {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.signin-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--outline-subtle);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  display: grid;
  gap: 16px;
}

.signin-brand { display: flex; align-items: center; gap: 12px; }
.signin-brand .wordmark { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }

.logo {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--teal);
  color: var(--on-teal);
  font-weight: 800;
  flex: none;
}

/* ---- Shell -------------------------------------------------------------- */

.shell { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--outline-subtle);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand .wordmark { font-weight: 700; letter-spacing: .08em; font-size: .95rem; text-transform: uppercase; }

.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { font-size: .85rem; }

.body { flex: 1; display: flex; min-height: 0; }

.sidenav {
  width: var(--sidenav-w);
  flex: none;
  padding: 12px;
  border-right: 1px solid var(--outline-subtle);
  background: var(--surface);
  overflow-y: auto;
}

.sidenav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.sidenav a:hover { background: var(--surface-2); }
.sidenav a.active { background: var(--ok-bg); color: var(--teal); font-weight: 650; }
.sidenav svg { width: 20px; height: 20px; flex: none; }

.view { flex: 1; min-width: 0; padding: 24px; overflow-x: hidden; }

.nav-toggle { display: none; }
.scrim { display: none; }

/* ---- Page header -------------------------------------------------------- */

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-head .actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- Cards & grids ------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--outline-subtle);
  border-radius: var(--radius);
  padding: 20px;
}

.cards { display: grid; gap: 16px; }
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.split { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat .label {
  font-size: .72rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 650;
}
.stat .value { font-size: 2rem; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }

/* ---- Bars (dashboard breakdowns) ---------------------------------------- */

.bars { display: grid; gap: 10px; margin-top: 14px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 30%) 1fr auto; gap: 12px; align-items: center; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 9px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--teal); }
.bar-row .count { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 2.5ch; text-align: right; }

/* ---- Toolbar ------------------------------------------------------------ */

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .search { flex: 1; min-width: 200px; }

/* ---- Table -------------------------------------------------------------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--outline-subtle);
  border-radius: var(--radius);
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: .92rem; }

th {
  text-align: left;
  font-size: .72rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--surface-2);
  padding: 11px 14px;
  white-space: nowrap;
  border-bottom: 1px solid var(--outline-subtle);
  position: sticky;
  top: 0;
}

td { padding: 12px 14px; border-bottom: 1px solid var(--outline-subtle); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
.strong { font-weight: 600; }

.empty { padding: 48px 24px; text-align: center; color: var(--text-dim); }

.pager { display: flex; align-items: center; gap: 12px; justify-content: flex-end; margin-top: 14px; }

/* ---- Chips -------------------------------------------------------------- */

.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text-dim);
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.danger { background: var(--danger-bg); color: var(--danger); }

/* ---- Buttons & inputs --------------------------------------------------- */

.btn {
  font: inherit;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: var(--on-teal); }
.btn.primary:hover { background: var(--teal-hover); border-color: var(--teal-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--teal); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { border-color: transparent; background: transparent; color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.small { padding: 5px 12px; font-size: .84rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 999px;
  border: 0; background: transparent; color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.field { display: grid; gap: 6px; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--text-dim); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
}
textarea { resize: vertical; min-height: 76px; }
input:focus-visible, select:focus-visible, textarea:focus-visible,
.btn:focus-visible, .icon-btn:focus-visible, .sidenav a:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}
input[aria-invalid="true"] { border-color: var(--danger); }

/* ---- Modal -------------------------------------------------------------- */

.modal {
  border: 1px solid var(--outline-subtle);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(720px, calc(100vw - 32px));
  max-height: min(86dvh, 900px);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgb(0 0 0 / .45); }
.modal-head { padding: 20px 24px 0; }
.modal-body { padding: 20px 24px; display: grid; gap: 16px; overflow-y: auto; }
.modal-foot {
  padding: 16px 24px;
  display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
  border-top: 1px solid var(--outline-subtle);
  position: sticky; bottom: 0; background: var(--surface);
}
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }

/* ---- Toasts ------------------------------------------------------------- */

.toasts {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  display: grid; gap: 8px;
  z-index: 100;
  width: min(520px, calc(100vw - 32px));
}
.toast {
  background: var(--surface);
  border: 1px solid var(--outline-subtle);
  border-left: 4px solid var(--teal);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 12px 16px;
}
.toast.bad { border-left-color: var(--danger); }

/* ---- Scanner ------------------------------------------------------------ */

.scan-stage {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 10;
  max-height: 62dvh;
}
.scan-stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
.reticle {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
}
.reticle > div {
  width: 62%; height: 34%;
  border: 3px solid rgb(255 255 255 / .85);
  border-radius: 18px;
}

/* ---- Responsive --------------------------------------------------------- */

@media (max-width: 860px) {
  .nav-toggle { display: grid; }
  .view { padding: 16px; }
  .who { display: none; }

  /* The rail becomes a drawer. Off-canvas rather than squeezed, matching the phone layout the
     Android app switches to at the same sort of width. */
  .sidenav {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: var(--shadow);
  }
  .sidenav.open { transform: none; }
  .scrim {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgb(0 0 0 / .4);
    z-index: 25;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
