/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: Georgia, 'Times New Roman', serif; color: #222; background: #f8f7f4; line-height: 1.6; }
a { color: #7b3b0e; }
a:hover { color: #4a2208; }

/* ===== Layout ===== */
.container { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.container-wide { max-width: min(1480px, calc(100vw - 40px)); }
.container-chat { padding-top: 20px; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { margin: 0; }

/* ===== Navbar ===== */
.navbar { background: #2c1810; color: #f8f7f4; padding: 12px 24px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; }
.navbar-brand { color: #e8c9a0; font-size: 1.3rem; font-weight: bold; text-decoration: none; }
.navbar-side { display: flex; align-items: center; gap: 16px; min-width: 0; }
.navbar-side-left { justify-content: flex-start; }
.navbar-side-right { justify-content: flex-end; }
.navbar-center { display: flex; justify-content: center; min-width: 0; }
.navbar-user { color: #e8c9a0; font-size: 0.9rem; display: inline-flex; align-items: center; gap: 8px; text-align: center; }
.navbar a { color: #e8c9a0; text-decoration: none; }
.navbar a:hover { text-decoration: underline; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.2;
  text-decoration: none;
  transition: opacity 0.15s;
  vertical-align: middle;
  appearance: none;
  -webkit-appearance: none;
  min-height: 38px;
}
.btn:hover { opacity: 0.88; }
.btn-primary { background: #7b3b0e; color: white; }
.btn-secondary { background: #e0d8cc; color: #333; }
.btn-success { background: #2e7d32; color: white; }
.btn-warning { background: #e65100; color: white; }
.btn-danger { background: #c62828; color: white; }
.btn-google { background: white; color: #444; border: 1px solid #ccc; padding: 8px 18px; font-size: 0.95rem; }
.btn-lg,
.btn-sm {
  padding: 8px 18px;
  font-size: 0.95rem;
  min-height: 38px;
}
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: stretch; }
.btn-group > form { display: flex; }
.btn-with-icon { gap: 8px; }
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
  line-height: 1;
  flex: 0 0 auto;
}
.btn-icon svg {
  width: 1em;
  height: 1em;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===== Flash messages ===== */
.flash { padding: 10px 16px; border-radius: 4px; margin-bottom: 16px; }
.flash-success { background: #e8f5e9; border-left: 4px solid #2e7d32; }
.flash-error { background: #ffebee; border-left: 4px solid #c62828; }

/* ===== Badge ===== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.78rem; font-weight: bold; text-transform: uppercase; letter-spacing: 0.03em; }
.badge { background: #e0d8cc; color: #555; }
.badge-published { background: #e8f5e9; color: #2e7d32; }
.badge-draft { background: #fff3e0; color: #e65100; }

/* ===== Login ===== */
.login-page { display: flex; justify-content: center; align-items: center; min-height: 70vh; }
.login-card { text-align: center; background: white; padding: 48px; border-radius: 8px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); }
.login-card h1 { font-size: 2rem; margin-bottom: 8px; }
.login-tagline { color: #777; margin-bottom: 32px; }

/* ===== Case list ===== */
.case-list { list-style: none; padding: 0; margin: 0; }
.case-item { background: white; padding: 16px 20px; border-radius: 6px; margin-bottom: 12px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.case-item-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.case-title-block { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.case-source-label { font-size: 0.82rem; font-weight: bold; letter-spacing: 0.04em; text-transform: uppercase; color: #8a6a52; }
.case-title { font-size: 1.1rem; font-weight: bold; text-decoration: none; color: #7b3b0e; }
.case-info { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.case-student-summary { text-align: right; }
.case-grade { font-weight: bold; color: #2c1810; }
.case-description { color: #666; margin: 0; font-size: 0.92rem; }
.empty-state,
.transcript-empty {
  background: white;
  border: 1px solid #e7ddd1;
  border-left: 4px solid #c9b39d;
  border-radius: 8px;
  padding: 16px 18px;
  color: #4b433d;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.empty-state { margin: 0; }
.empty-state p,
.transcript-empty p { margin: 0; }
.empty-state p + p,
.transcript-empty p + p { margin-top: 8px; }
.empty-state-title,
.transcript-empty-title {
  font-weight: 600;
  color: #2c1810;
}
.empty-state-hint,
.transcript-empty-hint {
  color: #6a625a;
  font-size: 0.94rem;
}
.case-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.case-state-badge { text-transform: none; }
.case-state-not-started { background: #eceff1; color: #455a64; }
.case-state-active { background: #e3f2fd; color: #1565c0; }
.case-state-ended { background: #fff3e0; color: #e65100; }
.case-state-evaluation-failed { background: #ffebee; color: #c62828; }
.case-state-evaluated { background: #e8f5e9; color: #2e7d32; }
.case-state-feedback-available { background: #ede7f6; color: #5e35b1; }
.case-state-finalized { background: #e8f5e9; color: #2e7d32; }
.muted-copy { color: #777; }
.case-reload-report {
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.case-reload-summary {
  background: #f5ede5;
  border-left: 4px solid #7b3b0e;
  border-radius: 4px;
  padding: 12px 16px;
  color: #4a2a10;
}
.case-reload-report-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.case-reload-item {
  background: white;
  border-radius: 6px;
  padding: 16px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.case-reload-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.case-reload-item-title {
  font-weight: bold;
  color: #2c1810;
}
.case-reload-badge {
  text-transform: none;
  white-space: nowrap;
}
.case-reload-badge-imported { background: #e8f5e9; color: #2e7d32; }
.case-reload-badge-imported-with-warnings { background: #fff3e0; color: #e65100; }
.case-reload-badge-skipped { background: #ffebee; color: #c62828; }
.case-reload-issues {
  margin: 12px 0 0;
  padding-left: 18px;
}
.case-reload-issue {
  margin-bottom: 8px;
}
.case-reload-issue-warning { color: #8a5200; }
.case-reload-issue-error { color: #a61b1b; }
.case-reload-success {
  margin: 12px 0 0;
  color: #2e7d32;
  font-weight: 600;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: bold; margin-bottom: 6px; }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid #ccc; border-radius: 4px; font-size: 0.95rem; font-family: inherit; }
.form-control:focus { outline: none; border-color: #7b3b0e; box-shadow: 0 0 0 2px rgba(123,59,14,0.15); }
.case-text-area { font-family: 'Courier New', monospace; font-size: 0.88rem; }
.form-actions { display: flex; gap: 12px; margin-top: 24px; }
.help-text { color: #777; font-size: 0.88rem; margin-bottom: 12px; }
.case-form { max-width: 800px; }
.student-case-panel { background: white; padding: 18px 20px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); width: fit-content; max-width: 100%; }
.student-case-note { margin-top: 0; margin-bottom: 14px; color: #555; }
.retry-form { margin-bottom: 12px; }
.reader-shell { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(260px, 0.9fr); gap: 24px; align-items: start; }
.reader-panel { background: white; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); overflow: hidden; }
.reader-panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 22px 24px 16px; border-bottom: 1px solid #eee2d6; }
.reader-panel-header h2 { margin: 0; }
.reader-description { margin: 6px 0 0; color: #6a625a; }
.case-reader-text,
.case-reference-body {
  white-space: pre-wrap;
  font-size: 1rem;
  line-height: 1.8;
  color: #2d241e;
  font-family: Georgia, 'Times New Roman', serif;
}
.case-reader-text { padding: 24px; min-height: 520px; }
.reader-sidebar { position: sticky; top: 24px; width: 100%; }

/* ===== Case Reader (single-column) ===== */
.reading-progress-track {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: rgba(0,0,0,0.09);
  z-index: 300;
  pointer-events: none;
}
.reading-progress-bar {
  height: 100%;
  width: 0%;
  background: #7b3b0e;
  transition: width 0.12s linear;
}

.case-action-bar {
  max-width: 760px;
  margin: 0 auto 16px;
  padding: 10px 0 12px;
  border-bottom: 1px solid #ddd5ca;
}
.case-action-bar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.case-action-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.case-action-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }


.case-context-note {
  max-width: 760px;
  margin: 0 auto 20px;
  padding: 11px 16px;
  border-radius: 4px;
  font-size: 0.92rem;
  border-left: 4px solid #ccc;
  line-height: 1.5;
}
.case-context-note-start    { background: #f5ede5; border-left-color: #7b3b0e; color: #4a2a10; }
.case-context-note-active   { background: #e3f2fd; border-left-color: #1565c0; color: #0d47a1; }
.case-context-note-ended    { background: #fff3e0; border-left-color: #e65100; color: #bf360c; }
.case-context-note-failed   { background: #ffebee; border-left-color: #c62828; color: #b71c1c; }
.case-context-note-evaluated{ background: #e8f5e9; border-left-color: #2e7d32; color: #1b5e20; }

.case-document {
  max-width: 760px;
  margin: 0 auto 56px;
  background: #fdf8f2;
  border: 1px solid #e2d0b8;
  border-radius: 3px;
  box-shadow: 0 3px 18px rgba(44,24,16,0.08), 0 1px 4px rgba(0,0,0,0.04);
  padding: 52px 64px 52px;
}
.case-document-header {
  text-align: center;
  margin-bottom: 36px;
  padding-bottom: 28px;
}
.case-document-ornament {
  color: #7b3b0e;
  font-size: 1.1rem;
  letter-spacing: 0.5em;
  margin: 6px 0;
  opacity: 0.45;
  user-select: none;
}
.case-document-title {
  font-size: 1.45rem;
  font-weight: bold;
  margin: 10px 0 6px;
  line-height: 1.3;
  color: #1e1008;
}
.case-document-caption {
  margin: 20px auto 6px;
  text-align: center;
}
.case-caption-parties {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 10px;
}
.case-caption-party {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: #2a1a08;
  letter-spacing: 0.01em;
  line-height: 1.35;
}
.case-caption-v {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.85rem;
  font-style: italic;
  color: #8a7060;
  letter-spacing: 0.08em;
  margin: 2px 0;
}
.case-caption-court {
  font-variant: small-caps;
  letter-spacing: 0.08em;
  color: #7b3b0e;
  text-transform: uppercase;
  font-size: 0.72rem;
  opacity: 0.8;
}
.case-syllabus {
  margin: 0 0 32px;
  padding: 4px 0;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.9rem;
  font-style: italic;
  color: #4a3828;
  line-height: 1.65;
  text-align: center;
}
.case-document-body {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.01rem;
  color: #27190f;
}
.case-paragraph {
  text-indent: 1.5em;
  margin: 0 0 0.1em;
  line-height: 1.82;
  text-align: justify;
  hyphens: auto;
}
.case-paragraph-first {
  text-indent: 0;
}
.case-paragraph-first::first-letter {
  float: left;
  font-size: 3.5rem;
  line-height: 0.82;
  padding-right: 7px;
  padding-top: 4px;
  color: #7b3b0e;
  font-weight: bold;
}
.case-paragraph-attribution {
  margin: 1.4em 0 0.6em;
  font-variant: small-caps;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  color: #3a2010;
  text-align: left;
}
.case-paragraph-note {
  margin: 1em 0;
  font-style: italic;
  font-size: 0.88rem;
  color: #7b6050;
  text-align: center;
}
.case-section-heading {
  margin: 2.4rem 0 1.2rem;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  font-variant: small-caps;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #5f3a1f;
}
.case-subsection-heading {
  margin: 1.8rem 0 0.7rem;
  font-size: 0.96rem;
  font-weight: 700;
  font-variant: small-caps;
  letter-spacing: 0.06em;
  color: #402513;
}
.case-section-divider {
  width: 100%;
  height: 1px;
  margin: 1.9rem 0 1.6rem;
  background: linear-gradient(90deg, transparent 0%, rgba(123,59,14,0.35) 18%, rgba(123,59,14,0.35) 82%, transparent 100%);
}
.case-paragraph-list {
  text-indent: 0;
  padding-left: 1.6rem;
  margin-left: 0.4rem;
}
.case-document-footer {
  margin-top: 44px;
  padding-top: 24px;
  border-top: 1px solid #dcc6af;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.case-sticky-bar {
  position: fixed;
  top: 3px;
  left: 0; right: 0;
  z-index: 290;
  background: #2c1810;
  color: #e8c9a0;
  padding: 9px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transform: translateY(-100%);
  transition: transform 0.22s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,0.22);
}
.case-sticky-bar.is-visible { transform: translateY(0); }
.case-sticky-title {
  font-size: 0.88rem;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  color: #e8c9a0;
}
.case-sticky-actions { display: flex; gap: 8px; flex-shrink: 0; }

.case-keypoints-section {
  max-width: 760px;
  margin: 0 auto 56px;
}

/* ===== Key points editor ===== */
.key-point-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.key-point-row .form-control { flex: 1; }
.weight-input { width: 80px; flex: 0 0 80px; }
.key-points-list { padding-left: 20px; }
.kp-weight { color: #999; font-size: 0.85rem; }

/* ===== Chat ===== */
.chat-page {
  --case-pane-width: 42%;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-page .navbar {
  flex: 0 0 auto;
}
.chat-page .container-chat {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-page.case-pane-collapsed { --case-pane-width: 0%; }
.chat-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #ddd; }
.chat-header h2 { margin: 0; }
.chat-layout {
  display: grid;
  grid-template-columns: minmax(300px, var(--case-pane-width)) 14px minmax(0, calc(100% - var(--case-pane-width)));
  gap: 0;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}
.case-reference-pane {
  background: linear-gradient(180deg, #f5ede3 0%, #efe3d6 100%);
  border: 1px solid #dcc6af;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.case-reference-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(123,59,14,0.12);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.case-reference-heading { min-width: 0; }
.case-reference-header h3 { margin: 0; }
.case-reference-body {
  padding: 16px 18px 20px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  font-size: 0.92rem;
  line-height: 1.55;
}
.chat-layout-divider {
  width: 14px;
  margin: 0 10px;
  cursor: col-resize;
  align-self: stretch;
  position: relative;
}
.chat-layout-divider::before {
  content: "";
  position: absolute;
  top: 24px;
  bottom: 24px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(123,59,14,0.16), rgba(123,59,14,0.46), rgba(123,59,14,0.16));
  border-radius: 999px;
}
.chat-main {
  min-width: 0;
  margin-left: 12px;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chat-page.case-pane-collapsed .chat-layout {
  grid-template-columns: 0 0 minmax(0, 1fr);
}
.chat-page.case-pane-collapsed .case-reference-pane,
.chat-page.case-pane-collapsed .chat-layout-divider {
  opacity: 0;
  pointer-events: none;
}
.chat-page.case-pane-collapsed .case-reference-pane {
  border-width: 0;
  max-height: 0;
}
.chat-page.case-pane-collapsed .chat-main {
  margin-left: 0;
}

.chat-window {
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 20px;
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  margin-bottom: 16px;
}

.chat-bubble { margin-bottom: 16px; max-width: 85%; }
.chat-bubble.user { margin-left: auto; }
.chat-bubble.assistant { margin-right: auto; }

.bubble-content {
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
}
.chat-bubble.user .bubble-content {
  background: #7b3b0e;
  color: white;
  border-bottom-right-radius: 4px;
}
.chat-bubble.assistant .bubble-content {
  background: #f0ebe3;
  color: #222;
  border-bottom-left-radius: 4px;
}

/* Anti-copy-paste on assistant messages */
.no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.chat-input-area { display: flex; gap: 12px; align-items: flex-end; }
.chat-input { flex: 1; padding: 10px 14px; border: 1px solid #ccc; border-radius: 6px; font-size: 0.95rem; font-family: inherit; resize: vertical; }
.chat-input:focus { outline: none; border-color: #7b3b0e; box-shadow: 0 0 0 2px rgba(123,59,14,0.15); }

/* ===== Evaluation ===== */
.eval-score-card {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: #2c1810;
  color: white;
  padding: 24px 32px;
  border-radius: 8px;
  margin-bottom: 24px;
  width: fit-content;
}
.score-number { font-size: 3rem; font-weight: bold; }
.score-label { font-size: 1.2rem; color: #e8c9a0; }

.eval-feedback { background: white; padding: 20px; border-radius: 6px; margin-bottom: 24px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.eval-feedback h2 { margin-top: 0; }
.eval-feedback-summary { padding: 22px 24px; }
.eval-feedback-body { margin: 0; font-size: 0.98rem; line-height: 1.7; color: #3a312a; }
.eval-feedback-body + .eval-feedback-body { margin-top: 14px; }

.kp-results { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.kp-result-card { background: white; padding: 16px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); border-left: 4px solid #ccc; }
.kp-result-card.demonstrated { border-left-color: #2e7d32; }
.kp-result-card.not-demonstrated { border-left-color: #c62828; }
.kp-result-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 8px; }
.kp-text { font-weight: bold; }
.kp-score { font-weight: bold; font-size: 1.1rem; white-space: nowrap; }
.kp-feedback-sections { display: flex; flex-direction: column; gap: 12px; }
.kp-feedback-section { display: flex; flex-direction: column; gap: 6px; }
.kp-feedback-label {
  font-size: 0.8rem;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8a6a52;
}
.kp-evidence-quote {
  margin: 0;
  padding: 12px 14px;
  border-left: 3px solid #c9b39d;
  border-radius: 6px;
  background: #f7f1ea;
  color: #3f3023;
  font-size: 0.95rem;
  line-height: 1.6;
}
.kp-rationale { color: #4b433d; margin: 0; font-size: 0.93rem; line-height: 1.68; }
.kp-status-label { font-weight: 600; color: #6a5c50; white-space: nowrap; font-size: 0.88rem; }

.feedback-status-note {
  padding: 14px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  border-left: 4px solid #7b3b0e;
}
.feedback-status-pending { background: #f5ede5; color: #4a2a10; }
.feedback-status-final { background: #e8f5e9; color: #1b5e20; border-left-color: #2e7d32; }

.review-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.review-summary-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.review-summary-card h2 { margin-top: 0; margin-bottom: 8px; }
.review-score { font-size: 2rem; font-weight: bold; margin: 0 0 8px; color: #2c1810; }
.review-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 20px;
  align-items: start;
}
.review-column { min-width: 0; }
.review-form { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.review-kp-controls { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.review-checkbox { display: inline-flex; align-items: center; gap: 8px; font-weight: bold; margin-bottom: 20px; }
.review-kp-edit-group { padding: 4px 0; }
.review-kp-divider { border: 0; border-top: 1px solid #ddd5ca; margin: 20px 0; }

/* ===== Loading ===== */
.loading-state { text-align: center; padding: 48px; color: #777; }
.error-state { background: white; padding: 24px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); width: fit-content; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 3px solid #ccc; border-top-color: #7b3b0e; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Results table ===== */
.results-table { width: 100%; border-collapse: collapse; background: white; border-radius: 6px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.results-table th { background: #2c1810; color: #e8c9a0; padding: 12px 16px; text-align: left; }
.results-table td { padding: 12px 16px; border-bottom: 1px solid #eee; }
.results-table tr:last-child td { border-bottom: none; }
.results-table-link {
  color: inherit;
  text-decoration: none;
}
.results-table-link:hover {
  color: #7b3b0e;
  text-decoration: underline;
  text-underline-offset: 0.12em;
}
.results-table-subtle-links {
  margin-top: 4px;
}
.results-table-secondary-link {
  font-size: 0.86rem;
  color: #7b3b0e;
  text-decoration: none;
}
.results-table-secondary-link:hover {
  text-decoration: underline;
  text-underline-offset: 0.12em;
}
.score-cell { font-size: 1.05rem; }
.eval-actions { margin-top: 24px; }

/* ===== Transcript (instructor review) ===== */
.transcript-section { margin-top: 28px; border: 1px solid #ddd5ca; border-radius: 8px; overflow: hidden; background: white; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.transcript-toggle { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: #f5ede5; border: none; cursor: pointer; font-size: 1rem; font-family: inherit; font-weight: bold; color: #2c1810; text-align: left; }
.transcript-toggle:hover { background: #eddccc; }
.transcript-toggle-icon { transition: transform 0.2s; font-size: 0.8rem; color: #7b3b0e; }
.transcript-section.open .transcript-toggle-icon { transform: rotate(180deg); }
.transcript-body { display: none; padding: 20px; flex-direction: column; gap: 12px; }
.transcript-section.open .transcript-body { display: flex; }
.transcript-body--page { display: flex; padding: 0; }
.transcript-message { display: flex; flex-direction: column; gap: 4px; max-width: 85%; }
.transcript-message--user { align-self: flex-end; align-items: flex-end; }
.transcript-message--assistant { align-self: flex-start; align-items: flex-start; }
.transcript-role { font-size: 0.78rem; font-weight: bold; color: #888; text-transform: uppercase; letter-spacing: 0.04em; }
.transcript-content { padding: 10px 14px; border-radius: 10px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: break-word; font-size: 0.95rem; }
.transcript-message--user .transcript-content { background: #7b3b0e; color: white; border-bottom-right-radius: 3px; }
.transcript-message--assistant .transcript-content { background: #f0ebe3; color: #222; border-bottom-left-radius: 3px; }
.transcript-time { font-size: 0.75rem; color: #aaa; }

@media (max-width: 640px) {
  .chat-page {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    display: block;
  }

  .chat-page .container-chat {
    display: block;
    overflow: visible;
  }

  .navbar {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .navbar-side,
  .navbar-side-left,
  .navbar-side-right,
  .navbar-center {
    justify-content: center;
    flex-wrap: wrap;
  }

  .page-header,
  .case-item-header,
  .case-reload-item-header,
  .kp-result-header,
  .chat-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .reader-shell,
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .case-info {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .case-document {
    padding: 28px 20px;
  }

  .case-document-title { font-size: 1.2rem; }

  .case-document-body::first-letter {
    font-size: 2.6rem;
  }

  .case-section-heading {
    letter-spacing: 0.12em;
  }

  .case-action-bar,
  .case-context-note,
  .case-keypoints-section {
    margin-left: 0;
    margin-right: 0;
    max-width: 100%;
  }

  .chat-layout-divider {
    display: none;
  }

  .chat-main {
    order: 1;
  }

  .case-reference-pane {
    order: 2;
    margin-top: 16px;
    min-height: auto;
  }

  .chat-main {
    margin-left: 0;
    margin-top: 0;
    min-height: auto;
    display: block;
  }

  .reader-sidebar,
  .case-reference-pane {
    position: static;
    display: block;
  }

  .case-reference-body {
    flex: none;
    min-height: auto;
    overflow: visible;
    max-height: none;
  }

  .chat-window {
    flex: none;
    min-height: 400px;
    max-height: none;
  }

  .case-reference-header {
    align-items: flex-start;
  }

  .case-student-summary {
    text-align: left;
  }

  .review-columns {
    grid-template-columns: 1fr;
  }

  .student-case-panel,
  .error-state {
    width: 100%;
  }
}
