/* Dashboard layout + chart chrome. Tokens live in tokens.css. */

/* ------------------------------------------------------------------ chrome */
/* The university bar: navy in both themes, with the seal's gold as the hairline
   under it. The identity should not change when the viewer flips the theme. */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  flex-wrap: wrap;
  padding: 10px clamp(14px, 3vw, 30px);
  background: linear-gradient(100deg, var(--brand-navy-deep), var(--brand-navy) 55%, var(--brand-navy-soft));
  border-bottom: 2px solid var(--brand-gold);
  color: #fff;
}
.topbar .brand__name { color: #fff; }
.topbar .brand__sub  { color: rgba(255, 255, 255, .62); }
.topbar .btn {
  background: rgba(255, 255, 255, .10); border-color: rgba(255, 255, 255, .22); color: #fff;
  text-decoration: none;
}
.topbar .btn:hover { background: rgba(255, 255, 255, .19); }
.topbar .btn:focus-visible { box-shadow: 0 0 0 3px rgba(245, 190, 23, .55); }
.topbar__actions { display: flex; align-items: center; gap: var(--sp-2); }
.whoami {
  font-size: 12.5px; color: rgba(255, 255, 255, .72); padding-right: 4px;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.filters {
  display: flex; align-items: flex-end; gap: var(--sp-2) var(--sp-3); flex-wrap: wrap;
  padding: 11px clamp(14px, 3vw, 30px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.filters .label { margin-bottom: 3px; font-size: 11px; color: var(--muted); font-weight: 400; }
/* last-sync note + HEMIS sync button, pushed to the right edge of the filters.
   The row is bottom-aligned (flex-end), so nudge the note onto the button's
   text line and let the auto margin claim all the space to its left. */
.sync-info { margin-left: auto; align-self: flex-end; padding-bottom: 9px;
             font-size: 12px; white-space: nowrap; }
.sync-info.is-err { color: var(--critical); }
.filters__presets { display: flex; gap: 2px; padding: 3px; background: var(--page); border-radius: 9px; }
.chip {
  font: inherit; font-size: 12.5px; padding: 6px 12px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text-2); cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip.is-on { background: var(--surface); color: var(--brand-navy); box-shadow: var(--shadow-1); font-weight: 600; }
:root[data-theme="dark"] .chip.is-on, :root:not([data-theme="light"]) .chip.is-on { color: var(--text); }
.chip:focus-visible { outline: none; box-shadow: var(--ring); }
.field { display: flex; flex-direction: column; }
.field--grow { flex: 1 1 190px; min-width: 150px; max-width: 320px; }
.input--sm { padding: 7px 10px; font-size: 13px; }

.wrap { padding: clamp(14px, 3vw, 30px); max-width: 1560px; margin: 0 auto; }
.wrap.is-stale { opacity: .5; transition: opacity .12s; }   /* hold, never skeleton-flash */
/* Stacked blocks (tiles, cards, grids) need breathing room between them.
   Pages with .section headings already space themselves; vertical margins
   collapse, so the bigger .section margin wins and nothing double-stacks. */
.wrap > * + * { margin-top: var(--sp-4); }

.section {
  font-size: 11.5px; font-weight: 600; letter-spacing: .055em; text-transform: uppercase;
  color: var(--muted); margin: var(--sp-6) 0 var(--sp-3);
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.section:first-of-type { margin-top: var(--sp-5); }
.section__hint { font-size: 11.5px; font-weight: 400; letter-spacing: 0; text-transform: none; }

/* ------------------------------------------------------------- stat tiles */
.tiles { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(min(178px, 100%), 1fr)); }
.tile {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 14px 16px 15px; box-shadow: var(--shadow-1);
}
.tile::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--tile-accent, var(--series-1));
}
.tile__label { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; text-transform: uppercase; font-weight: 550; }
.tile__value { font-size: 29px; font-weight: 640; letter-spacing: -.025em; margin-top: 6px; line-height: 1.1; }
.tile__sub   { font-size: 12.5px; color: var(--text-2); margin-top: 3px; }

/* ----------------------------------------------------------------- cards */
.grid { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr)); align-items: start; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr)); }
.grid--tables { grid-template-columns: repeat(auto-fit, minmax(min(290px, 100%), 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 15px 16px 12px; box-shadow: var(--shadow-1); min-width: 0;
}
.card--wide { grid-column: 1 / -1; }
.card__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-2) var(--sp-3); margin-bottom: 12px; flex-wrap: wrap;
}
.card__head > div:first-child { flex: 1 1 190px; min-width: 0; }
.card__head h2 { font-size: 14.5px; }
.card__note { font-size: 12.5px; color: var(--muted); margin-top: 3px; max-width: 54ch; }
.card__body { min-width: 0; overflow-x: auto; }
.empty { color: var(--muted); font-size: 13px; padding: 26px 2px; text-align: center; }

