:root {
  --bg: #08111f;
  --bg-soft: #0b1627;
  --surface: #111d31;
  --surface-2: #16243b;
  --surface-3: #1b2d49;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.24);
  --text: #f8fafc;
  --muted: #95a3b8;
  --muted-2: #64748b;
  --accent: #4f46e5;
  --accent-blue: #2f81f7;
  --accent-violet: #8b5cf6;
  --accent-teal: #22d3ee;
  --accent-green: #22c55e;
  --accent-amber: #f59e0b;
  --danger: #fb7185;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
  --radius-xl: 22px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --sidebar-width: 280px;
}

:root[data-theme="light"] {
  --bg: #f4f7fb;
  --bg-soft: #eef3fb;
  --surface: #ffffff;
  --surface-2: #f8fbff;
  --surface-3: #eef4ff;
  --border: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --muted: #536179;
  --muted-2: #7a879a;
  --accent: #1d4ed8;
  --accent-blue: #2563eb;
  --accent-violet: #7c3aed;
  --accent-teal: #0891b2;
  --accent-green: #16a34a;
  --accent-amber: #d97706;
  --danger: #e11d48;
  --shadow: 0 18px 46px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 70% -10%, rgba(79, 70, 229, 0.24), transparent 34%),
    radial-gradient(circle at 12% 10%, rgba(34, 211, 238, 0.13), transparent 28%),
    var(--bg);
}

button, input, a { font: inherit; }
a { color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: linear-gradient(180deg, rgba(9, 18, 34, 0.95), rgba(7, 13, 25, 0.95));
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 22px;
  color: #eef2ff;
  z-index: 20;
}

:root[data-theme="light"] .sidebar {
  background: #0a1530;
  color: #eef2ff;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  text-decoration: none;
  font-weight: 900;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #1d4ed8, #101b35 72%);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.14);
}

.brand-title { font-size: 18px; font-weight: 900; line-height: 1.1; }
.brand-subtitle { font-size: 12px; color: rgba(226, 232, 240, 0.72); margin-top: 4px; }

.sidebar__nav { display: grid; gap: 6px; }
.nav-section {
  margin: 14px 10px 6px;
  color: rgba(226, 232, 240, 0.55);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 12px;
  color: rgba(241, 245, 249, 0.82);
  border: 1px solid transparent;
  transition: 0.18s ease;
}
.nav-item span { width: 20px; text-align: center; color: rgba(203, 213, 225, 0.85); }
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-item--active {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.85), rgba(47, 129, 247, 0.55));
  color: #fff;
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: 0 12px 28px rgba(79, 70, 229, 0.18);
}

.sidebar__spacer { flex: 1; }
.premium-card {
  border: 1px solid rgba(167, 139, 250, 0.23);
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.18), rgba(15, 23, 42, 0.8));
  border-radius: 18px;
  padding: 16px;
}
.premium-card__icon { color: #a78bfa; font-size: 24px; margin-bottom: 8px; }
.premium-card__title { font-weight: 900; margin-bottom: 6px; }
.premium-card__text { color: rgba(226, 232, 240, 0.72); font-size: 13px; line-height: 1.35; }
.premium-card__button {
  margin-top: 12px;
  display: block;
  text-align: center;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 11px;
  background: linear-gradient(135deg, #4f46e5, #2563eb);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
}

.user-mini {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  padding: 12px;
  border-top: 1px solid rgba(226, 232, 240, 0.12);
}
.user-mini__name { font-weight: 800; }
.user-mini__role { color: rgba(226, 232, 240, 0.62); font-size: 12px; }
.user-mini__chevron { color: rgba(226, 232, 240, 0.55); }

.main-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: rgba(8, 17, 31, 0.72);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
:root[data-theme="light"] .topbar { background: rgba(244, 247, 251, 0.76); }
.menu-button { display: none; }
.breadcrumb { color: var(--muted); font-size: 14px; }
.topbar__right { display: flex; align-items: center; gap: 12px; }
.icon-button, .menu-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: 0.18s ease;
}
.icon-button:hover, .menu-button:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.icon-button--badge { position: relative; }
.icon-button--badge span {
  position: absolute;
  right: -5px;
  top: -5px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 10px;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--bg);
}
.user-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}
.user-panel__name { font-size: 13px; font-weight: 800; }
.user-panel__role { font-size: 11px; color: var(--muted); }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2563eb, #101827);
  color: #fff;
  font-weight: 900;
}
.avatar--small { width: 34px; height: 34px; }

