/* web/static/css/app.css
   Shared design system for the School Attendance dashboard.
   Loaded by base.html on every page. Page templates may add
   page-specific rules in extra_head, but tokens and shared
   components live here so all pages stay consistent.

   Class contract kept from the old base.html embedded styles:
   .btn .btn-primary .btn-danger .btn-sm .badge .badge-*
   .tabs .filter-bar .export-bar .table-wrap .flash .flash-*
   .thumb .thumb-missing #live-dot
*/

/* ── Design tokens ─────────────────────────────────────── */
:root {
  /* Ink & surfaces */
  --ink:          #16192e;
  --ink-2:        #4a5068;
  --ink-3:        #8b91a7;
  --surface:      #ffffff;
  --bg:           #f2f4f9;
  --line:         #e4e8f1;
  --line-strong:  #ccd2e0;

  /* Brand */
  --brand:        #3b6ef6;
  --brand-strong: #2c56cc;
  --brand-soft:   #e8eefe;

  /* Status */
  --ok:        #22c55e;  --ok-soft:        #dcfce7;  --ok-ink:        #15803d;
  --warn:      #f59e0b;  --warn-soft:      #fef3c7;  --warn-ink:      #92400e;
  --danger:    #ef4444;  --danger-soft:    #fee2e2;  --danger-ink:    #991b1b;
  --early:     #f97316;  --early-soft:     #ffedd5;  --early-ink:     #9a3412;
  --neutral:   #64748b;  --neutral-soft:   #eef1f6;  --neutral-ink:   #334155;

  /* Sidebar */
  --side-bg:     #14162b;
  --side-line:   #262a49;
  --side-ink:    #a7adc6;
  --side-active: #1f2340;

  /* Elevation, shape, type */
  --shadow-1: 0 1px 3px rgba(22, 25, 46, .07);
  --shadow-2: 0 4px 16px rgba(22, 25, 46, .11);
  --shadow-3: 0 12px 32px rgba(22, 25, 46, .18);
  --radius:    12px;
  --radius-sm: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --sidebar-w: 232px;
  --topbar-h:  58px;
}

