:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --text: #1c1a22;
  --muted: #625e6b;
  --line: #e4ded3;
  --accent: #d9501e;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --ok: #1b7a43;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15141a;
    --surface: #211f27;
    --text: #f2f0f5;
    --muted: #a9a5b2;
    --line: #38353f;
    --accent: #ff7a45;
    --accent-text: #1c1a22;
    --danger: #ff8a80;
    --ok: #6fd69b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { margin: 0; font-size: 24px; }
h2 { margin: 0 0 16px; font-size: 22px; }
h3 { margin: 28px 0 12px; font-size: 16px; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }

button, input, select { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
  max-width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label input, label select { color: var(--text); font-size: 15px; }

button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.link { background: none; border: none; color: var(--muted); }
button.danger { color: var(--danger); }
button.small { padding: 4px 8px; font-size: 13px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { display: grid; gap: 14px; width: min(360px, 100%); }
.login p { margin: 0; }
.login input { width: 100%; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.top nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.top nav button { background: none; border-color: transparent; }
.top nav button.current { background: var(--bg); border-color: var(--line); font-weight: 600; }

.content { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }
.tab { display: none; }
.tab.current { display: block; }

.message { margin: 0 0 16px; padding: 10px 14px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.message.bad { color: var(--danger); }

.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 16px; }
.grow { flex: 1 1 200px; }
.grow input { width: 100%; }
#user-query { flex: 1 1 240px; }

.update-form { display: grid; gap: 12px; max-width: 640px; }
.update-form p { margin: 0; }
.update-form .row { margin: 0; }
textarea { width: 100%; color: var(--text); }
a { color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
td.actions { display: flex; flex-wrap: wrap; gap: 6px; }
td input { width: 96px; }
td input.wide { width: 140px; }
.code { font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.state-ok { color: var(--ok); }
.state-bad { color: var(--danger); }
.state-off { color: var(--muted); }

.turns { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.turn { max-width: 720px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.turn p { margin: 4px 0; overflow-wrap: anywhere; }
.turn-learner { align-self: flex-end; }
.turn-teacher { align-self: flex-start; }
.turn-correction { color: var(--ok); }
.turn-note { color: var(--danger); }
.note-form { margin: 8px 0 0; }
.analysis { margin-top: 12px; }
.analysis h4 { margin: 0 0 8px; }
.issue { padding: 8px 0; border-top: 1px solid var(--line); }
.issue p { margin: 4px 0; overflow-wrap: anywhere; }
