:root {
  --canvas: #f4f1e9;
  --paper: #fffdf8;
  --paper-blue: #eef4ff;
  --ink: #172033;
  --soft: #566176;
  --faint: #606b7d;
  --line: #dcd8cd;
  --blue-line: #c9d9f5;
  --blue: #2457d6;
  --blue-deep: #173b9c;
  --amber: #ce7114;
  --amber-soft: #fff0d9;
  --ok: #147a62;
  --ok-soft: #e4f5ef;
  --danger: #b83a45;
  --danger-soft: #fdecee;
  --shadow: 0 1px 0 rgb(23 32 51 / 5%), 0 14px 36px rgb(46 55 75 / 8%);
  --ease: cubic-bezier(.22, 1, .36, 1);
  --spring: cubic-bezier(.2, .9, .25, 1.15);
}
* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
  font-family: "Segoe UI Variable", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(rgb(44 52 68 / 9%) .6px, transparent .6px);
  background-size: 7px 7px;
  content: "";
  opacity: .24;
  pointer-events: none;
}
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
h1, h2 { text-wrap: balance; }
h1 { font-size: clamp(27px, 3vw, 42px); line-height: 1.12; letter-spacing: -.045em; }
h2 { font-size: 19px; line-height: 1.3; letter-spacing: -.02em; }
button, input, select, textarea { font: inherit; }
button, select, .drop, summary { cursor: pointer; touch-action: manipulation; }
.skip-link { position: fixed; top: 10px; left: 10px; z-index: 1000; padding: 10px 14px; background: var(--ink); color: white; transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }
button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--blue);
  border-radius: 9px;
  background: var(--blue);
  color: white;
  font-weight: 700;
  box-shadow: 0 2px 0 var(--blue-deep);
  transition: background-color 160ms, border-color 160ms, color 160ms, box-shadow 160ms, opacity 160ms, transform 120ms;
}
button:hover { border-color: var(--blue-deep); background: var(--blue-deep); }
button:active { box-shadow: none; transform: translateY(2px); }
button:disabled { cursor: not-allowed; opacity: .42; box-shadow: none; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, .drop:focus-within { outline: 3px solid rgb(36 87 214 / 30%); outline-offset: 2px; }
.ghost { border-color: var(--line); background: transparent; color: var(--soft); box-shadow: none; }
.ghost:hover { border-color: var(--ink); background: var(--paper); color: var(--ink); }
.danger { border-color: var(--danger); background: var(--danger); box-shadow: 0 2px 0 #81252e; }
.danger:hover { border-color: #922c36; background: #922c36; }
.eyebrow, .step { display: block; margin-bottom: 9px; color: var(--blue); font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }

/* Editorial archive cover */
.login-shell { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, .75fr); overflow: hidden; }
.login-intro { position: relative; display: flex; flex-direction: column; justify-content: space-between; min-height: 100dvh; padding: clamp(40px, 7vw, 104px); background: var(--blue); color: white; }
.login-intro::after { position: absolute; right: -56px; bottom: -56px; width: min(42vw, 540px); aspect-ratio: 1; border: 64px solid rgb(255 255 255 / 13%); border-radius: 50%; content: ""; }
.login-intro .folio { font-size: 11px; font-weight: 800; letter-spacing: .18em; }
.login-intro h1 { max-width: 720px; font-size: clamp(48px, 7vw, 98px); letter-spacing: -.065em; }
.login-intro > p { max-width: 580px; color: rgb(255 255 255 / 78%); font-size: 17px; }
.archive-mark { display: flex; align-items: center; gap: 14px; font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.archive-mark i { width: 42px; height: 42px; border: 10px solid var(--amber-soft); border-radius: 50%; }
.login-card { align-self: center; width: min(430px, calc(100% - 48px)); margin: 24px auto; display: grid; gap: 18px; padding: 40px; border: 1px solid var(--line); border-top: 6px solid var(--amber); background: var(--paper); box-shadow: var(--shadow); }
.login-card h2 { font-size: 30px; }
.login-card p { color: var(--soft); }
.login-card small { min-height: 20px; color: var(--danger); }

/* Horizontal archive index — deliberately no dashboard sidebar */
.shell { min-height: 100dvh; }
aside { position: sticky; top: 0; z-index: 30; display: grid; grid-template-columns: auto minmax(420px, 1fr) auto; align-items: center; min-height: 76px; padding: 10px clamp(20px, 4vw, 64px); border-bottom: 1px solid var(--line); background: rgb(255 253 248 / 96%); }
.brand { display: flex; align-items: center; gap: 11px; min-width: 176px; font-weight: 800; }
.brand > i { width: 25px; height: 32px; border: 2px solid var(--blue); background: var(--paper-blue); box-shadow: 6px 6px 0 var(--amber-soft); transform: rotate(-3deg); }
.brand small { display: block; margin-top: 1px; color: var(--faint); font-size: 8px; letter-spacing: .15em; }
nav { display: flex; justify-content: center; gap: 2px; }
nav button { position: relative; min-height: 42px; padding: 0 13px; border: 0; background: transparent; color: var(--soft); box-shadow: none; font-size: 13px; white-space: nowrap; }
nav button:hover { background: var(--paper-blue); color: var(--blue); }
nav button.active { background: transparent; color: var(--ink); }
nav button.active::after { position: absolute; right: 13px; bottom: 2px; left: 13px; height: 3px; background: var(--amber); content: ""; }
.connection { display: flex; align-items: center; justify-content: flex-end; gap: 7px; color: var(--faint); font-size: 11px; white-space: nowrap; }
.connection i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
main { width: min(1440px, 100%); margin: 0 auto; padding: 48px clamp(20px, 4vw, 64px) 80px; }
main > header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.identity { display: flex; align-items: center; gap: 12px; }
.identity span { color: var(--soft); font-size: 12px; }
.identity .ghost { min-height: 38px; }
.view.view-enter { animation: view-in 420ms var(--ease) both; }

/* Open ledger metrics */
.metrics { display: grid; grid-template-columns: 1.35fr repeat(3, 1fr); margin-bottom: 20px; border-block: 1px solid var(--line); }
.metric { position: relative; min-height: 112px; padding: 20px 22px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric:first-child::before { position: absolute; top: -1px; left: 0; width: 72px; height: 4px; background: var(--blue); content: ""; }
.metric span { color: var(--soft); font-size: 11px; font-weight: 700; }
.metric strong { display: block; margin-top: 11px; font-size: 30px; font-variant-numeric: tabular-nums; line-height: 1; }
.metric:first-child strong { color: var(--blue); }
.metric small { display: block; margin-top: 9px; color: var(--faint); }
.workspace { display: grid; grid-template-columns: minmax(420px, 1.35fr) minmax(340px, .65fr); gap: 20px; }
.panel { border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow); }
.upload, .evidence, .preview, .form-panel, .audit-panel { padding: 26px; }
.upload { position: relative; border-top: 6px solid var(--blue); }
.upload::after { position: absolute; top: 22px; right: 22px; width: 48px; height: 48px; border: 12px solid var(--amber-soft); border-radius: 50%; content: ""; }
.evidence { border-color: var(--blue-line); background: var(--paper-blue); box-shadow: none; }
.panel-head { margin-bottom: 20px; }
.panel-head p, .action-head p, .form-panel p { margin-top: 6px; color: var(--soft); }
.drop { position: relative; min-height: 190px; display: grid; place-items: center; align-content: center; gap: 8px; margin-bottom: 14px; padding: 24px; border: 2px dashed #9eb5e5; background: #f5f8ff; text-align: center; transition: background-color 180ms, border-color 180ms, transform 180ms; }
.drop:hover { border-color: var(--blue); background: #edf3ff; transform: translateY(-2px); }
.drop strong { font-size: 17px; }
.drop span { max-width: 480px; color: var(--soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload > button { width: 100%; }
.weights { display: grid; gap: 14px; }
.weights.empty { min-height: 206px; place-items: center; color: var(--faint); }
.weight-row { display: grid; grid-template-columns: 80px minmax(80px, 1fr) 92px; align-items: center; gap: 12px; }
.weight-row strong, .weight-row span { font-size: 12px; }
.weight-row span { color: var(--soft); text-align: right; font-variant-numeric: tabular-nums; }
.track { height: 8px; overflow: hidden; background: #d6e1f5; }
.track i { display: block; height: 100%; background: var(--blue); transform-origin: left; animation: grow-bar 600ms var(--ease) both; }

/* Reconciliation sheet */
.preview { margin-top: 20px; border-top: 6px solid var(--amber); animation: reveal-sheet 480ms var(--spring) both; }
.preview-summary { display: grid; grid-template-columns: repeat(5, 1fr); margin-bottom: 20px; border-block: 1px solid var(--line); }
.preview-summary div { padding: 16px; border-right: 1px solid var(--line); }
.preview-summary div:last-child { border-right: 0; }
.preview-summary strong { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.preview-summary span { display: block; margin-top: 4px; color: var(--faint); font-size: 11px; }
.notice { margin-bottom: 18px; padding: 14px 16px; border-left: 4px solid var(--amber); background: var(--amber-soft); color: #70420d; }
.preview-actions { display: flex; justify-content: flex-end; gap: 10px; }
.match-list { display: grid; gap: 8px; margin-bottom: 20px; }
.match-list details { border: 1px solid var(--line); background: #fffefa; }
.match-list summary { display: flex; justify-content: space-between; gap: 16px; min-height: 48px; align-items: center; padding: 10px 14px; }
.match-list summary span { color: var(--soft); font-size: 11px; }
.history-line { display: grid; grid-template-columns: 62px 1fr 170px; gap: 12px; align-items: center; padding: 11px 14px; border-top: 1px solid var(--line); }
.history-line time { color: var(--faint); font-variant-numeric: tabular-nums; }

/* Tables and forms */
.toolbar, .action-head { display: flex; gap: 10px; margin-bottom: 18px; }
.action-head { align-items: flex-end; justify-content: space-between; }
.toolbar input { width: min(480px, 100%); }
.two-column, .system-grid { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 20px; }
.system-grid { grid-template-columns: 1fr 1fr; margin-bottom: 20px; }
.audit-panel { margin-top: 20px; }
.audit-panel .table-wrap { margin: 18px -26px -26px; box-shadow: none; }
.table-wrap { max-width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: #f8f6f0; color: var(--soft); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
td { color: var(--soft); font-variant-numeric: tabular-nums; }
tbody tr { transition: background-color 140ms; }
tbody tr:hover { background: #f8faff; }
.table-wrap td strong, .table-wrap td small { display: block; }
.table-wrap td strong { color: var(--ink); }
.table-wrap td small { margin-top: 4px; color: var(--faint); font-size: 10px; }
.empty-cell { padding: 48px !important; color: var(--faint) !important; text-align: center !important; }
input, select, textarea { width: 100%; min-height: 44px; padding: 0 13px; border: 1px solid #cfcabe; border-radius: 8px; background: white; color: var(--ink); transition: border-color 160ms, box-shadow 160ms; }
textarea { min-height: 112px; padding: 12px; resize: vertical; }
.login-card label, .stack label, dialog label { display: grid; gap: 7px; color: var(--soft); font-size: 12px; font-weight: 650; }
.stack { display: grid; gap: 14px; margin-top: 20px; }
.mini { min-height: 34px; margin-right: 6px; padding: 0 11px; font-size: 11px; }
.status, .pending { display: inline-flex; align-items: center; min-height: 25px; padding: 3px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.status.joined { background: var(--ok-soft); color: var(--ok); }
.status.left { background: var(--danger-soft); color: var(--danger); }
.pending { background: var(--amber-soft); color: #85500d; }
.secret { display: grid; gap: 8px; margin-top: 16px; padding: 14px; border-left: 4px solid var(--amber); background: var(--amber-soft); overflow-wrap: anywhere; }
.secret code, td code { color: #8a5009; font-family: Consolas, monospace; }
dialog { width: min(520px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-top: 6px solid var(--danger); background: var(--paper); color: var(--ink); box-shadow: 0 28px 80px rgb(23 32 51 / 24%); }
dialog[open] { animation: dialog-in 260ms var(--ease) both; }
dialog::backdrop { background: rgb(23 32 51 / 54%); }
dialog form { display: grid; gap: 16px; padding: 26px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
#toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; max-width: min(390px, calc(100% - 48px)); padding: 13px 16px; border-left: 5px solid var(--amber); background: var(--ink); color: white; box-shadow: 0 14px 32px rgb(23 32 51 / 20%); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity 180ms, transform 240ms var(--ease); }
#toast.show { opacity: 1; transform: translateY(0); }
@keyframes view-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes reveal-sheet { from { opacity: 0; transform: translateY(22px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes grow-bar { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@media (max-width: 1120px) {
  aside { grid-template-columns: auto 1fr; }
  nav { grid-column: 1 / -1; order: 3; justify-content: flex-start; overflow-x: auto; padding-top: 6px; }
  .connection { justify-self: end; }
  .workspace { grid-template-columns: 1fr; }
  .weights.empty { min-height: 120px; }
}
@media (max-width: 760px) {
  body { font-size: 16px; }
  .login-shell { grid-template-columns: 1fr; }
  .login-intro { min-height: 38dvh; padding: 34px 24px; }
  .login-intro h1 { font-size: clamp(42px, 13vw, 64px); }
  .login-intro > p, .archive-mark { display: none; }
  .login-card { padding: 28px 24px; }
  aside { position: static; padding: 12px 16px; }
  .connection { display: none; }
  .brand { min-width: 0; }
  nav { margin-right: -16px; padding-bottom: 3px; }
  nav button { min-height: 44px; }
  main { padding: 28px 16px 64px; }
  main > header { align-items: flex-start; }
  .identity { align-items: flex-end; flex-direction: column; gap: 6px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric { min-height: 106px; padding: 16px 12px; border-bottom: 1px solid var(--line); }
  .metric:nth-last-child(-n+2) { border-bottom: 0; }
  .workspace, .two-column, .system-grid { grid-template-columns: minmax(0, 1fr); }
  .upload, .evidence, .preview, .form-panel, .audit-panel { padding: 20px; }
  .upload::after { display: none; }
  .drop { min-height: 160px; }
  .preview-summary { grid-template-columns: 1fr 1fr; }
  .preview-summary div { border-bottom: 1px solid var(--line); }
  .preview-summary div:nth-child(2n) { border-right: 0; }
  .toolbar, .action-head { align-items: stretch; flex-direction: column; }
  .history-line { grid-template-columns: 58px minmax(0, 1fr); }
  .history-line time { grid-column: 2; }
  .match-list summary { align-items: flex-start; flex-direction: column; }
  .preview-actions { flex-direction: column-reverse; }
  .preview-actions button { width: 100%; }
  #toast { right: 16px; bottom: 16px; max-width: calc(100% - 32px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