.content {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 30px 32px 48px;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.page-header h1 { margin: 0; font-size: clamp(24px, 3vw, 34px); line-height: 1.1; }
.page-header p { margin: 8px 0 0; color: var(--muted); }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
}
.dashboard-grid__main, .dashboard-grid__side { display: grid; gap: 18px; align-content: start; }
.card, .topic-card, .topic-row, .metric-card, .action-card, .recommend-card {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 96%, transparent), color-mix(in srgb, var(--surface-2) 96%, transparent));
  box-shadow: var(--shadow);
}
.card {
  border-radius: var(--radius-xl);
  padding: 20px;
}
.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.card__head h2 { margin: 0; font-size: 18px; }
.card__head p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.section-gap { margin-top: 18px; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.metrics-grid--compact { grid-template-columns: repeat(3, 1fr); }
.metric-card {
  border-radius: 18px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: none;
}
.metric-card__icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-violet));
  font-weight: 900;
}
.metric-card__value { font-size: 26px; font-weight: 950; letter-spacing: -0.03em; }
.metric-card__label { color: var(--muted); font-size: 13px; }
.metric-card__hint { color: var(--muted-2); font-size: 12px; margin-top: 4px; }

.topic-list { display: grid; gap: 10px; }
.topic-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(170px, 240px) auto auto;
  gap: 14px;
  align-items: center;
  text-decoration: none;
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: none;
  transition: 0.18s ease;
}
.topic-row:hover, .topic-card:hover, .action-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.topic-icon {
  width: 52px;
  height: 52px;
  border-radius: 17px;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: #fff;
  background: var(--accent-blue);
}
.topic-icon--blue { background: linear-gradient(135deg, #0ea5e9, #2563eb); }
.topic-icon--violet { background: linear-gradient(135deg, #8b5cf6, #4f46e5); }
.topic-icon--teal { background: linear-gradient(135deg, #14b8a6, #0891b2); }
.topic-icon--amber { background: linear-gradient(135deg, #f59e0b, #b45309); }
.topic-row__title, .topic-card h3 { font-size: 16px; font-weight: 900; }
.topic-row__meta, .topic-card p { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.topic-row__numbers { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; color: var(--muted); }
.topic-row__numbers b { color: var(--text); }
.progress {
  height: 9px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface-3) 70%, #000);
  border: 1px solid var(--border);
}
.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-violet));
}
.progress--large { height: 12px; margin: 16px 0; }
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.chip--success { color: #7ee787; background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.22); }
.arrow { color: var(--muted); font-size: 24px; }
.link { color: color-mix(in srgb, var(--accent-blue) 80%, var(--text)); text-decoration: none; font-weight: 800; }

.recommend-card {
  min-height: 190px;
  border-radius: var(--radius-xl);
  padding: 22px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  background: radial-gradient(circle at 80% 20%, rgba(139, 92, 246, 0.35), transparent 36%), linear-gradient(135deg, #1e1b4b, #111827);
  color: #fff;
  overflow: hidden;
}
.recommend-card h2 { margin: 0 0 14px; }
.recommend-card p { color: rgba(226, 232, 240, 0.78); line-height: 1.45; }
.rocket { font-size: 72px; align-self: end; filter: drop-shadow(0 12px 24px rgba(139, 92, 246, 0.35)); }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 16px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-blue));
  color: #fff;
  text-decoration: none;
  font-weight: 900;
  cursor: pointer;
  transition: 0.18s ease;
}
.button:hover { transform: translateY(-1px); filter: brightness(1.05); }
.button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.button--ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.button--small { min-height: 34px; padding: 8px 12px; font-size: 13px; }
.button-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.line-chart { width: 100%; height: 170px; margin-top: 6px; }
.chart-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.split-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.split-list h3 { font-size: 14px; margin: 0 0 10px; }
.split-list a {
  display: block;
  padding: 12px;
  text-decoration: none;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.split-list span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.success-text { color: #7ee787; }
.warning-text { color: #fbbf24; }

.next-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.action-card {
  border-radius: var(--radius-xl);
  padding: 18px;
  min-height: 150px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  text-decoration: none;
  overflow: hidden;
}
.action-card h3 { margin: 0 0 8px; }
.action-card p { color: var(--muted); font-size: 13px; line-height: 1.4; }
.action-card__art { align-self: end; font-size: 80px; opacity: 0.45; }
.action-card--blue { background: linear-gradient(135deg, rgba(37, 99, 235, 0.25), rgba(15, 23, 42, 0.4)); }
.action-card--violet { background: linear-gradient(135deg, rgba(124, 58, 237, 0.28), rgba(15, 23, 42, 0.4)); }
:root[data-theme="light"] .action-card--blue { background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), #fff); }
:root[data-theme="light"] .action-card--violet { background: linear-gradient(135deg, rgba(124, 58, 237, 0.12), #fff); }

.topics-page-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.topic-card {
  display: flex;
  gap: 16px;
  align-items: center;
  text-decoration: none;
  padding: 18px;
  border-radius: var(--radius-xl);
  transition: 0.18s ease;
}
.topic-card__body { flex: 1; min-width: 0; }
.topic-card h3 { margin: 0; }
.topic-card__footer { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; margin-top: 14px; color: var(--muted); font-size: 13px; }

.topic-detail-grid, .bank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stat-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}
.stat-box span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.stat-box b { font-size: 22px; }
.hint-box {
  margin-top: 16px;
  background: rgba(47, 129, 247, 0.12);
  border: 1px solid rgba(47, 129, 247, 0.2);
  border-radius: 16px;
  padding: 14px;
  color: color-mix(in srgb, var(--accent-blue) 70%, var(--text));
}

.task-sidebar { align-self: start; }
.task-list { display: grid; gap: 8px; }
.task-list__item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.task-list__item:hover, .task-list__item.is-active { border-color: var(--accent-blue); background: color-mix(in srgb, var(--surface-3) 84%, var(--accent-blue)); }
.task-list__num { font-weight: 950; color: var(--muted); }
.solve-panel__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}
.task-text {
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: 18px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 18px;
  font-size: 18px;
  line-height: 1.5;
  overflow-x: auto;
}
.math-content > :first-child { margin-top: 0; }
.math-content > :last-child { margin-bottom: 0; }
.math-content p { margin: 0 0 0.85em; }
.math-content ul,
.math-content ol { margin: 0 0 0.85em; padding-left: 1.5em; }
.math-content li + li { margin-top: 0.3em; }
.math-content blockquote {
  margin: 0 0 0.85em;
  padding: 0.7em 0.9em;
  border-left: 3px solid var(--accent-violet);
  background: color-mix(in srgb, var(--surface-3) 86%, var(--accent-violet));
  border-radius: 0 12px 12px 0;
  color: var(--muted);
}
.math-content pre,
.math-content code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.math-content pre {
  margin: 0 0 0.85em;
  padding: 0.8em;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  overflow-x: auto;
}
.math-content :not(pre) > code {
  padding: 0.12em 0.35em;
  border-radius: 6px;
  background: var(--surface-3);
}
.math-content table {
  width: 100%;
  margin: 0 0 0.85em;
  border-collapse: collapse;
}
.math-content th,
.math-content td {
  padding: 0.55em 0.7em;
  border: 1px solid var(--border);
  text-align: left;
}
.math-content th { background: var(--surface-3); }
.math-content .katex-display {
  margin: 0.85em 0;
  padding: 0.15em 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.answer-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 14px; }
.input {
  width: 100%;
  min-height: 44px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0 14px;
  outline: none;
}
.input:focus { border-color: var(--accent-blue); box-shadow: 0 0 0 4px rgba(47, 129, 247, 0.14); }
.answer-result {
  margin-top: 12px;
  border-radius: 15px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  font-weight: 800;
}
.answer-result--ok { color: #7ee787; background: rgba(34, 197, 94, 0.1); border-color: rgba(34, 197, 94, 0.22); }
.answer-result--bad { color: #fda4af; background: rgba(244, 63, 94, 0.1); border-color: rgba(244, 63, 94, 0.22); }
.is-hidden { display: none !important; }

.test-panel { max-width: 900px; }
.test-top { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.test-task { margin-top: 18px; }
.test-result h2 { margin: 0 0 8px; }
.test-result p { color: var(--muted); }

.recommendation-list { display: grid; gap: 14px; }
.recommendation-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}
.recommendation-item h2 { margin: 0 0 6px; }
.recommendation-item p { margin: 0; color: var(--muted); }
.loading, .error-card {
  min-height: 220px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-xl);
  color: var(--muted);
}
.error-card { place-items: start; }

.reveal { animation: reveal 0.28s ease both; }
@keyframes reveal {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1180px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 88vw);
    transform: translateX(-105%);
    transition: 0.2s ease;
  }
  .sidebar--open { transform: translateX(0); }
  .menu-button { display: grid; }
  .topbar { padding: 14px 18px; }
  .content { padding: 22px 18px 40px; }
  .topbar__left { display: none; }
  .user-panel { display: none; }
  .topic-row { grid-template-columns: auto 1fr; }
  .topic-row__progress, .topic-row .chip, .arrow { grid-column: 2; }
  .topic-detail-grid, .bank-grid, .topics-page-grid, .next-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .metrics-grid, .metrics-grid--compact, .stats-grid, .test-top { grid-template-columns: 1fr; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .answer-row { grid-template-columns: 1fr; }
  .split-list { grid-template-columns: 1fr; }
  .recommendation-item { grid-template-columns: 1fr; }
}

/* ===== Fix pack: layout polish after first testing ===== */
/* Sidebar: independent scrolling + desktop collapse */
.sidebar {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.28); border-radius: 999px; }

.menu-button { display: grid; }
.topbar__left { min-width: 0; }
.breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(420px, 45vw);
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breadcrumb::before {
  content: "•";
  color: var(--accent-blue);
  font-size: 20px;
  line-height: 0;
}

@media (min-width: 921px) {
  .app-shell.app-shell--sidebar-collapsed {
    grid-template-columns: 0 minmax(0, 1fr);
  }
  .app-shell.app-shell--sidebar-collapsed .sidebar {
    transform: translateX(-105%);
    opacity: 0;
    pointer-events: none;
  }
}

/* Topbar clickable elements */
.user-panel { text-decoration: none; cursor: pointer; }
.icon-button:focus-visible, .menu-button:focus-visible, .user-panel:focus-visible, .nav-item:focus-visible, .button:focus-visible {
  outline: 3px solid rgba(47, 129, 247, 0.35);
  outline-offset: 2px;
}

/* Topic rows: no text overlap on narrow widths */
.topic-row {
  grid-template-columns: 52px minmax(180px, 1fr) minmax(210px, 280px) auto 18px;
  grid-template-areas: "icon main progress chip arrow";
  align-items: center;
  min-height: 86px;
}
.topic-row .topic-icon { grid-area: icon; }
.topic-row__main { grid-area: main; min-width: 0; }
.topic-row__progress { grid-area: progress; min-width: 0; }
.topic-row > .chip { grid-area: chip; justify-self: start; }
.topic-row > .arrow { grid-area: arrow; justify-self: end; }
.topic-row__title, .topic-row__meta {
  overflow-wrap: anywhere;
}
.topic-row__numbers {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

@media (max-width: 1120px) {
  .topic-row {
    grid-template-columns: 52px minmax(0, 1fr) auto;
    grid-template-areas:
      "icon main arrow"
      "icon progress progress"
      ". chip chip";
    row-gap: 10px;
  }
  .topic-row > .chip { justify-self: start; }
}

@media (max-width: 620px) {
  .topic-row {
    grid-template-columns: 52px minmax(0, 1fr);
    grid-template-areas:
      "icon main"
      "progress progress"
      "chip chip";
    padding: 14px;
  }
  .topic-row > .arrow { display: none; }
  .topic-row__progress { grid-column: 1 / -1; }
}

/* Metrics: prevent cramped vertical text */
.metrics-grid,
.metrics-grid--compact {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.metric-card {
  min-width: 0;
  align-items: flex-start;
}
.metric-card > div:last-child { min-width: 0; }
.metric-card__label,
.metric-card__hint {
  line-height: 1.35;
  word-break: normal;
  overflow-wrap: normal;
}
.metric-card__value { line-height: 1.05; }

/* Mobile topbar spacing */
@media (max-width: 560px) {
  .topbar__right { gap: 8px; }
  .icon-button, .menu-button { width: 38px; height: 38px; border-radius: 12px; }
  .breadcrumb { max-width: 38vw; }
}

/* Toast for temporary clickable controls */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(14px);
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, #000);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: opacity 0.18s ease, transform 0.18s ease;
  font-weight: 750;
}
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}


/* ===== Fix pack v3: dashboard overlap, sidebar behavior, stats page ===== */
html, body { overflow-x: hidden; }
.main-area { min-width: 0; width: 100%; overflow-x: hidden; }
.content { max-width: 1280px; }
.topbar { gap: 16px; z-index: 60; }
.topbar__right { position: relative; z-index: 80; flex-shrink: 0; }
.icon-button, .menu-button, .user-panel { position: relative; z-index: 81; pointer-events: auto; }

/* On medium screens the right dashboard column goes below the main content.
   This prevents the chart/side cards from covering topic rows. */
@media (max-width: 1440px) {
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
  .dashboard-grid__side {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    display: grid;
  }
  .dashboard-grid__side .recommend-card { min-height: 220px; }
}
@media (max-width: 980px) {
  .dashboard-grid__side { grid-template-columns: 1fr; }
}

/* The sidebar becomes an overlay earlier, so the main content is not squeezed.
   It still scrolls independently and can be hidden/opened. */
@media (max-width: 1200px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    height: 100vh;
    transform: translateX(-105%);
    box-shadow: 24px 0 80px rgba(0,0,0,0.35);
  }
  .sidebar.sidebar--open { transform: translateX(0); }
  .menu-button { display: grid; }
}

/* Prevent topic rows from becoming too wide and causing horizontal overlay. */
.topic-list { min-width: 0; }
.topic-row { min-width: 0; }
.topic-row__progress .progress { min-width: 140px; }
@media (max-width: 760px) {
  .topic-row__progress .progress { min-width: 0; }
}

/* Extra protection against cramped metric cards. */
.metrics-grid,
.metrics-grid--compact {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.metric-card { min-height: 112px; }
.metric-card__value { white-space: nowrap; }

/* Stats page */
.stats-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.filter-field {
  display: grid;
  gap: 7px;
}
.filter-field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.select {
  width: 100%;
  min-height: 44px;
  border-radius: 13px;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface-2);
  padding: 0 12px;
  outline: none;
}
.select:focus { border-color: var(--accent-blue); box-shadow: 0 0 0 4px rgba(47, 129, 247, 0.14); }
.stats-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
  align-items: start;
}
.stats-layout__main,
.stats-layout__side { display: grid; gap: 18px; min-width: 0; }
.stats-insight {
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  line-height: 1.45;
}
.stats-insight b { color: var(--text); }
.stats-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 10px;
}
.stats-table th {
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 0 10px;
}
.stats-table td {
  padding: 12px 10px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.stats-table td:first-child { border-left: 1px solid var(--border); border-radius: 14px 0 0 14px; font-weight: 900; }
.stats-table td:last-child { border-right: 1px solid var(--border); border-radius: 0 14px 14px 0; }
.stats-focus-card { min-height: 118px; }
.stats-chart-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.stats-dynamic-chart .line-chart { height: 220px; }
.stats-note-list { display: grid; gap: 10px; }
.stats-note {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--muted);
}
.stats-note b { color: var(--text); display: block; margin-bottom: 4px; }
@media (max-width: 1180px) {
  .stats-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .stats-toolbar { grid-template-columns: 1fr; }
  .stats-table { min-width: 720px; }
  .stats-table-wrap { overflow-x: auto; padding-bottom: 4px; }
}

/* ===== Visual cleanup: professional icon system, no emoji/sticker look ===== */
.icon {
  width: 1.15em;
  height: 1.15em;
  display: block;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.nav-item__icon,
.icon-button > [data-icon],
.menu-button > [data-icon],
.premium-card__icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.nav-item__icon {
  width: 22px;
  height: 22px;
  color: rgba(203, 213, 225, 0.9);
}
.nav-item__icon .icon { width: 20px; height: 20px; }
.nav-item--active .nav-item__icon { color: #fff; }

.icon-button .icon,
.menu-button .icon {
  width: 19px;
  height: 19px;
}

.icon-button--badge .badge-count {
  position: absolute;
  right: -5px;
  top: -5px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 10px;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--bg);
  line-height: 1;
}
.icon-button--badge > [data-icon] { pointer-events: none; }

.premium-card__icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: #c4b5fd;
  background: rgba(167, 139, 250, 0.12);
  border: 1px solid rgba(167, 139, 250, 0.22);
  margin-bottom: 10px;
  font-size: inherit;
}
.premium-card__icon .icon { width: 20px; height: 20px; }

.topic-icon .icon {
  width: 25px;
  height: 25px;
  stroke-width: 1.9;
}

.metric-card__icon .icon {
  width: 22px;
  height: 22px;
  stroke-width: 2;
}

.action-card {
  position: relative;
  overflow: hidden;
}
.action-card__icon {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  align-self: end;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.11);
  border: 1px solid rgba(255, 255, 255, 0.16);
}
.action-card__icon .icon {
  width: 30px;
  height: 30px;
  stroke-width: 1.8;
}
.action-card__art,
.rocket { display: none !important; }

.recommend-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.recommend-card__icon {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.22);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}
.recommend-card__icon .icon {
  width: 25px;
  height: 25px;
}

.page-header h1,
.card__head h2,
.recommend-card h2 {
  letter-spacing: -0.02em;
}

.answer-result--ok::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--accent-green);
  display: inline-block;
  margin-right: 8px;
  vertical-align: 1px;
}
.answer-result--bad::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--danger);
  display: inline-block;
  margin-right: 8px;
  vertical-align: 1px;
}

