:root {
  color-scheme: dark;
  --bg: #212121;
  --bg-elevated: #2f2f2f;
  --bg-elevated-soft: #262626;
  --sidebar: #171717;
  --panel: #1e1e1e;
  --panel-strong: #303030;
  --border: #2d2d2d;
  --border-soft: #3a3a3a;
  --ink: #ececec;
  --muted: #a3a3a3;
  --muted-soft: #7c7c7c;
  --accent: #f3f3f3;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100svh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 12px;
  gap: 14px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  overflow-x: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 6px 2px;
}

.logo-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #2d2d2d, #1e1e1e);
  border: 1px solid var(--border-soft);
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.sidebar-title h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.sidebar-kicker {
  margin: 0 0 4px;
  color: var(--muted-soft);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 12px;
  padding-right: 2px;
  overflow-x: hidden;
}

.sidebar-nav {
  display: grid;
  gap: 8px;
}

.nav-group {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid transparent;
  color: var(--ink);
  background: transparent;
}

.nav-item--button {
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.nav-item--button[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.nav-item--active {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.nav-icon {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #2b2b2b;
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 700;
}

.nav-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-copy strong {
  font-size: 0.95rem;
  font-weight: 500;
}

.nav-copy small {
  color: var(--muted);
  line-height: 1.35;
}

.nav-chevron {
  margin-left: auto;
  color: var(--muted-soft);
  font-size: 1rem;
  line-height: 1;
  transition: transform 160ms ease;
}

.nav-item--button[aria-expanded="true"] .nav-chevron {
  transform: rotate(180deg);
}

.nav-drawer {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 220ms ease, opacity 160ms ease;
}

.nav-drawer.is-open {
  max-height: 420px;
  opacity: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}

.settings-panel--embedded {
  margin-left: 18px;
  background: #1b1b1b;
  border-color: #2a2a2a;
  box-shadow: none;
}


.panel-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.panel-kicker {
  margin: 0;
  color: var(--muted-soft);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.panel h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.panel label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.panel label span,
.muted,
.status,
.document-card p,
.upload-zone small {
  color: var(--muted);
}

.chat-history {
  display: grid;
  gap: 8px;
}

.chat-history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #252525;
  color: var(--ink);
  padding: 8px;
}

.chat-history-open {
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 4px;
  text-align: left;
  cursor: pointer;
}

.chat-history-open strong,
.chat-history-open small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-history-open small {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.4;
}

.chat-delete-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}

.chat-delete-btn:hover {
  background: rgba(248, 113, 113, 0.16);
  color: #f87171;
}

.chat-history-item strong{
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
}

.chat-history-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.4;
}

.chat-history-item.is-active {
  border-color: var(--border-soft);
  background: #2e2e2e;
}

.upload-zone {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  min-height: 112px;
  border: 1px dashed var(--border-soft);
  border-radius: 16px;
  background: #232323;
  text-align: center;
  cursor: pointer;
  position: relative;
}

.upload-zone-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-width: 0;
  text-align: center;
}

#upload-file-name {
  max-width: 100%;
  min-width: 0;
  color: var(--ink);
  font-weight: 600;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.upload-zone.has-file #upload-file-name {
  color: var(--ink);
}

.upload-zone.has-file #upload-file-hint {
  color: var(--muted);
}

.upload-check {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #22c55e;
  color: #08110a;
  font-weight: 700;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 160ms ease, transform 160ms ease;
}

.upload-zone.is-uploaded {
  border-color: rgba(34, 197, 94, 0.5);
  background: #1f2b22;
}

.upload-zone.is-uploaded .upload-check {
  opacity: 1;
  transform: scale(1);
}


.upload-zone span {
  color: var(--ink);
  font-weight: 500;
}

.upload-zone input {
  display: none;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 11px 13px;
  background: #252525;
  color: var(--ink);
}

select:focus,
input:focus,
textarea:focus {
  outline: 2px solid rgba(255, 255, 255, 0.12);
  outline-offset: 1px;
}

.upload-panel .primary {
  width: 100%;
}

button.primary {
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  background: #f0f0f0;
  color: #151515;
  font-weight: 700;
  cursor: pointer;
}

.workspace-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100svh;
  background: var(--bg);
}

.study-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  grid-template-rows: auto 1fr;
  gap: 18px;
  padding: 20px;
  min-width: 0;
  height: 100svh;
  overflow: hidden;
}