/* segmented chart-type switch, top-right of a card */
.seg { display: flex; gap: 1px; padding: 2px; background: var(--page); border-radius: 8px; flex: 0 0 auto; }
.seg button {
  font: inherit; font-size: 11.5px; padding: 4px 9px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.seg button:hover { color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); font-weight: 550; }
.seg button:focus-visible { outline: none; box-shadow: var(--ring); }
/* larger segmented control for a settings choice (theme) */
.seg--lg { display: inline-flex; }
.seg--lg button { font-size: 13px; padding: 8px 16px; }

/* on/off switch (turnstile control) */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch__slider {
  position: absolute; inset: 0; border-radius: 999px; background: var(--border-firm);
  transition: background .15s;
}
.switch__slider::before {
  content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: var(--shadow-1);
}
.switch input:checked + .switch__slider { background: var(--good, var(--brand-navy)); }
.switch input:checked + .switch__slider::before { transform: translateX(20px); }
.switch input:focus-visible + .switch__slider { box-shadow: var(--ring); }
.ts-stat { font-size: 13px; }
.ts-stat .ok { color: var(--good); } .ts-stat .warn { color: var(--critical); }

/* ----------------------------------------------------------------- charts */
svg { display: block; max-width: 100%; }
.c-grid  { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.c-axis  { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.c-tick  { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.c-label { fill: var(--text-2); font-size: 12px; }
.c-value { fill: var(--text); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.c-line  { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-dot   { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.c-hit   { fill: transparent; cursor: crosshair; }
.c-cross { stroke: var(--axis); stroke-width: 1; }
.c-bar   { fill: var(--series-1); }
.c-seg   { stroke: var(--surface); stroke-width: 2; }   /* 2px surface gap, not a border */
.c-seg:hover, .c-seg:focus { filter: brightness(1.1); outline: none; }

/* donut: figure + legend side by side, stacking when narrow */
.donut { display: flex; align-items: center; gap: var(--sp-5); flex-wrap: wrap; }
.donut__fig { position: relative; flex: 0 0 auto; }
.donut__center {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none;
}
.donut__total { font-size: 25px; font-weight: 640; letter-spacing: -.02em; line-height: 1.1; }
.donut__cap   { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 1px; }
.legend { flex: 1 1 180px; min-width: 165px; display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.legend li { display: grid; grid-template-columns: 10px 1fr auto auto; align-items: center; gap: 9px; font-size: 13px; }
.legend__swatch { width: 10px; height: 10px; border-radius: 3px; }
.legend__name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend__val  { font-variant-numeric: tabular-nums; font-weight: 600; }
.legend__pct  { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; min-width: 42px; text-align: right; }

/* a single-row breakdown is a figure, not a one-bar bar chart */
.statline { padding: 6px 2px 18px; }
.statline__value { font-size: 42px; font-weight: 640; letter-spacing: -.025em; line-height: 1.05; }
.statline__label { font-size: 13.5px; color: var(--text-2); margin-top: 5px; }
.statline__sub   { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ----------------------------------------------------------------- tables */
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 7px 10px 7px 0; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--muted); font-weight: 550; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; padding-right: 2px; }
td.wrap-cell { white-space: normal; min-width: 190px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.score-chip {
  display: inline-block; min-width: 34px; text-align: center;
  padding: 2px 7px; border-radius: 5px; font-weight: 600; color: #fff; font-variant-numeric: tabular-nums;
}
[data-card="recent"] .card__body { max-height: 470px; overflow-y: auto; }

/* ---------------------------------------------------------------- tooltip */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; opacity: 0;
  transform: translate(-50%, -100%);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-firm); border-radius: var(--r-sm);
  padding: 8px 11px; font-size: 12.5px; line-height: 1.5;
  box-shadow: var(--shadow-2); max-width: 290px;
}
.tooltip.is-on { opacity: 1; }
.tooltip b { font-weight: 640; }
.tooltip .t-dim { color: var(--muted); }

/* load failure: a banner above the content, since the header no longer
   carries a status line */
.banner {
  margin: 0 0 var(--sp-3); padding: 10px 13px; border-radius: var(--r-sm);
  background: color-mix(in oklab, var(--critical) 12%, transparent);
  border: 1px solid color-mix(in oklab, var(--critical) 38%, transparent);
  color: var(--text); font-size: 13px;
}
.banner[hidden] { display: none; }

/* "Barchasini ko'rish" sits under the chart, not in the header, so it reads as
   an action on the list rather than another view switch */
.card__foot { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--grid); }
.card__foot .btn { width: 100%; justify-content: center; font-size: 12.5px; }
[data-card="teachers"] .card__body { max-height: none; }

/* ------------------------------------------------------------- sub-pages */
.crumbs { margin-bottom: var(--sp-3); font-size: 13px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-4);
}
.page-head h1 { font-size: 21px; }
.page-head p { font-size: 13px; margin-top: 3px; }
.page-head__tools { display: flex; align-items: flex-end; gap: var(--sp-3); flex-wrap: wrap; }
.page-head__tools .label { font-size: 11px; color: var(--muted); margin-bottom: 3px; display: block; }
.page-head__tools .input { min-width: 170px; }
.page-head__tools .seg { padding: 3px; }
.page-head__tools .seg button { padding: 5px 11px; font-size: 12px; }
#list-card .card__body { max-height: none; }

/* a right-aligned first column (rank) needs breathing room before the next
   header, otherwise "O'RIN" and "O'QITUVCHI" read as one word */
th.num:first-child, td.num:first-child { padding-right: 16px; min-width: 46px; }

/* the Excel link is an <a download>, not a button — keep it on the same line */
.topbar #export { text-decoration: none; }

/* ------------------------------------------------- teacher x subject table */
/* A count cell doubles as its own bar: the number stays readable, the tint
   shows the share, so five columns read as a histogram without a chart. */
.tally {
  display: inline-block; min-width: 36px; padding: 3px 8px;
  border-radius: 5px; font-variant-numeric: tabular-nums; font-weight: 600;
  text-align: center; color: var(--text);
}
.tally--zero { color: var(--muted); font-weight: 400; background: none; }

tr.row--total td { background: var(--surface-2); font-weight: 600; border-top: 1px solid var(--axis); }
tr.row--total td:first-child { color: var(--text); }
tr.row--sub td:first-child { padding-left: 18px; color: var(--text-2); font-weight: 400; }
tr.row--sub td:first-child::before { content: '└ '; color: var(--muted); }

/* teacher rows are disclosures: the whole row is the hit target */
tr.row--total { cursor: pointer; }
tr.row--total:hover td { background: color-mix(in oklab, var(--surface-2) 70%, var(--series-1) 6%); }
tr.row--total:focus-visible { outline: none; }
tr.row--total:focus-visible td { box-shadow: inset 0 0 0 2px var(--series-1); }

.disclose { display: inline-flex; align-items: center; gap: 8px; }
.disclose__chev {
  display: inline-block; width: 14px; text-align: center; color: var(--muted);
  font-size: 15px; line-height: 1; transition: transform .12s;
}
.disclose.is-open .disclose__chev { transform: rotate(90deg); color: var(--text-2); }
.disclose__count {
  font-size: 11px; font-weight: 500; color: var(--muted);
  background: var(--page); border-radius: 999px; padding: 2px 8px; white-space: nowrap;
}

/* ------------------------------------------------------------ admin pages */
.btn--xs { padding: 3px 9px; font-size: 11.5px; border-radius: 6px; }
.btn--danger { color: var(--critical); border-color: color-mix(in oklab, var(--critical) 40%, transparent); }
.btn--danger:hover:not(:disabled) { background: color-mix(in oklab, var(--critical) 12%, transparent); }
.row-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill--good { background: color-mix(in oklab, var(--good) 16%, transparent); color: var(--good); }

tr.row--muted td { color: var(--muted); }
tr.row--muted td:first-child { opacity: .75; }

.qr-thumb { border-radius: 4px; background: #fff; padding: 1px; flex: none; }

.pager { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.pager .btn:disabled { opacity: .4; }

.deflist { display: grid; grid-template-columns: minmax(130px, auto) 1fr; gap: 8px 18px; margin: 0; font-size: 13px; }
.deflist dt { color: var(--muted); }
.deflist dd { margin: 0; color: var(--text); }
.deflist a { color: var(--series-1); }

/* ------------------------------------------------------------- QR sheet */
.qr-sheet { display: grid; gap: 10px; grid-template-columns: repeat(7, minmax(0, 1fr)); }
@media (max-width: 1150px) { .qr-sheet { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (max-width: 900px)  { .qr-sheet { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 700px)  { .qr-sheet { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 520px)  { .qr-sheet { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 380px)  { .qr-sheet { grid-template-columns: 1fr; } }
.qr-card {
  margin: 0; padding: 9px 7px 8px; text-align: center; break-inside: avoid; min-width: 0;
  background: var(--surface); border: 1px dashed var(--axis); border-radius: var(--r-md);
}
.qr-card__room { font-size: clamp(15px, 1.15vw, 20px); font-weight: 700; color: var(--brand-navy);
                 letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; }
.qr-card__bld { font-size: 9.5px; color: var(--muted); margin: 1px 0 6px; line-height: 1.25;
                overflow-wrap: anywhere; }
.qr-card__img { width: 100%; height: auto; aspect-ratio: 1; background: #fff; border-radius: 5px; }
.qr-card__hint { font-size: 8.5px; color: var(--muted); margin-top: 5px; line-height: 1.25; }
:root[data-theme="dark"] .qr-card__room, :root:not([data-theme="light"]) .qr-card__room { color: var(--accent-ink); }

.qr-card--clickable { cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .12s; }
.qr-card--clickable:hover { border-color: var(--brand-navy); box-shadow: var(--shadow-1); transform: translateY(-1px); }
.qr-card--clickable:focus-visible { outline: 2px solid var(--brand-navy); outline-offset: 2px; }

/* --------------------------------------------- enlarged single-QR modal */
.qr-modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: color-mix(in oklab, #0b1b2b 62%, transparent);
}
.qr-modal[hidden] { display: none; }
.qr-modal__box {
  position: relative; width: min(420px, 100%); text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-2); padding: 26px 24px 20px;
}
.qr-modal__close {
  position: absolute; top: 8px; right: 10px; width: 34px; height: 34px;
  border: 0; background: transparent; color: var(--muted); font-size: 24px; line-height: 1;
  cursor: pointer; border-radius: var(--r-sm);
}
.qr-modal__close:hover { background: var(--surface-2); color: var(--text-2); }
.qr-modal__card { margin: 0; }
.qr-modal__room { font-size: 30px; font-weight: 800; color: var(--brand-navy); letter-spacing: -.02em; line-height: 1.1; }
.qr-modal__bld { font-size: 13px; color: var(--muted); margin: 3px 0 14px; }
.qr-modal__img { width: 100%; max-width: 320px; height: auto; aspect-ratio: 1; background: #fff; border-radius: 8px; padding: 8px; }
.qr-modal__hint { font-size: 12px; color: var(--muted); margin-top: 12px; }
.qr-modal__actions { display: flex; gap: 10px; justify-content: center; align-items: center; margin-top: 18px; }
:root[data-theme="dark"] .qr-modal__room, :root:not([data-theme="light"]) .qr-modal__room { color: var(--accent-ink); }

@media print {
  .side, .appbar, .filters, .scrim, #error, #note { display: none !important; }
  .app { display: block; }
  .wrap { padding: 0; max-width: none; }
  /* 7 across is right on screen; on A4 that is a ~25 mm code, so print
     4 across — still 24 doors a page and comfortably scannable */
  .qr-sheet { grid-template-columns: repeat(4, 1fr) !important; gap: 8px; }
  .qr-card { border-color: #999; background: #fff; }
  .qr-card__room { color: #133654; }
  body { background: #fff; }

  /* "Chop etish" inside the modal prints just that one enlarged code */
  body.qr-printing-one #page, body.qr-printing-one #tooltip { display: none !important; }
  body.qr-printing-one .qr-modal {
    position: static; display: block; padding: 0; background: none;
  }
  body.qr-printing-one .qr-modal__box {
    width: auto; border: 0; box-shadow: none; padding: 0; margin: 0 auto;
  }
  body.qr-printing-one .qr-modal__close, body.qr-printing-one .qr-modal__actions { display: none !important; }
  body.qr-printing-one .qr-modal__room { color: #133654; }
  body.qr-printing-one .qr-modal__img { max-width: 70mm; }
}

/* a right-aligned column jams into whatever follows it (actions, a QR thumb) */
th.num + th, td.num + td { padding-left: 16px; }

/* a two-column definition list has no room on a phone */
@media (max-width: 560px) { .deflist { grid-template-columns: 1fr; gap: 2px 0; } .deflist dd { margin-bottom: 10px; } }

/* ----------------------------------------------------- time override */
.timeform { display: flex; align-items: flex-end; gap: var(--sp-3); flex-wrap: wrap; margin-top: 12px; }
.timebox {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 11px 14px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px;
}
.timebox.is-on { background: color-mix(in oklab, var(--warning) 15%, transparent);
                 border-color: color-mix(in oklab, var(--warning) 50%, transparent); }
.timebox__big {
  font-size: 22px; font-weight: 650; letter-spacing: .02em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums;
}
.timebox__lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* while the clock is shifted, every page says so — students are affected too */
.timewarn {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--warning); color: #3a2a00;
  padding: 7px clamp(14px, 3vw, 30px); font-size: 13px; font-weight: 550;
}
.timewarn a { color: #3a2a00; }
.timewarn[hidden] { display: none; }

.pill--off { background: var(--surface-2); color: var(--muted); }
.asked { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; }
.asked li { color: var(--text); }
