:root {
  --bg: #ffffff; --fg: #1d232a; --muted: #6b7480; --line: #dfe3e8; --head: #f4f6f8; --sec: #e9edf2;
  --today: #fff6d6; --sel: #eef4ff; --cur: #2f6fde; --plan: #8a929c; --neg: #c0392b; --good: #1e8449;
  --strong: #eaf6ee; --menu: #ffffff; --banner: #fff3b0; --btn: #f1f3f6;
  --missing-frame: #b53142; --missing-frame-soft: #da737dba; --missing-ink: #a02634; --missing-fill: #fff0f1; --missing-fill-strong: #ffd2d7;
  --missing-ripple: #b53142cc; --missing-ripple-mid: #b5314266; --missing-ripple-end: #b5314200;
  --open-day-frame: #b66518; --open-day-soft: #d990499c;
  --closed-day-frame: #327455; --closed-day-fill: #edf7f0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15191e; --fg: #e6e9ed; --muted: #9aa3ad; --line: #2c333b; --head: #1c2127; --sec: #222931;
    --today: #3a3420; --sel: #1d2a3d; --cur: #6aa0ff; --plan: #8d96a0; --neg: #ff7b6b; --good: #5fd08a;
    --strong: #1b3024; --menu: #20262d; --banner: #4a4214; --btn: #262d35;
    --missing-frame: #ff878f; --missing-frame-soft: #ce616d91; --missing-ink: #ffc1c6; --missing-fill: #432831; --missing-fill-strong: #6a2a36;
    --missing-ripple: #ff878fcc; --missing-ripple-mid: #ff878f66; --missing-ripple-end: #ff878f00;
    --open-day-frame: #f1a65b; --open-day-soft: #d9904977;
    --closed-day-frame: #76c69b; --closed-day-fill: #234337;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 13px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
a { color: var(--cur); }
button, .btn { font: inherit; padding: 3px 9px; border: 1px solid var(--line); border-radius: 5px; background: var(--btn);
  color: var(--fg); cursor: pointer; text-decoration: none; white-space: nowrap; }
button[aria-pressed="true"] { background: var(--cur); color: #fff; border-color: var(--cur); }
button.link { border: 0; background: none; color: var(--cur); padding: 0; }
form.inline { display: inline; }

/* the one-screen page: header, grid (sideways scroll only), one bottom line */
/* the padlock button: a clear call to action while the selected day can be closed */
.lock-icon { width: 1.05em; height: 1.05em; vertical-align: -.15em; margin-right: .35em; fill: none; stroke: currentColor;
  stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#dayLock.cta { background: #205c48; border-color: #205c48; color: #fff; font-weight: 650; }
#dayLock.cta:hover { background: #174837; }
body.gridpage { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
/* iPhone Safari zooms into any focused field under 16px and stays zoomed */
@media (pointer: coarse) { input.edit, #views input.money:not(.big) { font-size: 16px; } }
.top { --top-accent: #205c48; background: var(--head); border-bottom: 1px solid var(--line); }
.top-main, .top-toolbar { display: flex; align-items: center; gap: 10px 16px; padding: 8px 16px; }
.top-main { background: var(--bg); }
.top-toolbar { border-top: 1px solid var(--line); justify-content: space-between; flex-wrap: wrap; }
.brand { font-size: 18px; font-weight: 750; letter-spacing: -.5px; white-space: nowrap; }
.top-account, .top-actions, .top-history { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; min-width: 0; }
.top-account { margin-left: auto; }
.top-account a, .top-account .link { color: var(--muted); text-decoration: none; font-weight: 550; }
.top-account a:hover, .top-account .link:hover { color: var(--fg); text-decoration: underline; }
.top-account .who { border-left: 1px solid var(--line); padding-left: 10px; overflow-wrap: anywhere; white-space: normal; }
.viewsw { display: flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--head); border: 1px solid var(--line); min-width: 0; }
.viewsw button { border: 0; background: transparent; border-radius: 6px; min-height: 30px; padding: 4px 10px; font-weight: 600; flex: 0 0 auto; }
.viewsw button:hover { background: var(--btn); }
.viewsw button[aria-pressed="true"], .top #planMode[aria-pressed="true"] { background: var(--top-accent); color: #fff; border-color: var(--top-accent); }
.top-actions > button, .top-actions > .btn, .top-history > button, .snaps select {
  min-height: 29px; border-radius: 7px; background: var(--bg); }
.top-actions > button:hover, .top-actions > .btn:hover, .top-history > button:hover { background: var(--btn); }
.top-history { max-width: 100%; }
.spacer { flex: 1; }
.sel, .who { color: var(--muted); white-space: nowrap; }
.status { color: var(--muted); overflow-wrap: anywhere; }
.status.good { color: var(--good); }
.status.bad { color: var(--neg); font-weight: 600; white-space: normal; }
.snaps { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); min-width: 0; }
.snaps select { font: inherit; color: var(--fg); max-width: 16em; min-width: 0; border: 1px solid var(--line); padding: 3px 6px; }
.top :focus-visible { outline: 2px solid var(--cur); outline-offset: 1px; }
.viewsw :focus-visible { outline-offset: -2px; }
.banner { background: var(--banner); padding: 5px 10px; font-weight: 500; }

.wrap { overflow-x: auto; overflow-y: auto; flex: 0 1 auto; max-height: 100%; }
table.grid { border-collapse: separate; border-spacing: 0; }
.grid th, .grid td { height: 23px; padding: 0 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  white-space: nowrap; }
.grid thead th { position: sticky; top: 0; background: var(--head); z-index: 2; font-weight: 600; height: 28px; }
.grid th.day { min-width: 82px; text-align: right; cursor: pointer; }
.grid th.day small { color: var(--muted); font-weight: 400; }
.grid th.day.today { background: var(--today); }
.grid th.day.missing { color: var(--neg); box-shadow: inset 0 -3px 0 var(--neg); }
.grid th.day[data-day-state="open"] { box-shadow: inset 0 -3px 0 var(--open-day-frame); }
.grid th.day[data-day-state="past-open"] { box-shadow: inset 0 -3px 0 var(--missing-frame); }
.grid th.day[data-day-state="closed"] { box-shadow: inset 0 -3px 0 var(--closed-day-frame); }
.grid th.lab { position: sticky; left: 0; z-index: 1; background: var(--bg); text-align: left; min-width: 228px;
  max-width: 228px; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.grid thead th.lab { z-index: 3; background: var(--head); }
.grid .tot { position: sticky; right: 0; background: var(--head); text-align: right; min-width: 104px; font-weight: 600;
  border-left: 2px solid var(--line); }
.grid thead th.tot { z-index: 3; }
.grid td { text-align: right; }
.grid td.in { cursor: cell; }
.grid td.in[data-closed] { cursor: default; }
.grid td.plan { color: var(--plan); font-style: italic; }
.grid td.today, .grid td.v.today { background: var(--today); }
.grid td.selcol, .grid th.selcol { background-color: var(--sel); }
.grid td.cur { outline: 2px solid var(--cur); outline-offset: -2px; }
.grid td.cur[data-needs-fact] { --missing-frame-width: 4px; }
[data-needs-fact], [data-missing-day] { animation: missing-fact-frame 1.8s ease-in-out infinite alternate; }
.grid td.in[data-needs-fact] { cursor: pointer; }
.fill-cue { display: block; border-radius: 4px; background: var(--missing-fill);
  color: var(--missing-ink); text-align: center; font-size: 11px; font-weight: 700; }
#views input.money[data-needs-fact]::placeholder { color: var(--missing-ink); opacity: 1; font-style: normal; }
@keyframes missing-fact-frame {
  from { box-shadow: inset 0 0 0 var(--missing-frame-width, 2px) var(--missing-frame); }
  to { box-shadow: inset 0 0 0 var(--missing-frame-width, 2px) var(--missing-frame-soft); }
}
.grid .neg { color: var(--neg); }
.grid tr.shopstart th, .grid tr.shopstart td { border-top: 2px solid var(--line); }
.grid tr.sec th.lab, .grid tr.sec td { background: var(--sec); font-weight: 700; }
.grid tr.sec th.lab small { font-weight: 400; color: var(--muted); }
.grid tr.calc th.lab { font-weight: 400; color: var(--muted); }
.grid tr.calc.sub th.lab { font-weight: 600; color: var(--fg); }
.grid tr.strong th, .grid tr.strong td { font-weight: 700; background: var(--strong); }
.grid tr.strong .tot { background: var(--strong); }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }
.chip { font-size: 11px; padding: 0 5px; border-radius: 9px; min-width: 52px; }
.grid .row-minus { color: var(--neg); padding: 0 5px; }
.add { font-size: 11px; padding: 0 6px; margin-left: 6px; }
input.edit { width: 100%; min-width: 70px; border: 0; outline: 0; background: transparent; color: var(--fg); font: inherit;
  padding: 0; }
[data-money] { text-align: right; }
input.edit.plan { font-style: italic; }

.bottom { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 6px 10px; border-top: 1px solid var(--line);
  color: var(--muted); }
.bottom .forecast { color: var(--fg); }
.bottom .up { color: var(--good); } .bottom .down { color: var(--neg); } .bottom .flat, .bottom .neutral { color: var(--fg); }
.bottom .few { font-style: italic; }

.menu { position: fixed; z-index: 10; background: var(--menu); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); width: 280px; }
.menu fieldset { border: 0; padding: 0; margin: 8px 0; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.menu legend { font-weight: 600; margin-bottom: 2px; }
.menu label { display: block; margin: 6px 0; }
.menu fieldset label { display: inline; margin: 0; }
.menu input[name="pct"] { font: inherit; width: 4.5em; text-align: right; }
.menu .note { color: var(--muted); margin: 4px 0 8px; font-size: 12px; }
.menu .danger { color: var(--neg); }

.action-dialog { width: min(32rem, calc(100% - 24px)); max-height: calc(100% - 24px); padding: 0; border: 1px solid var(--line);
  border-radius: 16px; background: var(--bg); color: var(--fg); box-shadow: 0 18px 56px #0004; }
.action-dialog::backdrop { background: #10241d80; }
.action-dialog form { padding: clamp(18px, 5vw, 24px); }
.action-dialog h2 { margin: 0; font-size: 20px; letter-spacing: -.3px; }
.action-dialog p { margin: 9px 0 12px; color: var(--muted); font-size: 14px; }
.action-dialog ul { margin: 0; padding: 13px 15px 13px 32px; border: 1px solid var(--line); border-radius: 10px; background: var(--head);
  font-size: 14px; line-height: 1.45; }
.action-dialog li + li { margin-top: 7px; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.dialog-actions button { min-height: 38px; padding: 6px 13px; border-radius: 8px; font-weight: 600; }
.dialog-actions [value="confirm"] { background: #205c48; border-color: #205c48; color: #fff; }
.dialog-actions [value="confirm"]:hover { background: #174837; }
.dialog-actions [value="confirm"].danger { background: #a13137; border-color: #a13137; }
.dialog-actions button:focus-visible { outline: 2px solid var(--cur); outline-offset: 2px; }

.login { max-width: 300px; margin: 18vh auto; padding: 0 16px; }
.login label { display: block; margin: 12px 0 4px; }
.login input { font-size: 22px; letter-spacing: 6px; width: 100%; padding: 8px; text-align: center; }
.login button { margin-top: 12px; width: 100%; padding: 8px; font-size: 15px; }
.error { color: var(--neg); }

.logpage { max-width: 1480px; margin: 0 auto; padding: clamp(12px, 2.5vw, 30px); }
.log-heading { margin: 0 0 16px; }
.log-heading h1 { margin: 0; font-size: 28px; letter-spacing: -.5px; }
.log-heading p { margin: 4px 0 0; color: var(--muted); }
.log-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.log-table-wrap:focus-visible { outline: 2px solid var(--cur); outline-offset: 2px; }
table.log { width: 100%; min-width: 700px; border-collapse: collapse; }
table.log th, table.log td { border-bottom: 1px solid var(--line); padding: 8px 12px; text-align: left; white-space: nowrap; }
table.log th { background: var(--sec); color: var(--fg); font-weight: 650; }
table.log tr:last-child td { border-bottom: 0; }
table.log tbody tr:nth-child(even) { background: var(--head); }
table.log tbody tr:hover { background: var(--sel); }
table.log td:first-child, table.log td:last-child { color: var(--muted); }
table.log .num { text-align: right; }
.log-action { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--sec); font-size: 12px; font-weight: 600; }
.log-action[data-action="plan"] { background: var(--today); }
.log-action[data-action="fact"] { background: var(--strong); color: var(--good); }
.log-action[data-action="snapshot"] { background: var(--sel); }

@media (max-width: 850px) {
  .top-main { flex-wrap: wrap; }
  .viewsw { order: 1; width: 100%; overflow-x: auto; scrollbar-width: thin; }
}

@media (max-width: 700px) {
  .grid th.lab { min-width: 124px; max-width: 124px; }
  .grid .tot { position: static; min-width: 92px; }   /* on a phone the days need the width; the total is at the end */
  .chip { min-width: 0; }
  .hint, .sel { display: none; }
  .top-main, .top-toolbar { gap: 7px 10px; padding: 6px 10px; }
  .top-account, .top-actions, .top-history { gap: 5px 7px; }
  .snaps select { max-width: min(16em, 45vw); }
}
