:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #7c3aed;
  --bot: #f1f5f9;
  --user: #2563eb;
  --user-text: #ffffff;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111a2e;
  --border: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --bot: #1e293b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app { display: flex; height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 300px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 22px;
}
.brand h1 { font-size: 18px; line-height: 1.1; }
.brand h1 span { color: var(--accent); }
.brand p { font-size: 12px; color: var(--muted); }

.profile-card { background: var(--bot); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.profile-card label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; }
.profile-card input, .grade-select {
  width: 100%; margin: 6px 0 12px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 14px;
}
.grade-select { cursor: pointer; }
.profile-card small { display: block; margin-top: -6px; color: var(--muted); font-size: 11px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; background: var(--bot); border: 1px solid var(--border); border-radius: 10px; padding: 4px; }
.tab {
  flex: 1; padding: 8px; border: none; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--primary); color: #fff; }

.panel.hidden { display: none; }

.subjects h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 10px; }
.subject-list { display: flex; flex-direction: column; gap: 6px; }
.subject {
  text-align: left; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text); font-size: 13px; cursor: pointer; transition: all 0.15s;
}
.subject:hover { border-color: var(--primary); }
.subject.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.session-box { margin-top: auto; background: var(--bot); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.session-box p { font-size: 12px; font-weight: 600; color: var(--muted); }
.session-box code {
  display: block; font-size: 11px; color: var(--text);
  word-break: break-all; margin: 8px 0; padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}

.sidebar-foot { font-size: 11px; color: var(--muted); text-align: center; }

/* ---------- Chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-head {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.teacher-avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.chat-head h2 { font-size: 17px; }
.chat-head p { font-size: 12px; color: var(--muted); }
.chat-head .btn { margin-left: auto; }

.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }

.msg { display: flex; }
.msg.bot { justify-content: flex-start; }
.msg.user { justify-content: flex-end; }

.bubble {
  max-width: 70%; padding: 12px 16px; border-radius: 16px;
  font-size: 14.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}
.msg.bot .bubble { background: var(--bot); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.user .bubble { background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; }

.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px 20px; }
.bubble strong { font-weight: 700; }

.composer {
  display: flex; gap: 10px; padding: 16px 24px;
  background: var(--surface); border-top: 1px solid var(--border);
}
.composer input {
  flex: 1; padding: 13px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 14.5px;
}
.composer input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ---------- Buttons ---------- */
.btn {
  padding: 10px 18px; border-radius: 10px; border: none;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.ghost:hover { border-color: var(--primary); }
.btn-block { width: 100%; margin-top: 10px; }

/* ---------- Loading overlay ---------- */
.loading {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  backdrop-filter: blur(3px);
}
.loading.hidden { display: none; }
.loading p { color: #fff; font-weight: 600; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.25); border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Timetable ---------- */
.timetable-toolbar { margin-bottom: 10px; }
.timetable-toolbar h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.timetable-toolbar p { font-size: 12px; color: var(--muted); margin-top: 4px; }

.timetable-grid { display: flex; flex-direction: column; gap: 12px; }
.timetable-empty { color: var(--muted); font-size: 13px; }

.tt-table {
  width: 100%; border-collapse: collapse; font-size: 11.5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
}
.tt-table th, .tt-table td { border: 1px solid var(--border); padding: 6px 5px; vertical-align: top; }
.tt-table thead th { background: var(--bot); font-size: 11px; text-transform: uppercase; color: var(--muted); }
.tt-time { font-weight: 700; color: var(--muted); white-space: nowrap; font-size: 10.5px; text-align: center; }

.tt-cell { text-align: center; }
.tt-cell strong { display: block; font-size: 11px; line-height: 1.25; }
.tt-cell small { display: block; font-size: 9px; color: var(--muted); margin-top: 2px; text-transform: capitalize; }

.tt-lesson { background: rgba(37, 99, 235, 0.10); }
.tt-break { background: rgba(100, 116, 139, 0.12); }
.tt-lunch { background: rgba(249, 115, 22, 0.12); }
.tt-assembly { background: rgba(124, 58, 237, 0.10); }
.tt-ppi { background: rgba(16, 185, 129, 0.14); }
.tt-nf { background: rgba(14, 165, 233, 0.12); }

.tt-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 10.5px; color: var(--muted); }
.tt-legend span { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; border: 1px solid var(--border); }
.dot.tt-lesson { background: rgba(37, 99, 235, 0.10); }
.dot.tt-break { background: rgba(100, 116, 139, 0.12); }
.dot.tt-lunch { background: rgba(249, 115, 22, 0.12); }
.dot.tt-assembly { background: rgba(124, 58, 237, 0.10); }
.dot.tt-ppi { background: rgba(16, 185, 129, 0.14); }
.dot.tt-nf { background: rgba(14, 165, 233, 0.12); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .session-box { display: none; }
  .bubble { max-width: 88%; }
  .subject-list { flex-direction: row; flex-wrap: wrap; }
  .subject { flex: 1 1 45%; }
}
