:root {
    --bg: #0f2a17; --bg2: #07160b; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f2fbf3; --muted: #bfdcc5; --accent: #69db7c; --accent-ink: #062b10; --field: rgba(255,255,255,.08);
    --soft: rgba(105,219,124,.15); --in: #69db7c; --out: #ffa94d; --cardc: #74c0fc; --bad: #ff8787; --bad-bg: rgba(255,135,135,.14);
    --over: #ffd43b; --over-bg: rgba(255,212,59,.13); --good-bg: rgba(105,219,124,.16);
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f4fbf5; --bg2: #e3f3e6; --card: #fff; --line: #cfe6d4; --ink: #0d2614; --muted: #3f5f47;
            --accent: #237032; --accent-ink: #fff; --field: #fbfefb; --soft: #e2f4e6; --in: #237032; --out: #b35309; --cardc: #1864ab;
            --bad: #c92a2a; --bad-bg: #fdecec; --over: #8a5a00; --over-bg: #fff4d6; --good-bg: #e2f4e6; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f4fbf5; --bg2: #e3f3e6; --card: #fff; --line: #cfe6d4; --ink: #0d2614; --muted: #3f5f47;
            --accent: #237032; --accent-ink: #fff; --field: #fbfefb; --soft: #e2f4e6; --in: #237032; --out: #b35309; --cardc: #1864ab;
            --bad: #c92a2a; --bad-bg: #fdecec; --over: #8a5a00; --over-bg: #fff4d6; --good-bg: #e2f4e6; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #0f2a17; --bg2: #07160b; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f2fbf3; --muted: #bfdcc5; --accent: #69db7c; --accent-ink: #062b10; --field: rgba(255,255,255,.08);
    --soft: rgba(105,219,124,.15); --in: #69db7c; --out: #ffa94d; --cardc: #74c0fc; --bad: #ff8787; --bad-bg: rgba(255,135,135,.14);
    --over: #ffd43b; --over-bg: rgba(255,212,59,.13); --good-bg: rgba(105,219,124,.16);
    color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding: clamp(1rem,4vw,2.5rem) 1rem 4rem; display: flex; justify-content: center;
       font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
       background: var(--bg2) linear-gradient(180deg, var(--bg), var(--bg2) 900px) no-repeat; touch-action: manipulation; }
.app { width: min(560px, 100%); min-width: 0; display: flex; flex-direction: column; }
.col-a, .col-b { display: contents; }
.app > .topbar, .app > .back { order: 0; }
.app > header { order: 1; }
.daybar { order: 2; }
.add { order: 3; }
.close { order: 4; }
.entries { order: 5; }
.totals { order: 6; }
.tools { order: 7; }
.app > .faq { order: 8; }
.app > footer { order: 9; }
.report { display: none; }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: 1.8rem; line-height: 1.2; letter-spacing: -.02em; }
.sub { margin: .4rem 0 0; color: var(--muted); font-size: 1rem; }
h2 { margin: 0 0 .7rem; font-size: 1.15rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label, legend { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); padding: 0; }
input[type=text], input[type=date], select { width: 100%; min-width: 0; min-height: 48px; padding: .6rem .8rem; font: inherit; font-size: 1.05rem; color: var(--ink);
       background: var(--field); border: 1px solid var(--line); border-radius: 12px; }
