:root {
  --paper: #f5efdf;
  --ivory: #fffaf0;
  --ivory-raised: #fffdf7;
  --ink: #102d68;
  --ink-soft: rgba(16, 45, 104, 0.72);
  --ink-faint: rgba(16, 45, 104, 0.5);
  --ink-ghost: rgba(16, 45, 104, 0.08);
  --vermilion: #d9482b;
  --vermilion-soft: rgba(217, 72, 43, 0.09);
  --line: rgba(16, 45, 104, 0.16);
  --line-soft: rgba(16, 45, 104, 0.09);
  --line-strong: rgba(16, 45, 104, 0.32);
  --success: #277052;
  --warning: #9a5b1f;
  --danger: #9e3426;
  --control: #f1ead9;
  --focus: rgba(217, 72, 43, 0.25);
  --sidebar: 236px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: "DM Sans", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  left: 16px;
  top: 12px;
  z-index: 100;
  padding: 9px 13px;
  background: var(--ink);
  color: var(--ivory);
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.kicker {
  margin: 0 0 6px;
  color: var(--vermilion);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.access-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(var(--line-soft) 1px, transparent 1px) 0 0 / 100% 32px,
    var(--paper);
}

.access-card {
  position: relative;
  width: min(100%, 620px);
  padding: 36px 44px 32px;
  overflow: hidden;
  background: var(--ivory);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.access-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--vermilion);
}

