/* Qisi Tutor. Themes follow docs/design: Clean (light), Dark, Notebook (warm).
   "device" = Clean by day, Dark at night. */
:root, [data-theme="clean"] {
  --bg: #FFFFFF; --surface: #F8FAFC; --text: #0F172A; --muted: #475569; --soft-text: #334155;
  --line: #E2E8F0; --control-line: #CBD5E1; --tutor-bg: #F1F5F9; --tutor-text: #0F172A;
  --accent: #2563EB; --on-accent: #FFFFFF; --accent-soft: #EFF6FF; --accent-text: #1D4ED8;
  --warn-bg: #FFF7ED; --warn-line: #FDBA74; --warn-text: #9A3412;
  --radius: 12px; --line-w: 1px; --heading-font: 'Inter', system-ui, sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #121417; --surface: #1B1E23; --text: #E7E9EC; --muted: #A3A9B2; --soft-text: #C4C9D0;
  --line: #2C3138; --control-line: #2C3138; --tutor-bg: #23272D; --tutor-text: #E7E9EC;
  --accent: #2DD4BF; --on-accent: #0B1F1D; --accent-soft: #1B2B2A; --accent-text: #5EEAD4;
  --warn-bg: #2A1F17; --warn-line: #7C4A1E; --warn-text: #FDBA74;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  [data-theme="device"] {
    --bg: #121417; --surface: #1B1E23; --text: #E7E9EC; --muted: #A3A9B2; --soft-text: #C4C9D0;
    --line: #2C3138; --control-line: #2C3138; --tutor-bg: #23272D; --tutor-text: #E7E9EC;
    --accent: #2DD4BF; --on-accent: #0B1F1D; --accent-soft: #1B2B2A; --accent-text: #5EEAD4;
    --warn-bg: #2A1F17; --warn-line: #7C4A1E; --warn-text: #FDBA74;
    color-scheme: dark;
  }
}
[data-theme="notebook"] {
  --bg: #FBF7EF; --surface: #FFFDF8; --text: #292524; --muted: #57534E; --soft-text: #44403C;
  --line: #E7E0D2; --control-line: #D6CFC2; --tutor-bg: #FFFFFF; --tutor-text: #292524;
  --accent: #C2410C; --on-accent: #FFFFFF; --accent-soft: #FDE7D3; --accent-text: #9A3412;
  --radius: 14px; --line-w: 1.5px; --heading-font: 'Fraunces', Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 'Inter', system-ui, sans-serif;
  -webkit-text-size-adjust: 100%; }
a { color: var(--accent-text); }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; border: var(--line-w) solid var(--control-line);
  background: var(--bg); color: var(--text); display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; cursor: pointer; font-size: 15px; text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
.btn.icon { width: 44px; padding: 0; }
.btn:focus-visible, .chip:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; flex: none; }

/* ---- login / theme / simple pages ---- */
.narrow { max-width: 420px; margin: 0 auto; padding: 32px 16px; min-height: 100%; display: flex;
  flex-direction: column; gap: 20px; }
.narrow h1 { font: 700 24px/1.2 var(--heading-font); margin: 8px 0 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 500; color: var(--soft-text); }
.input { min-height: 48px; padding: 10px 14px; border-radius: 12px; border: var(--line-w) solid var(--control-line);
  background: var(--surface); width: 100%; }
textarea.input { min-height: 110px; resize: vertical; line-height: 1.5; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 56px; }
.pw-eye { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 48px; height: 44px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; display: flex;
  align-items: center; justify-content: center; border-radius: 10px; }
