/* Editorial & Archival Ledger Design System
 * Palette: Cool Architectural Stone + Deep Ink + Oxford Cobalt
 * Typography: Newsreader (Editorial Serif) + Inter (UI Sans), tabular-nums
 * Strict 3-size body scale: 20px (--text-heading), 15px (--text-body), 13px (--text-sm)
 */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #eceff3;
  --rule: #dde2e9;
  --rule-strong: #c4ccd6;

  --ink: #0f172a;
  --ink-2: #334155;
  --ink-muted: #556173;

  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-tint: #eef3ff;

  --status-review: #1d4ed8;
  --status-revision: #6d28d9;
  --status-accepted: #047857;
  --status-rejected: #b91c1c;
  --status-wait: #b45309;

  --font-serif: "Newsreader", "Songti SC", "Noto Serif SC", Georgia, serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", sans-serif;

  --text-heading: 1.25rem;  /* 20px */
  --text-body: 0.9375rem;   /* 15px */
  --text-sm: 0.8125rem;     /* 13px */

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --radius: 6px;
}

[data-theme="dark"] {
  --bg: #0d1017;
  --surface: #131722;
  --surface-muted: #1b2130;
  --rule: #232a3b;
  --rule-strong: #364057;

  --ink: #f1f5f9;
  --ink-2: #cbd5e1;
  --ink-muted: #94a3b8;

  --accent: #60a5fa;
  --accent-btn: #2563eb;
  --accent-hover: #3b82f6;
  --accent-tint: rgba(96, 165, 250, 0.14);

  --status-review: #60a5fa;
  --status-revision: #a78bfa;
  --status-accepted: #34d399;
  --status-rejected: #f87171;
  --status-wait: #fbbf24;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Single-line compact header */
.header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color 180ms var(--ease-out), background-color 180ms var(--ease-out);
}

.header.is-scrolled {
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom-color: var(--rule);
}

.header-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.wordmark {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 20px;
}

.text-action {
  background: none;
  border: none;
  padding: 4px 0;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 160ms var(--ease-out);
}

.text-action:hover {
  color: var(--ink);
}

.text-action-danger:hover {
  color: var(--status-rejected);
}

.btn-primary {
  background: var(--accent-btn, var(--accent));
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: border-color 160ms var(--ease-out), background-color 160ms var(--ease-out);
}

.btn-secondary:hover {
  background: var(--surface-muted);
}

/* Main workspace */
.main {
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 20px 28px 64px;
  flex: 1;
}

/* Masthead & Architectural Metrics Strip */
.masthead {
  margin-bottom: 28px;
}

.masthead-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.masthead h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(1.85rem, 3vw, 2.35rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--ink);
}

.meta-date {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.metrics-strip {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}

.metric-cell {
  padding: 16px 20px;
  border-right: 1px solid var(--rule);
}

.metric-cell:last-child {
  border-right: none;
}

.metric-cell dt {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  font-weight: 400;
  margin-bottom: 4px;
}

.metric-cell dd {
  margin: 0;
  font-size: var(--text-heading);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.metric-note {
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--ink-muted);
}

.metric-accent {
  color: var(--accent);
}

.metric-warn {
  color: var(--status-wait);
}

/* Controls bar with connected segmented tabs */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  background: var(--surface-muted);
  padding: 3px;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
}

.seg-item {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out);
}

.seg-item:hover {
  color: var(--ink);
}

.seg-item.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.search-wrap {
  flex: 0 1 280px;
  width: 100%;
}

.search-field {
  width: 100%;
  padding: 8px 12px;
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 160ms var(--ease-out);
}

.search-field::placeholder {
  color: var(--ink-muted);
}

.search-field:focus {
  border-color: var(--accent);
}

/* Ledger list — open editorial bands, zero nested card cages */
.ledger-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.ms-section {
  background: var(--surface);
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--rule);
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
  display: grid;
  grid-template-columns: minmax(260px, 34%) 1fr;
}

/* Left summary column */
.ms-aside {
  padding: 24px 24px 24px 26px;
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 20px;
}

.ms-aside-sticky {
  position: sticky;
  top: 84px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.ms-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--text-heading);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.ms-meta-row {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

.status-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
  font-weight: 500;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--ink-muted);
}

.dot-active, .dot-in_progress { background: var(--status-review); }
.dot-revision { background: var(--status-revision); }
.dot-accepted { background: var(--status-accepted); }
.dot-rejected { background: var(--status-rejected); }
.dot-paused, .dot-withdrawn { background: var(--ink-muted); }

