/* «Чек»: every screen is a printed receipt on a counter. Own palette in two schemes (data-scheme is set from
   Telegram's colorScheme in app.js); JetBrains Mono on the paper, Onest for the app around it. */
:root {
  --page: #e4e7eb;
  --paper: #ffffff;
  --ink: #1f2329;
  --faded: #6b727c;
  --rule: #c9ced5;          /* decoration: leaders, cuts */
  --rule-strong: #8a919b;   /* edges of things you can press or fill (3:1 on the paper) */
  --red: #c0392b;
  --on-red: #ffffff;
  --shadow: 0 6px 18px rgba(0, 0, 0, .22);
  --backdrop: rgba(0, 0, 0, .45);
  --green: #2b7a4b;
  --press: rgba(0, 0, 0, .05);
  --mono: "JetBrains Mono", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", ui-monospace, monospace;
  --ui: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
    "Noto Color Emoji";
  --z: 7px;   /* the teeth of the torn edge */
  color-scheme: light;
}
[data-scheme="dark"] {
  --page: #161616;
  --paper: #262626;
  --ink: #ececec;
  --faded: #9b9b9b;
  --rule: #474747;
  --rule-strong: #7a7a7a;
  --red: #ff7a66;
  --on-red: #1a1a1a;
  --backdrop: rgba(0, 0, 0, .65);
  --green: #6cc790;
  --press: rgba(255, 255, 255, .06);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.45 var(--ui);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
body { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---- top bar and tabs -------------------------------------------------------------------------------- */
.top { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: 8px 8px 6px; background: var(--page); }
.top h1 { margin: 0; font: 600 18px/1.2 var(--ui); letter-spacing: -.01em; text-align: center; }
.nav-btn { width: 44px; height: 44px; border: 0; background: none; color: var(--ink); font-size: 26px; line-height: 1; }
.nav-btn:disabled { opacity: .25; cursor: default; }

main { padding: 2px 12px 0; }
.tab { display: none; }
.tab.active { display: block; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--paper);
  border-top: 1.5px dashed var(--rule); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; border: 0; background: none; color: var(--faded); padding: 9px 0 10px; display: flex;
  flex-direction: column; align-items: center; gap: 3px; font: 500 11.5px/1 var(--ui); min-height: 56px; }
.tabs button.active { color: var(--ink); }
.tabs svg { width: 24px; height: 24px; }

.fab { position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 6; height: 52px;
  padding: 0 22px 0 18px; border: 0; border-radius: 3px; background: var(--ink); color: var(--paper);
  font: 600 16px/1 var(--ui); display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow); }
.fab span { font-size: 24px; font-weight: 400; margin-top: -2px; }

/* ---- the paper ------------------------------------------------------------------------------------------ */
.paper { background: var(--paper); margin: 6px 0 14px; padding: 18px 18px calc(var(--z) + 18px);
  font: 14px/1.55 var(--mono); font-variant-numeric: tabular-nums;
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(2 * var(--z)) 100%;
  mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(2 * var(--z)) 100%; }
.paper h2 { margin: 0 0 8px; font: 600 15px/1.3 var(--mono); }
.head { text-align: center; color: var(--faded); margin-bottom: 14px; }
.head b { display: block; color: var(--ink); font-weight: 600; font-size: 15px; }

.row { display: flex; align-items: baseline; gap: 6px; width: 100%; }
.row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.row .dots { flex: 1; min-width: 14px; border-bottom: 2px dotted var(--rule); transform: translateY(-4px); }
.row .val { white-space: nowrap; }
.row.sub { color: var(--faded); }
.row.indent .name { padding-left: 2ch; }
.row.plus .val, .row.plus .name { color: var(--green); }
.tap { border: 0; background: none; padding: 11px 0; margin: 0; min-height: 44px; text-align: left; font: inherit;
  border-radius: 4px; }   /* the whole line is the button: 44px tall */
.tap:active { background: var(--press); }

.cut { border: 0; border-top: 1.5px dashed var(--rule); margin: 12px 0; }
.total { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; margin-bottom: 2px; }
.total .big { font-size: 26px; letter-spacing: -.02em; }
.minus { color: var(--red); }
.plus { color: var(--green); }
.section { color: var(--faded); margin: 2px 0 6px; }
.blank { color: var(--faded); text-align: center; padding: 10px 0 4px; font-family: var(--ui); }

/* limits: printed segments, red ink once the limit is passed */
.limit { margin: 0 0 12px; }
.limit:last-child { margin-bottom: 0; }
.meter { position: relative; height: 10px; margin: 5px 0 3px;
  background: repeating-linear-gradient(90deg, var(--rule-strong) 0 5px, transparent 5px 7px); }