/* ── Reset & base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--brand-soft); }

a { color: var(--brand); }

/* Focus visibility for keyboard users */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--side-bg);
  color: var(--side-ink);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 60;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--side-line);
  color: #fff;
  text-decoration: none;
}
.brand-mark {
  width: 36px; height: 36px; flex-shrink: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #7c9dfa);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.brand-text { line-height: 1.25; min-width: 0; }
.brand-text b  { display: block; font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { display: block; font-size: 11px; color: var(--side-ink); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  margin: 2px 0;
  color: var(--side-ink);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 9px;
  transition: background .13s, color .13s;
}
.sidebar nav a:hover { background: var(--side-active); color: #e6e9f5; }
.sidebar nav a.active {
  background: var(--side-active);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--brand);
}
.sidebar nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  font-variant-numeric: tabular-nums;
}
.sidebar nav a.active svg { opacity: 1; color: var(--brand); }
.sidebar-primary-nav { display: flex; flex-direction: column; }
.sidebar nav a.sidebar-emergency-link {
  margin-top: 8px;
  border: 1px solid rgba(249, 115, 22, .28);
  color: #f9b37e;
}
.sidebar nav a.sidebar-emergency-link:hover,
.sidebar nav a.sidebar-emergency-link.active {
  background: rgba(249, 115, 22, .12);
  border-color: rgba(249, 115, 22, .46);
  color: #ffd1ad;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--side-line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.font-switcher { display: flex; gap: 4px; }
.font-switcher button {
  flex: 1;
  padding: 4px 0;
  border-radius: 7px;
  background: none;
  color: var(--side-ink);
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--side-line);
  cursor: pointer;
  transition: all .13s;
}
.font-switcher button:hover { color: #fff; border-color: var(--side-ink); }

.lang-switcher { display: flex; gap: 4px; }
.lang-switcher a {
  flex: 1;
  text-align: center;
  padding: 5px 0;
  border-radius: 7px;
  color: var(--side-ink);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--side-line);
  transition: all .13s;
}
.lang-switcher a:hover { color: #fff; border-color: var(--side-ink); }
.lang-switcher a.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.logout-link {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px;
  border-radius: 9px;
  color: #f0908f;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .13s;
}
.logout-link:hover { background: rgba(239, 68, 68, .12); color: #ff9f9e; }
.logout-link svg { width: 16px; height: 16px; }

/* ── Main column ───────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }

.topbar {
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 0 22px;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 { font-size: 16.5px; font-weight: 700; flex: 1; letter-spacing: -.01em; display: flex; align-items: center; min-width: 0; }

/* Hamburger — hidden on desktop */
.menu-btn {
  display: none;
  background: none; border: none; cursor: pointer;
  width: 38px; height: 38px;
  border-radius: 9px;
  color: var(--ink);
  align-items: center; justify-content: center;
  flex-shrink: 0;
}
.menu-btn:hover { background: var(--neutral-soft); }
.topbar-quick-link {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink-2);
  background: rgba(255, 255, 255, .72);
  text-decoration: none;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
}
.topbar-quick-link:hover {
  color: var(--primary);
  border-color: rgba(79, 70, 229, .28);
  background: var(--primary-soft);
  transform: translateY(-1px);
}
.topbar-quick-link:focus-visible { outline: 3px solid rgba(79, 70, 229, .22); outline-offset: 2px; }
.topbar-quick-link svg { width: 18px; height: 18px; }
.sidebar-scrim {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 17, 34, .5);
  z-index: 55;
}

.content { padding: 22px; flex: 1; }
.content > :first-child { margin-top: 0; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 18px;
}
.card + .card { margin-top: 16px; }
.card-title {
  font-size: 11.5px; font-weight: 700; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 12px;
}

/* ── Tables ────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  background: var(--surface);
}
table { border-collapse: collapse; width: 100%; background: var(--surface); }
th {
  background: var(--surface);
  color: var(--ink-3);
  padding: 11px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}
td { padding: 9px 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: #f7f9fd; }

/* ── Badges ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2.5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  opacity: .75;
}
.badge-present    { background: var(--ok-soft);      color: var(--ok-ink); }
.badge-late       { background: var(--warn-soft);    color: var(--warn-ink); }
.badge-absent     { background: var(--danger-soft);  color: var(--danger-ink); }
.badge-early_exit { background: var(--early-soft);   color: var(--early-ink); }
.badge-unknown    { background: var(--neutral-soft); color: var(--neutral-ink); }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  transition: background .13s, border-color .13s, box-shadow .13s, transform .06s;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #d43333; }
.btn-outline {
  background: var(--surface);
  color: var(--ink-2);
  border-color: var(--line-strong);
}
.btn-outline:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--neutral-soft); }
.btn-sm { padding: 4.5px 10px; font-size: 12px; border-radius: 7px; }

/* ── Flash messages ────────────────────────────────────── */
.flash {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid transparent;
}
.flash-error   { background: var(--danger-soft); color: var(--danger-ink); border-color: #fbc9c9; }
.flash-success { background: var(--ok-soft);     color: var(--ok-ink);     border-color: #b7ecc8; }

/* ── Tabs & filter bar (legacy contract) ───────────────── */
.tabs {
  display: flex; gap: 3px;
  background: #e9ecf4;
  border-radius: 10px;
  padding: 3px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  margin-bottom: 18px;
  align-items: center;
}
.tabs a, .tabs span {
  padding: 6px 15px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all .13s;
}
.tabs a.active, .tabs span.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1);
  font-weight: 600;
}
.tabs a:hover:not(.active) { color: var(--ink); }

/* ── Workspace navigation ─────────────────────────────────
   The sidebar names the staff decision; these route-backed tabs retain each
   specialist screen, its URL and its permission boundary. */
.workspace-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: 48px;
  margin: 0 0 18px;
  padding: 5px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-1);
}
.workspace-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 14px;
  border-radius: 8px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  transition: background .13s, color .13s, box-shadow .13s;
}
.workspace-tab:hover { background: var(--neutral-soft); color: var(--ink); }
.workspace-tab.active {
  background: var(--brand-soft);
  color: var(--brand-strong);
  box-shadow: inset 0 0 0 1px rgba(59, 110, 246, .12);
}
.workspace-tab.active::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 3px;
  height: 2px;
  border-radius: 999px;
  background: var(--brand);
}

