:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1c2431;
  --muted: #6b7684;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --line: #e3e7ec;
  --err: #b3261e;
  --ok: #2f6f4f;
  --bot: #eef2f5;
  --student: #dcefe4;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 720px; margin: 0 auto; padding: 24px 16px 60px; }
header { text-align: center; margin-bottom: 20px; }
h1 { font-size: 24px; margin: 0; }
.sub { color: var(--muted); margin: 4px 0 0; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
h2 { font-size: 18px; margin: 0 0 14px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 0; }
input, select, textarea {
  width: 100%; margin-top: 6px; padding: 11px 12px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; font-family: inherit; }
button {
  margin-top: 14px; padding: 11px 16px; font-size: 15px; font-weight: 600;
  border: none; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  cursor: pointer;
}
button.ghost { background: #eef1f4; color: var(--ink); }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; }
.row button { flex: 0 0 auto; }
.hidden { display: none !important; }
.err { color: var(--err); font-size: 14px; min-height: 18px; margin: 8px 0 0; }
.ok { color: var(--ok); font-size: 14px; min-height: 18px; margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 6px; }
h2.tight { margin-bottom: 2px; }
.subnote { color: var(--muted); font-size: 13px; font-style: italic;
  margin: 0 0 16px; }
.confirm { font-size: 17px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab { margin: 0; flex: 1; background: #eef1f4; color: var(--ink); font-size: 13px; padding: 9px; }
.tab.active { background: var(--accent); color: #fff; }
.dhead { display: flex; justify-content: space-between; align-items: baseline; }
.turns { color: var(--muted); font-size: 13px; }
.limits { background: #fff7e6; border: 1px solid #f0e0b8; color: #6a5320;
  font-size: 13px; border-radius: 9px; padding: 9px 11px; margin: 4px 0 10px; }
.chat { position: relative; display: flex; flex-direction: column; gap: 10px; margin: 8px 0 14px; max-height: 52vh; overflow-y: auto; }
.bubble { padding: 10px 13px; border-radius: 12px; max-width: 85%; white-space: pre-wrap; }
.bubble.bot { background: var(--bot); align-self: flex-start; border-bottom-left-radius: 3px; }
.bubble.student { background: var(--student); align-self: flex-end; border-bottom-right-radius: 3px; }
.bubble .tag { display: inline-block; margin-top: 6px; margin-right: 6px; font-size: 11px;
  color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 1px 8px; }
.composer .row { margin-top: 4px; }
.ended { margin-top: 12px; padding: 14px; border-radius: 10px; background: #eef2f5;
  color: var(--ink); font-size: 15px; }
.feedback { margin-top: 12px; }
.feedback textarea { width: 100%; }
.mocknote { text-align: center; color: var(--muted); font-size: 12px; margin-top: 10px; }

/* ---------------- Phone-friendly (student side) ---------------- */
@media (max-width: 640px) {
  .wrap { padding: 14px 12px 48px; }
  h1 { font-size: 21px; }
  .card { padding: 16px; border-radius: 12px; }
  /* 16px inputs stop iOS Safari from auto-zooming on focus */
  input, select, textarea { font-size: 16px; padding: 12px; }
  button { font-size: 16px; padding: 13px 16px; width: 100%; }
  .row { flex-direction: column; }
  .row button { width: 100%; }
  .tabs { flex-direction: row; }
  .tab { font-size: 14px; }
  .chat { max-height: 60vh; }
  .bubble { max-width: 92%; }
  .dhead { flex-wrap: wrap; }
}

/* ---------------- Admin dashboard ---------------- */
body.admin { background: #eef1f4; }
.admin-wrap { max-width: 1180px; margin: 0 auto; padding: 20px 18px 80px; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 12px; }
.admin-head h1 { font-size: 22px; text-align: left; }
.admin-head .sub { text-align: left; }
.weekpick select { width: auto; display: inline-block; margin-left: 6px; }
.rosterbar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; margin: 4px 0 12px; }
.rosterbar .stat { font-weight: 600; }
.rosterbar .rosterupload { display: flex; gap: 8px; align-items: center; }
.rosterbar input[type=file] { width: auto; margin: 0; font-size: 13px; }
.rosterbar button { margin: 0; }
.rosterbar .hint { margin: 0; }
#roster-result.ok { color: var(--ok); font-size: 13px; }
#roster-result.err { color: var(--err); font-size: 13px; }
.weekbar { display: flex; gap: 18px; margin: 6px 0 14px; }
.weekbar .stat { background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; font-size: 14px; }
.tablewrap { background: #fff; border: 1px solid var(--line); border-radius: 12px;
  overflow: auto; }
table#report { width: 100%; border-collapse: collapse; font-size: 13px; }
table#report th, table#report td { padding: 8px 9px; text-align: left;
  border-bottom: 1px solid var(--line); white-space: nowrap; }
table#report th { background: #f6f8fa; position: sticky; top: 0; font-weight: 600; }
table#report th.sortable { cursor: pointer; user-select: none; }
table#report th.sortable:hover { background: #eef2f5; }
table#report th.sort-asc::after { content: " ▲"; font-size: 10px; color: var(--muted); }
table#report th.sort-desc::after { content: " ▼"; font-size: 10px; color: var(--muted); }
table#report.hide-sec .secth, table#report.hide-sec .seccol { display: none; }
table#report tr.dim td { color: #97a1ad; }
.tablecontrols { display: flex; gap: 16px; align-items: center; margin: 4px 0 8px; }
.tablecontrols label { margin: 0; color: var(--ink); font-size: 14px; }
.tablecontrols select { width: auto; display: inline-block; margin: 0 0 0 6px; }
.tablecontrols .hint { margin: 0; }
.pill { display: inline-block; font-size: 11px; background: #eef2f5;
  border: 1px solid var(--line); border-radius: 20px; padding: 0 7px; color: var(--ink); }
.pill.warn { background: #fdecea; border-color: #f2c4bd; color: #9b2c22; }
.pill.ok { background: #e8f3ec; border-color: #bfe0cc; color: #2f6f4f; }
button.link { margin: 0; background: none; color: var(--accent); padding: 2px 4px;
  font-size: 13px; text-decoration: underline; }
.reading-panel { background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 16px; margin: 0 0 14px; }
.reading-panel h3 { margin: 0 0 8px; font-size: 15px; }
.reading-display { white-space: pre-wrap; font-size: 14px; line-height: 1.5; }
.reading-display.muted { color: var(--muted); font-style: italic; }
.grounding { background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; margin: 0 0 14px; }
.grounding h3 { margin: 0 0 4px; font-size: 15px; }
.grounding .groundlist { margin: 6px 0 0; padding-left: 18px; }
.grounding .groundlist li { margin: 3px 0; }
.missing { background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-top: 16px; }
.missing h3 { margin: 0 0 6px; font-size: 16px; }
.missing ul { margin: 6px 0 0; padding-left: 18px; }
.missing li { margin: 3px 0; }

.overlay { position: fixed; inset: 0; background: rgba(20,28,38,.45);
  display: flex; justify-content: flex-end; z-index: 50; }
.drawer { background: #fff; width: min(760px, 94vw); height: 100%; overflow-y: auto;
  padding: 22px 24px 60px; box-shadow: -4px 0 24px rgba(0,0,0,.15); }
.drawer .close { position: sticky; top: 0; float: right; }
.drawer h2 { margin: 0 0 12px; }
.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; margin-bottom: 16px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13px;
  border-bottom: 1px dotted var(--line); padding: 3px 0; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; }
.notesimg img { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; }
.drawer .chat { max-height: none; }
.btags { margin-top: 5px; }
.retr { align-self: flex-end; max-width: 85%; margin: -4px 0 4px; font-size: 12px; }
.retr summary { cursor: pointer; color: var(--muted); }
.retr-item { border-left: 2px solid var(--line); padding: 3px 0 3px 8px; margin: 5px 0; }
.retr-snip { color: var(--muted); font-style: italic; margin-top: 2px; }
