:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #21252e;
  --line: #2b313c;
  --text: #e7ebf2;
  --muted: #97a0b0;
  --accent: #4f8cff;
  --green: #36c98a;
  --red: #ff6b6b;
  --yellow: #f2c14e;
  --pad: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px;
}

body {
  min-height: 100vh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

/* ── Top bar ── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) var(--pad) 10px;
  background: rgba(15,17,21,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .title { font-size: 20px; font-weight: 700; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 18px; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Content ── */
main { padding: var(--pad); display: flex; flex-direction: column; gap: 12px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* ── Segmented control (period) ── */
.segment { display: flex; gap: 6px; background: var(--surface); padding: 4px;
  border-radius: 12px; border: 1px solid var(--line); }
.segment button {
  flex: 1; padding: 9px 6px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted); font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.segment button.active { background: var(--accent); color: #fff; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px; }
.card h3 { margin: 0 0 4px; font-size: 14px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .4px; }

.kpi { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.kpi .big { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.kpi .unit { color: var(--muted); font-size: 15px; }

.rows { display: flex; flex-direction: column; }
.row { display: flex; justify-content: space-between; align-items: center;
  padding: 11px 0; border-top: 1px solid var(--line); gap: 10px; }
.row:first-child { border-top: 0; }
.row .label { color: var(--muted); font-size: 15px; }
.row .val { font-weight: 700; text-align: right; }
.row .val small { color: var(--muted); font-weight: 600; margin-left: 6px; }

/* строка с мини-графиком: фикс-колонка под подпись → спарклайны выровнены по вертикали */
.row.sparkrow { display: grid; grid-template-columns: 130px auto 1fr; align-items: center; column-gap: 10px; }
.row.sparkrow .label { white-space: nowrap; }
.sparkcell { display: flex; justify-content: flex-start; min-width: 0; }
.spark { flex: 0 0 auto; align-self: center; display: block; opacity: .9; }

.delta { font-size: 13px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.delta.up { color: var(--green); background: rgba(54,201,138,.12); }
.delta.down { color: var(--red); background: rgba(255,107,107,.12); }

.profit .big { color: var(--green); }
.profit.neg .big { color: var(--red); }

/* ── List items (stocks/supplies/soinvest) ── */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; display: flex; justify-content: space-between;
  align-items: center; gap: 10px; cursor: pointer; }
.item:active { background: var(--surface-2); }
.item .main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.item .art { font-weight: 700; font-variant-numeric: tabular-nums; }
.item .sub { color: var(--muted); font-size: 13px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.item .num { font-weight: 800; white-space: nowrap; text-align: right; }
.item .num.hot { color: var(--red); }
.item .num small { display: block; font-size: 12px; color: var(--muted);
  font-weight: 600; margin-top: 2px; }
.item .mid { display: flex; flex-direction: column; gap: 2px; text-align: center;
  color: var(--muted); font-size: 12px; white-space: nowrap; line-height: 1.25;
  flex: 0 0 auto; }
.item .mid b { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.item .mid.editable { border: 1px dashed var(--line); border-radius: 8px;
  padding: 4px 8px; cursor: pointer; }
.item .mid.editable:active { background: var(--surface-2); }

/* заголовок «Что дозаказать» + мини-переключатель горизонта */
.ph-head { display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 6px 2px 0; }
.segment.mini { flex: 0 0 auto; padding: 3px; }
.segment.mini button { flex: 0 0 auto; padding: 6px 12px; font-size: 13px; }

/* мини-форма быстрой правки (коэф/горизонт) */
.qe-field { display: flex; flex-direction: column; gap: 5px; }
.qe-field span { color: var(--muted); font-size: 13px; }
.qe-field input { width: 100%; padding: 12px; border-radius: 12px; font-size: 16px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  font-variant-numeric: tabular-nums; }
.qe-field input:focus { outline: none; border-color: var(--accent); }
.qe-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

/* ── Chips (filters) ── */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600;
  cursor: pointer; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Buttons ── */
.btn { display: block; width: 100%; text-align: center; padding: 13px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 15px; font-weight: 700; cursor: pointer;
  text-decoration: none; }
.btn:active { background: var(--surface-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.section-title { font-size: 13px; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px; margin: 6px 2px 0; }

.note { color: var(--muted); font-size: 13px; line-height: 1.4; padding: 0 2px; }
.warn { color: var(--yellow); font-size: 13px; }

/* ── Tab bar ── */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: rgba(15,17,21,.95); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; background: none; border: 0; color: var(--muted);
  padding: 9px 0 8px; font-size: 11px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; }
.tab .tab-ico { font-size: 21px; filter: grayscale(1) opacity(.7); }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { filter: none; }

/* ── Settings form (закупки) ── */
.settings-form .field { display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.settings-form .field:first-of-type { border-top: 0; }
.settings-form .field span { color: var(--muted); font-size: 14px; }
.settings-form .field input { width: 120px; padding: 9px 11px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  font-size: 15px; text-align: right; font-variant-numeric: tabular-nums; }
.settings-form .field input:focus { outline: none; border-color: var(--accent); }

/* ── Misc ── */
.back { color: var(--accent); font-weight: 700; cursor: pointer; padding: 4px 0;
  display: inline-flex; align-items: center; gap: 5px; }
.spinner { text-align: center; color: var(--muted); padding: 30px 0; }
.hidden { display: none !important; }

.health-banner { position: sticky; top: 0; z-index: 9; background: rgba(255,107,107,.16);
  color: var(--red); border-bottom: 1px solid rgba(255,107,107,.4);
  padding: 9px var(--pad); font-size: 13px; font-weight: 600; line-height: 1.35; }

.pw-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(9,10,13,.94);
  display: flex; align-items: center; justify-content: center; padding: 24px; }
.pw-box { width: 100%; max-width: 340px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 18px; padding: 22px;
  display: flex; flex-direction: column; gap: 12px; }
.pw-title { font-size: 20px; font-weight: 800; }
.pw-sub { color: var(--muted); font-size: 14px; margin-top: -6px; }
.pw-input { width: 100%; padding: 13px; border-radius: 12px; font-size: 16px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }

.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); padding: 11px 16px; border-radius: 12px;
  font-size: 14px; max-width: 88%; z-index: 30; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
