:root {
  --bg: #f2f5fa;
  --card: #ffffff;
  --line: #e2e8f1;
  --ink: #142037;
  --muted: #5d6a7e;
  --soft: #e9eef5;
  --blue: #2556d9;
  --blue-soft: #e4ecfd;
  --green: #18945a;
  --orange: #e2911c;
  --red: #d24a52;
  --green-bg: #f1faf5; --green-bd: #c4e6d4;
  --blue-bg: #f2f6fe;  --blue-bd: #cad8f3;
  --red-bg: #fff5f5;   --red-bd: #f2cdd0;
  --orange-bg: #fff8ee; --orange-bd: #f2dcb5;
  --chart-bg: #fafcfe;
  --shadow: 0 1px 2px rgba(20, 32, 55, .04), 0 6px 24px rgba(20, 32, 55, .05);
  color-scheme: light;
}
/* Тёмная тема — по умолчанию; светлая включается в «Ещё» */
:root[data-theme="dark"] {
  --bg: #0e1420; --card: #161e2d; --line: #263247; --ink: #e8eef8; --muted: #95a3b8;
  --soft: #1f2a3d; --blue: #5b8cff; --blue-soft: #1d2c4d; --green: #3cc47f; --orange: #f0a93c;
  --red: #f06b72;
  --green-bg: #12261d; --green-bd: #1f4a35; --blue-bg: #141f36; --blue-bd: #26385e;
  --red-bg: #2a161a; --red-bd: #4e2830; --orange-bg: #2a2114; --orange-bd: #4f3d1d;
  --chart-bg: #131b29; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }
svg { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* --- шапка --- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top-in { max-width: 820px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.acc-btn {
  display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 62%;
  border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 6px 10px 6px 6px; text-align: left;
}
.acc-btn .chev { width: 18px; height: 18px; flex: none; color: var(--muted); }
.acc-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.acc-text small { color: var(--muted); font-size: 12px; }
.acc-text b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ava {
  width: 36px; height: 36px; border-radius: 11px; flex: none; display: grid; place-items: center;
  background: var(--blue); color: #fff; font-weight: 800; font-size: 16px;
}
.ava.all { background: var(--ink); color: var(--card); }
.ava.demo { background: var(--orange); }
.acc-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.acc-opt {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  border: 1.5px solid var(--line); background: var(--card); border-radius: 16px; padding: 10px 12px;
}
.acc-opt.on { border-color: var(--blue); background: var(--blue-bg); }
.acc-opt .acc-text { flex: 1; }
.acc-opt .acc-text small { font-size: 13px; }
.acc-opt .check { width: 22px; height: 22px; color: var(--blue); flex: none; visibility: hidden; }
.acc-opt.on .check { visibility: visible; }
.acc-opt.add { border-style: dashed; color: var(--blue); font-weight: 700; text-decoration: none; }
.acc-opt.add .ava { background: var(--blue-soft); color: var(--blue); }
.server-btn {
  display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 16px;
  background: var(--blue-soft); color: var(--blue); font-weight: 700; font-size: 17px; padding: 10px 16px; position: relative;
}
.server-btn svg { width: 22px; height: 22px; }
.sync-dot { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; display: none; }
.sync-dot.err { display: block; background: var(--red); }
.sync-dot.run { display: block; background: var(--orange); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }

/* --- страница --- */
.view { max-width: 820px; margin: 0 auto; padding: 14px 16px 24px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 26px;
  padding: 22px 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card.accent { border-top: 4px solid var(--blue); }
#connect { scroll-margin-top: calc(84px + env(safe-area-inset-top)); }
.card h2 { margin: 0; font-size: 24px; letter-spacing: -.01em; line-height: 1.2; }
.card .sub { margin: 4px 0 16px; color: var(--muted); font-size: 15px; }
.page-title { font-size: 28px; margin: 6px 4px 14px; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 13.5px; margin: 12px 0 0; }

/* --- переключатели --- */
.chips { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; margin: 0 -20px 12px; padding: 0 20px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; background: var(--soft); color: var(--ink); border-radius: 16px;
  padding: 11px 18px; font-size: 17px; white-space: nowrap;
}
.chip.on { background: var(--blue); color: #fff; }
.chips.small .chip { font-size: 15px; padding: 7px 14px; border-radius: 12px; font-weight: 600; color: var(--muted); }
.chips.small .chip.on { background: var(--blue-soft); color: var(--blue); }
.chip .n { opacity: .7; margin-left: 4px; font-weight: 500; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 4px 0 12px; font-weight: 600; color: var(--muted); font-size: 15px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

/* --- график --- */
.chart { background: var(--chart-bg); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; touch-action: pan-y; user-select: none; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .cursor { stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 4 4; opacity: .7; }
.chart .xl { fill: var(--muted); stroke: none; font: 12px Georgia, "Times New Roman", serif; text-anchor: middle; }
.chart .hit { fill: transparent; stroke: none; cursor: pointer; }
.chart-empty { padding: 50px 16px; text-align: center; color: var(--muted); }

.detail { background: var(--blue-bg); border-radius: 16px; padding: 14px 18px; margin-top: 16px; }
.detail b.date { font-size: 18px; display: block; margin-bottom: 8px; }
.detail .cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.detail .lbl { color: var(--muted); font-weight: 600; font-size: 15px; }
.detail .val { font-size: clamp(17px, 5.6vw, 24px); font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.detail .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- плитки --- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { border: 1.5px solid var(--line); border-radius: 18px; padding: 14px 16px; background: var(--card); min-width: 0; }
.tile.wide { grid-column: 1 / -1; }
.tile .lbl { font-weight: 600; color: var(--muted); font-size: 15px; }
.tile .val { font-size: 34px; font-weight: 800; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile .val small { font-size: 15px; font-weight: 500; color: var(--muted); }
.tile .hint { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tile.green { background: var(--green-bg); border-color: var(--green-bd); } .tile.green .val { color: var(--green); }
.tile.blue { background: var(--blue-bg); border-color: var(--blue-bd); } .tile.blue .val { color: var(--blue); }
.tile.red { background: var(--red-bg); border-color: var(--red-bd); } .tile.red .val { color: var(--red); }
.tile.orange { background: var(--orange-bg); border-color: var(--orange-bd); } .tile.orange .val { color: var(--orange); }
.tile.plain .val, .tiles.four .tile .val { font-size: 22px; white-space: nowrap; overflow-wrap: normal; }
.section-lbl { margin: 18px 2px 10px; font-weight: 700; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }

.range { display: flex; gap: 8px; align-items: center; margin: -4px 0 14px; flex-wrap: wrap; }
.range input { border: 1px solid var(--line); border-radius: 12px; background: var(--card); padding: 7px 10px; font-size: 15px; }

/* --- списки --- */
.search { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 12px 14px; font-size: 16px; margin-bottom: 12px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; text-align: left; width: 100%;
}
.row .t { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { color: var(--muted); font-size: 14px; }
.row .sum { font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--soft); color: var(--muted); white-space: nowrap; justify-self: end; }
.pill.closed { background: var(--green-bg); color: var(--green); }
.pill.delivered, .pill.in_transit, .pill.ready_to_ship { background: var(--blue-bg); color: var(--blue); }
.pill.on_confirmation, .pill.in_dispute { background: var(--orange-bg); color: var(--orange); }
.pill.canceled, .pill.on_return { background: var(--red-bg); color: var(--red); }
.more-btn { margin: 12px auto 0; display: block; }

.item { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; }
.item .head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.item .t { font-weight: 700; }
.item .price { font-weight: 800; white-space: nowrap; }
.item .meta { color: var(--muted); font-size: 13.5px; margin: 2px 0 10px; }
.item .nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.item .nums div { background: var(--soft); border-radius: 12px; padding: 6px 8px; min-width: 0; }
.item .nums b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.item .nums span { font-size: 12px; color: var(--muted); }
.item .foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; margin-top: 10px; font-size: 14px; }
.cost { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.cost input { width: 92px; border: 1px solid var(--line); border-radius: 10px; padding: 5px 8px; background: var(--bg); text-align: right; }
.pos { color: var(--green); font-weight: 700; } .neg { color: var(--red); font-weight: 700; }

/* --- формы и кнопки --- */
.btn { border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 700; background: var(--blue); color: #fff; }
.btn.ghost { background: var(--blue-soft); color: var(--blue); }
.btn.danger { background: var(--red-bg); color: var(--red); }
.btn:disabled { opacity: .55; cursor: default; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-weight: 600; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field input { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; background: var(--bg); }
.err { color: var(--red); font-size: 14px; white-space: pre-line; }
.acc-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.acc-row:first-of-type { border-top: 0; }
.acc-row .actions { display: flex; gap: 8px; flex: none; }
.acc-row .btn { padding: 8px 12px; font-size: 14px; }
ol.steps { padding-left: 20px; margin: 0 0 14px; color: var(--muted); font-size: 14.5px; }
.empty { text-align: center; padding: 30px 10px; }
.empty .btn { margin: 6px; }

/* --- нижнее меню --- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 8px max(10px, calc((100vw - 820px) / 2)) calc(8px + env(safe-area-inset-bottom));
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px;
  border-radius: 18px; text-decoration: none; color: var(--muted); font-weight: 700; font-size: 13px;
}
.tabbar a svg { width: 28px; height: 28px; }
.tabbar a.on { background: var(--blue-soft); color: var(--blue); }

/* --- шторка --- */
.sheet-back { position: fixed; inset: 0; background: rgba(10, 18, 32, .4); z-index: 40; }
.sheet {
  position: fixed; z-index: 41; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(640px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 26px 26px 0 0; padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
}
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 22px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0; font-size: 15px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-weight: 600; overflow-wrap: anywhere; }
.timeline { list-style: none; padding: 0; margin: 8px 0 0; }
.timeline li { padding: 6px 0 6px 18px; position: relative; font-size: 15px; }
.timeline li::before { content: ""; position: absolute; left: 2px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); }
.timeline li span { color: var(--muted); float: right; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(100px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 50; font-size: 15px; max-width: calc(100% - 32px);
}

/* --- вход --- */
.login { max-width: 380px; margin: 12vh auto 0; }
body.locked .tabbar, body.locked .top { display: none; }

@media (min-width: 720px) {
  .tiles.four { grid-template-columns: repeat(4, 1fr); }
  .list.grid2 { display: grid; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 380px) {
  .tile .val { font-size: 28px; }
  .detail .val { font-size: 20px; }
  .chip { font-size: 15px; padding: 9px 14px; }
}