@media (max-width: 560px) {
  .recommend-card { grid-template-columns: 1fr; }
  .recommend-card__icon { width: 46px; height: 46px; }
  .action-card__icon { width: 54px; height: 54px; }
}
.icon-button--badge > [data-icon] {
  position: static;
  min-width: auto;
  height: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: currentColor;
  font-size: inherit;
}

/* ===== Topbar panels: search and notifications ===== */

.topbar-panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  padding: 88px 28px 28px;
  background: rgba(2, 6, 23, 0.42);
  backdrop-filter: blur(10px);
}

.topbar-panel {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 116px);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  background:
    radial-gradient(circle at 100% 0%, rgba(79, 70, 229, 0.18), transparent 32%),
    var(--surface);
  box-shadow: var(--shadow);
}

.topbar-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.topbar-panel__head h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.topbar-panel__head p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar-panel__close {
  flex: 0 0 auto;
  font-size: 22px;
  line-height: 1;
}

.topbar-panel__body {
  padding: 18px 20px 20px;
  overflow: auto;
  max-height: calc(100vh - 210px);
}

.quick-search {
  display: grid;
  gap: 8px;
}

.quick-search span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.quick-search input {
  width: 100%;
  border: 1px solid var(--border-strong);
  outline: none;
  border-radius: 16px;
  padding: 13px 14px;
  color: var(--text);
  background: var(--surface-2);
}

