/* Campus: one stylesheet, light and dark. No inline styles anywhere (the Content-Security-Policy forbids them). */

@font-face {
  font-family: "Figtree";
  src: url("../fonts/figtree-latin-wght-normal.woff2") format("woff2");
  font-weight: 300 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212;
}
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("../fonts/bricolage-grotesque-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212;
}

:root {
  color-scheme: light dark;
  --bg: #EEF2F6;
  --card: #FFFFFF;
  --text: #14213D;
  --muted: #5B6677;
  --line: #D9E0E8;
  --field-line: #B9C4D2;
  --primary: #14213D;
  --on-primary: #FFFFFF;
  --hover: #E3E9F1;
  --soft: #F3F6FA;
  --avatar: #DCE4F0;
  --flash-bg: #E3ECFB;
  --flash-fg: #10285C;
  --error-bg: #FBE5E3;
  --error-fg: #7A1510;
  --danger: #B3261E;
  --danger-text: #B3261E;
  --focus: #1F4FD8;
  --school: #14213D;
  --department: #0E7C7B;
  --course: #F2B134;
  --on-course: #14213D;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1523;
    --card: #172033;
    --text: #E8EDF5;
    --muted: #A3AEC2;
    --line: #2A3550;
    --field-line: #3C4A6B;
    --primary: #E8EDF5;
    --on-primary: #0E1523;
    --hover: #202C45;
    --soft: #1D2840;
    --avatar: #2A3550;
    --flash-bg: #1C2E54;
    --flash-fg: #CFE0FF;
    --error-bg: #3A1B1A;
    --error-fg: #FFC9C4;
    --danger-text: #FF9A91;
    --focus: #8FB0FF;
    --school: #3A4A73;
    --mark-bg: #5A4A12;
  }
  mark { background: var(--mark-bg); color: #FFF2C6; }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }  /* our own display rules must never un-hide an element marked hidden */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  background: var(--bg); color: var(--text);
  font: 400 16px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--display); letter-spacing: -0.01em; margin: 0; line-height: 1.15; }
