/* Studio C ledger. Design reasons are in DESIGN.md next to this app. */
:root {
  --bg: #16140f;        /* dark ledger cover, warm so the paper-toned ink reads like a book, not a terminal */
  --raise: #1e1c16;     /* dialogs and sheets only */
  --rule: #3b372d;      /* hairline ledger ruling */
  --rule-strong: #6b6455;
  --ink: #ece5d3;       /* paper tone used as text */
  --muted: #a8a08c;     /* 7.4:1 on --bg */
  --accent: #f0805f;    /* red pencil: reserved for notes and the note tool */
  --accent-ink: #1a0f0a;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Source Sans 3", system-ui, sans-serif;
  --r: 3px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  padding-bottom: 96px;
}
.wrap { max-width: 920px; margin: 0 auto; padding: 0 20px; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 12px; background: var(--ink); color: var(--bg); padding: 8px 12px; z-index: 50; }
[hidden] { display: none !important; }

/* figures: tabular lining numerals so money columns line up like a ledger */
.num, .money, td.amt { font-family: var(--serif); font-variant-numeric: tabular-nums lining-nums; }

/* ---------- header ---------- */
.top { border-bottom: 1px solid var(--rule); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; flex-wrap: wrap; }
.brand { font: 600 1.35rem/1.1 var(--serif); margin: 0; }
.brand span { font-weight: 400; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 4px; }
.who { color: var(--muted); font-size: .9rem; padding: 0 8px; }
.link-btn {
  background: none; border: 0; color: var(--ink); font: inherit; cursor: pointer;
  min-height: 44px; padding: 0 10px; border-radius: var(--r); text-decoration: underline;
  text-decoration-color: var(--rule-strong); text-underline-offset: 4px; display: inline-flex; align-items: center;
}
.link-btn:hover { text-decoration-color: var(--ink); }
.count { font-family: var(--serif); color: var(--accent); margin-left: 4px; }

/* ---------- states ---------- */
.state { color: var(--muted); padding: 48px 0; max-width: 46ch; }
.state strong { color: var(--ink); display: block; font: 600 1.15rem var(--serif); margin-bottom: 4px; }
.state button { margin-top: 12px; }

/* ---------- sync line ---------- */
.synced { color: var(--muted); font-size: .9rem; margin: 20px 0 0; }

/* ---------- open money (focal point) ---------- */
.open { display: grid; grid-template-columns: 1fr 1fr; gap: 0 40px; margin: 28px 0 8px; }
.open h2 { font: 400 1rem var(--sans); color: var(--muted); margin: 0 0 2px; }
.open .big { font: 600 clamp(2.2rem, 7vw, 3.2rem)/1.05 var(--serif); font-variant-numeric: tabular-nums lining-nums; margin: 0 0 12px; padding-bottom: 10px; border-bottom: 3px double var(--rule-strong); }
.open ul { list-style: none; margin: 0; padding: 0; }
.open li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.open li .label { min-width: 0; }
.open li .money { white-space: nowrap; }
.open li small { display: block; color: var(--muted); font-size: .85rem; }
.open .none { color: var(--muted); padding: 8px 0; }

/* ---------- toolbar ---------- */
.tools { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: end; margin: 36px 0 8px; padding-top: 20px; border-top: 1px solid var(--rule); }
.tools label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.tools input, .tools select {
  background: transparent; color: var(--ink); font: inherit; border: 1px solid var(--rule-strong); border-radius: var(--r);
  min-height: 44px; padding: 0 10px; width: 100%;
}
.tools .grow { flex: 1 1 240px; }
.tools .who-filter { flex: 0 1 200px; }

/* ---------- project ledger pages ---------- */
.group-h { font: 600 1.25rem var(--serif); margin: 36px 0 4px; }
.group-h small { font: 400 .9rem var(--sans); color: var(--muted); margin-left: 8px; }
.project { border-top: 1px solid var(--rule-strong); }
.project > summary { list-style: none; cursor: pointer; padding: 14px 0; display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; align-items: baseline; }
.project > summary::-webkit-details-marker { display: none; }
.project > summary:hover .p-title { text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 4px; }
.p-title { font: 600 1.1rem/1.3 var(--serif); }
.p-title::before { content: "+"; display: inline-block; width: 1.1em; color: var(--muted); font-family: var(--sans); }
.project[open] .p-title::before { content: "–"; }
.p-meta { color: var(--muted); font-size: .9rem; grid-column: 1; padding-left: 1.1em; }
.p-sum { grid-column: 2; grid-row: 1 / span 2; text-align: right; font-size: .9rem; color: var(--muted); }
.p-sum b { color: var(--ink); font: 600 1.05rem var(--serif); font-variant-numeric: tabular-nums lining-nums; display: block; }
.p-body { padding: 0 0 24px 1.1em; }
.p-flags { color: var(--muted); font-size: .9rem; margin: 0 0 12px; }
.p-index { font-size: .9rem; margin: 0 0 16px; }
.p-index span { color: var(--muted); }