#amount, #count { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
input[type=date] { -webkit-appearance: none; appearance: none; display: block; }
input[type=date]::-webkit-date-and-time-value { text-align: left; }
input[aria-invalid="true"] { border-color: var(--bad); }
select option { color: #111; background: #fff; }
input:focus-visible, button:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.kind input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
::placeholder { color: var(--muted); opacity: .75; }
.hint { margin: .45rem 0 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.hint:empty { margin: 0; }
.hint.first { margin-top: 0; }
[hidden] { display: none !important; }
.field { min-width: 0; }
.warn { margin: .6rem 0 0; padding: .5rem .7rem; border-radius: 12px; background: var(--over-bg); border-left: 5px solid var(--over); font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }

/* the day */
.day-nav { display: grid; grid-template-columns: 52px minmax(0, 1fr) 52px; align-items: center; gap: .5rem; }
.nav-btn { width: 52px; height: 52px; border: 1px solid var(--line); border-radius: 14px; background: var(--field); color: var(--ink); font: inherit; font-size: 1.8rem; line-height: 1; cursor: pointer; }
.day-mid { text-align: center; min-width: 0; }
.day-title { margin: 0; font-size: 1.2rem; font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; }
.day-title .today-tag { display: inline-block; margin-left: .35rem; padding: 0 .45rem; border-radius: 999px; background: var(--soft); color: var(--accent); font-size: .8rem; vertical-align: middle; }
#date-box label { margin-top: .7rem; }
.link.center { margin: .2rem auto 0; text-align: center; }
.now-line { margin: .6rem 0 0; text-align: center; font-weight: 700; color: var(--muted); overflow-wrap: anywhere; }
.now-line b { color: var(--ink); font-variant-numeric: tabular-nums; }
.now-line:empty { display: none; }

/* what happened: six big choices, money in on the left, money out on the right */
.kinds { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }
.kinds legend { grid-column: 1 / -1; float: left; width: 100%; margin-top: 0; }
.kind { margin: 0; display: block; position: relative; cursor: pointer; }
.kind input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.kind span { display: flex; align-items: center; justify-content: center; min-height: 52px; height: 100%; padding: .4rem .5rem; border: 2px solid var(--line); border-left-width: 6px; border-radius: 12px;
       background: var(--field); color: var(--ink); font-size: .95rem; font-weight: 700; text-align: center; line-height: 1.2; }
.kind.in span { border-left-color: var(--in); } .kind.out span { border-left-color: var(--out); } .kind.card-k span { border-left-color: var(--cardc); }
.kind.in input:checked + span { border-color: var(--in); background: var(--good-bg); }
.kind.out input:checked + span { border-color: var(--out); background: var(--over-bg); }
.kind.card-k input:checked + span { border-color: var(--cardc); background: var(--soft); }
.kind-hint { min-height: 1.3em; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.chip { min-height: 40px; padding: 0 .75rem; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink); font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; max-width: 100%; overflow-wrap: anywhere; }
.chip[aria-pressed="true"] { border-color: var(--out); background: var(--over-bg); }

.amount-row, .count-row { display: flex; align-items: stretch; gap: .4rem; min-width: 0; }
.amount-row input, .count-row input { flex: 1 1 auto; }
.count-row .primary.small { flex: none; min-height: 48px; }
.cur-tag { display: flex; align-items: center; padding: 0 .7rem; border: 1px solid var(--line); border-radius: 12px; background: var(--field); font-weight: 700; color: var(--muted); flex: none; }
.preview { margin: .9rem 0 0; padding: .55rem .75rem; border-radius: 12px; background: var(--field); border: 1px dashed var(--line); font-weight: 600; overflow-wrap: anywhere; }
.preview:empty { display: none; }

/* buttons */
.primary, .secondary, .danger { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; padding: .5rem .8rem; border-radius: 12px;
       font: inherit; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; line-height: 1.2; overflow-wrap: anywhere; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.add .primary#save { margin-top: 1rem; min-height: 54px; font-size: 1.1rem; }
.secondary { border: 1px solid var(--line); background: var(--field); color: var(--ink); font-weight: 600; }
.secondary.small, .primary.small, .danger.small { width: auto; min-height: 42px; padding: 0 .8rem; font-size: .92rem; margin: 0; }
.danger { border: 1px solid var(--bad); background: transparent; color: var(--bad); font-weight: 600; margin-top: .9rem; }
.link { display: block; min-height: 44px; margin-top: .3rem; padding: 0 .1rem; border: 0; background: none; color: var(--accent); font: inherit; font-size: .95rem; font-weight: 600; text-align: left; cursor: pointer; }
.link.inline { display: inline; min-height: 0; margin: 0; padding: .4rem .2rem; text-decoration: underline; font-size: .9rem; }
.link.small-link { min-height: 40px; margin: 0; font-size: .9rem; }
.danger-link { color: var(--bad); margin-top: .6rem; }
.err { margin: .4rem 0 0; color: var(--bad); font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
.err:empty { margin: 0; }
.msg { margin: 0; color: var(--muted); font-size: .95rem; overflow-wrap: anywhere; }
.msg.show { margin-top: .8rem; padding: .6rem .75rem; border-radius: 12px; background: var(--soft); color: var(--ink); }
.entries .msg.show { margin: 0 0 .8rem; }
.msg .undo { margin-left: .2rem; font-weight: 700; }
.row-btns { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .6rem; }
.row-btns > button { flex: 1 1 6rem; }
.panel { margin-top: .5rem; padding: .7rem .7rem .75rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card); min-width: 0; }
.panel label:first-child { margin-top: 0; }
.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }
.tool-grid .wide { grid-column: 1 / -1; }

/* entries: each in its own box */
.empty { margin: .2rem 0 0; color: var(--muted); text-align: center; }
.items { display: grid; gap: .6rem; }
.item { border: 1px solid var(--line); border-left: 6px solid var(--ic, var(--line)); border-radius: 14px; padding: .6rem .75rem; background: var(--field); min-width: 0; }
.item.in { --ic: var(--in); } .item.out { --ic: var(--out); } .item.card-k { --ic: var(--cardc); }
.i-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .6rem; align-items: baseline; }
.i-what { margin: 0; font-weight: 800; overflow-wrap: anywhere; }
.i-amt { margin: 0; font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; color: var(--ic); text-align: right; overflow-wrap: anywhere; }
.i-sub { margin: .1rem 0 0; font-size: .86rem; color: var(--muted); overflow-wrap: anywhere; }
.i-btns { display: flex; gap: .4rem; margin-top: .5rem; }
.i-btns button { flex: 1 1 0; }
.item.editing { outline: 3px solid var(--accent); outline-offset: 1px; }
.item .panel { margin-top: .5rem; }
.item .panel label { margin-top: .6rem; }
.item .panel .field:first-child label { margin-top: 0; }

/* the closing sum */
.sum { border: 1px solid var(--line); border-radius: 14px; padding: .6rem .8rem; background: var(--field); }
.sum-row { display: flex; justify-content: space-between; align-items: baseline; gap: .8rem; padding: .25rem 0; min-width: 0; }
.sum-row span { color: var(--muted); font-weight: 600; min-width: 0; }
.sum-row b { font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; min-width: 0; }
.sum-row.plus b { color: var(--in); } .sum-row.minus b { color: var(--out); }
.sum-row.total { margin-top: .3rem; padding-top: .5rem; border-top: 2px solid var(--line); }
.sum-row.total span { color: var(--ink); font-weight: 800; font-size: 1.05rem; }
.sum-row.total b { font-size: 1.6rem; line-height: 1.2; }
.open-from { margin: -.15rem 0 0; font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.open-from:empty { display: none; }
.close > label { margin-top: 1rem; }
.result { margin-top: .9rem; padding: .7rem .85rem; border-radius: 14px; border: 2px solid var(--line); background: var(--field); }
.result.short { border-color: var(--bad); background: var(--bad-bg); }
.result.over { border-color: var(--over); background: var(--over-bg); }
.result.ok { border-color: var(--in); background: var(--good-bg); }
.r-main { margin: 0; font-size: 1.25rem; font-weight: 800; line-height: 1.3; overflow-wrap: anywhere; }
.result.short .r-main { color: var(--bad); } .result.over .r-main { color: var(--over); } .result.ok .r-main { color: var(--in); }
.result.none .r-main { font-size: 1rem; font-weight: 600; color: var(--muted); }
.r-sub { margin: .2rem 0 0; font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.r-sub:empty { display: none; }
#diff-sales { margin-top: .6rem; }
.day-sales { margin-top: .9rem; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }
.day-sales:empty { display: none; }
.carry { margin: .7rem 0 .8rem; font-weight: 600; overflow-wrap: anywhere; }
.carry:empty { display: none; }
.notes { display: grid; gap: .35rem; }
.note-row { display: grid; grid-template-columns: 5.5rem minmax(0, 6rem) minmax(0, 1fr); align-items: center; gap: .5rem; }
.note-row label { margin: 0; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.note-row input { min-height: 42px; padding: .3rem .6rem; text-align: center; }
.note-row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); overflow-wrap: anywhere; }
.notes-total { margin: .7rem 0 0; font-weight: 700; }
.notes-total b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* totals */
#period { margin-bottom: .2rem; }
.totals > label:first-of-type { margin-top: 0; }
.tiles { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: .8rem; }
.tile { border: 2px solid var(--line); border-radius: 14px; padding: .55rem .7rem; background: var(--field); min-width: 0; display: flex; flex-direction: column; }
.tile.in { border-color: var(--in); } .tile.out { border-color: var(--out); } .tile.net { border-color: var(--accent); }
.tile.short { border-color: var(--bad); } .tile.over { border-color: var(--over); }
.t-label { font-size: .82rem; font-weight: 700; color: var(--muted); line-height: 1.25; }
.t-val { font-size: clamp(1.05rem, 5vw, 1.55rem); font-weight: 800; line-height: 1.25; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile.short .t-val { color: var(--bad); } .tile.over .t-val { color: var(--over); }
.t-sub { font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.t-sub:empty { display: none; }
.sub-h { margin: 1.1rem 0 .4rem; font-size: 1rem; }
.cats { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.cats li { display: flex; justify-content: space-between; gap: .8rem; padding: .35rem .6rem; border-radius: 10px; background: var(--field); border: 1px solid var(--line); min-width: 0; }
.cats li span { overflow-wrap: anywhere; min-width: 0; }
.cats li b { font-variant-numeric: tabular-nums; flex: none; }
.days { display: grid; gap: .4rem; }
.drow { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .6rem; align-items: center; width: 100%; padding: .45rem .65rem; border: 1px solid var(--line); border-radius: 10px;
        background: var(--field); color: var(--ink); font: inherit; text-align: left; cursor: pointer; min-width: 0; }
.drow .d-date { font-weight: 700; overflow-wrap: anywhere; }
.drow .d-sub { grid-column: 1 / -1; font-size: .84rem; color: var(--muted); overflow-wrap: anywhere; }
.drow .d-diff { font-weight: 700; font-size: .88rem; text-align: right; }
.d-diff.short { color: var(--bad); } .d-diff.over { color: var(--over); } .d-diff.ok { color: var(--in); } .d-diff.none { color: var(--muted); font-weight: 600; }
.t-tools { margin-top: 1rem; }

/* questions */
.faq { margin-top: 1.2rem; }
.faq details { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 .5rem; background: var(--card); }
.faq summary { cursor: pointer; padding: .75rem .9rem; font-weight: 600; min-height: 44px; }
.faq details p { margin: 0; padding: 0 .9rem .8rem; color: var(--muted); }
footer { margin-top: 1.4rem; text-align: center; font-size: .9rem; }
footer a { color: var(--muted); }

.back { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; margin: 0 0 .5rem; padding: 0 1rem 0 .8rem; border: 1px solid var(--line, rgba(127,127,127,.4)); border-radius: 999px; color: var(--muted, var(--mut, inherit)); font-size: .92rem; font-weight: 600; text-decoration: none; background: transparent; }
.back:hover { color: var(--ink, inherit); border-color: currentColor; }
.back:focus-visible { outline: 3px solid var(--accent, var(--acc, #fff)); outline-offset: 2px; }

/* narrow phones */
@media (max-width: 400px) {
    .card { padding: .95rem .85rem; }
    .kind span { font-size: .9rem; padding: .35rem .4rem; }
    .note-row { grid-template-columns: 4.6rem minmax(0, 5rem) minmax(0, 1fr); gap: .4rem; }
    .sum-row.total { flex-wrap: wrap; column-gap: .5rem; }
    .sum-row.total b { font-size: 1.3rem; margin-left: auto; }
    #count { font-size: 1.15rem; padding-left: .6rem; padding-right: .6rem; }
}
@media (max-width: 359px) {
    .tool-grid, .day-sales { grid-template-columns: minmax(0, 1fr); }
    .tiles { grid-template-columns: minmax(0, 1fr); }
    .count-row { flex-wrap: wrap; }
    .count-row input { flex-basis: 60%; }
    .count-row .primary.small { flex: 1 1 100%; }
    .kind span { font-size: .85rem; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
}

/* printing: only the report */
@media print {
    body { background: #fff; color: #000; padding: 0; display: block; font-size: 11pt; }
    .app > *:not(.report) { display: none !important; }
    .app { display: block; width: 100%; }
    .report { display: block !important; }
    .report h2 { font-size: 16pt; margin: 0 0 .3rem; }
    .report h3 { font-size: 12pt; margin: .9rem 0 .2rem; }
    .report p { margin: .1rem 0; }
    .report table { width: 100%; border-collapse: collapse; margin-top: .3rem; font-size: 9.5pt; }
    .report th, .report td { border: 1px solid #999; padding: 2px 5px; text-align: left; }
    .report td.n, .report th.n { text-align: right; }
    .report thead { display: table-header-group; }
    .report tr { break-inside: avoid; }
}

/* laptops and desktops: the day across the top, writing entries on the left, the drawer and the totals on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 1.5rem; align-items: start; }
    .app > * { grid-column: 1 / -1; }
    .col-a, .col-b { display: block; min-width: 0; }
    .app > .topbar { grid-row: 1; }
    .app > header { grid-row: 2; }
    .app > .daybar { grid-row: 3; width: min(620px, 100%); justify-self: center; }
    .app > .col-a { grid-column: 1; grid-row: 4; }
    .app > .col-b { grid-column: 2; grid-row: 4; }
    .app > .faq { grid-row: 5; width: min(760px, 100%); justify-self: center; }
    .app > footer { grid-row: 6; width: min(760px, 100%); justify-self: center; }
    .app > .report { grid-row: 7; }
    header h1 { font-size: 2.3rem; }
    .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .kinds { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
