/* Thai flag colours, matching mobile/src/theme.js */
:root {
  --blue: #2d2a4a;
  --blue-dark: #1a1830;
  --blue-light: #e4e3ef;
  --red: #a51931;
  --red-dark: #7a1124;
  --red-light: #f9e1e5;
  --white: #f4f5f8;
  --text: #2b2a33;
  --muted: #6e6d78;
  --faint: #aaa9b3;
  --border: #e3e3ea;
  --bg: #ffffff;
  --panel: #f7f7fa;
  --ok: #2e7d4f;
  --radius: 10px;
  font-family: system-ui, -apple-system, 'Segoe UI', 'Noto Sans Thai', sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, textarea { font: inherit; color: inherit; }

/* ---------- Buttons ---------- */
.btn {
  border: 2px solid var(--border);
  background: #fff;
  border-radius: var(--radius);
  padding: 7px 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { color: var(--red); }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.small { padding: 3px 8px; font-size: 13px; border-width: 1px; }
.icon-btn {
  border: none; background: none; cursor: pointer; padding: 2px 5px; border-radius: 6px;
  color: var(--muted); font-size: 14px; line-height: 1;
}
.icon-btn:hover { background: var(--blue-light); color: var(--blue); }
.icon-btn:disabled { visibility: hidden; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(var(--red) 0 16.6%, var(--white) 16.6% 33.3%, var(--blue) 33.3% 66.6%, var(--white) 66.6% 83.3%, var(--red) 83.3%);
}
.login-card {
  background: #fff; border-radius: 18px; padding: 32px; width: 100%; max-width: 400px; text-align: center;
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.25);
}
.login-card img { width: 96px; height: 96px; border-radius: 24px; }
.login-card h1 { color: var(--blue); margin: 14px 0 4px; }
.login-card p { color: var(--muted); margin: 6px 0 20px; line-height: 1.5; }
.login-card .btn { width: 100%; padding: 12px; }
.login-card .field { text-align: left; }
.login-card .login-error { color: var(--red); font-weight: 700; min-height: 1.4em; margin: 4px 0 12px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-rows: auto 6px 1fr; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 18px; }
.topbar img { width: 36px; height: 36px; border-radius: 9px; }
.topbar .brand { font-weight: 900; color: var(--blue); font-size: 18px; }
.topbar .spacer { flex: 1; }
.chip { background: var(--panel); border-radius: 999px; padding: 4px 11px; font-size: 13px; color: var(--muted); }
.chip b { color: var(--text); }
.flag { background: linear-gradient(var(--red) 0 16.6%, var(--white) 16.6% 33.3%, var(--blue) 33.3% 66.6%, var(--white) 66.6% 83.3%, var(--red) 83.3%); }
.main { display: grid; grid-template-columns: 320px 1fr; min-height: 0; }

/* ---------- Sidebar ---------- */
.sidebar { border-right: 2px solid var(--border); overflow-y: auto; padding: 12px 10px 40px; background: var(--panel); }
.side-section { font-size: 12px; font-weight: 800; letter-spacing: 0.06em; color: var(--faint); margin: 14px 8px 6px; }
.unit { margin-bottom: 4px; }
.row {
  display: flex; align-items: center; gap: 4px; padding: 5px 6px; border-radius: 8px; cursor: pointer;
}
.row:hover { background: #fff; }
.row.active { background: var(--blue); color: #fff; }
.row.active .icon-btn { color: #fff; }
.row.active .icon-btn:hover { background: rgb(255 255 255 / 0.15); }
.row .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unit > .row .label { font-weight: 800; }
.row .num { font-size: 12px; color: var(--faint); min-width: 26px; }
.row.active .num { color: rgb(255 255 255 / 0.7); }
.lessons { margin-left: 14px; }
.warn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex: none; }
.add-link { font-size: 13px; color: var(--blue); padding: 4px 8px; cursor: pointer; border: none; background: none; font-weight: 700; }
.add-link:hover { text-decoration: underline; }

/* ---------- Content ---------- */
.content { overflow-y: auto; padding: 22px 28px 60px; }
.content h2 { margin: 0 0 4px; color: var(--blue); }
.crumbs { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.card { border: 2px solid var(--border); border-radius: 14px; padding: 16px 18px; margin-bottom: 18px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 700; color: var(--muted); }
input.text, textarea.text {
  border: 2px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; background: #fff;
}
input.text:focus, textarea.text:focus { outline: none; border-color: var(--blue); }
input.thai { font-size: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dirty { color: var(--red); font-weight: 700; font-size: 13px; }

table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: 12px; color: var(--faint); font-weight: 800; letter-spacing: 0.04em; padding: 4px 6px; }
table.grid td { padding: 3px 4px; vertical-align: top; }
table.grid td.tools { white-space: nowrap; width: 1%; padding-top: 9px; }
table.grid td.idx { width: 1%; color: var(--faint); font-size: 12px; padding-top: 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tok { font-size: 13px; padding: 1px 7px; border-radius: 6px; background: var(--blue-light); color: var(--blue); }
.tok.bad { background: var(--red-light); color: var(--red-dark); font-weight: 700; }

.problems { border: 2px solid var(--red-light); background: #fff8f9; border-radius: 12px; padding: 10px 14px; margin-bottom: 18px; }
.problems h3 { color: var(--red); margin: 0 0 6px; font-size: 15px; }
.problems ul { margin: 0; padding-left: 18px; }
.problems li { margin: 3px 0; }
.ok-note { color: var(--ok); font-weight: 700; font-size: 14px; }

.ex { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.ex .type { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; color: #fff; background: var(--blue); border-radius: 5px; padding: 2px 6px; margin-right: 8px; }
.ex .opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.ex .opt { border: 1px solid var(--border); border-radius: 7px; padding: 2px 8px; font-size: 14px; }
.ex .opt.correct { border-color: var(--ok); color: var(--ok); font-weight: 700; }

.empty { color: var(--muted); text-align: center; margin-top: 18vh; }
.empty img { width: 120px; border-radius: 28px; opacity: 0.9; }

/* ---------- Toast & modal ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--blue); color: #fff;
  padding: 10px 18px; border-radius: 10px; font-weight: 700; box-shadow: 0 6px 20px rgb(0 0 0 / 0.2); z-index: 20;
}
.toast.error { background: var(--red); }
.modal-bg { position: fixed; inset: 0; background: rgb(20 18 40 / 0.45); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 20px; }
.modal { background: #fff; border-radius: 16px; padding: 22px; max-width: 440px; width: 100%; }
.modal h3 { margin: 0 0 8px; }
.modal p { color: var(--muted); margin: 0 0 18px; line-height: 1.5; }
.modal .actions { justify-content: flex-end; }

@media (max-width: 800px) {
  .main { grid-template-columns: 1fr; }
  .sidebar { max-height: 40vh; border-right: none; border-bottom: 2px solid var(--border); }
  .topbar .chip { display: none; }
}