.access-brand, .sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}
.access-brand { justify-content: space-between; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.access-brand img { width: 156px; height: auto; }
.access-brand span, .sidebar-brand span {
  color: var(--ink-faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.access-copy { padding: 48px 0 28px; }
.access-copy h1 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(46px, 8vw, 68px);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 0.95;
}
.access-copy > p:last-child { max-width: 460px; margin: 18px 0 0; color: var(--ink-soft); font-size: 15px; }
.access-actions { min-height: 52px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.google-button { min-height: 44px; }
.access-status { margin: 8px 0 0; color: var(--ink-soft); font-size: 12px; }
.access-status.is-error { color: var(--danger); }
.access-loading, .panel-loading { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); }
.access-loading span, .panel-loading span {
  width: 14px;
  height: 14px;
  border: 1px solid var(--line-strong);
  border-top-color: var(--vermilion);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.access-rule { display: flex; align-items: center; gap: 12px; margin: 32px 0 14px; color: var(--ink-faint); font-family: "Cormorant Garamond", serif; }
.access-rule::before, .access-rule::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.access-rule span { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; font-size: 12px; }
.access-note { margin: 0; text-align: center; color: var(--ink-faint); font-size: 11px; }

.button, .text-button, .icon-button, .nav-item, .dialog-close, .link-button {
  border: 0;
  cursor: pointer;
}
.button {
  min-height: 40px;
  padding: 10px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.015em;
}
.button-primary { background: var(--ink); color: var(--ivory); }
.button-primary:hover { background: #0c2454; }
.button-outline { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.button-outline:hover { background: var(--ink-ghost); }
.button-danger { background: transparent; border-color: rgba(158, 52, 38, 0.3); color: var(--danger); }
.button-danger:hover { background: rgba(158, 52, 38, 0.07); border-color: rgba(158, 52, 38, 0.5); }
.button:disabled, .icon-button:disabled, .text-button:disabled { cursor: wait; opacity: 0.52; }

.hq-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.hq-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 28px 20px 20px;
  background: var(--paper);
  border-right: 1px solid var(--line);
}
.sidebar-brand { padding: 0 8px 24px; }
.sidebar-brand img { width: 126px; }
.sidebar-brand span { margin-left: auto; color: var(--vermilion); }
.sidebar-label { margin: 18px 8px 10px; color: var(--ink-faint); font-size: 9px; font-weight: 700; letter-spacing: 0.15em; text-transform: uppercase; }
.hq-nav { display: grid; gap: 2px; }
.nav-item {
  position: relative;
  display: grid;
  grid-template-columns: 25px 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 9px;
  background: transparent;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 13px;
}
.nav-item span { color: var(--ink-faint); font-size: 9px; font-variant-numeric: tabular-nums; }
.nav-item::before { content: ""; position: absolute; left: -20px; top: 7px; bottom: 7px; width: 3px; background: transparent; }
.nav-item:hover { background: var(--ink-ghost); }
.nav-item.is-active { background: rgba(255, 250, 240, 0.68); font-weight: 700; }
.nav-item.is-active::before { background: var(--vermilion); }
.sidebar-footer { margin-top: auto; padding: 18px 8px 2px; border-top: 1px solid var(--line); }
.sidebar-footer p { margin: 0 0 6px; color: var(--ink-faint); font-size: 10px; }
.sidebar-footer a { font-size: 12px; font-weight: 600; text-decoration: none; }
.sidebar-footer a:hover { color: var(--vermilion); }

.hq-workspace { min-width: 0; }
.hq-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 94px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(22px, 4vw, 52px);
  background: rgba(245, 239, 223, 0.96);
  border-bottom: 1px solid var(--line);
}
.hq-topbar h1 { margin: 0; font-family: "Cormorant Garamond", serif; font-size: 32px; font-weight: 600; line-height: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.owner-chip { display: flex; align-items: center; gap: 9px; margin-right: 8px; }
.owner-monogram { display: grid; place-items: center; width: 34px; height: 34px; background: var(--ivory); border: 1px solid var(--line); border-radius: 50%; color: var(--vermilion); font-family: "Cormorant Garamond", serif; font-weight: 600; }
.owner-chip > span:last-child { display: grid; line-height: 1.25; }
.owner-chip small, .owner-chip em { color: var(--ink-faint); font-size: 9px; font-style: normal; }
.owner-chip strong { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.owner-chip em { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { display: grid; place-items: center; width: 38px; height: 38px; background: transparent; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.icon-button:hover { background: var(--ivory); }
.icon-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.text-button { min-height: 38px; padding: 0 5px; background: transparent; color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.text-button:hover { color: var(--vermilion); }

.workspace-main { padding: 36px clamp(22px, 4vw, 52px) 72px; }
.view-panel { max-width: 1380px; margin: 0 auto; }
.panel-loading { min-height: 180px; justify-content: center; }
.section-intro { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 22px; }
.section-intro h2 { margin: 0; font-family: "Cormorant Garamond", serif; font-size: 27px; font-weight: 600; }
.section-intro p { max-width: 620px; margin: 5px 0 0; color: var(--ink-soft); }
.section-note { margin: 0; color: var(--ink-faint); font-size: 11px; }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; background: var(--ivory); }
.metric { min-height: 126px; padding: 20px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--ink-faint); font-size: 9px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.metric strong { display: block; margin-top: 20px; font-family: "Cormorant Garamond", serif; font-size: 35px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.metric.attention strong { color: var(--vermilion); }
.overview-ledger { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr); gap: 20px; margin-top: 20px; }
.ledger-card { padding: 24px; background: var(--ivory); border: 1px solid var(--line); border-radius: var(--radius-md); }
.ledger-card header { display: flex; justify-content: space-between; gap: 16px; align-items: baseline; padding-bottom: 15px; border-bottom: 1px solid var(--line); }
.ledger-card h3 { margin: 0; font-family: "Cormorant Garamond", serif; font-size: 22px; font-weight: 600; }
.ledger-card header span { color: var(--ink-faint); font-size: 10px; }
.money-list { margin: 0; }
.money-list > div { display: flex; justify-content: space-between; gap: 20px; padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.money-list > div:last-child { border-bottom: 0; }
.money-list dt { color: var(--ink-soft); }
.money-list dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.queue-list { display: grid; gap: 0; }
.queue-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.queue-item:last-child { border-bottom: 0; }
.queue-item span { color: var(--ink-soft); }
.queue-item strong { min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; }

.filter-bar { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin-bottom: 14px; padding: 14px; background: rgba(255, 250, 240, 0.58); border: 1px solid var(--line); border-radius: var(--radius-md); }
.filter-bar label { display: grid; gap: 5px; color: var(--ink-faint); font-size: 9px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; }
.filter-bar label:first-child { flex: 1 1 280px; }
.filter-bar input { width: 100%; }
input, select, textarea {
  min-height: 40px;
  padding: 9px 11px;
  background: var(--control);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
input:focus, select:focus, textarea:focus { border-color: var(--vermilion); outline: 3px solid var(--focus); outline-offset: 0; }

.table-card { overflow: hidden; background: var(--ivory); border: 1px solid var(--line); border-radius: var(--radius-md); }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; min-width: 820px; border-collapse: collapse; font-size: 12px; }
.data-table th { padding: 11px 14px; background: rgba(16, 45, 104, 0.035); border-bottom: 1px solid var(--line); color: var(--ink-faint); font-size: 9px; font-weight: 700; letter-spacing: 0.08em; text-align: left; text-transform: uppercase; white-space: nowrap; }
.data-table td { padding: 13px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: rgba(16, 45, 104, 0.025); }
.cell-primary { display: block; font-weight: 700; }
.cell-secondary { display: block; margin-top: 2px; color: var(--ink-faint); font-size: 10px; }
.mono { font-variant-numeric: tabular-nums; }
.order-ref { max-width: 150px; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; white-space: nowrap; }
.status-pill { display: inline-flex; align-items: center; min-height: 23px; padding: 3px 8px; background: var(--ink-ghost); border-radius: 999px; color: var(--ink-soft); font-size: 9px; font-weight: 700; letter-spacing: 0.04em; text-transform: capitalize; white-space: nowrap; }
.status-pill.is-attention { background: var(--vermilion-soft); color: var(--danger); }
.status-pill.is-good { background: rgba(39, 112, 82, 0.1); color: var(--success); }
.link-button { padding: 2px 0; background: transparent; border-bottom: 1px solid var(--line-strong); font-size: 11px; font-weight: 700; }
.link-button:hover { color: var(--vermilion); border-color: var(--vermilion); }
.table-actions { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.pagination span { color: var(--ink-faint); font-size: 10px; }

.empty-state, .error-state { min-height: 210px; display: grid; align-content: center; justify-items: start; padding: 30px; background: var(--ivory); border: 1px solid var(--line); border-radius: var(--radius-md); }
.empty-state h3, .error-state h3 { margin: 0; font-family: "Cormorant Garamond", serif; font-size: 24px; }
.empty-state p, .error-state p { max-width: 540px; margin: 7px 0 16px; color: var(--ink-soft); }
.error-state { border-left: 3px solid var(--vermilion); }

.story-list { display: grid; gap: 16px; }
.story-review { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.7fr); gap: 24px; padding: 22px; background: var(--ivory); border: 1px solid var(--line); border-radius: var(--radius-md); }
.story-copy h3 { margin: 5px 0 5px; font-family: "Cormorant Garamond", serif; font-size: 23px; }
.story-copy > p { color: var(--ink-soft); }
.story-images { display: grid; grid-template-columns: repeat(2, minmax(130px, 1fr)); gap: 10px; margin-top: 16px; }
figure { margin: 0; }
.story-images img, .proof-grid img, .payment-proof { display: block; width: 100%; max-height: 230px; object-fit: contain; background: var(--control); border: 1px solid var(--line); border-radius: var(--radius-sm); }
figcaption { margin-top: 5px; color: var(--ink-faint); font-size: 9px; }
.review-form { display: grid; gap: 13px; }
.review-form label:not(.check-line) { display: grid; gap: 5px; font-size: 11px; font-weight: 700; }
.review-form label > span { color: var(--ink-faint); font-size: 9px; font-weight: 400; }
.reject-guidance { margin: 0; padding: 10px 12px; background: var(--vermilion-soft); border-left: 2px solid var(--danger); color: var(--danger); font-size: 10px; }
.payment-decision-actions { display: flex; justify-content: flex-end; gap: 8px; }
.check-line { display: grid; grid-template-columns: 17px 1fr; gap: 9px; align-items: start; color: var(--ink-soft); font-size: 10px; }
.check-line input { min-height: auto; width: 15px; height: 15px; margin: 2px 0 0; padding: 0; accent-color: var(--vermilion); }
.review-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-error { padding: 9px 10px; background: var(--vermilion-soft); border-left: 2px solid var(--danger); color: var(--danger); font-size: 10px; }

.hq-dialog {
  width: min(920px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  background: var(--ivory);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  color: var(--ink);
}
.hq-dialog::backdrop { background: rgba(8, 22, 50, 0.48); }
.compact-dialog { width: min(590px, calc(100vw - 28px)); }
.dialog-shell { max-height: calc(100vh - 30px); overflow-y: auto; }
.dialog-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: start; justify-content: space-between; gap: 20px; padding: 22px 24px 17px; background: rgba(255, 250, 240, 0.97); border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-family: "Cormorant Garamond", serif; font-size: 28px; line-height: 1; }
.dialog-close { width: 36px; height: 36px; background: transparent; border: 1px solid var(--line); border-radius: 50%; font-size: 22px; line-height: 1; }
.dialog-close:hover { background: var(--ink-ghost); }
.dialog-body { padding: 24px; }
.detail-docket { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.detail-docket > div { padding: 12px; border-right: 1px solid var(--line); }
.detail-docket > div:last-child { border-right: 0; }
.detail-docket dt { color: var(--ink-faint); font-size: 8px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.detail-docket dd { margin: 4px 0 0; font-size: 11px; font-weight: 700; overflow-wrap: anywhere; }
.detail-section { margin-top: 22px; }
.detail-section h3 { margin: 0 0 10px; padding-bottom: 7px; border-bottom: 1px solid var(--line); font-family: "Cormorant Garamond", serif; font-size: 21px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.detail-grid p { margin: 0 0 5px; color: var(--ink-soft); }
.letter-copy { max-height: 320px; overflow: auto; margin: 10px 0 0; padding: 16px; background: var(--control); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); color: var(--ink); font: 13px/1.65 "DM Sans", sans-serif; white-space: pre-wrap; overflow-wrap: anywhere; }
.proof-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.payment-summary { margin-bottom: 20px; padding: 15px; background: var(--control); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.payment-summary p { margin: 3px 0; }
.payment-summary code { display: block; margin-top: 9px; padding: 8px; background: var(--ivory); overflow-wrap: anywhere; }
.payment-proof { max-height: 280px; margin-top: 12px; }

.toast { position: fixed; z-index: 100; right: 22px; bottom: 22px; max-width: min(360px, calc(100vw - 44px)); padding: 12px 15px; background: var(--ink); border-radius: var(--radius-sm); color: var(--ivory); font-size: 11px; }

@media (max-width: 1160px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .metric:nth-child(3) { border-right: 0; }
  .metric:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .story-review { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .hq-shell { display: block; }
  .hq-sidebar { position: sticky; z-index: 30; height: auto; padding: 12px 16px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-brand { display: none; }
  .sidebar-label { margin: 0 0 8px; }
  .hq-nav { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: thin; }
  .nav-item { display: flex; flex: 0 0 auto; width: auto; padding: 8px 11px; white-space: nowrap; }
  .nav-item span { display: none; }
  .nav-item::before { inset: auto 9px -1px; width: auto; height: 2px; }
  .sidebar-footer { display: none; }
  .hq-topbar { top: 55px; min-height: 80px; }
  .overview-ledger { grid-template-columns: 1fr; }
}

@media (max-width: 660px) {
  .access-shell { padding: 14px; }
  .access-card { padding: 26px 24px 24px; }
  .access-brand img { width: 130px; }
  .access-brand span { display: none; }
  .access-copy { padding: 38px 0 24px; }
  .hq-topbar { align-items: start; padding: 14px 18px; }
  .hq-topbar h1 { font-size: 27px; }
  .owner-chip { display: none; }
  .workspace-main { padding: 26px 16px 54px; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .metric { min-height: 108px; }
  .metric:nth-child(2), .metric:nth-child(4) { border-right: 0; }
  .metric:nth-child(3) { border-right: 1px solid var(--line); }
  .metric:nth-child(4) { border-bottom: 1px solid var(--line); }
  .metric strong { margin-top: 14px; font-size: 30px; }
  .section-intro { display: block; }
  .section-note { margin-top: 8px; }
  .filter-bar { align-items: stretch; }
  .filter-bar label { flex: 1 1 100%; }
  .filter-bar .button { flex: 1; }
  .story-images, .detail-grid { grid-template-columns: 1fr; }
  .detail-docket { grid-template-columns: repeat(2, 1fr); }
  .detail-docket > div:nth-child(2) { border-right: 0; }
  .detail-docket > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .dialog-header, .dialog-body { padding-left: 17px; padding-right: 17px; }
}

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