/* Studyinfo Explorer — mobile-first. Phone < 760px · Tablet 760–1199px · PC ≥ 1200px */
:root {
  --bg: #F4F6F8; --surface: #FFFFFF; --ink: #0E1A2B; --ink2: #253244; --muted: #4B5563;
  --line: #DCE1E8; --line2: #C3CCD8; --accent: #1C5FAF; --accent-ink: #164C8C; --accent-soft: #E6EFFA;
  --money-bg: #E5F4EC; --money: #145C38; --warn-bg: #FEF3E2; --warn: #8A3B0C; --ai-bg: #FFF1E6; --ai: #8A3B0C;
  --chip: #EEF1F5; --chip-ink: #344054; --danger: #B42318; --danger-bg: #FEECEB; --seg: #E3E8EF;
  --shadow: 0 1px 2px rgba(14, 26, 43, .08), 0 4px 16px rgba(14, 26, 43, .06);
  --radius: 14px; --font: Figtree, system-ui, -apple-system, "Segoe UI", sans-serif;
  --on-accent: #FFFFFF;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D141E; --surface: #151E2B; --ink: #E8EDF4; --ink2: #CBD5E1; --muted: #9AA6B6;
    --line: #253244; --line2: #34445A; --accent: #6FA8E8; --accent-ink: #9CC4F0; --accent-soft: #19304C;
    --money-bg: #12382A; --money: #86D7AC; --warn-bg: #3A2614; --warn: #F5B67A; --ai-bg: #3A2416; --ai: #F5B67A;
    --chip: #1F2A3A; --chip-ink: #CBD5E1; --danger: #F59A93; --danger-bg: #3B1716; --seg: #1F2A3A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --on-accent: #0D141E; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0D141E; --surface: #151E2B; --ink: #E8EDF4; --ink2: #CBD5E1; --muted: #9AA6B6;
  --line: #253244; --line2: #34445A; --accent: #6FA8E8; --accent-ink: #9CC4F0; --accent-soft: #19304C;
  --money-bg: #12382A; --money: #86D7AC; --warn-bg: #3A2614; --warn: #F5B67A; --ai-bg: #3A2416; --ai: #F5B67A;
  --chip: #1F2A3A; --chip-ink: #CBD5E1; --danger: #F59A93; --danger-bg: #3B1716; --seg: #1F2A3A; --on-accent: #0D141E; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
svg.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 18px; height: 18px; }