.quick-search input:focus {
  border-color: rgba(47, 129, 247, 0.55);
  box-shadow: 0 0 0 4px rgba(47, 129, 247, 0.14);
}

.quick-results {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.quick-result {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  text-decoration: none;
  background: color-mix(in srgb, var(--surface-2) 78%, transparent);
  transition: 0.16s ease;
}

.quick-result:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.quick-result__type {
  display: inline-flex;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 999px;
  color: #bfdbfe;
  background: rgba(47, 129, 247, 0.16);
  font-size: 12px;
  font-weight: 850;
}

.quick-result__content {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.quick-result__content b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-result__content small {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-loading,
.empty-state {
  padding: 18px;
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
  color: var(--muted);
  background: rgba(148, 163, 184, 0.06);
}

.empty-state--compact {
  display: grid;
  gap: 6px;
}

.empty-state--compact b {
  color: var(--text);
}

.notification-list {
  display: grid;
  gap: 12px;
}

.notification-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
}

.notification-card--accent {
  border-color: rgba(47, 129, 247, 0.28);
  background: rgba(47, 129, 247, 0.11);
}

.notification-card b {
  display: block;
  margin-bottom: 6px;
}

.notification-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.notification-card code {
  padding: 2px 6px;
  border-radius: 8px;
  color: var(--text);
  background: rgba(148, 163, 184, 0.14);
}

@media (max-width: 700px) {
  .topbar-panel-backdrop {
    justify-content: center;
    padding: 76px 16px 16px;
  }

  .topbar-panel {
    width: 100%;
  }

  .quick-result {
    grid-template-columns: 1fr;
  }

  .quick-result__type {
    justify-self: start;
  }
}

/* ===== Header and branding polish ===== */

.logo {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border-radius: 14px;
  background:
    radial-gradient(circle at 24% 20%, rgba(147, 197, 253, 0.35), transparent 32%),
    linear-gradient(135deg, #2563eb 0%, #1e3a8a 48%, #111827 100%);
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.18);
}

.logo::after {
  content: "";
  position: absolute;
  right: 7px;
  bottom: 8px;
  width: 16px;
  height: 3px;
  border-radius: 999px;
  background: rgba(191, 219, 254, 0.9);
  transform: rotate(-28deg);
  opacity: 0.85;
  z-index: -1;
}

.brand-title {
  letter-spacing: -0.03em;
}

.brand-subtitle {
  max-width: 170px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breadcrumb {
  min-height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.breadcrumb::before {
  content: "";
  width: 4px;
  height: 20px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent-blue), var(--accent-violet));
  box-shadow: 0 0 18px rgba(47, 129, 247, 0.35);
}

:root[data-theme="light"] .breadcrumb {
  color: #0f172a;
}

.topbar-panel__close {
  display: grid;
  place-items: center;
  padding: 0;
  line-height: 1;
  font-size: 0;
}

.topbar-panel__close::before {
  content: "×";
  display: block;
  color: currentColor;
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
  transform: translateY(-1px);
}

/* ===== Clickable brand ===== */

.brand-link {
  color: inherit;
  text-decoration: none;
  border-radius: 18px;
  transition: 0.18s ease;
}

.brand-link:hover {
  transform: translateY(-1px);
}

.brand-link:focus-visible {
  outline: 3px solid rgba(47, 129, 247, 0.35);
  outline-offset: 4px;
}

.brand-link:hover .logo {
  box-shadow:
    0 16px 34px rgba(37, 99, 235, 0.26),
    0 0 0 1px rgba(191, 219, 254, 0.18) inset;
}

.brand-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.brand-copy .brand-title,
.brand-copy .brand-subtitle {
  display: block;
}

/* ===== Theme toggle icon polish ===== */

#themeToggle .icon {
  width: 22px;
  height: 22px;
}

#themeToggle .icon path[style*="fill"] {
  stroke: none;
}

