:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #1b2030;
  --muted: #62697d;
  --border: #dde1ea;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --accent-soft: #e5ecfc;
  --ok: #1d8a52;
  --ok-soft: #e1f4ea;
  --bad: #c2372f;
  --bad-soft: #fbe7e5;
  --warn-soft: #fff4dc;
  --warn-ink: #7a5300;
  --exam: #c2372f;
  --project: #7b45c9;
  --assignment: #2f5bd3;
  --quiz: #c27a12;
  --reading: #1d8a52;
  --other: #62697d;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(20 30 60 / 6%), 0 4px 16px rgb(20 30 60 / 6%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151d;
    --surface: #1a1e29;
    --surface-2: #232837;
    --text: #e6e9f2;
    --muted: #9aa1b5;
    --border: #2e3446;
    --accent: #6b8ff0;
    --accent-ink: #0d1220;
    --accent-soft: #233056;
    --ok: #4cc488;
    --ok-soft: #173326;
    --bad: #f0786f;
    --bad-soft: #3a1f1d;
    --warn-soft: #3a2f14;
    --warn-ink: #f2cf7c;
    --exam: #f0786f;
    --project: #b58cf2;
    --assignment: #6b8ff0;
    --quiz: #e8a94a;
    --reading: #4cc488;
    --other: #9aa1b5;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

button { font: inherit; cursor: pointer; border-radius: 8px; }
button:disabled { opacity: .55; cursor: wait; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; padding: 8px 16px; font-weight: 600; }
.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); padding: 7px 12px; font-size: 14px; border-radius: 8px; }
.ghost:hover { background: var(--surface-2); }
.link { background: none; border: 0; color: var(--accent); padding: 0; font-size: 13px; }
.icon { background: none; border: 0; color: var(--muted); font-size: 20px; line-height: 1; padding: 4px 8px; }
.icon:hover { color: var(--bad); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.pad { padding: 24px; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.sub { margin: 0; font-size: 13px; color: var(--muted); }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: minmax(340px, 1fr) minmax(380px, 1.15fr); gap: 16px; padding: 16px; min-height: 0; }
.chat, .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

/* chat */
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.welcome { color: var(--muted); padding: 8px 4px; }
.welcome h2 { color: var(--text); margin: 0 0 6px; font-size: 20px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; overflow-wrap: anywhere; }
.msg p { margin: 0 0 6px; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 4px 0 6px; padding-left: 20px; }
.msg code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.model { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.error { background: var(--bad-soft); color: var(--bad); }
.att { font-size: 12px; opacity: .85; margin-bottom: 4px; }
.trace { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.chip { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 99px; }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.thinking { display: flex; gap: 5px; padding: 14px; }
.thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.thinking span:nth-child(2) { animation-delay: .2s; }
.thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { width: 100%; resize: vertical; min-height: 52px; max-height: 220px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.composer-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.file-btn { cursor: pointer; display: inline-block; }
.attachment { display: flex; gap: 10px; align-items: center; font-size: 13px; background: var(--accent-soft); color: var(--accent); padding: 6px 10px; border-radius: 8px; }
.attachment[hidden] { display: none; }

/* tabs */
.tabs { display: flex; gap: 4px; padding: 8px 8px 0; border-bottom: 1px solid var(--border); }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 14px 10px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.badge { background: var(--surface-2); color: var(--muted); font-size: 12px; padding: 0 7px; border-radius: 99px; }
.dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; }
.dot[hidden] { display: none; }
.tabpane { flex: 1; overflow-y: auto; padding: 12px 16px 20px; }
.section { font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 20px 0 8px; }

/* deadlines */
.deadlines { list-style: none; margin: 0; padding: 0; }
.deadline { display: grid; grid-template-columns: auto 1fr auto auto; gap: 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.deadline.done .dl-title { text-decoration: line-through; color: var(--muted); }
.deadline.urgent .dl-date strong { color: var(--bad); }
.dl-title { font-weight: 600; }
.dl-meta { font-size: 13px; color: var(--muted); }
.dl-date { text-align: right; font-size: 13px; display: flex; flex-direction: column; white-space: nowrap; }
.dl-date span { color: var(--muted); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.tag.t-exam { color: var(--exam); } .tag.t-project { color: var(--project); } .tag.t-assignment { color: var(--assignment); }
.tag.t-quiz { color: var(--quiz); } .tag.t-reading { color: var(--reading); }

/* plan */
.proposal { border: 2px dashed var(--accent); border-radius: var(--radius); padding: 12px; background: var(--accent-soft); margin-bottom: 8px; }
.proposal-head { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; margin-bottom: 8px; }
.proposal-head p { margin: 2px 0 0; font-size: 13px; }
.proposal-actions { display: flex; gap: 8px; }
.plan-meta { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.warnings { background: var(--warn-soft); color: var(--warn-ink); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 10px; }
.warnings p { margin: 2px 0; }
.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
.day.today { border-color: var(--accent); }
.day-head { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.block { border-left: 3px solid var(--other); background: var(--surface-2); border-radius: 6px; padding: 5px 8px; margin-bottom: 5px; display: grid; grid-template-columns: auto 1fr; column-gap: 8px; font-size: 13px; }
.block .hrs { font-weight: 700; grid-row: span 2; }
.block .b-course { font-size: 12px; color: var(--muted); }
.block.t-exam { border-color: var(--exam); } .block.t-project { border-color: var(--project); } .block.t-assignment { border-color: var(--assignment); }
.block.t-quiz { border-color: var(--quiz); } .block.t-reading { border-color: var(--reading); }
.due-next { font-size: 12px; color: var(--bad); font-weight: 600; margin-top: 4px; }

/* quiz */
.quiz-head { font-size: 16px; margin-bottom: 10px; }
.question { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin: 0 0 10px; }
.question legend { font-weight: 600; padding: 0 4px; }
.choice { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.choice:hover { background: var(--surface-2); }
.choice input { accent-color: var(--accent); }
.choice.right { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.choice.wrong { background: var(--bad-soft); color: var(--bad); text-decoration: line-through; }
.explain { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.result { font-size: 16px; padding: 8px 0; }
.history { list-style: none; padding: 0; margin: 0; }
.history li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.score { font-weight: 600; color: var(--ok); }
.score.low { color: var(--bad); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 10px; }
  .chat { height: 70vh; }
  .panel { min-height: 60vh; }
  .top { padding: 10px 16px; }
}
