/* ============================================================
   Apple-inspired theme layer
   Loaded AFTER style.css. Keeps every existing class name so all
   pages inherit the new look without markup rewrites.

   Surface: utility (study tool / dashboard). Chrome may use a
   translucent material; content uses opaque grouped surfaces.
   Corners are continuous where the browser supports corner-shape.
   ============================================================ */

:root {
  /* Semantic colours — light */
  --bg: #f2f2f7;                 /* grouped background */
  --bg-elev: #ffffff;            /* content surface */
  --bg-soft: #f2f2f7;            /* recessed row / hover fill */
  --bg-hover: #e9e9ee;
  --text: #000000;
  --text-soft: rgba(60, 60, 67, .82);
  --text-mute: rgba(60, 60, 67, .68);
  --border: rgba(60, 60, 67, .22);
  --border-strong: rgba(60, 60, 67, .34);

  /* One accent: system blue, darkened for white text (4.8:1) */
  --primary: #0a6fe0;
  --primary-hover: #0b63c8;
  --primary-soft: rgba(10, 111, 224, .12);

  --success: #1b7f3b;
  --success-soft: rgba(52, 199, 89, .14);
  --danger: #c4122a;
  --danger-soft: rgba(255, 56, 60, .12);
  --warn: #9a5b00;
  --warn-soft: rgba(255, 141, 40, .16);

  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .05);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, .14);
  --radius: 20px;
  --radius-sm: 12px;
  --radius-lg: 28px;
  --canvas-bg: #ffffff;
  --ink: #14181f;
  --header-h: 64px;

  --fill: rgba(120, 120, 128, .14);
  --fill-strong: rgba(120, 120, 128, .22);
  --material-bar: rgba(255, 255, 255, .72);
  --material-menu: rgba(255, 255, 255, .88);
  --focus-ring: 3px solid rgba(10, 111, 224, .55);
}

html[data-theme="dark"] {
  --bg: #000000;
  --bg-elev: #1c1c1e;
  --bg-soft: #2c2c2e;
  --bg-hover: #3a3a3c;
  --text: #ffffff;
  --text-soft: rgba(235, 235, 245, .62);
  --text-mute: rgba(235, 235, 245, .52);
  --border: rgba(84, 84, 88, .64);
  --border-strong: rgba(120, 120, 128, .72);

  --primary: #0a84ff;
  --primary-hover: #409cff;
  --primary-soft: rgba(10, 132, 255, .20);

  --success: #30d158;
  --success-soft: rgba(48, 209, 88, .18);
  --danger: #ff6165;
  --danger-soft: rgba(255, 97, 101, .16);
  --warn: #ffa056;
  --warn-soft: rgba(255, 160, 86, .16);

  --shadow: none;
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .6);
  --canvas-bg: #ffffff;
  --ink: #10141a;

  --fill: rgba(118, 118, 128, .32);
  --fill-strong: rgba(118, 118, 128, .44);
  --material-bar: rgba(18, 18, 20, .68);
  --material-menu: rgba(28, 28, 30, .92);
  --focus-ring: 3px solid rgba(64, 156, 255, .65);
}

/* ---------- Base ---------- */
* { -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans", "Noto Sans CJK SC", sans-serif;
  font-size: 17px;
  line-height: 1.55;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

h1, h2, h3, h4 { color: var(--text); font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 34px; line-height: 1.2; margin-bottom: 6px; }
h2 { font-size: 22px; line-height: 1.3; }
h3 { font-size: 17px; line-height: 1.35; font-weight: 650; }
p { margin: 0 0 .8em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

code, pre, .mono {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

::selection { background: rgba(10, 111, 224, .22); }
::placeholder { color: var(--text-mute); opacity: 1; }

:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ---------- Toolbar (functional glass layer) ---------- */
.topbar {
  height: var(--header-h);
  padding-inline: clamp(16px, calc((100vw - 1200px) / 2 + 24px), 120px);
  background: var(--material-bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  box-shadow: none;
  gap: 10px;
}

.brand { gap: 10px; font-size: 17px; font-weight: 700; margin-right: 10px; }
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-size: 15px; font-weight: 700;
  box-shadow: none;
}

.nav { gap: 2px; }
.nav a {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--text-soft);
  font-size: 15px;
  font-weight: 500;
  transition: background .2s ease, color .2s ease, transform .2s ease;
}
.nav a:hover { background: var(--fill); color: var(--text); }
.nav a.active {
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .10);
}
html[data-theme="dark"] .nav a.active { background: var(--bg-soft); box-shadow: none; }

.topbar-right { gap: 4px; }

.icon-btn {
  width: 40px; height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-soft);
  font-size: 17px;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.icon-btn:hover { background: var(--fill); color: var(--text); border: 0; }
.icon-btn:active { transform: scale(.94); }
.icon-btn.on { background: var(--primary-soft); color: var(--primary); border: 0; }
.icon-btn svg { width: 20px; height: 20px; display: block; }
#themeIcon .icon-sun { display: none; }
#themeIcon .icon-moon { display: block; }
html[data-theme="dark"] #themeIcon .icon-sun { display: block; }
html[data-theme="dark"] #themeIcon .icon-moon { display: none; }

.avatar {
  width: 32px; height: 32px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 650;
  text-transform: none;
}

/* ---------- Layout ---------- */
.page {
  max-width: 1200px;
  padding: 28px clamp(16px, 3vw, 32px) 56px;
}
.page-head { margin-bottom: 22px; align-items: flex-start; }
.page-head .sub { color: var(--text-soft); font-size: 15px; margin-top: 2px; }
.page-head h1 { font-size: 34px; }

.row { gap: 10px; }
.grid { gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); }

