/* SBS Face Attendance — shared styles
   Friendly, high-contrast, large-touch UI meant for a school entrance kiosk. */
:root {
  --bg: #0b1220;
  --bg-soft: #131c2f;
  --card: #182238;
  --card-2: #1e2a44;
  --line: #2a3855;
  --ink: #eef3ff;
  --ink-dim: #9fb0d0;
  --brand: #3b82f6;
  --brand-2: #60a5fa;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --gold: #fbbf24;
  --radius: 22px;
  --shadow: 0 20px 60px rgba(0,0,0,.45);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Devanagari", Roboto, sans-serif;
}
[data-theme="light"] {
  --bg: #f4f7fd; --bg-soft: #ffffff; --card: #ffffff; --card-2: #f0f4fb;
  --line: #dbe4f3; --ink: #12203a; --ink-dim: #5c6b87; --shadow: 0 16px 44px rgba(20,40,80,.12);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink);
  background: radial-gradient(1200px 700px at 15% -10%, #1d3564 0%, transparent 60%),
              radial-gradient(1000px 600px at 110% 10%, #2a1d55 0%, transparent 55%),
              var(--bg);
  -webkit-font-smoothing: antialiased;
}
[data-theme="light"] body { background: radial-gradient(900px 500px at 10% -10%, #dbe9ff 0%, transparent 60%), var(--bg); }
a { color: var(--brand-2); }
button { font-family: inherit; }

/* ---------- layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-soft) 70%, transparent);
  backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 40;
}
.logo { display: flex; align-items: center; gap: 12px; font-weight: 800; letter-spacing: .2px; }
.logo .mark {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--brand), #8b5cf6); color: #fff;
  font-size: 17px; font-weight: 900; box-shadow: 0 6px 18px rgba(59,130,246,.45);
}
.logo small { display: block; font-weight: 600; font-size: 11.5px; color: var(--ink-dim); letter-spacing: .4px; }
.spacer { flex: 1; }
.nav { display: flex; gap: 8px; }
.nav a {
  padding: 9px 15px; border-radius: 12px; text-decoration: none; color: var(--ink-dim);
  font-weight: 650; font-size: 14px; border: 1px solid transparent;
}
.nav a:hover { background: var(--card); color: var(--ink); }
.nav a.active { background: var(--brand); color: #fff; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 22px; }

/* ---------- cards & controls ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card p.sub { margin: 0 0 16px; color: var(--ink-dim); font-size: 13.5px; }
.grid { display: grid; gap: 18px; }
.btn {
  appearance: none; border: 0; cursor: pointer; border-radius: 14px;
  padding: 13px 20px; font-size: 15px; font-weight: 700; color: #fff;
  background: linear-gradient(160deg, var(--brand), #2563eb);
  box-shadow: 0 8px 22px rgba(37,99,235,.35); transition: transform .12s ease, filter .12s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.ghost { background: var(--card-2); color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.btn.good { background: linear-gradient(160deg, #34d399, #10b981); box-shadow: 0 8px 22px rgba(16,185,129,.3); }
.btn.bad  { background: linear-gradient(160deg, #f87171, #ef4444); box-shadow: 0 8px 22px rgba(239,68,68,.3); }
.btn.sm { padding: 8px 13px; font-size: 13px; border-radius: 11px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
label.f { display: block; margin-bottom: 12px; }
label.f span { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-dim); margin-bottom: 6px; letter-spacing: .3px; }
input, select {
  width: 100%; padding: 12px 14px; border-radius: 13px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--ink); font-size: 15px; font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--card-2); border: 1px solid var(--line); color: var(--ink-dim);
}
.pill.good { color: #86efac; border-color: #14532d; background: #052e16; }
.pill.warn { color: #fcd34d; border-color: #78350f; background: #2a1a05; }
.pill.bad  { color: #fca5a5; border-color: #7f1d1d; background: #2a0808; }
[data-theme="light"] .pill.good { color:#166534; background:#dcfce7; border-color:#bbf7d0; }
[data-theme="light"] .pill.warn { color:#92400e; background:#fef3c7; border-color:#fde68a; }
[data-theme="light"] .pill.bad  { color:#991b1b; background:#fee2e2; border-color:#fecaca; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px; color: var(--ink-dim); }
tbody tr:hover { background: var(--card-2); }
.avatar { width: 40px; height: 40px; border-radius: 12px; object-fit: cover; background: var(--card-2); flex: 0 0 auto; }
/* The identity cell pairs a photo with a name on both layouts. */
td.cell-main { display: flex; align-items: center; gap: 12px; }

/* ---------- camera stage ---------- */
.stage { position: relative; width: 100%; aspect-ratio: 4/3; border-radius: 26px; overflow: hidden; background: #000; }
.stage video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.stage canvas.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stage .veil { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(4,8,18,.72); font-weight: 700; }

.hint {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  padding: 12px 22px; border-radius: 999px; font-size: 17px; font-weight: 750;
  background: rgba(8,14,28,.78); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,.14);
  color: #fff; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis;
}
.hint.good { background: rgba(16,120,60,.85); border-color: rgba(134,239,172,.5); }
.hint.warn { background: rgba(140,90,10,.85); border-color: rgba(252,211,77,.5); }
.hint.bad  { background: rgba(140,25,25,.85); border-color: rgba(252,165,165,.5); }

@keyframes popIn { from { opacity: 0; transform: translateY(24px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes pulseRing { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.55); } 70% { box-shadow: 0 0 0 26px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
@keyframes floatUp { from { opacity:0; transform: translateY(10px);} to {opacity:1; transform:none;} }
.fade-in { animation: floatUp .35s ease both; }

/* ==========================================================================
   MOBILE / APP MODE
   Phones get a different shape, not a squeezed desktop: a bottom tab bar,
   full-bleed camera, tables as cards, and controls that only make sense with
   a mouse and a big screen simply removed.
   ========================================================================== */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 62px;
}

/* Bottom tab bar — hidden on desktop, shown on phones. */
.tabbar { display: none; }

/* Anything marked desktop-only disappears on a phone. */
@media (max-width: 760px) {
  .desktop-only { display: none !important; }
}
@media (min-width: 761px) {
  .mobile-only { display: none !important; }
}

@media (max-width: 760px) {
  html, body { overscroll-behavior-y: none; }
  body {
    /* dvh follows the iOS URL bar as it collapses; vh does not. */
    min-height: 100dvh;
    padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
    -webkit-tap-highlight-color: transparent;
  }

  .topbar {
    padding: calc(10px + var(--safe-top)) 16px 10px;
    gap: 10px;
  }
  .topbar .nav { display: none; }
  .logo .mark { width: 36px; height: 36px; border-radius: 11px; font-size: 14px; }
  .logo { font-size: 15px; }
  .logo small { font-size: 10.5px; }

  .wrap { padding: 14px 14px calc(20px + var(--safe-bottom)); }
  .card { padding: 16px; border-radius: 18px; }
  .grid { grid-template-columns: 1fr !important; }
  .row { flex-direction: column; gap: 0; }
  .row > * { width: 100%; min-width: 0; }

  /* Touch targets: 44px is the smallest reliably tappable size. */
  .btn { padding: 15px 20px; font-size: 16px; min-height: 48px; width: 100%; }
  .btn.sm { padding: 11px 14px; font-size: 14px; min-height: 40px; width: auto; }
  /* 16px stops iOS Safari zooming the page when a field is focused. */
  input, select { font-size: 16px; padding: 14px; min-height: 48px; }

  .scroll { max-height: none; overflow: visible; border: 0; border-radius: 0; }

  /* Tables become stacked cards. Each cell carries its own label. */
  table, thead, tbody, tr, td { display: block; width: 100%; }
  table thead { display: none; }
  table tbody tr {
    background: var(--card-2); border: 1px solid var(--line);
    border-radius: 16px; padding: 12px 14px; margin-bottom: 10px;
  }
  table tbody tr:hover { background: var(--card-2); }
  table td {
    border: 0; padding: 5px 0; display: flex; align-items: center;
    justify-content: space-between; gap: 14px; text-align: right;
  }
  table td::before {
    content: attr(data-label);
    font-size: 11.5px; font-weight: 750; letter-spacing: .5px;
    text-transform: uppercase; color: var(--ink-dim);
    text-align: left; flex: 0 0 auto;
  }
  table td:empty { display: none; }
  table td[data-label=""]::before { content: none; }
  table td.cell-main { justify-content: flex-start; text-align: left; padding-bottom: 8px; }
  table td.cell-main::before { content: none; }
  table td .avatar { width: 44px; height: 44px; }

  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    padding: 6px calc(6px + var(--safe-left)) calc(6px + var(--safe-bottom)) calc(6px + var(--safe-right));
    background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
    backdrop-filter: blur(18px);
    border-top: 1px solid var(--line);
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 7px 4px; border-radius: 13px; text-decoration: none;
    color: var(--ink-dim); font-size: 10.5px; font-weight: 700; letter-spacing: .2px;
  }
  .tabbar a svg { width: 22px; height: 22px; stroke-width: 1.9; }
  .tabbar a.active { color: var(--brand-2); }
  .tabbar a.active svg { stroke: var(--brand-2); }
  .tabbar a:active { background: var(--card-2); }

  /* Horizontally scrolling section tabs (admin). */
  .tabs {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin: 0 -14px 14px; padding: 0 14px 2px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; padding: 11px 16px; font-size: 14px; }

  /* Filters pair up two-per-row instead of stacking five deep above the data. */
  .toolbar { gap: 10px; }
  .toolbar > * { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .toolbar > .toolbar-full { flex: 1 1 100%; }
  /* A cell whose value is just a dash is noise inside a card. */
  table td.dash { display: none; }

  #toasts { left: 14px; right: 14px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); }
  #toasts > * { max-width: none !important; }
}

/* Installed app: no browser chrome, so give the header the status bar space. */
@media (display-mode: standalone) {
  .topbar { padding-top: calc(12px + var(--safe-top)); }
  .install-hint { display: none !important; }
}