.meter i { position: absolute; inset: 0 auto 0 0;
  background: repeating-linear-gradient(90deg, var(--ink) 0 5px, transparent 5px 7px); }
.meter.over i { background: repeating-linear-gradient(90deg, var(--red) 0 5px, transparent 5px 7px); }
.limit .note { font-size: 12.5px; color: var(--faded); }
.limit .note.near { color: var(--ink); font-weight: 600; }
.limit .note.minus { color: var(--red); }

/* days as a barcode: a thicker bar is a dearer day */
.barcode { display: block; width: 100%; height: 64px; margin-top: 6px; }
.barcode .past { fill: var(--ink); }
.barcode .future { fill: var(--rule-strong); }
.barcode .marker { fill: var(--ink); }
.barcode .picked { fill: var(--red); }
.barcode { touch-action: pan-y; cursor: pointer; }
.barcode-legend { position: relative; display: flex; justify-content: space-between; color: var(--faded);
  font-size: 12px; margin-top: 4px; min-height: 18px; }
.barcode-legend .today { position: absolute; top: 0; color: var(--ink); white-space: nowrap; }
.barcode-pick { margin-top: 6px; min-height: 22px; }

/* records waiting for a category: a stub above the receipt */
.inbox { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 60px;
  margin: 6px 0 4px; padding: 10px 12px 10px 14px; border: 1.5px dashed var(--rule-strong); border-radius: 0;
  background: none; color: var(--ink); text-align: left; font: 14px/1.35 var(--mono); }
.inbox-text { display: flex; flex-direction: column; min-width: 0; }
.inbox-text b { font-weight: 600; }
.inbox-text span { color: var(--faded); font-size: 13px; }
.inbox-go { flex: none; padding: 10px 14px; background: var(--ink); color: var(--paper); font: 600 14px/1 var(--ui); }
.inbox:active { background: var(--press); }

/* «Разобрать»: one record at a time */
.sort-count { color: var(--faded); font: 13px var(--mono); margin-top: -8px; }
.sort-op { text-align: center; padding: 4px 0 14px; border-bottom: 1.5px dashed var(--rule); font-family: var(--mono); }
.sort-amount { font: 600 30px/1.2 var(--mono); letter-spacing: -.02em; }
.sort-amount.plus { color: var(--green); }
.sort-note { font-size: 16px; margin-top: 4px; overflow-wrap: anywhere; }
.sort-day { color: var(--faded); font-size: 13px; margin-top: 2px; }
.sort-actions { display: flex; justify-content: space-between; gap: 12px; }
.sort-done { text-align: center; margin: 0; padding: 20px 0 8px; font: 15px var(--mono); }
.chips.busy .chip:not(.active) { opacity: .45; }

/* operations: one slip per day */
.filter { width: 100%; margin: 6px 0 4px; padding: 11px 12px; border: 0; border-radius: 0; background: var(--paper);
  color: var(--ink); font: 14px var(--mono); }
.slip { padding-top: 14px; padding-bottom: calc(var(--z) + 12px); margin-bottom: 10px; }
.slip .day { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.op { display: block; width: 100%; min-height: 44px; border: 0; background: none; text-align: left; font: inherit;
  padding: 9px 0; border-radius: 4px; }
.op:active { background: var(--press); }
.op .cat { display: block; color: var(--faded); font-size: 12.5px; }
.op-body { display: block; min-width: 0; flex: 1; }

/* «Выбрать»: a box before every record, a whole day by its heading, the actions in a bar over the tabs */
.ops-tools { display: flex; gap: 12px; align-items: center; }
.ops-tools .filter { flex: 1; min-width: 0; }
.pick-toggle { flex: none; margin-top: 2px; }
.op.picking { display: flex; gap: 10px; align-items: flex-start; }
.op .box { flex: none; width: 20px; height: 20px; margin-top: 2px; border: 1.5px solid var(--rule-strong);
  display: flex; align-items: center; justify-content: center; font: 600 14px/1 var(--ui); }
.op.picked .box { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.op.picked .box::after { content: "✓"; }
.day-pick { width: 100%; min-height: 44px; border: 0; background: none; padding: 0; margin-bottom: 2px; font: inherit;
  font-weight: 600; text-align: left; align-items: center; }
.day-pick .day-all { font-weight: 400; color: var(--faded); text-decoration: underline; text-underline-offset: 3px; }
.pickbar { position: fixed; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom)); z-index: 7;
  background: var(--paper); border-top: 1.5px dashed var(--rule-strong); padding: 10px 12px 12px; box-shadow: var(--shadow); }
