:root {
  --paper: #f4f3ee;
  --surface: #ffffff;
  --sunken: #f9f8f4;
  --ink: #17201c;
  --muted: #5b6660;
  --faint: #8a938d;
  --line: #dddbd1;
  --line-strong: #c4c1b4;
  --accent: #1d4a39;
  --accent-ink: #ffffff;
  --accent-soft: #e6efe9;
  --warn: #7a4f00;
  --warn-soft: #fbf0d4;
  --warn-line: #e6cf96;
  --bad: #962d2d;
  --bad-soft: #fbeaea;
  --radius: 6px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
/* scroll-padding keeps focused / scrolled-to controls clear of the fixed save bar */
html { -webkit-text-size-adjust: 100%; scroll-padding-bottom: 90px; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.45 var(--sans); }
h1, h2, h3, p { margin: 0; }
h1 { font: 600 26px/1.2 var(--serif); letter-spacing: -0.01em; }
h2 { font: 600 13px/1.3 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.boot { padding: 48px; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- chrome ---- */
.ribbon { background: var(--ink); color: #e9ece9; font-size: 12.5px; padding: 6px 20px; letter-spacing: 0.02em; }
.ribbon b { color: #f3d58a; font-weight: 600; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1240px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 28px; min-height: 56px; flex-wrap: wrap; }
.brand { font: 600 18px/1 var(--serif); color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 18px 10px 16px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; font-weight: 500; }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.who { display: flex; align-items: center; gap: 12px; font-size: 13px; text-align: right; }
.who strong { display: block; font-weight: 600; }
main { max-width: 1240px; margin: 0 auto; padding: 28px 20px 120px; }

/* ---- controls ---- */
button, .btn { font: 500 14px/1 var(--sans); padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; min-height: 38px; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--ink); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { background: #163a2d; }
button.quiet { border-color: transparent; background: transparent; color: var(--accent); padding: 6px 8px; min-height: 32px; }
button.quiet:hover { background: var(--accent-soft); }
button.danger { color: var(--bad); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input[type="text"], input[type="search"], input[type="email"], input[type="date"], select {
  font: 15px/1.2 var(--sans); color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 9px 10px; width: 100%; min-height: 40px;
}
input.num { text-align: right; }
input[aria-invalid="true"] { border-color: var(--bad); background: var(--bad-soft); }
label, .label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field { min-width: 0; }
.err { color: var(--bad); font-size: 12.5px; margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.card > h2 { margin-bottom: 14px; }
.card-note { font-size: 12.5px; color: var(--muted); margin: -8px 0 14px; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.pill.pending { background: var(--warn-soft); color: var(--warn); }
.pill.completed { background: var(--accent-soft); color: var(--accent); }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 4px; margin: 0 4px 4px 0; background: var(--sunken); }
.chip.readonly { background: transparent; border-style: dashed; color: var(--muted); }
.chip .chip-x { min-height: 0; height: 18px; padding: 0 4px; margin-left: 4px; line-height: 1; }
.chip.admin { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.notice { border: 1px solid var(--warn-line); background: var(--warn-soft); color: #4d3300; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.notice p + p { margin-top: 6px; }
.notice.info { border-color: var(--line); background: var(--sunken); color: var(--muted); }
.conflict { margin-top: 6px; padding: 8px 10px; border: 1px solid var(--warn-line); background: var(--warn-soft); font-size: 13px; color: #4d3300; border-radius: 4px; }
.conflict button { margin-left: 4px; }

/* ---- page head / filters ---- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.tile .label { margin: 0; }
.tile .value { font: 600 22px/1.3 var(--serif); font-variant-numeric: tabular-nums; }
.filters { display: grid; grid-template-columns: minmax(200px, 1.4fr) minmax(180px, 1fr) auto; gap: 12px; align-items: end; margin-bottom: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--muted); min-height: 38px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* ---- data grid ---- */
.grid-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line-strong); background: var(--sunken); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th.r, td.r { text-align: right; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--sunken); }
td .biz { font-weight: 600; color: var(--ink); text-decoration: none; }
td .biz:hover { text-decoration: underline; }
td .sub { font-size: 12.5px; color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.count { font-size: 13px; color: var(--muted); margin: 10px 2px 0; }

/* ---- persona picker ---- */
.picker { max-width: 760px; margin: 32px auto; }
.picker h1 { margin-bottom: 8px; }
.personas { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 20px; }
.persona { display: block; text-align: left; white-space: normal; padding: 14px 16px; min-height: 96px; line-height: 1.4; align-items: flex-start; }
.persona strong { display: block; font-size: 15px; }
.persona span { display: block; font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 3px; }

/* ---- editor ---- */
.back { display: inline-block; margin-bottom: 14px; text-decoration: none; font-size: 14px; }
.deal-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.deal-meta { color: var(--muted); margin: 6px 0 20px; font-size: 14px; }
.factstrip { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; font-size: 13.5px; }
.factstrip h2 { margin-bottom: 8px; font-size: 12px; }
.factstrip dl { margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px 16px; }
.factstrip dt { color: var(--muted); font-size: 12px; }
.factstrip dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.conflicts { margin-bottom: 14px; }

/* ---- worksheet ---- */
.sheet-card { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); margin-bottom: 16px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; }
.sheet-tools button { min-height: 32px; padding: 6px 12px; }
.cellbar { display: flex; align-items: stretch; border-top: 1px solid var(--line-strong); background: var(--sunken); }
.cellbar .ref { flex: 0 0 56px; display: flex; align-items: center; justify-content: center; font: 600 13px/1 var(--sans); border-right: 1px solid var(--line-strong); font-variant-numeric: tabular-nums; }
.cellbar .what { flex: 0 1 230px; min-width: 0; display: flex; align-items: center; padding: 0 10px; font-size: 12.5px; color: var(--muted); border-right: 1px solid var(--line-strong); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cellbar input { flex: 1; min-width: 0; border: 0; border-radius: 0; min-height: 34px; padding: 6px 10px; font-size: 14px; background: var(--surface); }
.cellbar input:read-only { background: var(--sunken); color: var(--muted); }
.cellbar input:focus-visible { outline-offset: -2px; }
.sheet-wrap { overflow-x: auto; border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
table.sheet { table-layout: fixed; border-collapse: separate; border-spacing: 0; width: 100%; min-width: 860px; font-size: 13.5px; touch-action: manipulation; }
.sheet col.w-rh { width: 40px; }
.sheet col.w-a { width: 23%; }
.sheet col.w-b { width: 17%; }
.sheet col.w-c { width: 96px; }
.sheet col.w-d { width: 140px; }
.sheet col.w-act { width: 44px; }
.sheet th, .sheet td { height: 30px; padding: 0 8px; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--surface); }
.sheet th { text-transform: none; letter-spacing: 0; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); background: #eceae2; border-color: var(--line-strong); padding: 0; user-select: none; }
.sheet th.on { background: #d6e3db; color: var(--accent); }
.sheet .rh { position: sticky; left: 0; z-index: 1; }
.sheet tr:last-child td { border-bottom: 1px solid var(--line); }
.sheet td { position: relative; cursor: cell; font-variant-numeric: tabular-nums; }
.sheet td.r { text-align: right; }
.sheet td.lk { background: var(--sunken); color: var(--muted); cursor: default; }
.sheet td.lbl { color: var(--ink); }
.sheet td.sec { background: #eceae2; color: var(--ink); font-size: 12px; font-weight: 600; letter-spacing: 0.03em; }
.sheet td.colhead { font-weight: 600; color: var(--ink); background: #f1efe8; }
.sheet td.sum { color: var(--ink); font-weight: 600; }
.sheet td.verdict { font-weight: 600; }
.sheet td.verdict.ok { color: var(--accent); }
.sheet td.verdict.off { color: var(--warn); }
.sheet td.gone { text-decoration: line-through; color: var(--faint); }
.sheet td.bad { background: var(--bad-soft); color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); }
.sheet td.theirs, .sheet tr.conflicted td.in { background: var(--warn-soft); }
.sheet td.flash { background: var(--accent-soft); transition: background 0.2s; }
.sheet td.act { padding: 0; text-align: center; cursor: default; background: var(--sunken); }
.sheet td:focus { outline: none; }
.sheet td.active { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 2; }
.sheet td.in.auto { color: var(--muted); font-style: italic; background: #fbfaf6; }
.sheet td.note { font-size: 12.5px; }
.sheet td.pick { padding: 0; }
.sheet td.pick select { display: block; width: 100%; height: 100%; min-height: 30px; border: 0; border-radius: 0; padding: 0 8px; font: inherit; font-weight: 600; color: var(--ink); background-color: var(--surface); cursor: pointer; }
.sheet td.pick select:focus { outline: none; }
.sheet td.pick.theirs select { background-color: var(--warn-soft); }
.problems ul.warn { color: var(--warn); font-weight: 600; margin-bottom: 4px; }
.sheet td.editing { padding: 0; overflow: visible; }
.sheet td.editing input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; border: 0; border-radius: 0; padding: 0 8px; font: inherit; background: var(--surface); outline: 2px solid var(--accent); outline-offset: -2px; box-shadow: 0 2px 10px rgba(23, 32, 28, 0.18); }
.rowbtn { min-height: 26px; height: 26px; width: 100%; padding: 0 4px; border: 0; background: transparent; color: var(--muted); font-size: 12.5px; justify-content: center; border-radius: 0; }
.rowbtn[hidden] { display: none; }
.rowbtn:hover { color: var(--bad); background: var(--bad-soft); }
.sheet-status { min-height: 20px; padding: 8px 14px 0; font-size: 13px; color: var(--ink); }
.problems { padding: 2px 14px 0; font-size: 13px; }
.problems ul { margin: 0; padding: 0; list-style: none; color: var(--bad); }
.problems .ok { color: var(--muted); }
.problems .cellref { min-height: 24px; padding: 2px 6px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sheet-help { padding: 6px 14px 12px; font-size: 12.5px; color: var(--muted); }
.note-preview { background: var(--sunken); border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
.note-preview .title { font-weight: 600; margin-bottom: 6px; }
.note-preview code { display: block; margin-top: 8px; font-size: 11.5px; color: var(--muted); word-break: break-all; }
.savebar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line-strong); box-shadow: 0 -4px 16px rgba(23, 32, 28, 0.06); z-index: 5; }
.savebar-in { max-width: 1240px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.savebar .state { flex: 1; font-size: 14px; color: var(--muted); min-width: 140px; }
.savebar .state.dirty { color: var(--warn); font-weight: 600; }

/* ---- access / integrations ---- */
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 400; color: var(--ink); margin: 0; min-height: 30px; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 14px; }
.group-label { font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
pre.body { margin: 0; white-space: pre-wrap; font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
code.html { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); word-break: break-all; }

#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 10; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); }

/* ---- tablet ---- */
@media (max-width: 980px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
}

/* ---- phone: grid becomes cards, editor stacks ---- */
@media (max-width: 720px) {
  html { scroll-padding-bottom: 150px; }
  h1 { font-size: 22px; }
  main { padding: 18px 14px 170px; }
  .ribbon { padding: 6px 14px; }
  .topbar-in { padding: 8px 14px 0; gap: 8px 16px; }
  .who { margin-left: auto; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .nav a { padding: 10px 10px 9px; }
  .filters { grid-template-columns: 1fr; }
  .seg { display: flex; }
  .seg button { flex: 1; justify-content: center; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; justify-content: center; }

  .grid-wrap { border: 0; background: transparent; overflow: visible; }
  .grid-wrap thead { position: absolute; left: -9999px; }
  .grid-wrap table, .grid-wrap tbody, .grid-wrap tr, .grid-wrap td { display: block; }
  .grid-wrap tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
  .grid-wrap td { padding: 0; border: 0; text-align: left !important; min-width: 0; }
  .grid-wrap td[data-label]::before { content: attr(data-label); display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
  .grid-wrap td.full { grid-column: 1 / -1; }
  .grid-wrap td.full::before { display: none; }

  .factstrip dl { grid-template-columns: 1fr 1fr; gap: 6px 14px; }
  .sheet th, .sheet td { height: 42px; }
  table.sheet { font-size: 15px; min-width: 780px; }
  .sheet col.w-act { width: 52px; }
  .rowbtn { height: 40px; font-size: 16px; }
  .cellbar { flex-wrap: wrap; }
  .cellbar .ref { min-height: 32px; }
  .cellbar .what { flex: 1; border-right: 0; color: var(--ink); font-weight: 600; }
  .cellbar input { flex-basis: 100%; border-top: 1px solid var(--line-strong); }
  .cellbar input, .sheet td.editing input { font-size: 16px; min-height: 44px; }
  .sheet td.editing input { min-height: 0; }
  .savebar-in { padding: 10px 14px; }
  .savebar .state { flex-basis: 100%; }
  .savebar button { flex: 1; justify-content: center; min-height: 44px; }
  button, .btn { min-height: 42px; }
  #toast { bottom: auto; top: 12px; }
}
