:root {
  color-scheme: dark;
  /* Тёмная тема приложения. Акцент берём из темы Telegram, если он есть. */
  --bg: #0f1319;
  --card: #171d26;
  --raised: #1f2733;
  --text: #e9edf3;
  --muted: #8c97a8;
  --accent: var(--tg-theme-button-color, #3b8cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: #2a3340;
  --good: #35c27a;
  --bad: #ff6b6b;
  --warn: #f0b429;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 0 0 24px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2 { margin: 0; font-size: 16px; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.status { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600;
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.run::before { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.chip.ok::before { background: var(--good); }
.chip.warn::before { background: var(--warn); }
.chip.bad::before { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }

nav#tabs {
  position: sticky; top: 53px; z-index: 4;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.tab {
  padding: 8px 4px; border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--raised); color: var(--text); }

main { padding: 12px 12px 0; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar input[type="search"] { flex: 1 1 auto; min-width: 0; }
input, select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--raised); color: var(--text); width: 100%;
}
button.primary, button.ghost, button.danger {
  padding: 9px 12px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; white-space: nowrap;
}
button.primary { background: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.danger { background: transparent; color: var(--bad); border-color: var(--line); }
button:disabled { opacity: .5; }

.list { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card.stale { box-shadow: inset 3px 0 0 var(--warn); }
.card-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.title { font-weight: 600; line-height: 1.3; word-break: break-word; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.badge {
  font-size: 12px; padding: 3px 8px; border-radius: 999px;
  background: var(--raised); color: var(--muted);
}
.badge.good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.badge.plain { background: transparent; border: 1px solid var(--line); }

.headline { text-align: right; white-space: nowrap; }
.headline .value { font-size: 20px; font-weight: 700; letter-spacing: -.2px; }
.headline .value.good { color: var(--good); }
.headline .value.bad { color: var(--bad); }
.headline .sub { font-size: 12px; color: var(--muted); }

.flow { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 6px; align-items: end; margin-top: 10px; }
.flow .step { min-width: 0; }
.flow .step .label { font-size: 11px; color: var(--muted); }
.flow .step .amount { font-size: 14px; font-weight: 600; white-space: nowrap; }
.flow .arrow { color: var(--muted); padding-bottom: 2px; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 14px; margin-top: 10px; }
.grid div { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; align-items: baseline; }
.grid span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid span:last-child { white-space: nowrap; }
.grid span:first-child { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions a { text-decoration: none; }
.links { display: flex; gap: 12px; margin-top: 10px; font-size: 13px; }
.links a { color: var(--accent); text-decoration: none; }
.section { margin: 22px 0 10px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.pager { display: flex; justify-content: center; gap: 10px; margin: 12px 0; }
.empty { padding: 26px 12px; text-align: center; color: var(--muted); }
.foot { margin: 16px 2px 0; }

.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.field .name { font-size: 14px; }
.field .hint { font-size: 12px; color: var(--muted); }
.field .control { flex: 0 0 auto; display: flex; gap: 6px; align-items: center; }
.field.wide { flex-wrap: wrap; }
.field.wide .control { flex: 1 1 100%; margin-top: 8px; }
.field.wide select { width: 100%; }
.field input { width: 110px; text-align: right; }
.switch { width: 52px; height: 30px; border-radius: 999px; border: 0; background: var(--line); position: relative; cursor: pointer; }
.switch { background: var(--raised); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #dfe5ee; transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(22px); }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.62); display: flex; align-items: flex-end; z-index: 20; }
.sheet-card {
  width: 100%; max-height: 88vh; overflow-y: auto; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-body-row { margin-bottom: 12px; }
.sheet label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: 88%; padding: 10px 14px; border-radius: 12px; z-index: 30;
  background: var(--raised); color: var(--text); border: 1px solid var(--line);
  font-size: 14px; text-align: center;
}

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.range { display: flex; gap: 8px; flex: 1 1 auto; }
.range label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.range input { width: 100%; padding: 7px 9px; }
.presets { display: flex; gap: 6px; }
.presets button {
  padding: 7px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 13px; cursor: pointer;
}
.presets button.on { background: var(--raised); color: var(--text); }
.total { background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.total .headline-profit { font-size: 26px; font-weight: 700; letter-spacing: -.4px; }
.total .headline-profit.good { color: var(--good); }
.total .headline-profit.bad { color: var(--bad); }
.total .cells { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.total .cell .label { font-size: 11px; color: var(--muted); }
.total .cell .amount { font-size: 15px; font-weight: 600; white-space: nowrap; }
