/* Design tokens, loaders and arrival animations adapted from Enrichable (MIT); see NOTICE.md. */
@font-face { font-family: 'Rethink Sans'; src: url('/demo/fonts/rethink-regular.ttf') format('truetype'); font-weight: 400 500; font-display: swap; }
@font-face { font-family: 'Rethink Sans'; src: url('/demo/fonts/rethink-semibold.ttf') format('truetype'); font-weight: 600 700; font-display: swap; }

:root {
  --font-sans: 'Rethink Sans', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, monospace;
  --brand: #2563eb; --brand-hover: #1d58d8; --blue-10: #e9effd; --blue-20: #d3e0fb; --active-bg: #eef3fe;
  --neutral-5: #f8f8f8; --neutral-80: #333333;
  --surface: #ffffff; --canvas: #fafafa; --fg: #000000; --fg-muted: #4d4d4d; --fg-subtle: #707070;
  --line: #e6e6e6; --line-subtle: #f0f0f0; --line-strong: #cccccc;
  --success: #15803d; --success-soft: #ecfdf3;
  --danger: #dc2626; --danger-strong: #b91c1c; --danger-soft: #fef2f2;
  --warning: #b45309; --warning-strong: #854d0e; --warning-soft: #fffbeb; --warning-line: #f4d46c;
  --radius-shell: 12px;
  --ease-emphasized: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-card: 0 0 0 1px rgb(0 0 0 / 0.06), 0 1px 1px rgb(0 0 0 / 0.05), 0 2px 4px rgb(0 0 0 / 0.06), 0 4px 14px -4px rgb(0 0 0 / 0.1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; font-family: var(--font-sans); color: var(--fg); background: var(--canvas);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body { margin: 0; min-height: 100dvh; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
button:focus-visible { outline: 1.5px solid var(--fg-subtle); outline-offset: 2px; }
::selection { background: var(--blue-20); }
.tabular { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Shell: sidebar on the canvas, content beside it. */
.shell { display: flex; height: 100dvh; overflow: clip; }
.sidebar { width: 212px; flex-shrink: 0; display: flex; flex-direction: column; gap: 18px; padding: 16px 10px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; font-size: 0.9375rem; font-weight: 600; }
.mark { display: grid; place-items: center; height: 24px; padding: 0 6px; border-radius: 6px; background: var(--brand);
  color: #fff; font-size: 0.6875rem; letter-spacing: .04em; }
nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link { display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 8px 0 12px; border-radius: 8px;
  font-size: 0.8125rem; color: var(--fg-muted); text-decoration: none; }
.nav-link svg { width: 16px; height: 16px; fill: none; stroke: var(--fg-subtle); stroke-width: 1.75; }
.nav-sub { padding-left: 38px; }
.nav-link.active { background: rgb(0 0 0 / 0.07); color: var(--neutral-80); font-weight: 500; }
.nav-link.muted { color: var(--fg-subtle); }
.sidebar-foot { margin-top: auto; padding: 0 12px; font-size: 0.75rem; color: var(--fg-subtle); }

main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 6px 8px 8px 0; overflow: clip; }

/* Toolbar: sheet name, status pills, primary action. */
.toolbar { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 4px 8px 8px; }
.title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
h1 { margin: 0; font-size: 0.9375rem; font-weight: 500; white-space: nowrap; }
.subtitle { font-size: 0.75rem; color: var(--fg-subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pills { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 9999px;
  font-size: 0.75rem; white-space: nowrap; font-variant-numeric: tabular-nums; animation: fade-in 150ms ease-out; }
.pill-run { background: var(--blue-10); color: var(--brand); }
.pill-demo { background: var(--warning-soft); color: var(--warning-strong); box-shadow: inset 0 0 0 1px var(--warning-line); font-weight: 500; align-self: center; }
.pill-ok { background: var(--success-soft); color: var(--success); }
.pill-warn { background: var(--warning-soft); color: var(--warning-strong); }
.meta { font-size: 0.75rem; color: var(--fg-subtle); white-space: nowrap; }
.btn-brand { display: inline-flex; align-items: center; justify-content: center; height: 32px; padding: 0 12px; border: 0;
  border-radius: 8px; background: var(--brand); color: #fff; font: inherit; font-size: 0.8125rem; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: background-color 150ms, scale 150ms, opacity 150ms; }
.btn-brand:hover:not(:disabled) { background: var(--brand-hover); }
.btn-brand:active:not(:disabled) { scale: 0.98; }
.btn-brand:disabled { opacity: .5; cursor: default; }

.keyform { display: flex; gap: 10px; align-items: center; padding: 0 8px 10px; font-size: 0.8125rem; }
.keyform input { font: inherit; height: 32px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; }
.error { margin: 0 8px 10px; padding: 8px 14px; border-radius: 8px; background: var(--danger-soft); color: var(--danger);
  font-size: 0.8125rem; }

/* The sheet: a hairline frame on the canvas, sticky grey header, row numbers. */
.sheet-pane { flex: 1; min-height: 0; display: flex; border: 1px solid var(--line); border-radius: var(--radius-shell);
  background: var(--surface); overflow: hidden;
  box-shadow: 0 1px 1px rgb(0 0 0 / 0.05), 0 2px 4px rgb(0 0 0 / 0.06), 0 4px 14px -4px rgb(0 0 0 / 0.1); }
.sheet-scroll { flex: 1; overflow: auto; overscroll-behavior: contain; }
.scrollbar-thin { scrollbar-width: thin; scrollbar-color: #808080 transparent; }
.sheet { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1080px; font-size: 0.8125rem; }
.sheet th { position: sticky; top: 0; z-index: 2; height: 36px; padding: 0 12px; background: var(--neutral-5); text-align: left;
  font-size: 0.75rem; font-weight: 400; color: var(--fg-muted); border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line); white-space: nowrap; }
.sheet th.num, .sheet td.num { text-align: right; }
.sheet td { height: 44px; padding: 0 12px; border-right: 1px solid var(--line-subtle); border-bottom: 1px solid var(--line-subtle);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.sheet .rownum { width: 44px; min-width: 44px; padding: 0; text-align: center; font-size: 0.75rem; color: var(--fg-subtle);
  font-variant-numeric: tabular-nums; border-right: 1px solid var(--line-subtle); }
.sheet th.rownum { border-right: 1px solid var(--line); }
.head-dot { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 9999px; background: var(--line-strong);
  vertical-align: middle; }
.running .head-dot { background: var(--brand); animation: backdrop-pulse 1.6s ease-in-out infinite; }
.portal { font-weight: 500; }
.portal small { display: block; font-size: 0.75rem; font-weight: 400; color: var(--fg-subtle); }
.tag { display: inline-flex; align-items: center; height: 20px; margin-left: 6px; padding: 0 7px; border-radius: 9999px;
  background: var(--neutral-5); color: var(--fg-subtle); font-size: 0.6875rem; font-weight: 400; vertical-align: 1px; }
.actor { color: var(--fg-muted); min-width: 110px; }
.cell-muted { color: var(--fg-subtle); }

/* Status cell: dot loader while queued or collecting; the active cell gets the brand ring. */
.status { position: relative; min-width: 300px; max-width: 320px; }
.status-inner { display: flex; align-items: center; gap: 8px; min-width: 0; }
.status-inner > span:last-child { overflow: hidden; text-overflow: ellipsis; }
tr.collecting .status { background: var(--active-bg); box-shadow: inset 0 0 0 1.5px var(--brand); color: var(--brand); font-weight: 500; }
tr.queued .status, tr.due .status { color: var(--fg-subtle); }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 9999px; font-size: 0.75rem;
  font-weight: 500; flex-shrink: 0; }
.chip-ok { background: var(--success-soft); color: var(--success); }
.chip-warn { background: var(--warning-soft); color: var(--warning-strong); box-shadow: inset 0 0 0 1px var(--warning-line); }
.chip-err { background: var(--danger-soft); color: var(--danger-strong); }
.chip-recv { background: var(--blue-10); color: var(--brand); }
.status-note { font-size: 0.75rem; color: var(--fg-subtle); font-weight: 400; }
tr.person td { background: #fffdf5; }

.cell-status-loader { width: 18px; height: 18px; display: grid; grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr); gap: 2.25px; flex-shrink: 0; }
.cell-status-loader > i { width: 100%; height: 100%; border-radius: 50%; animation: cell-status-shimmer ease-in-out infinite; }
@keyframes cell-status-shimmer {
  0%, 34%, 100% { opacity: .13; }
  8% { opacity: var(--status-peak); }
  15% { opacity: .3; }
  23% { opacity: var(--status-echo); }
}

.spinner { display: inline-block; width: 12px; height: 12px; border-radius: 9999px; border: 1.5px solid var(--brand);
  border-top-color: transparent; animation: spin 700ms linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes backdrop-pulse { 50% { opacity: 0.35; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes content-in { from { opacity: 0; transform: translateY(6px) scale(0.985); } }
.sheet-pane, .toolbar { animation: content-in 200ms var(--ease-emphasized); }

.foot { margin: 10px 8px 0; font-size: 0.75rem; color: var(--fg-subtle); }

@media (prefers-reduced-motion: reduce) {
  .cell-status-loader > i { animation: none !important; opacity: var(--status-rest, .5) !important; }
  .running .head-dot, .sheet-pane, .toolbar, .pill { animation: none; }
  .spinner { animation-duration: 1.5s; }
}
@media (width < 860px) {
  .sidebar { display: none; }
  main { padding-left: 8px; }
  .toolbar { flex-wrap: wrap; }
  .pills { margin-left: 0; flex-wrap: wrap; }
}
