:root {
  --yellow: #ffc928;
  --yellow-dark: #e6b313;
  --ink: #1c1d21;
  --ink-soft: #3a3b40;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e5ea;
  --muted: #8a8d96;
  --green: #1faa59;
  --radius: 12px;
  --sidebar-w: 270px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button { font-family: inherit; cursor: pointer; }

/* ---------- Brand ---------- */
.brand { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.brand.small { font-size: 20px; }
.brand .logo {
  background: var(--yellow); color: var(--ink); padding: 2px 8px;
  border-radius: 8px; margin-right: 1px;
}

/* ---------- Auth ---------- */
.auth-screen {
  min-height: 100%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, #fff6d6, var(--bg));
}
.auth-card {
  background: var(--panel); width: 380px; max-width: 92vw; padding: 36px 32px;
  border-radius: 18px; box-shadow: 0 16px 48px rgba(0,0,0,.10); text-align: center;
}
.tagline { color: var(--muted); margin: 6px 0 24px; }
.tabs { display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  flex: 1; padding: 9px 6px; border: 1px solid var(--border); background: #fafbfc;
  border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-soft);
}
.tab.active { background: var(--yellow); border-color: var(--yellow-dark); color: var(--ink); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px;
}
.auth-form input:focus { outline: 2px solid var(--yellow); border-color: var(--yellow); }
.auth-form button {
  padding: 12px; border: none; border-radius: 10px; background: var(--ink); color: #fff;
  font-weight: 700; font-size: 15px; margin-top: 4px;
}
.auth-form button:hover { background: #000; }
.error { color: #d23; font-size: 13px; margin-top: 14px; min-height: 16px; }

/* ---------- App layout ---------- */
.app { display: flex; height: 100%; }
.sidebar {
  width: var(--sidebar-w); background: var(--ink); color: #fff; display: flex;
  flex-direction: column; flex-shrink: 0;
}
.sidebar-head { padding: 18px 16px; display: flex; align-items: center; justify-content: space-between; }
.sidebar-head .brand .logo { background: var(--yellow); }
#btn-new {
  background: var(--yellow); color: var(--ink); border: none; padding: 7px 12px;
  border-radius: 8px; font-weight: 700; font-size: 13px;
}
.session-list { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.session-list li {
  padding: 10px 12px; border-radius: 8px; font-size: 14px; color: #d6d7dc;
  cursor: pointer; display: flex; justify-content: space-between; gap: 6px; align-items: center;
}
.session-list li:hover { background: rgba(255,255,255,.08); }
.session-list li.active { background: rgba(255,201,40,.18); color: #fff; }
.session-list li .del { opacity: 0; color: #ff8080; font-size: 16px; line-height: 1; }
.session-list li:hover .del { opacity: .8; }
.session-list li .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
#user-label { color: #b9bac1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-logout { background: transparent; color: #b9bac1; border: 1px solid rgba(255,255,255,.2); border-radius: 7px; padding: 5px 10px; font-size: 12px; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.empty-state { margin: auto; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--ink); }
.empty-state button {
  margin-top: 14px; background: var(--yellow); color: var(--ink); border: none;
  padding: 11px 20px; border-radius: 10px; font-weight: 700;
}
.chat { display: flex; flex-direction: column; height: 100%; }
.chat-head {
  padding: 16px 22px; border-bottom: 1px solid var(--border); background: var(--panel);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
#chat-title { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.export-group { display: flex; gap: 8px; flex-shrink: 0; }
.export-btn {
  background: #fff; border: 1px solid var(--yellow-dark); color: var(--ink);
  padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 600;
}
.export-btn:hover { background: var(--yellow); }

.attachments { padding: 8px 22px 0; display: flex; flex-wrap: wrap; gap: 8px; background: var(--panel); }
.chip {
  background: #fff7da; border: 1px solid var(--yellow-dark); border-radius: 20px;
  padding: 5px 12px; font-size: 12px; display: flex; align-items: center; gap: 8px;
}
.chip .x { cursor: pointer; color: #b08600; font-weight: 700; }

.messages { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 860px; width: 100%; align-self: center; }
.msg .bubble {
  padding: 12px 16px; border-radius: var(--radius); font-size: 14.5px; line-height: 1.5;
}
.msg.user .bubble { background: var(--ink); color: #fff; margin-left: auto; max-width: 70%; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--border); }

.q-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-top: 10px;
}
.q-card .q-text { font-weight: 700; margin-bottom: 10px; }
.q-card ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.q-card li { padding: 8px 12px; border-radius: 8px; background: #f6f7f9; font-size: 14px; display: flex; gap: 8px; }
.q-card li.correct { background: #e7f7ee; border: 1px solid var(--green); font-weight: 600; }
.q-card li .mark { font-weight: 800; }
.q-card li.correct .mark { color: var(--green); }
.q-card .expl { margin-top: 10px; font-size: 13px; color: var(--muted); font-style: italic; }

/* ---------- Composer ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 10px; padding: 14px 22px;
  border-top: 1px solid var(--border); background: var(--panel);
}
.attach-btn {
  font-size: 22px; cursor: pointer; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--border); background: #fafbfc; line-height: 1;
}
.attach-btn:hover { background: #fff7da; }
#composer-input {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 14px; font-size: 14.5px; font-family: inherit; max-height: 160px;
}
#composer-input:focus { outline: 2px solid var(--yellow); border-color: var(--yellow); }
.num-wrap {
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  border-radius: 10px; padding: 4px 10px; background: #fafbfc; font-size: 13px; color: var(--muted);
}
.num-wrap input { width: 46px; border: none; background: transparent; font-size: 15px; font-weight: 700; color: var(--ink); text-align: center; }
.num-wrap input:focus { outline: none; }
#btn-generate {
  background: var(--yellow); color: var(--ink); border: none; padding: 12px 22px;
  border-radius: 10px; font-weight: 800; font-size: 15px; white-space: nowrap;
}
#btn-generate:hover { background: var(--yellow-dark); }
#btn-generate:disabled { opacity: .55; cursor: default; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 50;
}
.spinner {
  display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(0,0,0,.2);
  border-top-color: var(--ink); border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