/* ===== Theme toggle custom icon ===== */

#themeToggle .theme-icon {
  width: 20px;
  height: 20px;
  display: block;
  color: var(--muted);
}

#themeToggle:hover .theme-icon {
  color: var(--text);
}

/* ===== Frontend polish v1: navigation, overlays and panels ===== */
body.is-overlay-open,
body.is-sidebar-open {
  overflow: hidden;
}

.sidebar {
  overflow: hidden;
}

.sidebar__nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.32) transparent;
}

.sidebar__nav::-webkit-scrollbar,
.quick-results::-webkit-scrollbar,
.topbar-panel__body::-webkit-scrollbar {
  width: 7px;
}

.sidebar__nav::-webkit-scrollbar-thumb,
.quick-results::-webkit-scrollbar-thumb,
.topbar-panel__body::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.28);
}

.sidebar__spacer {
  display: none;
}

.premium-card,
.user-mini {
  flex: 0 0 auto;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: none;
  border: 0;
  padding: 0;
  background: rgba(2, 6, 23, 0.54);
  backdrop-filter: blur(4px);
  cursor: default;
}

.sidebar-backdrop.is-visible {
  display: block;
}

@media (max-width: 1200px) {
  .sidebar {
    z-index: 110;
  }
}

.topbar-panel-backdrop--search .topbar-panel {
  max-height: min(650px, calc(100vh - 116px));
}

