:root {
  --bg: #fbf9f1;
  --surface: #ffffff;
  --border: #e7e1d0;
  --text: #20293a;
  --muted: #6e6959;
  --primary: #223a5e;
  --primary-dark: #16283f;
  --primary-tint: #eef1f6;
  --teacher: #223a5e;
  --student: #0f7a54;
  --accent: #10b981;
  --danger: #dc2626;
  --highlight: #fde68a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.container.narrow { max-width: 440px; }
.container.wide { max-width: 1180px; }

.review-layout {
  display: flex;
  align-items: flex-start;
  gap: 28px;
}
.review-main {
  flex: 1 1 auto;
  min-width: 0;
}
.review-sidebar {
  width: 340px;
  flex-shrink: 0;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding-bottom: 20px;
}
@media (max-width: 860px) {
  .review-layout { flex-direction: column; }
  .review-sidebar { width: 100%; position: static; max-height: none; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar .brand { font-weight: 700; font-size: 1.1rem; }
.topbar .brand a { color: var(--text); }
.brand-accent { color: var(--student); }
.topbar .right { display: flex; align-items: center; gap: 14px; font-size: 0.92rem; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge.teacher { background: #e4e9f0; color: var(--teacher); }
.badge.student { background: #dcf3e8; color: var(--student); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

h1 { font-size: 1.6rem; margin: 0 0 6px; }
h2 { font-size: 1.2rem; margin: 0 0 14px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
p.subtitle { color: var(--muted); margin-top: 0; }

.role-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 24px;
}

.role-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  transition: border-color 0.15s, transform 0.15s;
}
.role-card:hover { border-color: var(--primary); transform: translateY(-2px); text-decoration: none; }
.role-card h3 { margin-bottom: 4px; }
.role-card p { color: var(--muted); font-size: 0.88rem; margin: 0; }
.role-card-teacher { border-top: 4px solid var(--teacher); }
.role-card-teacher h3 { color: var(--teacher); }
.role-card-teacher:hover { border-top-color: var(--teacher); }
.role-card-student { border-top: 4px solid var(--student); }
.role-card-student h3 { color: var(--student); }
.role-card-student:hover { border-top-color: var(--student); }

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

label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }

input[type="text"], input[type="email"], input[type="password"], textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
textarea { resize: vertical; min-height: 90px; }

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

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  background: var(--primary);
  color: white;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:hover, .btn:hover { background: var(--primary-dark); text-decoration: none; }
button.secondary, .btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover, .btn.secondary:hover { background: var(--bg); }
button.danger { background: var(--danger); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
button.small, .btn.small { padding: 6px 12px; font-size: 0.82rem; }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.needs-review-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  background: #fef3c7;
  color: #92400e;
}

.error-msg {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
}
.hidden { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

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

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.list-item:hover { border-color: var(--primary); }
.list-item .title { font-weight: 600; }
.list-item .meta { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }

.list-item-link {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.list-item-link:hover { text-decoration: none; }
.list-item .row-action-btn { margin-left: 10px; flex-shrink: 0; }

.list-item.locked-item { background: var(--bg); }

.class-code {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: var(--primary-tint);
  color: var(--primary-dark);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.9rem;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}

.breadcrumb { font-size: 0.85rem; color: var(--muted); margin-bottom: 14px; }
.breadcrumb a { color: var(--muted); }

.roster-toggle {
  background: none;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text);
}
.roster-toggle:hover { background: none; }
.roster-toggle #rosterChevron {
  display: inline-block;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--muted);
  transition: transform 0.15s;
}
.roster-toggle #rosterChevron.expanded { transform: rotate(90deg); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  background: none; color: var(--muted); border-radius: 0;
  padding: 10px 4px; margin-right: 20px; border-bottom: 2px solid transparent;
}
.tab-btn:hover { background: none; color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

#submissionView {
  overflow-x: auto;
  max-width: 100%;
}

.docx-container {
  /* zoom scales rendered output without rescaling the layout width it was
     computed against, so pre-shrink the box by the same factor to compensate */
  width: calc(100% / 1.2);
  zoom: 1.2;
}
.docx-container section {
  /* docx-preview bakes the source file's own page margins in as inline padding,
     which can be huge and vary wildly between documents — override with a
     consistent, modest inset instead so every upload renders predictably. */
  width: 100% !important;
  padding: 16px !important;
  box-sizing: border-box;
}

/* Submission text + highlighting */
.annotated-text {
  white-space: pre-wrap;
  line-height: 1.8;
  font-size: 1rem;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  user-select: text;
}
.annotated-text mark {
  background: var(--highlight);
  border-radius: 3px;
  padding: 1px 0;
  cursor: pointer;
}
.annotated-text mark.active { background: #fbbf24; }

.annotation-popover {
  position: absolute;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 14px;
  width: 320px;
}
.annotation-popover textarea { min-height: 60px; }
.bank-list { max-height: 140px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.bank-pick {
  text-align: left;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 400;
  font-size: 0.82rem;
  padding: 6px 10px;
}
.bank-pick:hover { background: var(--primary-tint); }

.annotation-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.annotation-card:hover { border-color: var(--primary); background: var(--primary-tint); }
.annotation-card .quote {
  font-style: italic;
  color: var(--muted);
  border-left: 3px solid var(--highlight);
  padding-left: 10px;
  margin: 0 0 6px;
  font-size: 0.88rem;
}

.rubric-card { margin-top: 24px; }
.rubric-score-badge {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary-dark);
  white-space: nowrap;
}
.rubric-criterion {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--bg);
}
.rubric-levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.rubric-level-btn {
  text-align: left;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  font-weight: 400;
}
.rubric-level-btn:hover { border-color: var(--primary); background: var(--primary-tint); }
.rubric-level-btn.selected {
  border-color: var(--primary);
  background: var(--primary-tint);
}
.rubric-level-btn .level-title-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 0.88rem;
}
.rubric-criterion-comment { min-height: 50px; font-size: 0.85rem; }

/* AI-use declaration */
.ai-tool-entry {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
  background: var(--bg);
}
.ai-tool-entry .field { margin-bottom: 10px; }
.ai-tool-entry .field:last-of-type { margin-bottom: 0; }
.ai-tool-summary {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--bg);
}
button.secondary.active-choice, .btn.secondary.active-choice {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