.pick-sum { display: flex; justify-content: space-between; gap: 12px; font: 14px var(--mono); margin-bottom: 8px; }
.pick-sum b { font-weight: 600; }
.pick-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.pick-actions .secondary { min-height: 44px; padding: 10px 6px; }
.secondary.bad { color: var(--red); border-color: var(--red); }

/* «Ещё» */
.cat-list { list-style: none; margin: 0 0 6px; padding: 0; }
.cat-list li { padding: 0; }
.cat-list .hidden-cat .name { opacity: .75; }
.row .val.minus { color: var(--red); }
.link { display: inline-flex; align-items: center; min-height: 44px; border: 0; background: none; color: var(--ink);
  padding: 0; margin-top: 2px; font: 600 14px var(--mono);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.hint { color: var(--faded); font: 13px/1.45 var(--ui); margin: 0 0 10px; }
.setting { padding: 10px 0; border-top: 1.5px dashed var(--rule); }
.setting:first-of-type { border-top: 0; padding-top: 2px; }
.setting-controls { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--ink); flex: none; }
.time, .day-select { font: 14px var(--mono); color: var(--ink); background: var(--page); border: 0; border-radius: 0;
  padding: 8px 10px; min-height: 44px; }
.time { width: 132px; flex: none; }
.day-select { flex: 1; min-width: 0; }

/* ---- sheet: a fresh receipt torn at the top ----------------------------------------------------------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; background: var(--backdrop); }
.sheet { width: 100%; max-height: 92vh; max-height: 92dvh; overflow-y: auto; background: var(--paper);
  padding: calc(var(--z) + 14px) 18px calc(18px + env(safe-area-inset-bottom));
  -webkit-mask: conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(2 * var(--z)) 100%;
  mask: conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(2 * var(--z)) 100%;
  animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-body { display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font: 600 17px/1.2 var(--ui); }
.close { width: 44px; height: 44px; margin: -8px -10px -8px 0; border: 0; background: none; color: var(--faded); font-size: 20px; }
.label { color: var(--faded); font: 13px var(--ui); margin-bottom: -6px; }
.field { width: 100%; min-height: 44px; font: 15px var(--ui); color: var(--ink); background: transparent; border: 0;
  border-bottom: 1.5px dashed var(--rule-strong); border-radius: 0; padding: 10px 0; }
.field:focus { outline: none; border-bottom: 1.5px solid var(--ink); box-shadow: 0 2px 0 var(--ink); }
.field.amount { font: 600 30px/1.2 var(--mono); text-align: center; letter-spacing: -.02em; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1.5px solid var(--ink); }
.seg button { border: 0; background: none; padding: 10px; font: 500 14px var(--ui); min-height: 44px; color: var(--faded); }
.seg button.active { background: var(--page); color: var(--ink); font-weight: 600; }   /* lighter than «Записать» */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1.5px dashed var(--rule-strong); background: none; padding: 7px 11px; font: 13.5px var(--mono); min-height: 40px; }
.chip.active { border: 1.5px solid var(--ink); background: var(--ink); color: var(--paper); }
.chip.suggest { border: 1.5px solid var(--ink); font-weight: 600; }   /* chosen before for similar words */
.primary { border: 0; padding: 15px; background: var(--ink); color: var(--paper); font: 600 16px var(--ui); min-height: 52px; }
.secondary { border: 1.5px solid var(--ink); background: none; padding: 12px; width: 100%; font: 600 14px var(--ui); }
.danger { border: 0; background: none; color: var(--red); padding: 12px; min-height: 44px; font: 600 15px var(--ui); }

/* a press shows; a save on its way is greyed out */
.fab:active, .primary:active { transform: scale(.98); }
.secondary:active, .danger:active, .chip:active, .seg button:active, .tabs button:active, .close:active,
.nav-btn:active, .link:active { opacity: .65; }
.primary:disabled, .secondary:disabled, .danger:disabled { opacity: .5; cursor: progress; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom));
  z-index: 20; width: max-content; max-width: calc(100vw - 32px); padding: 10px 16px; background: var(--ink);
  color: var(--paper); font: 500 14px/1.35 var(--ui); text-align: center; box-shadow: var(--shadow); }
.toast.bad { background: var(--red); color: var(--on-red); }

.empty { text-align: center; color: var(--faded); padding: 40px 16px; }