.topbar-panel-backdrop--notifications .topbar-panel {
  width: min(480px, calc(100vw - 32px));
}

.topbar-panel__body {
  scrollbar-gutter: stable;
}

.quick-results {
  max-height: min(430px, calc(100vh - 310px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
}

.quick-result:focus-visible,
.notification-card__action:focus-visible {
  outline: 3px solid rgba(47, 129, 247, 0.35);
  outline-offset: 2px;
}

.notification-card {
  position: relative;
}

.notification-card__label {
  display: inline-flex;
  margin-bottom: 8px;
  color: var(--accent-blue);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.notification-card__action {
  display: inline-flex;
  margin-top: 12px;
  color: #93c5fd;
  font-size: 14px;
  font-weight: 850;
  text-decoration: none;
}

.notification-card__action:hover {
  text-decoration: underline;
}

.badge-count[hidden] {
  display: none !important;
}

:root[data-theme="light"] .topbar-panel-backdrop,
:root[data-theme="light"] .auth-backdrop {
  background: rgba(15, 23, 42, 0.28);
}

:root[data-theme="light"] .notification-card__action {
  color: #1d4ed8;
}

@media (max-width: 700px) {
  .topbar-panel-backdrop {
    align-items: flex-end;
    padding: 16px;
  }

  .topbar-panel {
    max-height: min(82vh, 720px);
    border-radius: 22px;
  }

  .topbar-panel__body {
    max-height: calc(82vh - 92px);
  }

  .quick-results {
    max-height: calc(82vh - 245px);
  }
}