.question-stage {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.question-stage-card {
  min-height: 280px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: #222;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.question-stage-card.empty {
  color: var(--muted);
}

.question-placeholder {
  max-width: 540px;
  text-align: center;
  line-height: 1.6;
  font-size: 1.05rem;
}

.study-answer-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.study-answer-form textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #202020;
  color: var(--ink);
  padding: 18px;
  font: inherit;
  line-height: 1.6;
}

.study-answer-actions {
  display: flex;
  justify-content: flex-end;
}

.study-answer-actions button {
  border: 0;
  border-radius: 999px;
  padding: 12px 22px;
  background: #f3f4f6;
  color: #111;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}

#next-question-btn {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border-soft);
}

#next-question-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.study-answer-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.study-insights {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.insights-panel {
  min-height: 0;
  overflow: hidden;
}

.insights-tabs {
  display: flex;
  gap: 8px;
}

.insights-tab {
  border: 1px solid var(--border);
  background: #262626;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}

.insights-tab.is-active {
  background: #f3f4f6;
  color: #111;
  border-color: transparent;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  border: 1px solid var(--border);
  background: #252525;
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  text-align: left;
  color: var(--ink);
}

.history-item.is-selected {
  border-color: var(--border-soft);
  background: #303030;
}

.history-mode-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.history-back-btn {
  border: 1px solid var(--border);
  background: #2a2a2a;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.history-item-header span {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.history-question {
  margin: 0;
  line-height: 1.5;
}


.progress-panel,
.evaluation-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.stage-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.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;
}

.question-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.question-body h3 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.4;
}

.question-label {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-soft);
}

.mcq-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.mcq-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #252525;
  color: var(--ink);
  cursor: pointer;
}

.mcq-option input {
  width: auto;
  margin-top: 2px;
  flex: 0 0 auto;
}

.mcq-option span {
  flex: 1;
  line-height: 1.5;
}

.mcq-option-note {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.mcq-option--correct {
  border-color: rgba(34, 197, 94, 0.6);
  background: rgba(34, 197, 94, 0.12);
}

.mcq-option--selected-wrong {
  border-color: rgba(248, 113, 113, 0.6);
  background: rgba(248, 113, 113, 0.12);
}

.mcq-option-explanation {
  margin-top: 8px;
  font-size: 0.92rem;
  line-height: 1.45;
  color: #b9e7c2;
}

.mcq-option--correct {
  border-color: #2f8f4e;
  background: rgba(47, 143, 78, 0.16);
}

.mcq-option-note {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.progress-summary,
.evaluation-summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.progress-summary-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.progress-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: #2a2a2a;
  font-size: 0.75rem;
  color: var(--ink);
}

.progress-meter {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #292929;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-meter-fill {
  height: 100%;
  background: linear-gradient(90deg, #f5f5f5, #bdbdbd);
  border-radius: 999px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.progress-item-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.progress-item-copy small {
  color: var(--muted);
}

.progress-item-score {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.progress-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #252525;
  border: 1px solid var(--border);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.progress-item.is-selected {
  border-color: rgba(243, 244, 246, 0.55);
  background: #343434;
}

.progress-item.is-current {
  border-color: var(--border-soft);
  background: #2e2e2e;
}

.progress-item.is-current.is-selected {
  border-color: #f3f4f6;
  background: #3a3a3a;
}

.status {
  min-height: 1.2em;
  font-size: 0.9rem;
}

.status.success {
  color: #d8ffd2;
}

.status.error {
  color: #ff9898;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}

.auth-card {
  width: min(440px, 100%);
  background: rgba(24, 24, 24, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  padding: 28px;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-toggle-btn,
.auth-logout-btn {
  margin-top: 12px;
}

.workspace-topbar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 0;
}

.workspace-topbar-spacer {
  flex: 1;
}

.account-menu {
  position: relative;
}

.account-avatar-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.account-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  min-width: 220px;
  background: #1c1c1c;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  z-index: 20;
}

.account-email {
  margin: 0 0 12px;
  color: rgba(255, 255, 255, 0.76);
  word-break: break-word;
}

.app-loading {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}

.app-loading-card {
  width: min(420px, 100%);
  background: rgba(24, 24, 24, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  padding: 28px;
  text-align: center;
}



::-webkit-scrollbar {
  width: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #3a3a3a;
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: #4b4b4b;
}

@media (max-width: 1180px) {
  .study-stage {
    grid-template-columns: 1fr;
  }

  .study-insights {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
}


@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-scroll {
    overflow: visible;
  }
}