table.ledger { width: 100%; border-collapse: collapse; margin: 6px 0 4px; }
.ledger caption { text-align: left; font: 600 1rem var(--serif); padding: 12px 0 6px; }
.ledger th { text-align: left; font-weight: 400; color: var(--muted); font-size: .85rem; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--rule-strong); }
.ledger td { padding: 9px 8px 9px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.ledger th.amt, .ledger td.amt { text-align: right; padding-right: 28px; white-space: nowrap; width: 1%; }
.ledger th:first-child, .ledger td:first-child { width: 22%; }
.ledger td.amt { font-size: 1.02rem; }
.ledger tfoot td { border-bottom: 3px double var(--rule-strong); font-weight: 600; }
.ledger .soft { color: var(--muted); }
.ledger .unknown { font-style: italic; color: var(--muted); }
.ledger td.note-cell { color: var(--muted); font-size: .92rem; }
.empty-row { color: var(--muted); padding: 10px 0; border-bottom: 1px solid var(--rule); }
.p-summary-line { color: var(--muted); font-size: .9rem; margin: 10px 0 0; }
.checkline { font-size: .9rem; margin: 8px 0 0; }
.checkline::before { content: "Check: "; color: var(--muted); }

/* ---------- note markers (accent) ---------- */
.mark {
  background: none; border: 0; padding: 0 2px; margin-left: 6px; cursor: pointer; font: 600 .8rem var(--sans);
  color: var(--accent); text-decoration: underline; text-underline-offset: 3px; min-height: 24px; vertical-align: baseline;
}

/* ---------- annotate mode ---------- */
.annotate-btn {
  position: fixed; right: 20px; bottom: 20px; z-index: 30; min-height: 48px; padding: 0 18px;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--r);
  font: 600 1rem var(--sans); cursor: pointer; box-shadow: 0 2px 0 rgba(0,0,0,.35);
}
.annotate-btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.annotate-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; padding: 14px 200px 14px 20px;
  background: var(--raise); border-top: 1px solid var(--accent); font-size: .95rem;
}
kbd { font: 600 .85em var(--sans); border: 1px solid var(--rule-strong); border-radius: var(--r); padding: 0 5px; }
body.annotating [data-target] { cursor: crosshair; }
body.annotating [data-target]:hover, body.annotating [data-target]:focus-visible {
  outline: 2px dashed var(--accent); outline-offset: 2px;
}
body.annotating .project > summary { cursor: crosshair; }
.flash { animation: flash 1.6s ease-out 1; }
@keyframes flash { from { outline: 2px solid var(--accent); outline-offset: 3px; } to { outline: 2px solid transparent; outline-offset: 3px; } }

/* ---------- dialogs ---------- */
dialog { background: var(--raise); color: var(--ink); border: 1px solid var(--rule-strong); border-radius: var(--r); padding: 22px; width: min(520px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(8, 7, 5, .7); }
dialog h2 { font: 600 1.2rem var(--serif); margin: 0 0 6px; }
.compose-on { color: var(--muted); margin: 0 0 16px; }
.compose-on span { color: var(--ink); }
dialog label { display: block; margin-bottom: 6px; }
textarea { width: 100%; background: var(--bg); color: var(--ink); border: 1px solid var(--rule-strong); border-radius: var(--r); font: inherit; padding: 10px; resize: vertical; }
textarea::placeholder { color: #8d8674; }
.hint { color: var(--muted); font-size: .88rem; margin: 8px 0 0; }
.form-error { color: var(--accent); margin: 10px 0 0; }
.form-error.neutral { color: var(--muted); }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.primary {
  background: var(--ink); color: var(--bg); border: 0; border-radius: var(--r); font: 600 1rem var(--sans);
  min-height: 44px; padding: 0 18px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; text-align: center;
}
.primary:disabled { opacity: .6; cursor: wait; }

dialog.sheet { margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(460px, 100vw); border-width: 0 0 0 1px; border-radius: 0; padding: 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 10px 22px; border-bottom: 1px solid var(--rule); position: sticky; top: 0; background: var(--raise); }
.sheet-head h2 { margin: 0; }
#notes-list { padding: 0 22px 32px; }
.note { padding: 14px 0; border-bottom: 1px solid var(--rule); }
.note-on { background: none; border: 0; color: var(--ink); font: 600 .95rem var(--serif); padding: 0; text-align: left; cursor: pointer; text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; min-height: 24px; }
.note-meta { color: var(--muted); font-size: .85rem; margin: 2px 0 6px; }
.note-body { margin: 0; white-space: pre-wrap; }
.note-status { font-size: .88rem; margin: 8px 0 0; }
.note-status.waiting { color: var(--accent); }
.note-reply { margin: 4px 0 0; padding-left: 12px; border-left: 1px solid var(--rule-strong); white-space: pre-wrap; }

.toast { position: fixed; left: 20px; bottom: 20px; z-index: 40; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: var(--r); max-width: calc(100vw - 200px); }

/* ---------- sign-in ---------- */
body.signin { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }
.signin-box { max-width: 420px; }
.signin-box .brand { font-size: 2rem; padding-bottom: 12px; border-bottom: 3px double var(--rule-strong); margin-bottom: 16px; }
.signin-box p { color: var(--muted); }
.signin-box .primary { margin-top: 12px; padding: 12px 18px; }

/* ---------- small screens ---------- */
@media (max-width: 680px) {
  .wrap { padding: 0 16px; }
  .who { display: none; }
  .open { grid-template-columns: 1fr; gap: 28px; }
  .project > summary { grid-template-columns: 1fr; }
  .p-sum { grid-column: 1; grid-row: auto; text-align: left; padding-left: 1.1em; }
  .p-sum b { display: inline; margin-right: 6px; }
  .p-body { padding-left: 0; }
  .ledger thead { display: none; }
  .ledger tr { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
  .ledger td { border: 0; padding: 0; width: auto !important; }
  .ledger td.amt { padding-right: 0; }
  .ledger td:empty { display: none; }
  .ledger td.amt { grid-column: 2; grid-row: 1; }
  .ledger td.wide { grid-column: 1 / -1; }
  .ledger tfoot tr { border-bottom: 3px double var(--rule-strong); }
  .ledger tfoot td { border: 0; }
  .annotate-bar { padding: 12px 16px 76px; }
  .toast { left: 16px; right: 16px; bottom: 80px; max-width: none; }
}
@media (prefers-reduced-motion: reduce) { .flash { animation: none; outline: 2px solid var(--accent); } }
