:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #15171a;
  --muted: #6b7280;
  --line: #e6e8eb;
  --grid: #eceef1;
  --accent: #2f5bea;
  --good: #1a8f4c;
  --bad: #d23b3b;
  --warn: #c98a12;
  --series-1: #2f5bea;
  --series-2: #1fa67a;
  --wb: #3d63e6;
  --wb-pale: #c6d3fa;
  --oz: #e0457b;
  --oz-pale: #f8cadb;
  --on-solid: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --card: #1b1d21;
    --text: #eceef1;
    --muted: #9aa1ac;
    --line: #2a2d33;
    --grid: #262930;
    --accent: #7b9bff;
    --good: #45c27d;
    --bad: #ff6b6b;
    --warn: #f0b545;
    --series-1: #6f8fff;
    --series-2: #3cc896;
    --wb: #6f8fff;
    --wb-pale: #2c3866;
    --oz: #ff6f9f;
    --oz-pale: #5c2a3d;
    --on-solid: #0d0e10;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; text-decoration: none; }
h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.tabs a.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

main { max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; }
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
details.card summary { cursor: pointer; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary h2::after { content: " ›"; color: var(--muted); }
details.card[open] summary { margin-bottom: 12px; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.delta { font-size: 12px; color: var(--muted); }
.delta.s1 { color: var(--good); }
.delta.s-1 { color: var(--bad); }
.note { font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 10px; padding: 8px 10px; margin: -4px 0 12px; }
.updated { font-size: 12px; color: var(--muted); margin-top: 10px; }

.months {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px;
  scrollbar-width: none;
}
.months::-webkit-scrollbar { display: none; }
.months a {
  flex: 0 0 auto; padding: 6px 12px; border-radius: 999px;
  background: var(--card); color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums;
}
.months a.on { background: var(--accent); color: #fff; }

.chart { position: relative; height: 240px; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.wb { background: var(--wb); } .sw.wb-pale { background: var(--wb-pale); }
.sw.oz { background: var(--oz); } .sw.oz-pale { background: var(--oz-pale); }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.total { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.total-row { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.note.after { margin: 12px 0 0; }

.pnl { width: 100%; border-collapse: collapse; font-size: 14px; }
.pnl th { text-align: right; font-weight: 600; color: var(--muted); font-size: 12px; padding: 0 0 6px 8px; }
.pnl td { padding: 7px 0; border-top: 1px solid var(--line); vertical-align: top; }
.pnl td.num { text-align: right; white-space: nowrap; padding-left: 8px; font-variant-numeric: tabular-nums; }
.pnl td.num .delta { display: block; font-size: 11px; }
.pnl tr.sub td:first-child { padding-left: 12px; color: var(--muted); font-size: 13px; }

.foot { text-align: center; font-size: 12px; color: var(--muted); padding: 0 16px 24px; }

/* Заказы и выкупы: переключатель агрегации, график с прокруткой вбок */
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 6px 0; border-radius: 8px;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.legend-note { font-size: 12px; color: var(--muted); margin: -2px 0 6px; }
.good { color: var(--good); }
.chart-scroll { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chart-scroll::-webkit-scrollbar { display: none; }
.chart-inner { position: relative; height: 280px; }
.totals-title { font-size: 13px; color: var(--muted); margin-top: 14px; }
.totals-title + .totals { margin-top: 6px; }
.total.all { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; }
.total.all .kpi-label { grid-column: 1 / -1; }

.login { max-width: 360px; margin: 24px auto; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login input {
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.login button {
  font: inherit; font-weight: 600; color: #fff; background: var(--accent);
  border: 0; border-radius: 10px; padding: 11px; margin-top: 4px;
}
.login-error { color: var(--bad); font-size: 13px; }
.foot a { color: inherit; }

.today-metric { display: flex; flex-direction: column; margin: 6px 0 8px; }
.today-metric span { font-size: 12px; color: var(--muted); }
.today-metric b { font-size: 15px; }
.today-metric small { font-size: 11px; color: var(--muted); }
.today-metric i { font-style: normal; font-weight: 600; }
.stale { color: var(--bad); }

/* Пояснения под значком (i) у заголовка карточки */
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.info { position: relative; font-size: 13px; font-weight: 400; }
.info summary {
  list-style: none; cursor: pointer; user-select: none;
  width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--muted);
  color: var(--muted); font: italic 700 11px/15px Georgia, serif; text-align: center;
}
.info summary::-webkit-details-marker { display: none; }
.info[open] summary { background: var(--text); border-color: var(--text); color: var(--card); }
.info-pop {
  position: absolute; z-index: 10; top: 26px; left: -60px; width: min(290px, calc(100vw - 48px));
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 4px 12px; box-shadow: 0 8px 28px rgba(0, 0, 0, .14); line-height: 1.4;
}
.info-pop p { margin: 8px 0; }
.updated-at { font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; background: var(--good); }
.dot.warn, .warn-text .dot { background: var(--warn); }
.warn-text { color: var(--warn); }

/* Обновление: кнопка-время в карточке "Сегодня" и жест "потянуть вниз" */
button.updated-at {
  font: inherit; font-size: 13px; background: none; border: 0; padding: 4px 0 4px 8px; margin: -4px 0;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.reload-icon { display: inline-block; margin-left: 6px; font-size: 14px; }
.updated-at.spinning .reload-icon, .ptr.spinning span { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ptr {
  position: fixed; z-index: 20; left: 50%; top: calc(env(safe-area-inset-top) + 8px);
  width: 34px; height: 34px; border-radius: 50%; transform: translate(-50%, 0); opacity: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--card); color: var(--muted); box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
  font-size: 18px; pointer-events: none;
}
.ptr.ready { color: var(--accent); }
.ptr.spinning { transform: translate(-50%, 40px); opacity: 1; color: var(--accent); }
