:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1a2233;
  --muted: #6b7280;
  --line: #e6e9f0;
  --brand: #2563eb;
  --brand-soft: #dbe4ff;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.06), 0 6px 20px rgba(20, 30, 60, 0.05);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.boot {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

button { font-family: inherit; cursor: pointer; }

.btn {
  border: none;
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.92rem;
}
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: #eef1f7; color: var(--ink); }
.btn.danger { background: #fdeaea; color: var(--red); }
.btn.small { padding: 6px 10px; font-size: 0.82rem; border-radius: 8px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 40px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.login-card .logo {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--brand-soft); color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.6rem; margin-bottom: 16px;
}
.login-card h1 { font-size: 1.4rem; margin: 0 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 24px; font-size: 0.92rem; }
.google-btn {
  display: inline-flex; align-items: center; gap: 10px;
  background: #fff; border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 10px; font-weight: 600; color: var(--ink);
  width: 100%; justify-content: center;
}
.google-btn:hover { background: #fafbff; }
.notice { margin-top: 16px; font-size: 0.86rem; }
.notice.error { color: var(--red); }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: var(--card); border-right: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.brand b { font-size: 1rem; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; color: var(--muted); font-weight: 600; font-size: 0.9rem;
  background: none; border: none; width: 100%; text-align: left;
}
.nav-item:hover { background: #f3f5fa; color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); }
.nav-spacer { flex: 1; }
.who { padding: 10px 12px; border-top: 1px solid var(--line); margin-top: 8px; display: flex; align-items: center; gap: 10px; }
.who .who-av { width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; object-fit: cover; }
.who .who-av.av-fallback { background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.8rem; }
.who .who-meta { min-width: 0; }
.who .name { font-weight: 600; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .email { font-size: 0.74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .role { font-size: 0.72rem; color: var(--brand); text-transform: capitalize; font-weight: 600; }

.main { flex: 1; padding: 28px 34px; max-width: 1180px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 1.35rem; }
.page-head .sub { color: var(--muted); font-size: 0.9rem; margin-top: 2px; }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px;
}
.grid { display: grid; gap: 16px; }
.stat-row { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 20px; }
.stat .label { color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.stat .value { font-size: 1.9rem; font-weight: 800; margin-top: 4px; }
.stat .value small { font-size: 0.95rem; font-weight: 600; color: var(--muted); }

.two-col { grid-template-columns: 1.4fr 1fr; align-items: start; }
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .sidebar { width: 64px; }
  .brand b, .nav-item span, .who { display: none; }
  .main { padding: 20px 16px; }
}

h3.card-title { margin: 0 0 14px; font-size: 1rem; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; font-size: 0.9rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tr.clickable:hover td { background: #f7f9fd; cursor: pointer; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 0.74rem; font-weight: 700; }
.pill.green { background: #e6f6ec; color: var(--green); }
.pill.gray { background: #eef0f4; color: var(--muted); }
.pill.red { background: #fdeaea; color: var(--red); }
.pill.amber { background: #fdf3e3; color: var(--amber); }

/* ---------- Bars ---------- */
.bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 9px; }
.bar-row .name { width: 190px; font-size: 0.86rem; flex-shrink: 0; }
.bar-track { flex: 1; height: 9px; background: #eef0f5; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--brand); }
.bar-row .pct { width: 42px; text-align: right; font-size: 0.84rem; font-weight: 700; color: var(--muted); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="email"], textarea, select {
  font-family: inherit; font-size: 0.92rem; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
  width: 100%;
}
textarea { min-height: 92px; resize: vertical; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin-bottom: 0; flex: 1; min-width: 180px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: #eef1f7; border-radius: 999px; padding: 5px 12px; font-size: 0.84rem;
  display: inline-flex; align-items: center; gap: 8px;
}
.chip.weak { background: #fdeaea; color: var(--red); }
.chip.strong { background: #e6f6ec; color: var(--green); }

.empty { color: var(--muted); font-size: 0.9rem; padding: 20px 0; text-align: center; }
.back-link { background: none; border: none; color: var(--brand); font-weight: 600; padding: 0; margin-bottom: 12px; font-size: 0.88rem; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1a2233; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 0.88rem; box-shadow: var(--shadow); z-index: 50; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--red); }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem;
  flex-shrink: 0;
}
img.avatar.av-img { object-fit: cover; background: none; }
.avatar.sm { width: 32px; height: 32px; font-size: 0.8rem; }
.student-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }

/* Breadcrumb */
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; font-size: 0.86rem; }
.crumbs .crumb { background: none; border: none; padding: 0; cursor: pointer; color: var(--brand); font-weight: 600; font-size: inherit; }
.crumbs .crumb:hover { text-decoration: underline; }
.crumbs .crumb.current { color: var(--muted); font-weight: 600; cursor: default; }
.crumbs .crumb-sep { color: var(--muted); }

/* Clickable chapter rows on the student page */
.bar-row.bar-click { cursor: pointer; padding: 5px 8px; margin: 0 -8px 4px; border-radius: 8px; transition: background .12s; }
.bar-row.bar-click:hover { background: #f2f6ff; }
.bar-row .bar-caret { width: 14px; text-align: right; color: var(--muted); font-weight: 700; }

/* Per-topic mini accuracy bar in the chapter breakdown table */
.mini-bar { display: inline-block; vertical-align: middle; width: 90px; height: 8px; background: #eef0f5; border-radius: 999px; overflow: hidden; }
.mini-fill { height: 100%; border-radius: 999px; }
.mini-pct { margin-left: 8px; font-size: 0.82rem; font-weight: 700; color: var(--muted); vertical-align: middle; }

.hint { color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.name-cell { display: flex; align-items: center; gap: 10px; }

/* Chapter / subtopic tile grid (Questions browser) */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tile { display: flex; align-items: center; gap: 12px; text-align: left; background: #f7f9fd; border: 1px solid var(--line); border-radius: 12px; padding: 14px; cursor: pointer; transition: background .12s, border-color .12s; }
.tile:hover { background: #eef4ff; border-color: var(--brand-soft); }
.tile-id { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.tile-body { flex: 1; min-width: 0; }
.tile-name { font-weight: 600; font-size: 0.92rem; }
.tile-sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.tile-caret { color: var(--muted); font-weight: 700; }

/* Question bank items */
.qitem-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.qitem-actions { margin-left: auto; display: flex; gap: 8px; }
.qitem-q { font-size: 0.95rem; line-height: 1.5; }
.row-actions { display: flex; gap: 10px; margin-top: 14px; }

/* Study-streak calendar (matches the app) */
.cal-topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.cal-nav { display: flex; align-items: center; gap: 10px; }
.cal-month { font-size: 0.88rem; font-weight: 700; color: var(--muted); min-width: 130px; text-align: center; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.cal-leg { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--muted); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head { margin-bottom: 4px; }
.cal-wd { text-align: center; font-size: 0.72rem; color: var(--muted); font-weight: 700; }
.cal-cell { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 5px 0; border-radius: 8px; }
.cal-cell.empty { visibility: hidden; }
.cal-cell.today { background: #eef4ff; }
.cal-cell.today .cal-day { color: var(--brand); font-weight: 700; }
.cal-day { font-size: 0.78rem; }
.cal-dot { width: 13px; height: 13px; border-radius: 50%; background: var(--line); flex-shrink: 0; }
.cal-dot.cal-5 { background: #16a34a; }
.cal-dot.cal-4 { background: #2563eb; }
.cal-dot.cal-3 { background: #eab308; }
.cal-dot.cal-2 { background: #f97316; }
.cal-dot.cal-1 { background: #dc2626; }
.cal-dot.cal-0 { background: #7f1d1d; }
.cal-dot.cal-none { background: var(--line); }

/* Support ticket comment thread */
.comment-thread { display: flex; flex-direction: column; gap: 12px; }
.comment { padding: 10px 12px; background: #f8f9fb; border: 1px solid var(--line); border-radius: 10px; }
.comment .list-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }

/* List range label + pagination */
.list-head { margin-bottom: 10px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 14px; }
.pager-info { font-size: 0.84rem; color: var(--muted); font-weight: 600; }
.btn.small[disabled] { opacity: 0.45; cursor: default; pointer-events: none; }

/* App-style strengths / weaknesses lists in the chapter detail */
.sw-block { margin-bottom: 14px; }
.sw-block:last-child { margin-bottom: 0; }
.sw-head { font-weight: 700; font-size: 0.9rem; margin-bottom: 6px; }
.sw-head.strong { color: var(--green); }
.sw-head.weak { color: var(--red); }
.sw-list { list-style: none; margin: 0; padding: 0; }
.sw-list li { padding: 3px 0 3px 18px; position: relative; font-size: 0.9rem; }
.sw-list li::before { content: "•"; position: absolute; left: 3px; color: var(--muted); }

/* Per-question practice session review */
.qa-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.qa-num { font-weight: 700; color: var(--muted); font-size: 0.85rem; }
.qa-question { font-weight: 600; font-size: 0.98rem; line-height: 1.5; margin-bottom: 12px; }
.qa-row { margin-top: 10px; }
.qa-label { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 700; margin-bottom: 3px; }
.qa-value { font-size: 0.92rem; line-height: 1.5; }

/* Rendered Markdown blocks (questions / feedback / solutions) */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md ol, .md ul { margin: 6px 0; padding-left: 24px; }
.md li { margin: 3px 0; }
.md code { background: #eef0f4; padding: 1px 5px; border-radius: 5px; font-size: 0.9em; }
.md .md-h { font-size: 0.95rem; margin: 10px 0 6px; }
.qa-value.answer { padding: 8px 11px; border-radius: 8px; background: #f4f6fb; border: 1px solid var(--line); }
.qa-value.answer.ok { background: #e6f6ec; border-color: #bce7cc; }
.qa-value.answer.wrong { background: #fdeaea; border-color: #f4c9c9; }
.qa-value.feedback { padding: 8px 11px; border-radius: 8px; background: #eff4ff; border: 1px solid var(--brand-soft); }
.qa-solution { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.qa-solution summary { cursor: pointer; font-weight: 700; font-size: 0.85rem; color: var(--brand); }
.qa-value.sol { margin-top: 10px; color: var(--ink); }

.section-gap { margin-top: 20px; }
.muted { color: var(--muted); }
.right { text-align: right; }
