:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0d9488;
  --accent-strong: #0f766e;
  --accent-soft: #ccfbf1;
  --user-bg: #e6fffb;
  --warn-bg: #fff7ed;
  --warn-text: #9a3412;
  --err-bg: #fef2f2;
  --err-text: #b91c1c;
  --code-bg: #f1f5f9;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Noto Sans KR", "Malgun Gothic", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --line: #334155;
    --accent: #2dd4bf;
    --accent-strong: #5eead4;
    --accent-soft: #134e4a;
    --user-bg: #134e4a;
    --warn-bg: #431407;
    --warn-text: #fdba74;
    --err-bg: #450a0a;
    --err-text: #fca5a5;
    --code-bg: #0b1220;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.6; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-strong); }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-strong); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 4px 10px; font-size: 14px; }
input[type=text], input[type=email], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
textarea { resize: vertical; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

/* 로그인·동의 화면 */
.center-screen { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 560px; }
.card h1 { margin: 0 0 4px; font-size: 24px; }
.card h2 { font-size: 18px; margin: 20px 0 6px; }
.card ul { margin: 6px 0; padding-left: 20px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
.notice { background: var(--warn-bg); color: var(--warn-text); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.error-text { color: var(--err-text); font-size: 14px; }

/* 학생 앱 레이아웃 */
.app { display: grid; grid-template-columns: 270px 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar .top { padding: 12px; }
.sidebar .top .btn { width: 100%; }
.conv-list { overflow-y: auto; flex: 1; padding: 0 8px 12px; }
.conv-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--accent-soft); font-weight: 600; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.header .title { font-weight: 700; flex: 1; min-width: 0; }
.menu-btn { display: none; }
.who { font-size: 14px; color: var(--muted); }
.mock-badge { background: var(--warn-bg); color: var(--warn-text); border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.ai-notice { background: var(--accent-soft); color: var(--text); font-size: 14px; padding: 6px 16px; text-align: center; }

.messages { flex: 1; overflow-y: auto; padding: 16px; }
.thread { max-width: 760px; margin: 0 auto; }
.msg { display: flex; margin: 14px 0; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user-bg); }
.msg.ai .bubble { background: var(--surface); border: 1px solid var(--line); }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble code { background: var(--code-bg); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.bubble pre { background: var(--code-bg); padding: 10px; border-radius: 8px; overflow-x: auto; margin: 6px 0; }
.bubble pre code { padding: 0; background: none; }
.mythink { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: 14px; color: var(--muted); }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.welcome { max-width: 640px; margin: 6vh auto 0; text-align: center; }
.welcome h2 { margin: 0 0 6px; font-size: 24px; }
.tips { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 12px 36px; margin: 16px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { border: 1px solid var(--accent); background: var(--surface); color: var(--accent-strong); border-radius: 999px; padding: 6px 14px; font-size: 14px; }
.chip:hover { background: var(--accent-soft); }

.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 10px 16px 14px; }
.composer-inner { max-width: 760px; margin: 0 auto; }
.banner { border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; font-size: 14px; }
.banner.err { background: var(--err-bg); color: var(--err-text); }
.banner.info { background: var(--warn-bg); color: var(--warn-text); }
.think-toggle { background: none; border: 0; color: var(--accent-strong); padding: 0 0 6px; font-size: 14px; }
.think-box { margin-bottom: 8px; }
.send-row { display: flex; gap: 8px; align-items: flex-end; }
.send-row textarea { flex: 1; }
.meta-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 25% 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; max-width: 300px; }
  .sidebar.open { transform: none; box-shadow: 4px 0 24px rgba(0,0,0,.25); }
  .menu-btn { display: inline-block; }
  .who { display: none; }
  .bubble { max-width: 96%; }
}

/* 교사 화면 */
.t-wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.t-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.t-head h1 { font-size: 22px; margin: 0; flex: 1; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { border: 0; background: none; padding: 8px 14px; border-bottom: 3px solid transparent; font-weight: 600; color: var(--muted); }
.tab.active { color: var(--accent-strong); border-bottom-color: var(--accent); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 26px; line-height: 1.2; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.panel h3 { margin: 0 0 10px; font-size: 16px; }
.cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.bar-row { display: grid; grid-template-columns: 110px 1fr 40px; gap: 8px; align-items: center; font-size: 14px; margin: 5px 0; }
.bar-row .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { background: var(--code-bg); border-radius: 6px; height: 14px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.filters { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 12px; align-items: end; }
.filters label { font-size: 13px; color: var(--muted); display: block; }
.flag { background: var(--err-bg); color: var(--err-text); border-radius: 6px; padding: 1px 6px; font-size: 12px; font-weight: 600; }
.tag { background: var(--accent-soft); border-radius: 6px; padding: 1px 6px; font-size: 12px; }
.qa { white-space: pre-wrap; overflow-wrap: anywhere; }
.report { white-space: pre-wrap; line-height: 1.7; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.ok-text { color: var(--accent-strong); font-size: 14px; }
