:root {
  --primary: #6b173c;
  --primary-dark: #4e0f2a;
  --primary-soft: #f7e8ef;
  --ink: #1f1720;
  --muted: #766a72;
  --line: #e7dde2;
  --paper: #fffafb;
  --white: #ffffff;
  --danger: #a52727;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #fff 0%, #fbf3f6 52%, #f5e4ec 100%);
}

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

button {
  border: 0;
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 800;
  color: var(--white);
  background: var(--primary);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 28px;
  overflow-y: auto;
  background: var(--primary);
  color: var(--white);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: var(--primary);
  background: var(--white);
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1rem;
}

.brand p,
.note {
  margin-top: 6px;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.5;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
}

.mode-tab {
  padding: 10px;
  color: rgba(255, 255, 255, 0.82);
  background: transparent;
}

.mode-tab.active {
  color: var(--primary);
  background: var(--white);
}

.sidebar-panel,
.main-panel {
  display: none;
}

.sidebar-panel.active {
  display: grid;
  gap: 18px;
}

.main-panel.active {
  display: grid;
}

.stack-form,
.teacher-tools {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  background: var(--white);
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(107, 23, 60, 0.14);
}

.stack-form button,
.inline-form button,
.google-login {
  color: var(--primary);
  background: var(--white);
}

.google-login {
  display: block;
  border-radius: 8px;
  padding: 12px 16px;
  text-align: center;
  text-decoration: none;
  font-weight: 800;
}

.teacher-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.status-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.86);
}

.dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #e6bd35;
}

.dot.ok {
  background: #54d17a;
}

.dot.bad {
  background: #ff7a7a;
}

.note {
  margin-top: auto;
  font-size: 0.92rem;
}

.history-panel {
  display: grid;
  gap: 10px;
  padding-top: 6px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading button,
.tiny-button,
#clear-dashboard-filters,
#refresh-dashboard {
  padding: 9px 12px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 0.88rem;
}

.compact-list,
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.list-item,
.empty-list-item,
.chip {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: var(--white);
  text-align: left;
  background: rgba(255, 255, 255, 0.1);
}

.chip {
  width: auto;
  padding: 7px 10px;
}

.list-item span,
.empty-list-item,
.muted-text {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 500;
}

.sidebar .list-item span,
.sidebar .empty-list-item {
  color: rgba(255, 255, 255, 0.78);
}

.main-panel {
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  padding: 28px;
}

.teacher-panel {
  grid-template-rows: auto minmax(0, 1fr);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-header h2 {
  max-width: 900px;
  font-size: 1.35rem;
  line-height: 1.3;
}

.session-pill {
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 800;
}

#reset-button {
  background: var(--primary-soft);
  color: var(--primary);
}

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

.review-messages {
  min-height: 0;
  padding: 0;
}

.message {
  display: flex;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(820px, 88%);
  padding: 14px 16px;
  border-radius: 8px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: 0 10px 32px rgba(44, 22, 35, 0.06);
}

.message.user .bubble {
  color: var(--white);
  background: var(--primary);
  border-color: var(--primary);
}

.message.system .bubble {
  color: var(--danger);
  background: #fff1f1;
  border-color: #f0c4c4;
}

.math-content pre {
  overflow-x: auto;
  margin: 10px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: #f6f0f3;
}

.math-content code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.92em;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

textarea {
  min-height: 74px;
  resize: vertical;
}

.empty-state {
  align-self: center;
  justify-self: center;
  max-width: 560px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--white);
}

.teacher-dashboard {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  padding-top: 20px;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(180px, 0.8fr) auto auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.summary-strip div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.summary-strip strong {
  display: block;
  color: var(--primary);
  font-size: 1.55rem;
}

.summary-strip span {
  color: var(--muted);
  font-size: 0.9rem;
}

.conversation-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(0, 1.35fr);
  gap: 16px;
  min-height: 0;
}

.conversation-list-panel,
.conversation-detail {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  gap: 12px;
}

.conversation-list,
.conversation-detail .messages {
  overflow-y: auto;
}

.conversation-list {
  display: grid;
  align-content: start;
  gap: 10px;
}

.conversation-card {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
  background: var(--white);
}

.conversation-card:hover {
  border-color: rgba(107, 23, 60, 0.42);
  box-shadow: 0 10px 30px rgba(44, 22, 35, 0.08);
}

.conversation-card strong {
  font-size: 1rem;
}

.conversation-card span {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.4;
}

.conversation-card small,
.card-kicker {
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    padding: 22px;
  }

  .note {
    margin-top: 0;
  }

  .main-panel {
    min-height: 68vh;
    padding: 20px;
  }

  .chat-header {
    flex-direction: column;
  }

  .chat-form,
  .filter-bar,
  .summary-strip,
  .conversation-layout {
    grid-template-columns: 1fr;
  }

  .conversation-list-panel,
  .conversation-detail {
    min-height: 300px;
  }
}