.muted { color: var(--text-mute); }
.soft { color: var(--text-soft); }
.small { font-size: 14px; }
.tiny { font-size: 12.5px; }

/* ---------- Surfaces ---------- */
.card {
  background: var(--bg-elev);
  border: 0;
  border-radius: var(--radius);
  box-shadow: none;
  padding: 20px;
}
.card.tight { padding: 16px; }

/* Nested content rows inside a grouped panel: a recessed fill,
   not a second card with its own border + shadow. */
.card .card,
.card .card.tight {
  background: var(--bg-soft);
  border: 0;
  border-radius: 16px;
  box-shadow: none;
}
.card .card .card { background: var(--bg-elev); }

.card-head { margin-bottom: 14px; align-items: baseline; }
.card-title { font-size: 16px; font-weight: 650; }

.stat {
  background: var(--bg-elev);
  border: 0;
  border-radius: var(--radius);
  box-shadow: none;
  padding: 18px;
}
.stat .k { font-size: 13px; font-weight: 500; color: var(--text-soft); }
.stat .v {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.15;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.stat .v small { font-size: 16px; font-weight: 600; color: var(--text-soft); }

/* ---------- Buttons ---------- */
.btn {
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--fill);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  box-shadow: none;
  transition: background .18s ease, color .18s ease, transform .18s ease, opacity .18s ease;
}
.btn:hover { background: var(--fill-strong); color: var(--text); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); filter: brightness(.97); }

.btn-success { background: var(--success-soft); color: var(--success); }
.btn-success:hover { background: var(--success-soft); color: var(--success); filter: brightness(.97); }

.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--fill); color: var(--text); }

.btn-sm { min-height: 34px; padding: 0 14px; font-size: 14px; }
.btn-lg { min-height: 50px; padding: 0 24px; font-size: 17px; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
label.field { margin-bottom: 16px; }
label.field > span.lbl {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 7px;
}

input[type=text], input[type=password], input[type=tel], input[type=number],
input[type=search], input[type=file], select, textarea {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--fill);
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
  transition: background .18s ease, border-color .18s ease, box-shadow .18s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: var(--bg-elev);
}
textarea { min-height: 96px; line-height: 1.55; }
input[type=file] { padding: 8px 10px; font-size: 14px; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-mute) 50%),
    linear-gradient(135deg, var(--text-mute) 50%, transparent 50%);
  background-position: calc(100% - 17px) 52%, calc(100% - 12px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
.check { font-size: 15px; color: var(--text-soft); }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--primary); }

/* ---------- Tables ---------- */
.table-wrap {
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow-x: auto;
}
table.tbl { font-size: 15px; }
table.tbl th {
  padding: 8px 12px;
  background: transparent;
  border-bottom: 1px solid var(--border);
  color: var(--text-mute);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}
table.tbl td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--border);
}
table.tbl tr:last-child td { border-bottom: 0; }
@media (hover: hover) and (pointer: fine) {
  table.tbl tbody tr:hover { background: var(--bg-soft); }
}
table.tbl td.num, .tabular { font-variant-numeric: tabular-nums; }

/* ---------- Tags ---------- */
.tag {
  gap: 5px;
  padding: 3px 10px;
  border: 0;
  border-radius: 999px;
  background: var(--fill);
  color: var(--text-soft);
  font-size: 12.5px;
  font-weight: 600;
}
.tag.blue { background: var(--primary-soft); color: var(--primary); }
.tag.green { background: var(--success-soft); color: var(--success); }
.tag.red { background: var(--danger-soft); color: var(--danger); }
.tag.amber { background: var(--warn-soft); color: var(--warn); }

