:root {
  color-scheme: light;
  --navy: #17233a;
  --blue: #2857c8;
  --blue-soft: #e9effd;
  --paper: #ffffff;
  --canvas: #eef1f5;
  --ink: #172033;
  --muted: #667085;
  --line: #d4dae4;
  --amber: #a96800;
  --amber-soft: #fff3d8;
  --green: #167153;
  --green-soft: #e1f3eb;
  --red: #a33a3a;
  --red-soft: #fbe7e7;
  --shadow: 0 12px 32px rgba(23, 35, 58, 0.12);
  --mobile-touch-target: 44px;
  font-family: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
}

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

button, select, input, textarea, a { outline-offset: 3px; }

:focus-visible { outline: 3px solid #7ca1ff; }

.topbar {
  height: 68px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 300px) auto auto;
  align-items: center;
  gap: 24px;
  padding: 0 18px;
  background: var(--navy);
  color: white;
}

.identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.identity > div { display: flex; flex-direction: column; min-width: 0; }
.identity strong { font-size: 16px; }
.identity span:not(.mark) { margin-top: 2px; color: #b9c5d9; font-size: 12px; }

.mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 2px solid white;
  font-weight: 800;
  font-size: 19px;
}

.progress { display: grid; gap: 7px; color: #d7deea; font-size: 12px; }
.progress-track { height: 4px; overflow: hidden; background: #3a4861; }
.progress-track span { display: block; width: 0; height: 100%; background: #85a9ff; transition: width 180ms ease; }
.collaboration-tools { display: flex; align-items: center; gap: 10px; color: #d7deea; font-size: 12px; }
.collaboration-tools .quiet-button { min-height: 34px; padding: 6px 10px; }

.quiet-button, .primary-button {
  min-height: 38px;
  border: 1px solid var(--line);
  padding: 8px 13px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  border-radius: 6px;
}

.topbar .quiet-button { border-color: #64718a; background: transparent; color: white; }
.primary-button { border-color: var(--blue); background: var(--blue); color: white; font-weight: 700; }
.quiet-button:hover, .primary-button:hover { filter: brightness(0.97); }
.quiet-button.disabled { opacity: 0.45; pointer-events: none; }

.workbench {
  height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: 286px minmax(520px, 1fr) minmax(420px, 42vw);
}

.navigation, .sheet, .document-panel { min-height: 0; }

.navigation {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #f7f8fa;
}

.navigation-controls { padding: 16px; border-bottom: 1px solid var(--line); }
.navigation label, .decision-dock > label { display: block; margin: 0 0 6px; font-size: 12px; font-weight: 700; color: #4b5568; }
.navigation select, .navigation input, .decision-dock textarea {
  width: 100%;
  border: 1px solid #bbc3d0;
  border-radius: 5px;
  padding: 9px 10px;
  background: white;
  color: var(--ink);
}
.navigation input { margin-bottom: 13px; }
.navigation select { margin-bottom: 13px; }

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.mode-switch button {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 7px 5px;
  background: white;
  color: #505a6c;
  cursor: pointer;
  font-size: 12px;
}
.mode-switch button.active { border-color: var(--blue); background: var(--blue-soft); color: #163b91; font-weight: 700; }

.review-list { overflow: auto; padding: 8px; }
.review-list-empty { padding: 22px 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.review-list button {
  width: 100%;
  display: grid;
  gap: 5px;
  margin-bottom: 6px;
  padding: 11px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.review-list button:hover { background: #edf0f5; }
.review-list button.active { border-color: #a9b9de; background: white; box-shadow: 0 3px 12px rgba(23,35,58,.08); }
.candidate-line { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.candidate-line strong { font-size: 13px; }
.candidate-line span { color: var(--muted); font-size: 11px; }
.list-status { font-size: 11px; color: var(--muted); }
.list-status.complete { color: var(--green); font-weight: 700; }
.list-status.priority { color: var(--amber); }

.sheet { position: relative; overflow: auto; background: var(--paper); }
.sheet-content { max-width: 850px; margin: 0 auto; padding: 30px 34px 270px; }

.review-header { padding-bottom: 24px; border-bottom: 2px solid var(--ink); }
.review-index { color: var(--blue); font-size: 13px; font-weight: 800; }
.review-header h1 { max-width: 780px; margin: 8px 0 15px; font-size: clamp(24px, 2.2vw, 35px); line-height: 1.12; letter-spacing: -0.025em; }
.candidate-title { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 17px; }
.candidate-title span { color: var(--muted); }

.status-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 17px; }
.status-chip { padding: 6px 9px; border-radius: 4px; font-size: 12px; font-weight: 700; background: #eef0f4; color: #445064; }
.status-chip.current { background: var(--blue-soft); color: #193c8c; }
.status-chip.priority { background: var(--amber-soft); color: #7a4800; }
.status-chip.human { background: var(--green-soft); color: #115a43; }

.review-section { padding: 25px 0; border-bottom: 1px solid var(--line); }
.review-section h2 { margin: 0 0 13px; font-size: 17px; letter-spacing: -0.01em; }
.review-section p { max-width: 76ch; margin: 0 0 12px; line-height: 1.62; }
.review-section ul { margin: 0; padding-left: 20px; }
.review-section li { max-width: 76ch; margin: 0 0 8px; line-height: 1.5; }
.review-section .muted { color: var(--muted); }

.lens-grid, .reasons-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.lens-block, .reason-block { padding: 15px; background: #f6f7f9; border-left: 3px solid #aeb8ca; }
.reason-block.keep { border-left-color: var(--green); }
.reason-block.reconsider { border-left-color: var(--amber); }
.lens-block strong, .reason-block strong { display: block; margin-bottom: 9px; font-size: 13px; }

.evidence-list { display: grid; gap: 10px; }
.evidence-card {
  width: 100%;
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  padding: 0;
  border: 1px solid var(--line);
  background: white;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.evidence-card:hover { border-color: #8196c4; box-shadow: 0 4px 16px rgba(23,35,58,.08); }
.evidence-page { display: grid; align-content: start; justify-items: center; gap: 2px; min-height: 100%; padding: 13px 5px; background: var(--navy); color: white; }
.evidence-page strong { font-size: 17px; }
.evidence-page span { font-size: 10px; color: #cbd4e4; }
.evidence-copy { padding: 13px 14px 13px 0; }
.evidence-copy blockquote { margin: 0 0 9px; color: #253047; font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-size: 15px; line-height: 1.48; }
.evidence-copy p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.evidence-source { display: block; margin-bottom: 6px; color: var(--blue); font-size: 11px; font-weight: 800; }

.comparison { margin-top: 20px; border: 1px solid var(--line); }
.comparison summary { padding: 12px 14px; cursor: pointer; font-weight: 700; background: #f6f7f9; }
.comparison table { width: 100%; border-collapse: collapse; font-size: 12px; }
.comparison th, .comparison td { padding: 8px 10px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
.comparison tr[data-key] { cursor: pointer; }
.comparison tr[data-key]:hover { background: var(--blue-soft); }

.human-question { padding: 18px; background: var(--navy); color: white; }
.human-question p { margin: 0; color: white; font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-size: 18px; line-height: 1.45; }

.group-responses { display: grid; gap: 8px; }
.group-response { padding: 13px 14px; border: 1px solid var(--line); border-left: 3px solid var(--blue); background: #f8f9fb; }
.group-response-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 7px; }
.group-response p { margin: 0; font-size: 13px; }

.decision-dock {
  position: sticky;
  z-index: 10;
  bottom: 0;
  width: min(850px, 100%);
  margin: 0 auto;
  padding: 16px 22px 18px;
  border-top: 1px solid #aeb7c6;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 -12px 30px rgba(23, 35, 58, 0.12);
  backdrop-filter: blur(12px);
}
.decision-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 10px; }
.decision-heading > div { display: flex; flex-direction: column; }
.decision-heading span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.revisit-control { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.decision-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 10px; }
.decision-options button { min-height: 38px; border: 1px solid var(--line); border-radius: 5px; background: white; color: #404b5f; cursor: pointer; font-size: 12px; }
.decision-options button.selected { border-color: var(--blue); background: var(--blue-soft); color: #193c8c; font-weight: 800; }
.decision-dock textarea { resize: vertical; min-height: 62px; max-height: 130px; }
.decision-navigation { display: flex; justify-content: space-between; margin-top: 10px; }

.document-panel { display: flex; flex-direction: column; border-left: 1px solid #202a3b; background: #273247; color: white; }
.document-heading { display: flex; justify-content: space-between; gap: 15px; align-items: start; padding: 16px; border-bottom: 1px solid #46536a; }
.document-heading > div { display: flex; flex-direction: column; min-width: 0; }
.document-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-heading span { margin-top: 3px; color: #b8c3d4; font-size: 11px; }
.document-kicker { margin: 0 0 4px !important; color: #89a9f4 !important; font-weight: 800; }
.document-actions { display: flex; gap: 7px; }
.close-document { display: none; }
.document-panel .quiet-button { flex: none; border-color: #65728a; background: transparent; color: white; font-size: 12px; }
.selected-quote { max-height: 126px; overflow: auto; margin: 0; padding: 14px 18px; border-bottom: 1px solid #46536a; color: #eef2f8; font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-size: 14px; line-height: 1.45; }
.document-message { padding: 9px 16px; background: #1b2537; color: #bcc7d8; font-size: 11px; }
#plan-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: #596579; }

.join-dialog { width: min(440px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 10px; box-shadow: 0 24px 80px rgba(15, 23, 42, .32); }
.join-dialog::backdrop { background: rgba(15, 23, 42, .72); backdrop-filter: blur(3px); }
.join-dialog form { display: grid; gap: 13px; padding: 28px; }
.join-dialog h2, .join-dialog p { margin: 0; }
.join-dialog p { color: var(--muted); line-height: 1.5; }
.join-dialog label { font-size: 12px; font-weight: 800; color: #4b5568; }
.join-dialog input { width: 100%; padding: 10px 11px; border: 1px solid #bbc3d0; border-radius: 5px; }
.join-dialog .document-kicker { color: var(--blue) !important; }
.join-error { min-height: 18px; color: var(--red); font-size: 12px; }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: minmax(230px, 1fr) auto auto; }
  .progress { display: none; }
  .workbench { grid-template-columns: 252px minmax(470px, 1fr) 38vw; }
  .sheet-content { padding-left: 24px; padding-right: 24px; }
  .decision-options { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .topbar { position: sticky; top: 0; z-index: 30; grid-template-columns: 1fr auto; height: auto; min-height: 68px; }
  .progress { display: none; }
  .collaboration-tools { grid-column: 1 / -1; padding-bottom: 10px; }
  .workbench { height: auto; min-height: calc(100vh - 68px); grid-template-columns: 230px 1fr; }
  .navigation { height: calc(100vh - 68px); position: sticky; top: 68px; }
  .sheet { overflow: visible; }
  .document-panel { position: fixed; z-index: 25; inset: 68px 0 0 230px; display: none; }
  .document-panel.open { display: flex; }
  .close-document { display: inline-block; }
  .lens-grid, .reasons-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  html, body { width: 100%; max-width: 100%; }
  body { overflow-x: hidden; }

  .topbar {
    position: relative;
    top: auto;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto auto;
    gap: 10px 12px;
    min-height: 0;
    padding: 10px 12px 12px;
  }
  .identity { grid-column: 1; grid-row: 1; gap: 9px; }
  .identity strong { font-size: 14px; line-height: 1.2; }
  .identity span:not(.mark) { font-size: 11px; }
  .mark { width: 30px; height: 30px; font-size: 17px; }
  .topbar > #export-decisions {
    grid-column: 2;
    grid-row: 1;
    min-height: var(--mobile-touch-target);
    padding: 8px 10px;
    font-size: 12px;
  }
  .progress {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    gap: 5px;
  }
  .collaboration-tools {
    grid-column: 1 / -1;
    grid-row: 3;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    width: 100%;
    padding-bottom: 0;
  }
  .collaboration-tools > span {
    align-self: center;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .collaboration-tools .quiet-button {
    min-height: var(--mobile-touch-target);
    padding: 8px 10px;
  }

  .workbench {
    width: 100%;
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
  }
  .navigation {
    position: static;
    top: auto;
    width: 100%;
    height: auto;
    min-width: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .navigation-controls { padding: 14px 12px 12px; }
  .navigation select, .navigation input { min-height: var(--mobile-touch-target); }
  .mode-switch { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .mode-switch button { min-height: var(--mobile-touch-target); padding: 7px 3px; }
  .review-list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(190px, 78vw);
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 12px 14px;
    scroll-padding-inline: 12px;
    scroll-snap-type: x proximity;
    overscroll-behavior-inline: contain;
  }
  .review-list button {
    min-height: 72px;
    margin: 0;
    scroll-snap-align: start;
  }

  .sheet { width: 100%; min-width: 0; overflow: visible; }
  .sheet-content { width: 100%; padding: 22px 16px 24px; }
  .review-header { padding-bottom: 20px; }
  .review-header h1 { margin-top: 7px; font-size: clamp(24px, 7.2vw, 29px); line-height: 1.16; }
  .candidate-title { font-size: 16px; }
  .review-section { padding: 21px 0; }
  .review-section p, .review-section li { line-height: 1.55; }
  .lens-grid, .reasons-grid { gap: 10px; }
  .lens-block, .reason-block { padding: 13px; }
  .evidence-card { grid-template-columns: 50px minmax(0, 1fr); }
  .evidence-page { padding-inline: 4px; }
  .evidence-copy { min-width: 0; padding: 12px 12px 12px 0; }
  .evidence-copy blockquote { font-size: 14px; overflow-wrap: anywhere; }
  .comparison { max-width: 100%; overflow-x: auto; }
  .comparison summary { position: sticky; left: 0; }
  .comparison table { min-width: 620px; }
  .human-question { padding: 16px; }
  .human-question p { font-size: 17px; }
  .group-response-heading { align-items: flex-start; }

  .decision-dock {
    position: static;
    width: 100%;
    padding: 18px 16px max(18px, env(safe-area-inset-bottom));
    box-shadow: 0 -6px 22px rgba(23, 35, 58, 0.08);
    backdrop-filter: none;
  }
  .decision-options { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .decision-options button { min-height: var(--mobile-touch-target); padding: 8px 6px; }
  .decision-options button:last-child { grid-column: 1 / -1; }
  .decision-dock textarea { min-height: 96px; max-height: 180px; }
  .decision-navigation { gap: 10px; }
  .decision-navigation button { min-height: var(--mobile-touch-target); min-width: 116px; }

  .document-panel {
    position: fixed;
    z-index: 60;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .document-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: max(12px, env(safe-area-inset-top)) 12px 12px;
  }
  .document-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .document-actions .quiet-button {
    display: grid;
    min-height: var(--mobile-touch-target);
    place-items: center;
    padding: 8px;
    text-align: center;
  }
  .selected-quote { max-height: 22dvh; padding: 12px 14px; }
  .document-message { padding: 8px 14px; }
  #plan-frame { min-height: 280px; }

  .join-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
  .join-dialog form { padding: 22px 18px max(22px, env(safe-area-inset-bottom)); }
  .join-dialog input, .join-dialog .primary-button { min-height: var(--mobile-touch-target); }
}

@media (max-width: 420px) {
  .collaboration-tools { grid-template-columns: 1fr 1fr; }
  .collaboration-tools > span { grid-column: 1 / -1; white-space: normal; }
  .collaboration-tools .quiet-button { width: 100%; }
  .decision-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .revisit-control { min-height: var(--mobile-touch-target); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