.pw-eye[aria-pressed="false"] .slash { display: none; }
.pw-eye[aria-pressed="true"] { color: var(--accent-text); }
.error { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-text);
  padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.ok { background: var(--accent-soft); color: var(--accent-text); padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.lang-switch { display: flex; gap: 8px; justify-content: flex-end; }
.lang-switch button { min-height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; }
.lang-switch button[aria-pressed="true"] { color: var(--accent-text); border-color: var(--accent); }

.theme-list { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.theme-opt { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 16px;
  border: 2px solid var(--line); background: var(--surface); cursor: pointer; }
.theme-opt:has(input:checked) { border-color: var(--accent); }
.theme-opt input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.swatch { width: 52px; height: 52px; border-radius: 10px; flex: none; display: flex; flex-direction: column;
  gap: 4px; padding: 8px; border: 1px solid var(--line); }
.swatch i { display: block; height: 7px; border-radius: 4px; }
.sw-device { background: linear-gradient(135deg, #FFFFFF 50%, #121417 50%); }
.sw-dark { background: #121417; } .sw-dark i { background: #2DD4BF; } .sw-dark i + i { background: #2C3138; }
.sw-clean { background: #FFFFFF; } .sw-clean i { background: #2563EB; } .sw-clean i + i { background: #E2E8F0; }
.sw-notebook { background: #FBF7EF; } .sw-notebook i { background: #C2410C; } .sw-notebook i + i { background: #E7E0D2; }
.theme-name { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft);
  color: var(--accent-text); }

/* ---- student chat ---- */
.chat { height: 100dvh; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who b { display: block; font: 700 16px/1.2 var(--heading-font); }
.who span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-actions { display: flex; gap: 6px; }
.chips { display: flex; gap: 8px; padding: 10px 16px; overflow-x: auto; scrollbar-width: none; flex: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; padding: 0 14px; border-radius: 20px; border: var(--line-w) solid var(--control-line);
  background: var(--bg); color: var(--soft-text); font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.chip.mode[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); }
.chips .sep { flex: none; width: 1px; background: var(--line); }
.tagline { margin: 0 16px; padding: 8px 12px; border-radius: 10px; background: var(--surface);
  border-left: 3px solid var(--accent); font-size: 13px; color: var(--muted); }
.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.msg.tutor { align-self: flex-start; background: var(--tutor-bg); color: var(--tutor-text);
  border-radius: 4px 16px 16px 16px; }
.msg.student { align-self: flex-end; background: var(--accent); color: var(--on-accent);
  border-radius: 16px 4px 16px 16px; }
.msg img { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; margin-bottom: 6px; }
.msg.note { align-self: center; max-width: 95%; background: transparent; color: var(--muted); font-size: 13px;
  text-align: center; padding: 4px 8px; }
.msg.typing { color: var(--muted); }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 280px; }
.compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg); }
.compose textarea { flex: 1; min-height: 44px; max-height: 140px; padding: 10px 16px; border-radius: 22px;
  border: var(--line-w) solid var(--control-line); background: var(--surface); resize: none; line-height: 1.4; }
.compose .send { border-radius: 50%; background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.preview-strip { display: flex; align-items: center; gap: 10px; padding: 8px 16px 0; }
.preview-strip img { height: 56px; border-radius: 8px; }
.menu { position: relative; }
.menu-pop { position: absolute; bottom: 52px; left: 0; z-index: 5; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 6px; display: flex; flex-direction: column;
  min-width: 250px; }
.menu-pop button { min-height: 44px; text-align: left; background: transparent; border: 0; padding: 0 12px;
  border-radius: 8px; cursor: pointer; }
.menu-pop button:hover { background: var(--surface); }
dialog { border: 0; border-radius: 16px; padding: 0; width: min(92vw, 420px); max-height: 80dvh;
  background: var(--bg); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--line); font-weight: 600; }
.dlg-body { padding: 8px; overflow-y: auto; max-height: 60dvh; display: flex; flex-direction: column; }
.dlg-body a, .dlg-body .row { display: flex; justify-content: space-between; gap: 8px; padding: 12px; border-radius: 10px;
  text-decoration: none; color: var(--text); min-height: 44px; align-items: center; }
.dlg-body a:hover { background: var(--surface); }

/* ---- parent ---- */
.parent { display: grid; grid-template-columns: 300px 1fr; min-height: 100dvh; }
.side { border-right: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 18px;
  background: var(--surface); }
.side h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.kid-btn { display: block; width: 100%; text-align: left; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); text-decoration: none; margin-bottom: 6px; }
.kid-btn[aria-current="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.conv-link { display: flex; flex-direction: column; padding: 10px 12px; border-radius: 10px; text-decoration: none;
  color: var(--text); }
.conv-link[aria-current="true"] { background: var(--accent-soft); }
.conv-link span:last-child { font-size: 13px; color: var(--muted); }
.flag { color: var(--warn-text); font-weight: 600; }
.main { padding: 20px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.card { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.card .big { font-size: 24px; font-weight: 700; }
.card label { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.searchbar { display: flex; gap: 8px; }
.transcript { border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.line { display: grid; grid-template-columns: 70px 1fr; gap: 10px; font-size: 15px; }
.line > span:first-child { font-size: 12px; font-weight: 600; color: var(--muted); padding-top: 3px; }
.line .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.line img { max-width: 260px; border-radius: 8px; display: block; margin-bottom: 4px; }
.blocked { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; padding: 10px 12px; }
.blocked > span:first-child { color: var(--warn-text); }
.blocked .draft { color: var(--soft-text); font-style: italic; margin-top: 6px; }
.keys { display: flex; gap: 8px; flex-wrap: wrap; } .keys img { height: 90px; border-radius: 8px; }
mark { background: #FDE68A; color: #111; border-radius: 3px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

/* settings */
.settings { max-width: 720px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-direction: column; gap: 20px; }
fieldset.box, .box { border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin: 0; display: flex;
  flex-direction: column; gap: 10px; }
.box legend, .box h2 { font-weight: 600; font-size: 16px; margin: 0; padding: 0 4px; }
.prog { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.prog label { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column;
  cursor: pointer; }
.prog label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.prog small, .hint { color: var(--muted); font-size: 13px; }
.lang-table { display: grid; grid-template-columns: 1fr 160px; gap: 8px 12px; align-items: center; }
.lang-table select, .box select { min-height: 44px; border-radius: 10px; border: 1px solid var(--control-line);
  background: var(--surface); padding: 0 10px; }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); }

/* admin */
table.plain { border-collapse: collapse; width: 100%; font-size: 14px; }
table.plain th, table.plain td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; }

.btn { white-space: nowrap; }
@media (max-width: 420px) {
  html[lang="fr"] .chat-head .lbl { display: none; }
  html[lang="fr"] #new-btn { width: 44px; padding: 0; }
}
@media (max-width: 800px) {
  .parent { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .cards { grid-template-columns: 1fr; }
  .line { grid-template-columns: 1fr; gap: 2px; }
  .prog { grid-template-columns: 1fr; }
  .lang-table { grid-template-columns: 1fr 130px; }
}