/* ---------- Filters ---------- */
.filters {
  gap: 10px;
  padding: 12px;
  margin-bottom: 18px;
  background: var(--bg-elev);
  border: 0;
  border-radius: var(--radius);
  box-shadow: none;
}
.filters select, .filters input {
  width: auto;
  min-width: 120px;
  min-height: 38px;
  height: 38px;
  padding: 4px 12px;
  font-size: 14px;
}
.filters input[type=search] { min-width: 200px; flex: 1; max-width: 300px; }
.filters .btn { min-height: 38px; }

/* ---------- Flash + alerts ---------- */
.flash-wrap { top: calc(var(--header-h) + 12px); right: 16px; }
.flash {
  position: relative;
  padding: 13px 16px 13px 40px;
  border: 0;
  border-radius: 16px;
  background: var(--material-menu);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .16);
  font-size: 15px;
  animation: appleSlideIn .32s cubic-bezier(.2, .9, .25, 1);
}
.flash::before {
  content: "";
  position: absolute;
  left: 16px; top: 50%;
  width: 9px; height: 9px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: var(--primary);
}
.flash.ok::before { background: var(--success); }
.flash.error::before { background: var(--danger); }
.flash .x { color: var(--text-mute); cursor: pointer; font-size: 14px; }
@keyframes appleSlideIn {
  from { opacity: 0; transform: translateY(-6px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.alert {
  padding: 13px 16px;
  border: 0;
  border-radius: 14px;
  background: var(--bg-soft);
  font-size: 14px;
}
.alert.warn { background: var(--warn-soft); color: var(--warn); border: 0; }
.alert.danger { background: var(--danger-soft); color: var(--danger); border: 0; }
.alert.ok { background: var(--success-soft); color: var(--success); border: 0; }

/* ---------- Empty state ---------- */
.empty { padding: 44px 20px; color: var(--text-mute); }
.empty .big { display: none; }
.empty strong { display: block; color: var(--text); font-size: 17px; font-weight: 650; margin-bottom: 4px; }

/* ---------- Auth ---------- */
.auth-wrap {
  min-height: 100vh;
  padding: 28px 20px;
  background:
    radial-gradient(760px 420px at 50% -12%, rgba(10, 111, 224, .10), transparent 70%),
    var(--bg);
}
.auth-card {
  max-width: 420px;
  padding: 34px 30px 28px;
  background: var(--bg-elev);
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.auth-card .brand { font-size: 19px; margin-bottom: 4px; }
.auth-card h1 { font-size: 26px; text-align: center; margin: 16px 0 4px; }
.auth-card .sub { color: var(--text-soft); font-size: 15px; margin-bottom: 24px; }
.auth-foot { margin-top: 18px; font-size: 14px; color: var(--text-mute); }

/* ---------- Pager ---------- */
.pager { gap: 8px; margin-top: 22px; }
.pager a, .pager span {
  min-width: 40px; height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-soft);
  font-size: 14px;
}
.pager a:hover { background: var(--fill); color: var(--text); }
.pager .cur { background: var(--primary); color: #fff; font-weight: 600; }
.pager .gap { background: none; }

/* ---------- Misc ---------- */
.img-tip { color: var(--text-mute); font-size: 12.5px; }
.stem-text { font-size: 14px; color: var(--text-soft); }
.stem-text summary { color: var(--text-mute); font-size: 13px; }

.btn svg { width: 17px; height: 17px; flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.anno-zoom {
  display: grid;
  place-items: center;
  border: 0;
  background: var(--material-menu);
  color: var(--text-soft);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.anno-zoom svg { width: 16px; height: 16px; }
.anno-bar .icon-btn { width: 34px; height: 34px; background: var(--fill); }
.anno-bar .icon-btn svg { width: 16px; height: 16px; }

/* Exam paper: one grouped surface, no outlined card stack */
.qcard { border: 0; box-shadow: none; border-radius: 22px; }

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  body { font-size: 16px; }
  h1 { font-size: 28px; }
  .page { padding: 18px 16px 48px; }
  .page-head h1 { font-size: 28px; }
  .brand span.name { display: none; }
  .card { padding: 16px; border-radius: 18px; }
  .stat { padding: 15px; border-radius: 18px; }
  .stat .v { font-size: 28px; }
  .flash-wrap { left: 12px; right: 12px; max-width: none; }
  .topbar { padding-inline: 12px; }
  .nav a { padding: 7px 11px; font-size: 14px; }
  .auth-card { padding: 28px 22px 24px; }
}

@media print {
  .topbar, .filters, .btn, .pager, .flash-wrap { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
