:root {
  --navy: #1F3864; --navy-deep: #16294A; --navy-ink: #1F2A3C;
  --gold: #C9A227; --gold-soft: #F6EED6;
  --paper: #F3F4F7; --white: #FFFFFF; --line: #D9DEE6; --line-soft: #ECEFF3;
  --muted: #5F6B7A; --danger: #B03A2E; --ok: #2E7D4F;
  --font: "Microsoft JhengHei", "微軟正黑體", "PingFang TC", "Noto Sans TC", "Heiti TC", system-ui, sans-serif;
  --rail: 208px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; line-height: 1.55; color: var(--navy-ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: 0; }
h1 { font-size: 22px; line-height: 1.3; }
h2 { font-size: 16px; color: var(--navy); padding-bottom: 6px; border-bottom: 1.5px solid var(--navy); margin-bottom: 12px; }
h3 { font-size: 14px; color: var(--navy); margin-bottom: 6px; }
p { margin: 0 0 8px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- layout ---------- */
.app { min-height: 100%; }
.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }
.rail { background: var(--navy); color: #fff; padding: 22px 0 16px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { padding: 0 22px 18px; border-bottom: 1px solid rgba(255,255,255,.14); margin-bottom: 10px; }
.brand b { display: block; font-size: 17px; font-weight: 600; letter-spacing: .5px; }
.brand span { display: block; font-size: 12px; opacity: .72; margin-top: 2px; }
.nav { display: flex; flex-direction: column; }
.nav a { color: #fff; padding: 9px 22px; border-left: 3px solid transparent; opacity: .82; }
.nav a:hover { opacity: 1; text-decoration: none; background: rgba(255,255,255,.06); }
.nav a.on { border-left-color: var(--gold); opacity: 1; background: rgba(255,255,255,.09); font-weight: 600; }
.rail-foot { margin-top: auto; padding: 14px 22px 0; font-size: 12px; opacity: .8; border-top: 1px solid rgba(255,255,255,.14); }
.rail-foot button { background: none; border: 0; color: #fff; padding: 0; cursor: pointer; text-decoration: underline; opacity: .9; }
.main { padding: 28px 32px 60px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.section { margin-bottom: 30px; }
.empty { color: var(--muted); padding: 14px 0; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; padding: 0; flex-direction: row; z-index: 20; }
  .brand, .rail-foot { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav a { border-left: 0; border-top: 3px solid transparent; padding: 8px 6px 10px; font-size: 12px; text-align: center; flex: 1; }
  .nav a.on { border-top-color: var(--gold); }
  .nav a.more-only { display: none; }
  .main { padding: 18px 16px 90px; }
  .grid2 { grid-template-columns: 1fr; gap: 18px; }
}
@media (min-width: 901px) { .nav a.mobile-only { display: none; } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-box { width: 100%; max-width: 380px; background: var(--white); border-top: 4px solid var(--navy); padding: 30px 32px 28px; }
.login-box b { display: block; font-size: 20px; color: var(--navy); }
.login-box .tag { color: var(--muted); font-size: 13px; margin-bottom: 22px; }

/* ---------- controls ---------- */
.btn { border: 1px solid var(--navy); background: var(--navy); color: #fff; padding: 7px 14px; border-radius: 3px; cursor: pointer; font-size: 13.5px; }
.btn:hover { background: var(--navy-deep); }
.btn.ghost { background: transparent; color: var(--navy); }
.btn.ghost:hover { background: rgba(31,56,100,.06); }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.danger:hover { background: rgba(176,58,46,.06); }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; padding: 7px 9px; border-radius: 3px; }
textarea { min-height: 74px; resize: vertical; }
label.f { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters > * { width: auto; min-width: 140px; }
.filters input[type=search] { min-width: 200px; }
.check { display: inline-flex; align-items: center; gap: 6px; }
.check input { width: auto; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; background: var(--white); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 600; color: var(--navy); background: #F7F8FB; padding: 9px 10px; border-bottom: 1.5px solid var(--navy); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #FBFAF4; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
tfoot td { font-weight: 600; border-top: 1.5px solid var(--navy); background: #F7F8FB; }
.pre { white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.gold { color: #8C6E12; }
.unpaid { color: #8C6E12; font-weight: 600; box-shadow: inset 0 -2px 0 var(--gold); }

/* status chips */
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 2px; border: 1px solid var(--line); white-space: nowrap; }
.chip.在讀 { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip.已簽約待開課 { background: var(--gold-soft); border-color: var(--gold); color: #6E5510; }
.chip.方案階段, .chip.待確認 { background: #fff; color: var(--muted); }
.chip.已完結 { background: var(--line-soft); color: var(--muted); border-color: var(--line-soft); }
.chip.paid { background: #E8F3EC; color: var(--ok); border-color: #CFE6D7; }
.chip.due { background: var(--gold-soft); color: #6E5510; border-color: var(--gold); }
.chip.done { background: var(--line-soft); color: var(--muted); }

/* ---------- dashboard ---------- */
.today { display: grid; grid-template-columns: 120px 1fr; gap: 24px; background: var(--white); border: 1px solid var(--line); border-left: 4px solid var(--navy); padding: 20px 24px; margin-bottom: 28px; }
.today .date b { display: block; font-size: 40px; line-height: 1; color: var(--navy); font-weight: 600; }
.today .date span { display: block; color: var(--muted); font-size: 13px; margin-top: 6px; }
.today ul { list-style: none; margin: 0; padding: 0; }
.today li { display: grid; grid-template-columns: 90px 1fr auto; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); align-items: baseline; }
.today li:last-child { border-bottom: 0; }
.today li .t { color: var(--muted); font-size: 13px; }
.today li .who { font-weight: 600; }
.today li .who span { font-weight: 400; color: var(--muted); }
@media (max-width: 600px) { .today { grid-template-columns: 1fr; gap: 10px; } .today li { grid-template-columns: 1fr; gap: 2px; } }
.statline { display: flex; gap: 28px; flex-wrap: wrap; color: var(--muted); font-size: 13.5px; margin-bottom: 26px; }
.statline b { color: var(--navy-ink); font-size: 18px; font-weight: 600; margin-right: 4px; }
.duelist { list-style: none; margin: 0; padding: 0; }
.duelist li { display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.duelist li .d { color: var(--muted); font-size: 13px; white-space: nowrap; }
.duelist li.over .d { color: var(--danger); font-weight: 600; }

/* ---------- student detail ---------- */
.stu-head { background: var(--white); border: 1px solid var(--line); border-top: 4px solid var(--navy); padding: 20px 24px; margin-bottom: 24px; }
.stu-head .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; }
.kv dd:empty::before { content: '—'; color: var(--line); }
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.subtabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); margin-bottom: -1px; }
.subtabs button.on { color: var(--navy); border-bottom-color: var(--gold); font-weight: 600; }

/* ---------- dialog / toast ---------- */
.dlg { border: 0; padding: 0; width: min(720px, 94vw); max-height: 92vh; background: var(--white); border-top: 4px solid var(--navy); }
.dlg::backdrop { background: rgba(22,41,74,.45); }
.dlg form { padding: 22px 26px 20px; overflow-y: auto; max-height: 92vh; }
.dlg h2 { border-bottom: 0; margin-bottom: 14px; font-size: 18px; }
.dlg .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.err { color: var(--danger); font-size: 13px; margin: 6px 0 0; min-height: 18px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--navy-ink); color: #fff; padding: 9px 16px; border-radius: 3px; font-size: 13.5px; z-index: 50; }
@media (max-width: 900px) { .toast { bottom: 84px; } }