.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.filter-bar select, .filter-bar input,
select.input, input.input, textarea.input {
  padding: 7px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  transition: border-color .13s, box-shadow .13s;
}
.filter-bar select:focus, .filter-bar input:focus,
select.input:focus, input.input:focus, textarea.input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.export-bar { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Live indicator ────────────────────────────────────── */
#live-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ── Thumbnails ────────────────────────────────────────── */
.thumb {
  width: 56px; height: 56px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}
.thumb-missing {
  width: 56px; height: 56px;
  background: var(--neutral-soft);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  color: var(--ink-3);
}

/* ── Empty state ───────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--ink-3);
}
.empty-state svg { width: 44px; height: 44px; opacity: .45; margin-bottom: 12px; }
.empty-state .empty-title { font-size: 14.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.empty-state .empty-hint  { font-size: 12.5px; }

/* ── Toasts ────────────────────────────────────────────── */
#toast-root {
  position: fixed;
  bottom: 18px; right: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  background: var(--ink);
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-3);
  animation: toastIn .22s cubic-bezier(.21, 1.02, .73, 1);
  max-width: 340px;
}
.toast.toast-success { background: #15803d; }
.toast.toast-error   { background: #b91c1c; }
.toast.leaving { animation: toastOut .18s ease-in forwards; }
@keyframes toastIn  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }

/* ── Skeleton loading ──────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #edf0f7 25%, #f6f8fc 50%, #edf0f7 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: 6px;
  color: transparent !important;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Utilities ─────────────────────────────────────────── */
.muted    { color: var(--ink-3); }
.nowrap   { white-space: nowrap; }
.tnum     { font-variant-numeric: tabular-nums; }
.mt-0 { margin-top: 0; }  .mb-0 { margin-bottom: 0; }

/* ── Mobile ────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.4, 0, .2, 1);
    box-shadow: var(--shadow-3);
  }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-scrim { display: block; }
  body.sidebar-open { overflow: hidden; }

  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 14px; }
  .content { padding: 14px; }
  .topbar h1 { font-size: 15px; }
  .workspace-nav {
    margin-bottom: 14px;
    border-radius: 10px;
  }
  .workspace-tab { padding-inline: 12px; }
}

@media (max-width: 480px) {
  /* Horizontal padding only. The vertical size is set by the touch rules
     below and must not be reduced here — a narrow screen is usually a finger,
     and shrinking the button is the opposite of what that needs. */
  .btn { padding-inline: 11px; }
  td, th { padding-left: 10px; padding-right: 10px; }
}

/* ── Touch targets ─────────────────────────────────────────
   Keyed on the pointer, not the viewport. A phone, a tablet and a touchscreen
   laptop all need a finger-sized target; a narrow desktop window does not, and
   sizing on width alone gets both cases wrong.

   44px is the floor Apple and Google both publish, and it is a floor rather
   than a suggestion: below it the miss rate climbs sharply, which on this app
   means a teacher mis-tapping while walking between lessons. Measured before
   this block existed, 24 of 25 controls on /my were under it and the smallest
   was 20px. */
@media (pointer: coarse) {
  .sidebar nav a,
  .sidebar-footer a,
  .sidebar-footer button,
  .sidebar-footer select,
  .workspace-tab,
  .menu-btn,
  .btn {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .btn, .workspace-tab, .menu-btn { justify-content: center; }

  /* The footer links sat at 4-5px vertical padding, which is where the 20px
     measurements came from. */
  .sidebar-footer a,
  .sidebar-footer button { padding-block: 10px; }

  .sidebar nav a { padding-block: 11px; }

  /* Row actions inside tables are the other habitual near-miss: they are
     small by design on a desktop and unchanged by the rules above. */
  td .btn-sm, td a.btn { min-height: 40px; padding-inline: 12px; }

  /* Dense tables. .table-wrap gives a table its own horizontal scroller, but
     29 tables across the templates are not wrapped in one, and an unwrapped
     wide table drags the whole PAGE sideways — which on a phone means the nav
     and the heading slide off with it.

     Making the table itself the scroller is the standard fallback and needs no
     template change. A table already inside a .table-wrap simply never
     overflows its parent, so the two do not fight. Wrapping the remaining
     tables properly is still the better fix; this stops the page breaking
     while that happens, and tests/test_mobile_css.py holds the count down. */
  table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Separate adjacent controls so a fingertip cannot span two of them. */
  .sidebar-footer a + a,
  .sidebar-footer button + button { margin-top: 4px; }
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
