:root {
  --bg: #f3f6fb;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-strong: #ffffff;
  --text: #162033;
  --muted: #64748b;
  --line: #dbe4f0;
  --accent: #2563eb;
  --accent-2: #7c3aed;
  --success: #10b981;
  --warning: #f59e0b;
  --user-bg: #e8f0ff;
  --assistant-bg: #f4f7fb;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.08), transparent 28%),
    radial-gradient(circle at top right, rgba(124, 58, 237, 0.08), transparent 24%),
    var(--bg);
}
a { color: #1d4ed8; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell {
  width: min(1380px, calc(100vw - 32px));
  margin: 20px auto;
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  transition: grid-template-columns 0.22s ease;
}
.app-shell.sidebar-expanded {
  grid-template-columns: 248px minmax(0, 1fr);
}
.panel {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  border-radius: 24px;
}
.sidebar {
  position: sticky;
  top: 20px;
  padding: 14px 10px;
  display: grid;
  gap: 14px;
  min-height: calc(100vh - 40px);
  transition: width 0.22s ease, padding 0.22s ease, transform 0.22s ease;
}
.sidebar-top {
  display: grid;
  gap: 10px;
}
.sidebar.collapsed .brand-block,
.sidebar.collapsed .sidebar-footer .muted,
.sidebar.collapsed .session-pill {
  display: none;
}
.sidebar.collapsed .nav-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
}
.sidebar:not(.collapsed) {
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.14);
}
.brand-block h1,
.section-top h2,
h3,
p { margin-top: 0; }
.brand-block h1 { margin-bottom: 8px; font-size: 24px; line-height: 1.15; }
.section-top h2 { margin-bottom: 6px; font-size: 28px; line-height: 1.2; }
.eyebrow {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent-2);
}
.small { font-size: 13px; }
.muted { color: var(--muted); }
.side-nav { display: grid; gap: 8px; }
.nav-link,
.chip,
.ghost,
.session-pill,
.mini-pill {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
}
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  text-align: left;
  padding: 12px 14px;
  color: #334155;
  font-weight: 700;
  box-shadow: none;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.nav-link:hover {
  background: #f8fbff;
  border-color: #cbdcf8;
  transform: translateX(1px);
}
.nav-icon {
  width: 22px;
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  color: currentColor;
}
.nav-text {
  white-space: nowrap;
  transition: opacity 0.16s ease;
}
.sidebar.collapsed .nav-link {
  justify-content: center;
  padding: 12px 8px;
}
.sidebar.collapsed .nav-link::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  padding: 8px 10px;
  border-radius: 10px;
  background: #111827;
  color: white;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.18);
}
.sidebar.collapsed .nav-link:hover::after {
  opacity: 1;
}
.sidebar.collapsed .nav-icon {
  font-size: 17px;
}
.nav-link.active {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.nav-link.active:hover {
  transform: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.nav-toggle {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 14px;
  justify-self: center;
  font-size: 18px;
}
.sidebar-footer { display: grid; gap: 8px; margin-top: auto; }
.session-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 12px;
  font-weight: 700;
  font-size: 13px;
}
.content-area { display: grid; gap: 18px; }
.page-section { padding: 24px; display: none; }
.page-section.active { display: block; }
.section-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}
.header-actions,
.exam-actions,
.quick-style-grid,
.action-panel-buttons,
.sub-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.home-grid,
.grid-2,
.upload-layout,
.context-grid { display: grid; gap: 16px; }
.home-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.upload-layout { grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.1fr); }
.section-grid { align-items: start; }
.metric-card,
.inset-panel,
.action-panel {
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 20px;
}
.metric-card { padding: 18px; }
.metric-label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.action-panel {
  margin-top: 18px;
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.inset-panel { padding: 18px; }
label {
  display: grid;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #334155;
}
input, select, textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: rgba(37,99,235,0.45); box-shadow: 0 0 0 4px rgba(37,99,235,0.08); }
.full-span { grid-column: 1 / -1; }
.upload-title { font-weight: 700; }
.upload-subtitle, .upload-meta, .hint { color: var(--muted); font-size: 14px; }
.upload-label input[type='file'] { padding: 10px; background: #fff; }
.status-card {
  margin-top: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
}
.status-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.mini-pill {
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #475569;
}
.elapsed-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
}
.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  margin-top: 12px;
}
.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.25s ease;
}
.exam-preview {
  margin-top: 14px;
  min-height: 320px;
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  white-space: pre-wrap;
  line-height: 1.65;
}
.exam-item { padding: 0 0 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.exam-item.ready {
  scroll-margin-top: 24px;
}
.exam-item:last-child { margin-bottom: 0; border-bottom: 0; padding-bottom: 0; }
.exam-row-top { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 10px; }
.exam-qtitle { font-size: 13px; font-weight: 800; color: var(--accent-2); text-transform: uppercase; }
.exam-item-kind {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.exam-item-kind.question { color: #1d4ed8; }
.exam-item-kind.guidance { color: #7c3aed; }
.exam-badge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: #475569;
}
.exam-badge.running { background: #fff7ed; border-color: #fed7aa; color: #c2410c; }
.exam-badge.done { background: #ecfdf5; border-color: #bbf7d0; color: #047857; }
.exam-question { font-weight: 700; margin-bottom: 12px; }
.exam-live-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}
.exam-live-grid.has-answer {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.exam-answer-block {
  background: rgba(255,255,255,0.78);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}
.exam-block-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.recognised-question-block {
  background: #f8fbff;
  border-color: #cfe0ff;
}
.answer-ready-block.is-ready {
  border-color: #bbd6ff;
  background: #ffffff;
}
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.compare-col {
  min-width: 0;
  padding: 12px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
}
.compare-label {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
}
.exam-answer-text {
  white-space: pre-wrap;
  line-height: 1.7;
  color: var(--text);
}
.chat { min-height: 340px; overflow: auto; display: grid; gap: 14px; padding-right: 4px; margin-top: 18px; }
.message { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 12px; align-items: start; }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, #dbeafe, #ede9fe);
  border: 1px solid #dbeafe;
}
.message[data-role='user'] .avatar { background: linear-gradient(135deg, #bfdbfe, #93c5fd); }
.role { margin-bottom: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.bubble {
  white-space: pre-wrap;
  line-height: 1.65;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--assistant-bg);
  overflow: hidden;
}
.message[data-role='user'] .bubble { background: var(--user-bg); border-color: #bfdbfe; }
.bilingual-content {
  display: grid;
  gap: 12px;
}
.lang-block {
  padding: 12px 0;
}
.lang-block + .lang-block {
  border-top: 1px solid rgba(0,0,0,0.06);
  padding-top: 12px;
}
.lang-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin-bottom: 8px;
}
.lang-text {
  white-space: pre-wrap;
  line-height: 1.7;
  color: var(--text);
}
.chat-settings-panel {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfdff;
  padding: 14px;
}
.chat-settings-toggle {
  font-size: 14px;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
  user-select: none;
}
.chat-settings-toggle::marker {
  color: var(--accent);
}
.chat-settings-body {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.composer { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 18px; }
.chat-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 12px;
  align-items: stretch;
}
textarea { min-height: 120px; resize: vertical; }
.chat-send-btn {
  align-self: stretch;
  height: 100%;
}
.composer-actions { margin-top: 12px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.chat-toolbar,
.message-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.message-tools {
  margin-top: 8px;
}
button {
  border: 0;
  border-radius: 16px;
  padding: 13px 18px;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 24px rgba(37,99,235,0.22);
}
button.secondary {
  background: #eef2ff;
  color: #3730a3;
  box-shadow: none;
  border: 1px solid #dbe4ff;
}
button.ghost {
  background: transparent;
  color: #475569;
  box-shadow: none;
  border: 1px solid var(--line);
}
button.small-action { padding: 10px 14px; font-size: 13px; }
button:disabled { opacity: 0.65; cursor: wait; }
.chip {
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  color: #334155;
}
.chip.active { color: white; border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #065f46;
  background: #ecfdf5;
  border: 1px solid #bbf7d0;
  padding: 8px 12px;
  border-radius: 999px;
}
.study-notes-body,
.history-list {
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  line-height: 1.7;
  white-space: pre-wrap;
}
.subject-dashboard-block {
  margin-top: 18px;
}
.compact-top {
  margin-bottom: 12px;
}
.compact-top h3 {
  margin-bottom: 0;
}
.subject-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.subject-card {
  width: 100%;
  text-align: left;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fbfdff;
  color: var(--text);
  box-shadow: none;
}
.subject-card.active {
  border-color: #bfd5ff;
  background: linear-gradient(180deg, #f8fbff, #eef4ff);
}
.subject-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.subject-card-meta {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 10px;
}
.subject-card-foot {
  font-size: 13px;
  color: #475569;
}
.history-item { padding: 14px 0; border-top: 1px solid var(--line); line-height: 1.6; }
.history-item:first-child { border-top: 0; padding-top: 0; }
.history-time { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.download-link {
  display: inline-flex;
  margin-top: 12px;
  font-weight: 700;
  text-decoration: none;
}
.hidden { display: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 72px minmax(0, 1fr);
    align-items: start;
  }
  .app-shell.sidebar-expanded {
    grid-template-columns: 220px minmax(0, 1fr);
  }
  .sidebar {
    position: sticky;
    top: 12px;
    left: auto;
    z-index: 1;
    min-height: calc(100vh - 24px);
    max-height: calc(100vh - 24px);
    overflow: auto;
  }
  .content-area { padding-top: 0; }
}
@media (max-width: 980px) {
  .home-grid,
  .grid-2,
  .upload-layout,
  .exam-live-grid.has-answer,
  .compare-grid,
  .subject-cards-grid,
  .chat-input-row { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 16px, 100%);
    margin: 8px auto 18px;
    gap: 12px;
    grid-template-columns: 60px minmax(0, 1fr);
  }
  .app-shell.sidebar-expanded {
    grid-template-columns: 196px minmax(0, 1fr);
  }
  .sidebar {
    width: auto;
    max-width: none;
    min-height: calc(100vh - 16px);
    max-height: calc(100vh - 16px);
  }
  .sidebar, .page-section { padding: 16px; border-radius: 20px; }
  .section-top, .composer-actions, .status-card-top, .exam-row-top, .action-panel { flex-direction: column; align-items: stretch; }
  button { width: 100%; }
  .nav-toggle { width: 44px; height: 44px; }
}
