/* Summaxx Mini App.
   Telegram supplies its own theme variables; ours are the fallback and the accents it has no
   opinion about. Everything is sized for a phone held in one hand: 16px gutters, tap targets
   that stay reachable, and type that stops at three sizes so a screen reads as one thing. */
:root {
  color-scheme: light;
  --bg: var(--tg-theme-secondary-bg-color, #F1F3F6);
  --card: var(--tg-theme-bg-color, #FFFFFF);
  --text: var(--tg-theme-text-color, #0C0D0F);
  --hint: var(--tg-theme-hint-color, #71777F);
  --line: #E3E6EB;
  --line-soft: #EEF0F4;
  --accent: var(--tg-theme-button-color, #1F7AE0);
  --accent-text: var(--tg-theme-button-text-color, #FFFFFF);
  --accent-soft: #E7F1FD;
  --accent-ink: #1663B8;
  --warn: #9A5B00;
  --warn-soft: #FFF2DC;
  --warn-line: #EFD6A6;
  --ok: #0E6B37;
  --ok-soft: #E3F6EA;
  --bad: #C5342A;
  --bad-soft: #FDECEA;
  --bad-line: #F3C7C2;
  --violet: #6B4BC6;
  --violet-soft: #EFEAFC;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 18px -10px rgba(16, 24, 40, .18);
  --r: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", system-ui, sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
  display: flex; flex-direction: column; min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 18px; font-weight: 680; letter-spacing: -0.25px; margin: 0; }
.grow { flex-grow: 1; min-width: 0; }
.sub { font-size: 12.5px; color: var(--hint); margin-top: 1px; }
.muted { color: var(--hint); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Never size svg globally: an icon with no sized parent grows to fill its card. */
.ico { width: 16px; height: 16px; flex: none; display: inline-flex; align-items: center; }
.ico svg, .badge-icon svg, .back svg, .tile svg { width: 100%; height: 100%; display: block; }

header {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
}
.badge-icon {
  width: 30px; height: 30px; flex: none; padding: 6px; border-radius: 9px;
  background: var(--accent-soft); color: var(--accent-ink);
}
.back {
  width: 30px; height: 30px; flex: none; padding: 5px; min-height: 0;
  border: none; background: none; color: var(--accent); cursor: pointer;
}

main { flex-grow: 1; padding: 13px 16px 18px; display: flex; flex-direction: column; gap: 11px; }
.empty { padding: 44px 0; text-align: center; color: var(--hint); font-size: 14px; }

/* ---- cards ------------------------------------------------------------------------------- */
.box {
  background: var(--card); border-radius: var(--r); overflow: hidden;
  box-shadow: var(--shadow);
}
.box-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px 9px;
  font-size: 11.5px; font-weight: 700; color: var(--hint); letter-spacing: .5px;
  border-bottom: 1px solid var(--line-soft);
}
.box-head .ico { color: var(--accent); }
/* Colour says what a section is, and three different ways of saying it keeps the screens
   from all looking alike.

   lead  — the one list a screen is actually about: a colour down its left edge, the way the
           waiting box has always had it. At most one per screen.
   quiet — everything secondary: the heading takes the colour, the card stays plain.
   alert — the rare card that must be noticed: softly filled, used for warnings and for
           anything about to be deleted. */
.box:has(> .box-head[class*="lead-"]) { border-left: 3px solid var(--line); }
.box:has(> .box-head.lead-accent) { border-left-color: var(--accent); }
.box:has(> .box-head.lead-ok) { border-left-color: var(--ok); }
.box:has(> .box-head.lead-warn) { border-left-color: var(--warn); }
.box:has(> .box-head.lead-bad) { border-left-color: var(--bad); }
.box:has(> .box-head.lead-violet) { border-left-color: var(--violet); }

.box-head.lead-accent, .box-head.quiet-accent { color: var(--accent-ink); }
.box-head.lead-ok, .box-head.quiet-ok { color: var(--ok); }
.box-head.lead-warn { color: var(--warn); }
.box-head.lead-bad { color: var(--bad); }
.box-head.lead-violet, .box-head.quiet-violet { color: var(--violet); }
.box-head[class*="lead-"] .ico, .box-head[class*="quiet-"] .ico { color: inherit; }
.box-head.quiet-grey { color: var(--hint); }

.box:has(> .box-head.alert-warn) { background: var(--warn-soft); }
.box:has(> .box-head.alert-bad) { background: var(--bad-soft); }
.box-head.alert-warn { color: var(--warn); border-bottom-color: var(--warn-line); }
.box-head.alert-bad { color: var(--bad); border-bottom-color: var(--bad-line); }
.box-head[class*="alert-"] .ico { color: inherit; }
.box:has(> .box-head[class*="alert-"]) .row { border-bottom-color: rgba(128, 128, 128, .18); }
.row { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); }
.row:last-child { border-bottom: none; }
.row-flex { display: flex; align-items: center; gap: 10px; }
/* A whole row that opens something. Looks like a row, behaves like a button. */
.row-tap {
  width: 100%; background: none; color: inherit; text-align: left;
  border-radius: 0; min-height: 0; font: inherit;
}
.row-tap:active { background: var(--line-soft); }

/* Kept for a card that needs attention beyond its heading colour. */
.card-new { box-shadow: var(--shadow); }

/* ---- numbers at a glance ------------------------------------------------------------------- */
/* Four of these across a phone, so they are tight and the label may wrap to two lines. */
.stats { display: flex; gap: 7px; }
.stat {
  flex: 1 1 0; background: var(--card); border-radius: 12px; padding: 9px 7px 8px;
  box-shadow: var(--shadow); min-width: 0; min-height: 0; text-align: left;
  display: block; border: 1.5px solid transparent; color: var(--text);
}
.stat b { display: block; font-size: 19px; font-weight: 700; letter-spacing: -.4px; line-height: 1.15; }
.stat span {
  display: block; font-size: 10.5px; line-height: 13px; color: var(--hint);
  margin-top: 2px; font-weight: 500;
}
.stat.accent b { color: var(--accent); }
.stat.ok b { color: var(--ok); }
.stat.warn b { color: var(--warn); }
.stat.bad b { color: var(--bad); }
/* The chosen filter: tinted to match its own colour, so the list below is never a mystery. */
.stat.on { border-color: currentColor; }
.stat.on.warn { background: var(--warn-soft); border-color: var(--warn-line); }
.stat.on.ok { background: var(--ok-soft); border-color: var(--ok); }
.stat.on.bad { background: var(--bad-soft); border-color: var(--bad-line); }
.stat.on.accent { background: var(--accent-soft); border-color: var(--accent); }
.stat.on span { color: var(--text); font-weight: 600; }

/* A small coloured square behind an icon, to tell list rows apart at a glance. */
.tile {
  width: 30px; height: 30px; flex: none; padding: 7px; border-radius: 9px;
  background: var(--accent-soft); color: var(--accent-ink);
}
.tile.ok { background: var(--ok-soft); color: var(--ok); }
.tile.warn { background: var(--warn-soft); color: var(--warn); }
.tile.bad { background: var(--bad-soft); color: var(--bad); }
.tile.violet { background: var(--violet-soft); color: var(--violet); }
.tile.grey { background: var(--line-soft); color: var(--hint); }

.chip {
  font-size: 10.5px; font-weight: 700; border-radius: 999px; padding: 4px 9px;
  white-space: nowrap; letter-spacing: .2px;
}
.chip.warn { color: var(--warn); background: var(--warn-soft); }
.chip.info { color: var(--accent-ink); background: var(--accent-soft); }
.chip.ok { color: var(--ok); background: var(--ok-soft); }
.chip.bad { color: var(--bad); background: var(--bad-soft); }
.chip.off { color: var(--hint); background: var(--line-soft); }
.count { border-radius: 999px; padding: 3px 8px; font-size: 11px; font-weight: 700; }

/* ---- buttons ------------------------------------------------------------------------------- */
/* Default is compact: a card's own actions sit on one line and do not shout. A button that
   finishes a screen says so with .btn-wide in the sticky footer. */
button, .btn {
  font: inherit; font-size: 14px; border: none; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 13px; font-weight: 600;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-soft { background: var(--accent-soft); color: var(--accent-ink); }
.btn-grey { background: var(--line-soft); color: var(--text); font-weight: 500; }
.btn-warn { background: var(--warn); color: #FFF; }
.btn-bad { background: var(--bad); color: #FFF; }
.btn-wide { width: 100%; min-height: 46px; font-size: 15px; border-radius: 12px; }
.btn-icon { min-width: 36px; padding: 0 9px; }
.btn:disabled, button:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled), button:active:not(:disabled) { transform: scale(.985); }
.btn svg, button svg { width: 16px; height: 16px; flex: none; }
/* Row actions hug the right instead of stretching across the card. */
.actions { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }
.actions.fill > * { flex-grow: 1; }

/* Two choices, one control. */
.seg { display: flex; gap: 4px; background: var(--line-soft); border-radius: 11px; padding: 4px; }
.seg button {
  flex: 1 1 0; min-height: 34px; border-radius: 8px; font-size: 13.5px;
  background: none; color: var(--hint); font-weight: 600;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.search {
  width: 100%; padding: 11px 13px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); color: inherit; font: inherit; font-size: 14px;
}
.search:focus { outline: none; border-color: var(--accent); }

.bar { height: 5px; background: var(--line-soft); border-radius: 3px; margin-top: 10px; }
.bar > i { display: block; height: 5px; background: var(--accent); border-radius: 3px; transition: width .2s; }

/* ---- invoice lines --------------------------------------------------------------------------- */
.line-name { font-size: 14px; font-weight: 600; }
.line-no {
  font-size: 11px; font-weight: 700; color: var(--hint); width: 18px; flex: none;
  text-align: center;
}
.line-meta { font-size: 12px; color: var(--hint); }
.disc {
  display: flex; align-items: center; gap: 5px; background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 9px; padding: 1px 9px;
}
.disc input {
  width: 52px; border: none; background: none; color: inherit;
  font: 700 15px/1 inherit; text-align: right; padding: 8px 0;
}
.disc input:focus { outline: none; }
.disc.set { border-color: var(--accent); background: var(--accent-soft); }
.unit { font-size: 11px; color: var(--hint); }
.hints { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; padding-left: 28px; }
.hint {
  font-size: 11.5px; font-weight: 600; color: var(--accent-ink); background: var(--accent-soft);
  border: none; border-radius: 999px; padding: 5px 10px; min-height: 0;
}

.totals { display: flex; justify-content: space-between; font-size: 13px; color: var(--hint); }
.totals + .totals { margin-top: 3px; }
.totals.big {
  font-size: 17px; font-weight: 750; color: var(--text); letter-spacing: -.3px;
  margin-top: 8px; padding-top: 9px; border-top: 1px solid var(--line-soft);
}
footer.sticky {
  position: sticky; bottom: 0; background: var(--card);
  border-top: 1px solid var(--line); box-shadow: 0 -4px 16px -12px rgba(16, 24, 40, .35);
  padding: 11px 16px calc(11px + env(safe-area-inset-bottom, 0px)); margin: 0 -16px -18px;
}
.note { font-size: 12px; line-height: 17px; color: var(--hint); }
pre.statement {
  font: 12px/19px ui-monospace, Menlo, monospace; white-space: pre-wrap;
  margin: 8px 0 0; overflow-x: auto;
}
.msg { padding: 12px 14px; }
.msg + .msg { border-top: 1px solid var(--line-soft); }
.msg p { margin: 0; font-size: 14px; line-height: 20px; }
.msg .actions { flex-wrap: wrap; }
/* The invoice is a tall page; at full width it pushed everything else off the screen. */
img.preview {
  width: 100%; display: block; border-radius: 11px; border: 1px solid var(--line);
  max-height: 180px; object-fit: cover; object-position: top; cursor: zoom-in;
}
img.preview.full { max-height: none; object-fit: contain; cursor: zoom-out; }
.preview-hint { font-size: 12px; color: var(--hint); text-align: center; margin-top: 6px; }

nav#tabs {
  position: sticky; bottom: 0; display: flex; gap: 2px; background: var(--card);
  border-top: 1px solid var(--line); padding: 7px 6px calc(7px + env(safe-area-inset-bottom, 0px));
}
nav#tabs button {
  flex: 1 1 0; flex-direction: column; gap: 3px; background: none; color: #8A9099;
  font-size: 10.5px; font-weight: 500; min-height: 0; padding: 5px 0; border-radius: 10px;
}
nav#tabs button svg { width: 21px; height: 21px; }
nav#tabs button.on { color: var(--accent); font-weight: 650; background: var(--accent-soft); }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(82px + env(safe-area-inset-bottom, 0px));
  background: #15181C; color: #FFF; border-radius: 11px; padding: 12px 14px;
  font-size: 14px; z-index: 20; box-shadow: 0 8px 28px rgba(0, 0, 0, .22);
}
[hidden] { display: none !important; }

:root:not([data-theme="light"]) { }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: var(--tg-theme-secondary-bg-color, #15171A);
    --card: var(--tg-theme-bg-color, #1F2226);
    --text: var(--tg-theme-text-color, #F2F3F5);
    --hint: var(--tg-theme-hint-color, #99A0A9);
    --line: #2D3136;
    --line-soft: #282C31;
    --accent-soft: #15314C;
    --accent-ink: #84C0EE;
    --warn-soft: #3B2D13;
    --warn: #E6B468;
    --warn-line: #4D3C1C;
    --ok-soft: #14301F;
    --ok: #6FCB8D;
    --bad-soft: #3A1E1B;
    --bad: #EC8F86;
    --bad-line: #4E2924;
    --violet-soft: #272150;
    --violet: #A997F0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
  .hint { background: var(--accent-soft); }
  .disc { border-color: #343940; }
  .search { border-color: var(--line); }
}