h1 { font-size: clamp(28px, 4vw, 34px); }
h2 { font-size: 22px; margin-bottom: 8px; }
h3 { font-size: 18px; }
p { margin: 0 0 12px; }
small { color: var(--muted); font-size: 14px; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.92em; overflow-wrap: anywhere; }
a { color: var(--text); }
img { max-width: 100%; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button, a, summary { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 12px; z-index: 20; background: var(--card); padding: 8px 12px; border-radius: 8px; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.sb {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 8px; padding: 20px 14px;
  background: var(--card); border-right: 1px solid var(--line);
}
.brand { font: 700 24px var(--display); color: var(--text); text-decoration: none; padding: 4px 14px 16px; letter-spacing: -0.01em; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 14px;
  border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a.on { background: var(--primary); color: var(--on-primary); }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: auto; padding: 0 6px;
  border-radius: 99px; background: var(--course); color: var(--on-course);
  font: 700 12px/1 var(--font); font-style: normal;
}
.user { margin-top: auto; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 10px; border-radius: 10px; color: inherit; text-decoration: none; }
.who { display: grid; min-width: 0; }
.who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { width: 100%; max-width: 1100px; min-width: 0; padding: 28px 32px 48px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.sub { color: var(--muted); margin: 4px 0 0; }
.account-link { display: none; align-items: center; min-height: 44px; padding: 0 12px; font-weight: 600; text-decoration: none; }
.back { display: inline-block; color: var(--muted); font-size: 14px; margin-bottom: 4px; }

/* ---------- cards and lists ---------- */
.card { background: var(--card); border-radius: 14px; padding: 20px; margin-bottom: 16px; }
.narrow { max-width: 640px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; align-items: start; margin-bottom: 24px; }
.grid-2 .card { margin-bottom: 0; }
.section-title { margin-bottom: 12px; }
.sub-title { margin: 20px 0 8px; font-size: 18px; }
.empty { color: var(--muted); margin: 8px 0; }
.more { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; }
.fine { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.block { display: block; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions form { margin: 0; }
.pager { margin: 0 0 16px; text-align: center; }

.tag { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; line-height: 1.5; }
.tag.school { background: var(--school); color: #fff; }
.tag.department { background: var(--department); color: #fff; }
.tag.course { background: var(--course); color: var(--on-course); }
.tag.ok { background: var(--department); color: #fff; }
.tag.warn { background: var(--course); color: var(--on-course); }
.tag.fail { background: var(--danger); color: #fff; }
b + .tag, .tag + .tag { margin-left: 8px; }
.finding { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
h2 + .finding, h2 + .sub + .finding { border-top: 0; }
.finding .tag { flex: none; min-width: 52px; text-align: center; }

.ann { padding: 14px 0; border-top: 1px solid var(--line); }
h2 + .ann, .feed > .ann:first-child { border-top: 0; }
.ann .row { margin-bottom: 6px; }
.ann .row:last-child { margin-bottom: 0; }
.ann p { margin: 4px 0 6px; color: var(--muted); white-space: pre-line; overflow-wrap: anywhere; }
.by { display: block; }
.link-danger {
  min-height: 44px; padding: 0 4px; background: none; border: 0; cursor: pointer;
  color: var(--danger-text); font: 600 14px var(--font); text-decoration: underline;
}

.lecture { display: flex; align-items: center; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
h2 + .lecture { border-top: 0; }
.lecture > div { flex: 1; min-width: 0; }
.lecture small { display: block; }
.time { font: 700 24px var(--display); width: 68px; font-variant-numeric: tabular-nums; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-height: 96px; padding: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: inherit; text-decoration: none;
}
.tile:active { transform: scale(0.98); }

.week { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 16px; }
.week .card { margin-bottom: 0; }
.day.today { outline: 2px solid var(--department); }

.tabs { display: flex; gap: 4px; margin: 0 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a {
  display: flex; align-items: center; min-height: 44px; padding: 0 16px; white-space: nowrap;
  color: var(--muted); font-weight: 500; text-decoration: none; border-bottom: 3px solid transparent;
}
.tabs a.on { color: var(--text); border-color: var(--primary); font-weight: 600; }

.avatar { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--avatar); font-weight: 600; font-size: 14px; }
.avatar.lec { background: var(--primary); color: var(--on-primary); }

.post { display: flex; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.feed > .post:first-child { border-top: 0; }
.post-body { flex: 1; min-width: 0; }
.post-body p { margin: 4px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.post-actions { margin: 0; }

.person { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 0; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
h2 + .person, .feed > .person:first-child { border-top: 0; }
.person.stacked { flex-wrap: wrap; }
.person.file { flex-wrap: wrap; row-gap: 8px; }

/* ---------- forms ---------- */
.stack { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; }
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.field.inline { min-width: 180px; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 0 14px;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming the page on focus */
  color: var(--text); background: var(--card); border: 1px solid var(--field-line); border-radius: 10px;
}
textarea { min-height: 96px; padding: 12px 14px; resize: vertical; }
input[type="file"] { min-height: 0; padding: 10px 14px; }
input[type="file"]::file-selector-button {
  margin-right: 12px; padding: 8px 14px; cursor: pointer;
  font: 600 15px var(--font); color: var(--text); background: var(--soft);
  border: 1px solid var(--field-line); border-radius: 8px;
}
input[type="search"] { -webkit-appearance: none; appearance: none; }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 20px;
  font: 600 16px var(--font); color: var(--on-primary); background: var(--primary); border: 1px solid var(--primary);
  border-radius: 10px; text-decoration: none; cursor: pointer;
}
.btn.ghost { color: var(--text); background: var(--card); border-color: var(--field-line); }
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.sm { min-height: 44px; padding: 0 14px; font-size: 15px; }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.5; cursor: default; }

.flash { margin: 0 0 16px; padding: 12px 16px; border-radius: 10px; background: var(--flash-bg); color: var(--flash-fg); }
.flash.error { background: var(--error-bg); color: var(--error-fg); }
.flash a { color: inherit; }

.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 16px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 0 0 16px; padding: 0; list-style: none; }
.codes li { padding: 10px 12px; background: var(--soft); border-radius: 10px; text-align: center; }
.codes code { font-size: 18px; letter-spacing: 0.04em; }

/* ---------- sign-in screens ---------- */
.auth-shell { min-height: 100vh; min-height: 100dvh; display: grid; justify-items: center; align-items: start; padding: max(28px, var(--safe-top)) 20px 32px; }
.auth-shell .main { max-width: 420px; padding: 0; }
.auth-card { display: grid; gap: 18px; }
.auth-card .card, .auth-card .flash, .auth-card p { margin: 0; }
.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-block .brand-mark { line-height: 1.1; }
.logo { flex: none; width: 44px; height: 44px; border-radius: 11px; }
.brand-mark { font: 700 28px var(--display); letter-spacing: -0.01em; margin: 0; }
.steps-bar { display: flex; gap: 8px; margin: 0; padding: 0; list-style: none; }
.steps-bar li { flex: 1; padding: 8px 0; text-align: center; font-size: 14px; font-weight: 600; color: var(--muted); background: var(--card); border-radius: 99px; }
.steps-bar li.done { background: var(--department); color: #fff; }
.steps-bar li.on { background: var(--primary); color: var(--on-primary); }
.plain-list { display: grid; gap: 6px; margin: 0; padding-left: 20px; }
.phrase {
  margin: 4px 0 12px; padding: 14px 12px; text-align: center; background: var(--soft); border-radius: 10px;
  font: 700 26px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.02em; overflow-wrap: anywhere;
}
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 44px; font-weight: 500; }
.check input { width: 24px; min-height: 24px; height: 24px; margin: 8px 0 0; flex: none; }

/* ---------- chat ---------- */
.chat { max-width: 720px; }
.chat-status { color: var(--muted); margin: 0 0 12px; }
.safety { margin: 0 0 12px; padding: 10px 14px; background: var(--soft); border-radius: 10px; }
.safety code { letter-spacing: 0.04em; }
.messages { display: flex; flex-direction: column; gap: 8px; min-height: 240px; max-height: 55vh; max-height: 55dvh; padding: 4px 0; overflow-y: auto; overscroll-behavior: contain; }
.bubble { align-self: flex-start; max-width: 80%; padding: 10px 14px; border-radius: 16px; background: var(--bg); overflow-wrap: anywhere; white-space: pre-wrap; }
.bubble.me { align-self: flex-end; background: var(--primary); color: var(--on-primary); }
.bubble.bad { background: var(--error-bg); color: var(--error-fg); font-style: italic; }
.bubble small { display: block; margin-top: 2px; font-size: 12px; color: inherit; opacity: 0.7; }
.composer { display: flex; gap: 8px; margin-top: 12px; }
.composer input { flex: 1; }
.qr-card { text-align: center; }
.qr { height: auto; padding: 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.qr.expired { opacity: 0.2; }
.qr-card .actions { justify-content: center; }

/* ---------- admin ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 16px; background: var(--card); border-radius: 14px; color: inherit; text-decoration: none; }
.stat b { font: 700 28px var(--display); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th { padding: 8px 10px; text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); }
.table td { padding: 10px; vertical-align: middle; border-bottom: 1px solid var(--line); }
.id-photo { max-height: 420px; margin: 12px 0; border: 1px solid var(--line); border-radius: 10px; }
.search { display: flex; gap: 8px; max-width: 520px; margin-bottom: 16px; }
.search input { flex: 1; min-width: 0; }
mark { padding: 0 2px; border-radius: 3px; background: #FFE9A8; color: #14213D; }

/* ---------- hover only where a real pointer exists ---------- */
@media (hover: hover) and (pointer: fine) {
  .nav a:hover { background: var(--hover); }
  .nav a.on:hover { background: var(--primary); }
  .tile:hover, .stat:hover { border-color: var(--text); }
  .btn.ghost:hover { border-color: var(--text); }
  .person.link:hover { background: var(--soft); }
  .link-danger:hover { text-decoration-thickness: 2px; }
}

/* ---------- tablet: icon rail, two columns where there is room ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 72px minmax(0, 1fr); }
  .sb { align-items: center; padding: 16px 10px; }
  .brand { padding: 4px 0 12px; }
  .brand span { display: none; }
  /* text stays in the page for screen readers; it is only invisible */
  .nav a .label, .who { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .nav a { justify-content: center; width: 48px; padding: 0; }
  .badge { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; margin: 0; padding: 0 5px; font-size: 11px; }
  .user { padding: 6px; }
  .main { padding: 24px 20px 40px; }
  .account-link { display: inline-flex; }
}
@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- phone: bottom tab bar ---------- */
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .sb {
    position: fixed; inset: auto 0 0 0; z-index: 5; height: auto; flex-direction: row; gap: 0;
    padding: 6px 6px calc(6px + var(--safe-bottom)); border-right: 0; border-top: 1px solid var(--line);
  }
  .brand, .user { display: none; }
  .nav { flex-direction: row; justify-content: space-around; gap: 0; width: 100%; }
  .nav a { flex: 1 1 0; min-width: 0; width: auto; flex-direction: column; gap: 2px; min-height: 48px; padding: 4px 2px; font-size: 12px; }
  .nav a .label { position: static; width: auto; height: auto; overflow: visible; clip: auto; white-space: nowrap; }
  .nav:has(> a:nth-child(5)) a { font-size: 11px; }
  .badge { top: 0; right: calc(50% - 22px); }
  .main { padding: 20px 16px calc(92px + var(--safe-bottom)); }
  .card { padding: 16px; }
  .form-row .btn { width: 100%; }
  .field.inline { min-width: 0; width: 100%; }
  .codes { grid-template-columns: 1fr 1fr; }
  .person.file .grow { flex: 1 1 100%; }  /* title on its own line, buttons underneath */
}

/* ---------- printing: the content only, in black on white (timetable, announcements, class lists) ---------- */
@media print {
  :root { --bg: #fff; --card: #fff; --text: #000; --muted: #333; --line: #999; --primary: #000; --on-primary: #fff; color-scheme: light; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .sb, .skip, .account-link, .tabs, .composer, .composer-card, .search, .btn, button, form, .more, .pager, .flash, input, textarea, select, .badge { display: none !important; }
  .app { display: block; }
  .main { max-width: none; padding: 0; }
  .card, .tile, .stat { border: 1px solid #999; border-radius: 0; break-inside: avoid; }
  .week { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  a { color: #000; text-decoration: none; }
  .tag { border: 1px solid #000; background: #fff !important; color: #000 !important; }
  mark { background: #fff; text-decoration: underline; }
}

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