/* Telegram hands the page its own theme variables; following them is what makes a
   Mini App feel native instead of like a website in a box. Every colour below has
   a fallback so the page is still legible if it is opened outside Telegram. */
:root {
  --bg:      var(--tg-theme-bg-color, #ffffff);
  --card:    var(--tg-theme-secondary-bg-color, #f4f4f7);
  --text:    var(--tg-theme-text-color, #16181c);
  --muted:   var(--tg-theme-hint-color, #7d8590);
  --accent:  var(--tg-theme-button-color, #2f7fe8);
  --onaccent:var(--tg-theme-button-text-color, #ffffff);
  --link:    var(--tg-theme-link-color, #2f7fe8);
  --line:    color-mix(in srgb, var(--muted) 24%, transparent);
  --pos:     #1f9d55;
  --neg:     #d1453b;
  --warn:    #c77700;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}

/* ---- header ---- */
header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: 10px 14px 0;
  border-bottom: 1px solid var(--line);
}
.bar { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.title { font-size: 17px; font-weight: 650; }
.who { font-size: 12px; color: var(--muted); margin-top: 1px; }
.ghost {
  background: none; border: none; color: var(--muted);
  font-size: 20px; padding: 2px 6px; cursor: pointer; line-height: 1;
}
.period {
  width: 100%; margin: 10px 0; padding: 9px 10px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; appearance: none;
}

/* ---- tabs ---- */
nav {
  position: sticky; top: 0; z-index: 15;
  display: flex; gap: 2px; overflow-x: auto;
  padding: 8px 10px; background: var(--bg);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
nav::-webkit-scrollbar { display: none; }
nav button {
  flex: 0 0 auto; border: none; background: none; color: var(--muted);
  padding: 7px 12px; border-radius: 999px; font-size: 14px; cursor: pointer;
  white-space: nowrap;
}
nav button.on { background: var(--accent); color: var(--onaccent); font-weight: 600; }

main { padding: 12px 14px 40px; }
.tab { display: none; }
.tab.on { display: block; }

/* ---- cards ---- */
.card {
  background: var(--card); border-radius: 14px;
  padding: 13px 14px; margin-bottom: 10px;
}
.card h3 {
  margin: 0 0 10px; font-size: 13px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
}

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 10px; }
.kpi { background: var(--card); border-radius: 14px; padding: 12px 13px; }
.kpi .v { font-size: 21px; font-weight: 680; letter-spacing: -.02em; }
.kpi .l { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kpi.wide { grid-column: 1 / -1; }

.row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row .main { min-width: 0; flex: 1; }
.row .name { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.row .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.muted { color: var(--muted); }

.tag {
  display: inline-block; font-size: 11px; padding: 1.5px 7px;
  border-radius: 999px; background: color-mix(in srgb, var(--muted) 18%, transparent);
  color: var(--muted); margin-right: 5px; vertical-align: 1px;
}
.tag.ret  { background: color-mix(in srgb, var(--neg) 16%, transparent); color: var(--neg); }
.tag.fail { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tag.ok   { background: color-mix(in srgb, var(--pos) 15%, transparent); color: var(--pos); }

.tap { cursor: pointer; }
.tap:active { opacity: .55; }

/* ---- filters ---- */
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: none;
  color: var(--muted); padding: 6px 12px; border-radius: 999px;
  font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); color: var(--onaccent); border-color: transparent; }

/* ---- buttons ---- */
button.action {
  width: 100%; padding: 12px; border: none; border-radius: 11px;
  background: var(--accent); color: var(--onaccent);
  font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 4px;
}
button.action.danger { background: var(--neg); color: #fff; }
button.action.flat {
  background: color-mix(in srgb, var(--muted) 16%, transparent); color: var(--text);
}
button.action:disabled { opacity: .5; }

.empty { text-align: center; color: var(--muted); padding: 34px 10px; font-size: 14px; }

/* ---- bottom sheet ---- */
/* An author `display` beats the browser's own [hidden] rule, so the sheet needs
   its own hidden case or it sits open over the page from the first paint. */
[hidden] { display: none !important; }

.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end;
}
.sheet-card {
  position: relative; width: 100%; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(22px); } to { transform: none; } }
.sheet-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--muted); font-size: 19px; cursor: pointer;
}
.sheet-card h2 { margin: 0 6px 12px 0; font-size: 18px; }
.sheet-card img { width: 100%; border-radius: 12px; margin: 10px 0; display: block; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0;
      border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-of-type { border-bottom: none; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; font-variant-numeric: tabular-nums; }

input[type=text] {
  width: 100%; padding: 11px; border-radius: 10px; font-size: 16px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  z-index: 80; max-width: 88vw; text-align: center;
}
