:root {
  color-scheme: light;
  --canvas: #f7f5ef;
  --surface: #fbfaf6;
  --surface-quiet: #efede4;
  --ink: #22231f;
  --muted: #6b6b63;
  --line: #d8d5cb;
  --control-line: #88877f;
  --olive: #667c32;
  --olive-dark: #536629;
  --amber: #78500f;
  --red: #aa4939;
  --focus: #20211d;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--canvas);
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--canvas); font-size: 15px; line-height: 1.45; }
a { color: inherit; }
button, select { font: inherit; }
button, a, select, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.loading {
  position: fixed;
  z-index: 20;
  inset: 14px auto auto 50%;
  transform: translateX(-50%);
  padding: 9px 14px;
  border: 1px solid var(--control-line);
  border-radius: 4px;
  background: var(--ink);
  color: var(--surface);
  font-size: 13px;
}
.loading-fallback { margin-left: 8px; }
.loading-fallback button {
  min-height: 30px;
  margin-left: 6px;
  border: 1px solid #d7d5cc;
  border-radius: 4px;
  background: transparent;
  color: var(--surface);
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(610px, 1fr) 426px;
  min-height: 100vh;
  max-width: 1680px;
  margin: 0 auto;
  background: var(--surface);
}

.rail, .workspace, .detail { min-width: 0; }
.rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 28px 14px 20px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin: 0 7px 34px;
  font-size: 20px;
  font-weight: 720;
  line-height: 1.15;
  text-decoration: none;
}

