:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1b1d21;
  --muted: #626a73;
  --line: #dfe3df;
  --accent: #0f766e;
  --accent-2: #9a3412;
  --soft: #e8f4f2;
  --warn: #fff2d7;
  --danger: #b42318;
  --shadow: 0 14px 45px rgba(27, 29, 33, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 7px;
  min-height: 40px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #b7c1bc;
}

button.primary,
.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 72px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(255, 255, 255, 0.92);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand,
.top-actions,
.icon-text,
.tab,
.file-button,
.send-button {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 245px;
}

.mark {
  width: 42px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #172a2a;
  color: white;
  font-weight: 800;
}

.brand h1,
.brand p,
.pane-head h2,
.pane-head p,
.side-head h2,
.side-head p {
  margin: 0;
}

.brand h1 {
  font-size: 19px;
  line-height: 1.1;
}

.brand p,
.pane-head p,
.side-head p {
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#tutor-select {
  min-height: 40px;
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  background: white;
}

.icon-text {
  gap: 8px;
  white-space: nowrap;
}

i,
svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.workspace {
  height: calc(100vh - 73px);
  display: grid;
  grid-template-columns: minmax(390px, 0.95fr) minmax(430px, 1.05fr);
  gap: 14px;
  padding: 14px;
}

.chat-pane,
.material-pane {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.pane-head,
.side-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.pane-head h2,
.side-head h2 {
  font-size: 18px;
}

.side-head {
  display: block;
}

.side-head.compact {
  padding-bottom: 8px;
}

.file-button {
  width: 42px;
  aspect-ratio: 1;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  max-width: 82%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  line-height: 1.45;
  background: #fbfcfb;
}

.message.user {
  align-self: flex-end;
  background: var(--soft);
}

.message.assistant {
  align-self: flex-start;
}

.message small {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 700;
}

.composer {
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
}

.composer textarea,
.builder-form textarea,
.builder-form input,
.builder-form select,
.dialog-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: white;
  color: var(--ink);
  resize: vertical;
}

.send-button {
  width: 46px;
  justify-content: center;
  align-self: end;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.material-pane {
  display: grid;
  grid-template-rows: auto 1fr;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
  background: #fafafa;
}

.tab {
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.tab.active {
  background: white;
  color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.side-panel {
  display: none;
  min-height: 0;
  overflow: auto;
}

.side-panel.active {
  display: block;
}

.citation-list,
.material-list,
.analytics-grid,
.student-table,
.flag-list {
  padding: 12px 16px;
}

.citation,
.material-item,
.flag-item,
.student-row,
.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fbfcfb;
}

.citation strong,
.material-item strong {
  display: block;
  margin-bottom: 6px;
}

.citation p,
.material-item p,
.flag-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.42;
}

.citation p + .chip-row,
.material-item p + .chip-row {
  margin-top: 9px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-row span,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 7px;
  padding: 2px 7px;
  font-size: 12px;
  color: #24514d;
  background: var(--soft);
}

.status-pill {
  margin-top: 9px;
  color: #5f3515;
  background: #fff2d7;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.student-view-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 16px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6faf8;
}

.student-view-card h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.student-view-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.student-view-card[hidden] {
  display: none;
}

.metric {
  margin: 0;
}

.metric b {
  display: block;
  font-size: 24px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.student-row {
  display: grid;
  grid-template-columns: 1.2fr repeat(3, 0.55fr);
  gap: 8px;
  align-items: center;
}

.student-row span,
.flag-item span {
  color: var(--muted);
  font-size: 12px;
}

.flag-item {
  background: var(--warn);
  border-color: #f2d08b;
}

.flag-item.severe {
  border-color: #f2a097;
  background: #fff0ee;
}

.builder-form {
  padding: 16px;
  display: grid;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.source-upload-form {
  border-top: 1px solid var(--line);
}

.builder-form.split {
  grid-template-columns: 1fr 150px;
}

.builder-form label,
.dialog-card label {
  display: grid;
  gap: 6px;
  color: #394047;
  font-size: 13px;
  font-weight: 700;
}

.builder-form .full,
.wide {
  grid-column: 1 / -1;
}

.wide {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.wide:disabled {
  cursor: progress;
  opacity: 0.64;
}

.file-row {
  min-height: 142px;
  padding: 22px;
  border: 2px dashed #9aa9a3;
  border-radius: 8px;
  place-items: center;
  text-align: center;
  background: #f6faf8;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.file-row:hover,
.file-row.dragging {
  border-color: #2f6f69;
  background: #edf7f4;
  box-shadow: inset 0 0 0 1px rgba(47, 111, 105, 0.18);
}

.file-row.uploading {
  cursor: progress;
  opacity: 0.72;
}

.file-row input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.file-row strong {
  color: #1f2a2d;
  font-size: 16px;
}

.file-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.dropzone-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 42px;
  block-size: 42px;
  border-radius: 8px;
  color: #24514d;
  background: #dceeea;
}

.form-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 22px 90px rgba(0, 0, 0, 0.24);
}

dialog::backdrop {
  background: rgba(18, 25, 28, 0.34);
}

.dialog-card {
  width: min(420px, calc(100vw - 28px));
  padding: 20px;
  display: grid;
  gap: 14px;
}

.dialog-card h2,
.dialog-card p {
  margin: 0;
}

.dialog-card p {
  color: var(--muted);
}

.dialog-card menu {
  padding: 0;
  margin: 4px 0 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 920px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  #tutor-select,
  .top-actions button {
    flex: 1 1 auto;
  }

  .workspace {
    height: auto;
    min-height: calc(100vh - 125px);
    grid-template-columns: 1fr;
  }

  .chat-pane {
    min-height: 68vh;
  }

  .material-pane {
    min-height: 60vh;
  }
}