/* ---------- shell ---------- */
.shell { min-height: 100%; display: flex; }
.sidenav { display: none; }
.view { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; padding-bottom: 84px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface); border-top: 1px solid var(--line); padding: 4px 4px calc(8px + env(safe-area-inset-bottom)); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 54px;
  color: var(--muted); font-size: 12px; font-weight: 600; text-decoration: none; position: relative; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.badge { position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: #C2410C; color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.topbar .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topbar h1 { font-size: 22px; font-weight: 700; }
.meta { font-size: 12px; color: var(--muted); }
.page { padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 12px; max-width: 900px; width: 100%; margin: 0 auto; }

/* ---------- controls ---------- */
.search { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 12px 0 14px; border: 1px solid var(--line2);
  border-radius: 12px; background: var(--surface); }
.search input { border: 0; outline: 0; flex: 1; min-width: 0; font-size: 16px; background: transparent; }
.search button { border: 0; background: transparent; color: var(--muted); min-width: 36px; height: 36px; border-radius: 8px; cursor: pointer; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 20px;
  border: 1px solid var(--line2); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip.money[aria-pressed="true"] { background: var(--money); border-color: var(--money); color: var(--surface); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line2); background: var(--surface); color: var(--ink); font-weight: 700;
  font-size: 15px; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ai { background: var(--ai-bg); border-color: transparent; color: var(--ai); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: .6; cursor: default; }
.btn.block { width: 100%; }
.linkbtn { border: 0; background: transparent; color: var(--accent); font-weight: 600; cursor: pointer; min-height: 44px; padding: 0 8px; }
.iconbtn { border: 0; background: transparent; color: var(--muted); width: 44px; height: 44px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.iconbtn[aria-pressed="true"] { color: var(--accent); }
.iconbtn[aria-pressed="true"] svg { fill: var(--accent-soft); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
input.input, select.input, textarea.input { height: 48px; padding: 0 12px; border: 1px solid var(--line2); border-radius: 10px;
  background: var(--surface); font-size: 16px; font-weight: 400; width: 100%; }
textarea.input { height: auto; min-height: 96px; padding: 12px; resize: vertical; line-height: 1.45; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; font-size: 15px; color: var(--ink2); cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); background: var(--seg); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { min-height: 42px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: 14px; color: var(--chip-ink); cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }
.error { padding: 10px 12px; border-radius: 10px; background: var(--danger-bg); color: var(--danger); font-size: 14px; font-weight: 600; }
.note { padding: 10px 12px; border-radius: 10px; background: var(--chip); color: var(--chip-ink); font-size: 14px; }

/* ---------- cards and tags ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card h2 { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.result { display: flex; flex-direction: column; gap: 8px; cursor: pointer; transition: border-color .15s; }
.result:hover { border-color: var(--line2); }
.result.selected { border: 2px solid var(--accent); padding: 13px; }
.result .title { font-size: 16px; font-weight: 600; line-height: 1.3; color: var(--ink); text-decoration: none; }
.result .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.result .head .iconbtn { margin: -10px -10px 0 0; }
.sub { font-size: 13px; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 4px 8px; border-radius: 6px; background: var(--chip); color: var(--chip-ink); font-size: 12px; font-weight: 700; line-height: 1.3; }
.tag.money { background: var(--money-bg); color: var(--money); }
.tag.country { background: var(--accent-soft); color: var(--accent-ink); }
.foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.fee { color: var(--ink2); font-weight: 600; }
.status { padding: 4px 10px; border-radius: 12px; font-size: 13px; font-weight: 700; white-space: nowrap; background: var(--chip); color: var(--chip-ink); }
.status.open { background: var(--accent); color: var(--on-accent); }
.status.upcoming { background: var(--warn-bg); color: var(--warn); }
.match { font-size: 13px; color: var(--muted); border-left: 3px solid var(--line); padding-left: 8px; }
.match b { color: var(--ink2); font-weight: 600; }
.list { display: flex; flex-direction: column; gap: 10px; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface), var(--chip), var(--surface)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- programme ---------- */
.prog { display: flex; flex-direction: column; gap: 14px; }
.prog h1 { font-size: 24px; line-height: 1.25; font-weight: 700; }
.statuscard { border-radius: var(--radius); padding: 14px; background: var(--chip); display: flex; flex-direction: column; gap: 4px; }
.statuscard.open { background: var(--accent-soft); color: var(--accent-ink); }
.statuscard.upcoming { background: var(--warn-bg); color: var(--warn); }
.statuscard strong { font-size: 15px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.fact span:first-child { font-size: 12px; color: var(--muted); }
.fact span:last-child { font-size: 15px; font-weight: 600; line-height: 1.3; }
.prose { font-size: 15px; line-height: 1.6; color: var(--ink2); overflow-wrap: anywhere; }
.prose p { margin: 0 0 10px; }
.prose ul, .prose ol { margin: 0 0 10px; padding-left: 20px; }
.prose li { margin-bottom: 4px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.kv > span:last-child { font-weight: 700; white-space: nowrap; }
.option { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; display: flex; flex-direction: column; gap: 10px; }
.option:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.doclist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.doclist li { display: flex; gap: 10px; align-items: flex-start; }
.actions { position: sticky; bottom: 72px; z-index: 10; display: flex; gap: 10px; padding: 10px 0; background: var(--bg); border-top: 1px solid var(--line); }
.hide-phone { display: none; }
.actions .btn { flex: 1; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--accent); min-height: 40px; display: flex; align-items: center; }

/* ---------- ask ---------- */
.ask-box { display: flex; flex-direction: column; gap: 10px; }
.qa { display: flex; flex-direction: column; gap: 10px; }
.qa .q { align-self: flex-end; max-width: 88%; background: var(--accent); color: var(--on-accent); padding: 10px 14px; border-radius: 16px 16px 4px 16px; font-weight: 600; }
.qa .a { background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.qa .who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ai); font-weight: 700; }
.cite { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 20px; padding: 0 5px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent-ink); font-size: 12px; font-weight: 700; text-decoration: none; vertical-align: 1px; }
.sources { display: flex; flex-direction: column; gap: 6px; }
.source { display: flex; gap: 8px; align-items: baseline; font-size: 14px; text-decoration: none; color: var(--ink2); }
.source b { color: var(--accent-ink); }

/* ---------- sheet (filters on phone/tablet) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(14, 26, 43, .45); z-index: 40; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 92vh; z-index: 41; background: var(--surface);
  border-radius: 20px 20px 0 0; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line2); margin: 8px auto 0; }
.sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 6px 20px; border-bottom: 1px solid var(--line); }
.sheet .sheet-body { overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 22px; }
.sheet .sheet-foot { padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; gap: 10px; }
.filters { display: flex; flex-direction: column; gap: 22px; }
.filters fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.filters legend { padding: 0; margin-bottom: 8px; font-size: 15px; font-weight: 700; }
.filters .wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.filters .grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.help { font-size: 13px; color: var(--muted); margin: 0; }
.filters .seg { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ---------- explore layout ---------- */
.explore { display: flex; flex: 1; min-height: 0; }
.explore .filters-col, .explore .detail-col { display: none; }
.explore .results-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.toolbar select { border: 0; background: transparent; font-weight: 700; color: var(--ink); font-size: 13px; min-height: 40px; cursor: pointer; }
.guides { display: flex; flex-direction: column; gap: 6px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .box { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 24px; }
.logo { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; }
.logo svg { width: 28px; height: 28px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--surface);
  padding: 12px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

/* ---------- tablet ---------- */
@media (min-width: 760px) {
  .tabbar { display: none; }
  .view { padding-bottom: 0; }
  .sidenav { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 76px; flex: none; position: sticky; top: 0; height: 100vh;
    background: var(--surface); border-right: 1px solid var(--line); padding: 14px 8px; }
  .sidenav .brand { margin-bottom: 10px; }
  .sidenav .brand span, .sidenav .saved { display: none; }
  .sidenav a.nav { width: 60px; min-height: 56px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none; position: relative; }
  .sidenav a.nav[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
  .sidenav .badge { top: 4px; left: 36px; }
  .sidenav .foot-meta { margin-top: auto; display: none; }
  .explore .results-col { flex: 0 0 420px; border-right: 1px solid var(--line); height: 100vh; overflow-y: auto; }
  .explore .detail-col { display: block; flex: 1; min-width: 0; height: 100vh; overflow-y: auto; background: var(--surface); }
  .explore .detail-col .page { max-width: 760px; }
  .actions { bottom: 0; }
  .facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .toast { bottom: 24px; }
  .hide-phone { display: inline; }
  .explore .detail-col .actions { background: var(--surface); }
  .sheet { left: auto; right: 24px; bottom: 24px; top: 24px; width: 420px; max-height: none; border-radius: 20px; }
  .sheet .grab { display: none; }
}

/* ---------- PC ---------- */
@media (min-width: 1200px) {
  .sidenav { width: 232px; align-items: stretch; padding: 18px 14px; }
  .sidenav .brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
  .sidenav .brand span { display: inline; font-size: 16px; font-weight: 700; }
  .sidenav a.nav { width: auto; min-height: 44px; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 0 10px; font-size: 15px; }
  .sidenav .badge { position: static; margin-left: auto; }
  .sidenav .saved { display: flex; flex-direction: column; gap: 2px; margin-top: 14px; }
  .sidenav .saved .label { padding: 0 10px 4px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
  .sidenav .saved a { display: block; padding: 9px 10px; border-radius: 8px; color: var(--ink2); font-size: 14px; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidenav .saved a:hover { background: var(--bg); }
  .sidenav .foot-meta { display: block; padding: 0 10px; font-size: 12px; color: var(--muted); }
  .explore .filters-col { display: block; flex: 0 0 292px; height: 100vh; overflow-y: auto; border-right: 1px solid var(--line); padding: 18px; }
  .explore .filters-btn { display: none; }
  .explore .results-col { flex: 1 1 460px; max-width: 640px; }
  .explore .detail-col { flex: 1 1 460px; }
}