.eyebrow {
  margin: 0 7px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.project-list, .section-nav { display: grid; gap: 3px; }
.project-link, .section-nav a {
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--muted);
  text-decoration: none;
}
.project-link.active, .section-nav a.active {
  background: var(--surface-quiet);
  color: var(--ink);
  font-weight: 620;
}
.project-counts { margin-left: auto; font-variant-numeric: tabular-nums; }
.project-dot, .status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 10px;
  border-radius: 50%;
  background: var(--muted);
}
.project-dot.holdtype, .status-dot.green { background: var(--olive); }
.project-dot.playphrase { background: #50534f; }
.status-dot.yellow { background: var(--amber); }
.status-dot.red { background: var(--red); }
.section-nav { margin-top: 30px; }

.summary {
  margin-top: auto;
  padding: 16px 12px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.summary .eyebrow { margin-left: 0; }
.summary-project + .summary-project { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.summary-project strong { display: flex; align-items: center; font-size: 14px; }
.summary-project dl { margin: 8px 0 0 20px; color: var(--muted); font-size: 13px; }
.summary-project dl div { display: flex; justify-content: space-between; gap: 12px; }
.summary-project dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }

.workspace {
  min-height: 100vh;
  padding: 28px 18px;
  background: var(--surface);
}
.page-header { padding: 0 10px 22px; }
.page-header h1 { margin: 0; font-size: 31px; line-height: 1.15; letter-spacing: -.025em; }
.page-header p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }

.tabs {
  display: flex;
  min-height: 52px;
  border-bottom: 1px solid var(--line);
}
.tabs a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 12px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.tabs a[aria-current="page"] { color: var(--ink); font-weight: 650; }
.tabs a[aria-current="page"]::after {
  position: absolute;
  right: 12px;
  bottom: -1px;
  left: 12px;
  height: 2px;
  background: var(--olive);
  content: "";
}

.refresh-status {
  margin: 14px 10px 0;
  padding: 12px 0 14px;
  border-bottom: 1px solid var(--line);
}
.refresh-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
}
.refresh-heading .eyebrow { margin: 0 0 3px; }
.refresh-heading > p { max-width: 330px; margin: 0; color: var(--muted); font-size: 11px; text-align: right; }
.refresh-projects { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 10px; }
.refresh-project { min-width: 0; padding-top: 9px; border-top: 2px solid var(--line); }
.refresh-project.usable { border-top-color: var(--olive); }
.refresh-project.missed, .refresh-project.partial, .refresh-project.attention { border-top-color: var(--amber); }
.refresh-project-title { display: flex; justify-content: space-between; gap: 12px; }
.refresh-project-title span { color: var(--muted); font-size: 12px; text-align: right; }
.refresh-project > p { margin: 3px 0 8px; color: var(--muted); font-size: 12px; }
.refresh-project dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 14px; margin: 0; font-size: 11px; }
.refresh-project dl div { display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.refresh-project dt { color: var(--muted); }
.refresh-project dd { margin: 0; overflow-wrap: anywhere; text-align: right; }
.refresh-project details { margin-top: 6px; color: var(--muted); font-size: 11px; }
.refresh-project details p { margin: 4px 0 0; }

.grok-status {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 16px;
  align-items: center;
  margin: 14px 10px 0;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.grok-status .eyebrow { margin: 0 0 3px; }
.grok-status p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.grok-status details { grid-column: 1 / -1; font-size: 12px; }
.grok-open {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--control-line);
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.grok-open:disabled { cursor: not-allowed; opacity: .55; }

.filters {
  display: grid;
  grid-template-columns: minmax(150px, 1.45fr) repeat(4, minmax(92px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding: 18px 10px 20px;
  border-bottom: 1px solid var(--line);
}
.filters label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.filters select, .filters button {
  min-height: 42px;
  border: 1px solid var(--control-line);
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
}
.filters select { width: 100%; padding: 0 30px 0 10px; }
.filters button { padding: 0 14px; cursor: pointer; }
.filters button:hover { border-color: var(--ink); }
.notice { margin: 12px 10px 0; padding: 10px 12px; border: 1px solid #d6c7ab; color: var(--amber); }

.queue { overflow: hidden; }
.queue-head, .queue-row {
  display: grid;
  grid-template-columns: 92px minmax(150px, 1.45fr) 112px 104px minmax(150px, 1fr);
  gap: 12px;
}
.queue-head {
  padding: 15px 10px 9px;
  color: var(--muted);
  font-size: 11px;
}
.queue-row {
  align-items: start;
  min-height: 76px;
  padding: 14px 10px;
  border-top: 1px solid var(--line);
  text-decoration: none;
}
.queue-row:hover, .queue-row.selected { background: var(--surface-quiet); }
.queue-row strong { font-size: 14px; font-weight: 640; line-height: 1.35; overflow-wrap: anywhere; }
.queue-row span { min-width: 0; color: #42443f; font-size: 12px; overflow-wrap: anywhere; }
.queue-row .source { color: var(--muted); }
.provider-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.provider-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-quiet);
  color: var(--ink);
  font-size: 10px;
  font-weight: 620;
  white-space: nowrap;
}
.queue-row small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.queue-row .status-dot { width: 7px; height: 7px; margin-right: 6px; }
.risk-label { color: var(--ink); font-weight: 620; }

.state-message { padding: 70px 24px; text-align: center; }
.state-message h2 { margin: 0; font-size: 22px; }
.state-message p { max-width: 480px; margin: 8px auto 20px; color: var(--muted); }
.state-message a { text-underline-offset: 4px; }
.state-message.error h2 { color: var(--red); }

.detail {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 32px 26px 24px;
  border-left: 1px solid var(--line);
  background: var(--surface);
}
.detail-close { display: none; }
.project-kicker { display: flex; align-items: center; margin: 0 0 25px; font-weight: 620; }
.detail > h2 { margin: 0 0 12px; font-size: 27px; line-height: 1.16; letter-spacing: -.02em; overflow-wrap: anywhere; }
.source-url { margin: 0 0 30px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.detail section { margin-top: 26px; }
.detail h3 { margin: 0 0 8px; font-size: 14px; }
.detail section p, .caution p, .research-note p { margin: 0; color: #4f504a; }
.source-fragment { padding-top: 22px; border-top: 1px solid var(--line); }
.source-fragment blockquote {
  max-height: 150px;
  margin: 0;
  overflow: auto;
  padding: 14px;
  border-radius: 6px;
  background: var(--surface-quiet);
  color: #4f504a;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.caution, .research-note {
  margin-top: 28px;
  padding: 16px;
  border: 1px solid #d6c7ab;
  border-radius: 7px;
  color: var(--amber);
}
.caution p, .research-note p { margin-top: 5px; font-size: 13px; }
.research-note { color: var(--ink); }
.actions { padding-top: 22px; border-top: 1px solid var(--line); }
.primary-action {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border-radius: 5px;
  background: var(--olive);
  color: white;
  font-weight: 650;
  text-decoration: none;
}
.primary-action:hover { background: var(--olive-dark); }
.source-unavailable {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--control-line);
  border-radius: 5px;
  color: var(--muted);
  font-size: 13px;
}
.feedback-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.feedback-form { display: grid; gap: 9px; }
.feedback-form label { font-size: 14px; font-weight: 650; }
.feedback-form select, .feedback-form button {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--control-line);
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
}
.feedback-form select { padding: 0 34px 0 10px; }
.feedback-form button { padding: 8px 12px; cursor: pointer; }
.feedback-form button:hover { border-color: var(--ink); }
.current-feedback { margin: 0; color: var(--ink); font-size: 13px; }
.feedback-help { margin: 9px 0 0; color: var(--muted); font-size: 12px; }
.secondary-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.secondary-actions button, .quiet-action button {
  width: 100%;
  min-height: 48px;
  padding: 8px;
  border: 1px solid var(--control-line);
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.secondary-actions button:hover, .quiet-action button:hover { border-color: var(--ink); }
.quiet-action { margin-top: 10px; }
.quiet-action button { min-height: 36px; border-color: transparent; color: var(--muted); font-size: 12px; }
.detail details { margin-top: 32px; padding-top: 18px; border-top: 1px solid var(--line); }
.detail summary { min-height: 38px; cursor: pointer; font-weight: 620; }
.technical { margin: 10px 0; font-size: 12px; }
.technical div { display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 5px 0; }
.technical dt { color: var(--muted); }
.technical dd { margin: 0; overflow-wrap: anywhere; }
.detail-empty { display: grid; place-content: center; height: 70vh; text-align: center; }
.detail-empty h2 { margin: 0; font-size: 20px; }
.detail-empty p { color: var(--muted); }

.grok-dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 18px 60px rgb(34 35 31 / 22%);
}
.grok-dialog::backdrop { background: rgb(34 35 31 / 36%); }
.grok-dialog h2 { margin: 0; font-size: 24px; }
.grok-dialog > form > p { color: var(--muted); }
.grok-confirmation { margin: 20px 0; }
.grok-confirmation div { display: grid; grid-template-columns: 88px 1fr; gap: 12px; padding: 6px 0; }
.grok-confirmation dt { color: var(--muted); }
.grok-confirmation dd { margin: 0; font-weight: 620; }
.grok-running { padding: 10px; border: 1px solid var(--line); }
.grok-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.grok-dialog-actions button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--control-line);
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.grok-dialog-actions .grok-confirm-primary {
  border-color: var(--olive);
  background: var(--olive);
  color: white;
  font-weight: 650;
}

@media (max-width: 1480px) {
  .filters { grid-template-columns: repeat(3, minmax(132px, 1fr)); }
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 176px minmax(0, 1fr); }
  .rail { padding-inline: 9px; }
  .brand { margin-inline: 7px; font-size: 17px; }
  .summary { display: none; }
  .project-link { padding: 8px; font-size: 12px; }
  .project-link .project-name { min-width: 0; overflow-wrap: anywhere; }
  .project-counts { font-size: 11px; }
  .section-nav { margin-top: 20px; }
  .section-nav a { padding: 8px; font-size: 12px; }
  .detail {
    position: fixed;
    z-index: 10;
    top: 0;
    right: 0;
    width: min(430px, calc(100vw - 176px));
    max-width: 100%;
    transform: translateX(100%);
    box-shadow: -12px 0 28px rgb(34 35 31 / 14%);
    transition: transform 180ms ease;
  }
  .detail.open { transform: translateX(0); }
  .detail[aria-hidden="true"] { visibility: hidden; }
  .detail-close {
    display: inline-flex;
    min-height: 36px;
    margin: 0 0 20px auto;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
  }
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 150px minmax(0, 1fr); }
  .workspace { padding-inline: 10px; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .refresh-heading { display: block; }
  .refresh-heading > p { margin-top: 4px; text-align: left; }
  .refresh-projects { grid-template-columns: 1fr; gap: 10px; }
  .filters button { grid-column: 1 / -1; }
  .queue-head { display: none; }
  .queue-row { grid-template-columns: minmax(0, 1fr) 100px; gap: 7px 12px; }
  .queue-row .source, .queue-row > span:nth-of-type(3) { display: none; }
  .queue-row > span:last-child { grid-column: 1 / -1; }
  .detail { width: calc(100vw - 150px); }
}

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