.ms-notes {
  margin: 10px 0 0;
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

.current-focus {
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.current-journal {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--ink);
  line-height: 1.4;
}

.current-subline {
  font-size: var(--text-sm);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.copy-id {
  background: none;
  border: none;
  border-bottom: 1px dashed var(--rule-strong);
  padding: 0;
  font-family: inherit;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  cursor: pointer;
  transition: color 160ms var(--ease-out), border-color 160ms var(--ease-out);
}

.copy-id:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.wait-emphasis {
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.wait-emphasis.is-long {
  color: var(--status-wait);
}

.wait-emphasis.is-critical {
  color: var(--status-rejected);
}

/* Reviewer progress meter */
.review-meter {
  margin-top: 4px;
}

.review-meter-head {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 6px;
}

.review-meter-track {
  height: 6px;
  background: var(--surface-muted);
  border-radius: 3px;
  overflow: hidden;
  display: flex;
}

.review-meter-done {
  background: var(--status-accepted);
}

.review-meter-accepted {
  background: var(--accent);
}

.ms-aside-actions {
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

/* Right submissions ledger column */
.ms-rounds {
  display: flex;
  flex-direction: column;
}

.round-row {
  border-bottom: 1px solid var(--rule);
}

.round-row:last-child {
  border-bottom: none;
}

.round-trigger {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 16px 24px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  transition: background-color 160ms var(--ease-out);
}

.round-trigger:hover {
  background: var(--surface-muted);
}

.round-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.round-num {
  font-size: var(--text-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  min-width: 26px;
}

.round-journal {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--ink);
}

.round-reason {
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

.round-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
}

.round-status-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
  font-weight: 500;
}

.round-chevron {
  color: var(--ink-muted);
  transition: transform 180ms var(--ease-out);
}

.round-row.is-open .round-chevron {
  transform: rotate(90deg);
}

.round-panel {
  padding: 4px 24px 20px 60px;
}

.round-panel.collapsed {
  display: none;
}

.round-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

.round-meta-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Timeline */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 16px;
  border-left: 1px solid var(--rule-strong);
}

.timeline-item {
  position: relative;
  padding: 4px 0 10px 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.timeline-item:last-child {
  padding-bottom: 2px;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 12px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--accent);
}

.timeline-item.is-reject::before {
  border-color: var(--status-rejected);
  background: var(--status-rejected);
}

.timeline-item.is-accept::before {
  border-color: var(--status-accepted);
  background: var(--status-accepted);
}

.ev-content {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  font-size: var(--text-body);
}

.ev-date {
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  min-width: 84px;
}

.ev-status {
  color: var(--ink);
  font-weight: 500;
}

.ev-reviews {
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 500;
}

.ev-notes {
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

.ev-delete {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms var(--ease-out), color 150ms var(--ease-out);
}

.timeline-item:hover .ev-delete,
.ev-delete:focus-visible {
  opacity: 1;
}

.ev-delete:hover {
  color: var(--status-rejected);
}

/* Decision comments disclosure */
.decision-disclosure {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}

.decision-disclosure summary {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}

.decision-disclosure summary:hover {
  color: var(--ink);
}

.decision-prose {
  margin: 10px 0 0;
  padding: 12px 16px;
  background: var(--bg);
  border-left: 2px solid var(--rule-strong);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.65;
  color: var(--ink-2);
  white-space: pre-wrap;
  max-width: 65ch;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
}

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--text-heading);
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: var(--ink-muted);
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
}

.close-btn:hover {
  color: var(--ink);
}

.modal-form {
  padding: 18px 20px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.field label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-2);
}

.field input,
.field select,
.field textarea {
  padding: 8px 10px;
  font-family: inherit;
  font-size: var(--text-body);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 160ms var(--ease-out);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

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

.modal-foot {
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Empty & loading */
.state-message {
  padding: 48px 20px;
  text-align: center;
  font-size: var(--text-body);
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px solid var(--rule);
}

/* Footer */
.footer {
  border-top: 1px solid var(--rule);
  background: var(--surface);
}

.footer-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 16px 28px;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 80;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
}

.toast.hidden {
  display: none;
}

/* Responsive */
@media (max-width: 860px) {
  .metrics-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .metric-cell:nth-child(2) {
    border-right: none;
  }
  .metric-cell:nth-child(1),
  .metric-cell:nth-child(2) {
    border-bottom: 1px solid var(--rule);
  }
  .ms-section {
    grid-template-columns: 1fr;
  }
  .ms-aside {
    border-right: none;
    border-bottom: 1px solid var(--rule);
    padding: 20px;
  }
  .ms-aside-sticky {
    position: static;
  }
  .round-trigger {
    padding: 14px 20px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .round-panel {
    padding: 4px 20px 18px 20px;
  }
}

@media (max-width: 560px) {
  .header-inner {
    padding: 12px 16px;
    gap: 10px;
  }
  .wordmark {
    font-size: 1.125rem;
  }
  .header-tools {
    gap: 12px;
  }
  .btn-primary {
    padding: 7px 12px;
  }
  .main {
    padding: 16px 16px 48px;
  }
  .masthead-top {
    flex-direction: column;
    gap: 4px;
  }
  .search-wrap {
    flex: 1 1 100%;
  }
  .segmented {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }
  .seg-item {
    padding: 6px 4px;
    text-align: center;
  }
  .footer-inner {
    padding: 14px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
