:root {
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series: #2a78d6;
  --series-soft: #cde2fb;
  --good: #0a7d0a;
  --critical: #c93636;
  --critical-bg: #fbe9e9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
  --nav-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #96958d;
    --accent: #3987e5;
    --series: #3987e5;
    --series-soft: #1c3a5e;
    --good: #3fbf3f;
    --critical: #ef7a7a;
    --critical-bg: #3a1f1f;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #96958d; --accent: #3987e5;
  --series: #3987e5; --series-soft: #1c3a5e; --good: #3fbf3f; --critical: #ef7a7a; --critical-bg: #3a1f1f; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
input { font: inherit; color: var(--text); }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 8px 0 4px; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--text-2); font-weight: 600; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 2px 0; }
.error { color: var(--critical); min-height: 1.2em; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px 22px; text-align: center; box-shadow: var(--shadow); }
.login-card form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 16px; }
.login-card input { width: 100%; }
.login-card input { text-align: center; font-size: 26px; letter-spacing: 8px; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }

/* layout */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--border); }
.top .title { font-size: 19px; font-weight: 700; }
.top .sub { font-size: 12.5px; color: var(--muted); }
main { padding: 12px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.tab { display: grid; gap: 12px; }
.banner { margin: 8px 16px 0; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 13px; }
.error-banner { background: var(--critical-bg); color: var(--critical); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

.hero { text-align: left; }
.hero-label { color: var(--text-2); font-size: 14px; }
.hero-value { font-size: 34px; font-weight: 750; letter-spacing: -.5px; margin: 2px 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero-note { color: var(--muted); font-size: 13px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; text-align: left; min-width: 0; box-shadow: var(--shadow); }
.tile.link { cursor: pointer; }
.tile.link:active { background: var(--surface-2); }
.tile-label { color: var(--text-2); font-size: 13px; }
.tile-value { font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-note { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile-note.bad { color: var(--critical); }

.rows { display: grid; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row .l { min-width: 0; overflow-wrap: anywhere; }
.row .r { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.row .s { color: var(--muted); font-size: 12.5px; }
.empty { color: var(--muted); padding: 8px 0; font-size: 14px; }

.btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 10px 14px; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; width: 42px; height: 42px; display: grid; place-items: center; cursor: pointer; font-size: 22px; flex: none; }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.daybar { display: flex; gap: 8px; align-items: center; }
.daybar input { flex: 1; min-width: 0; height: 42px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); padding: 0 10px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 8px 14px; cursor: pointer; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.custom-range { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.custom-range input { flex: 1 1 130px; min-width: 0; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); padding: 0 8px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; padding: 9px; font-size: 14px; }

.search { display: flex; gap: 8px; }
.search input { flex: 1; min-width: 0; height: 46px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); padding: 0 12px; font-size: 16px; }

.item { padding: 12px 0; border-top: 1px solid var(--border); }
.item:first-child { border-top: 0; }
.item-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.item-name { font-weight: 600; overflow-wrap: anywhere; }
.item-qty { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.variants { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.variant { background: var(--surface-2); border-radius: 8px; padding: 4px 8px; font-size: 13px; }
.variant b { font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--critical-bg); color: var(--critical); }
.phone { color: var(--accent); text-decoration: none; font-size: 13.5px; }

/* chart */
.chart { position: relative; width: 100%; height: 220px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--series); }
.chart .bar.dim { opacity: .45; }
.chart .hit { fill: transparent; cursor: pointer; }
.table-view summary { cursor: pointer; color: var(--accent); font-size: 14px; margin-top: 10px; }
.table-view table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { padding: 6px 4px; border-top: 1px solid var(--border); text-align: right; }
.table-view th:first-child, .table-view td:first-child { text-align: left; }
.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--text); color: var(--bg); padding: 8px 10px; border-radius: 10px; font-size: 13px; line-height: 1.45; max-width: 240px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }

/* bottom nav */
.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.bottom button { border: 0; background: transparent; height: var(--nav-h); display: grid; place-items: center; align-content: center; gap: 3px; font-size: 12px; color: var(--muted); cursor: pointer; }
.bottom svg { width: 24px; height: 24px; }
.bottom button.active { color: var(--accent); font-weight: 600; }

/* tarix sahifasi */
.detail { position: fixed; inset: 0; z-index: 10; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.detail .top { justify-content: flex-start; }
.detail-title { min-width: 0; }
.detail-title .title { font-size: 17px; overflow-wrap: anywhere; }
.detail-body { padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.tab { grid-template-columns: minmax(0, 1fr); }
.variant { overflow-wrap: anywhere; max-width: 100%; }
.detail { overflow-x: hidden; }
.clickable { cursor: pointer; }
.clickable:active { background: var(--surface-2); }
.row.clickable, .item.clickable { margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.chev { color: var(--muted); margin-left: 4px; }
.move-qty { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); margin-left: 4px; }
.tag.warn { background: var(--critical-bg); color: var(--critical); }
.loading { color: var(--muted); padding: 24px 0; text-align: center; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); padding: 2px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 14px; }
.crumbs button { border: 0; background: none; color: var(--accent); padding: 4px 2px; cursor: pointer; }
.crumbs span { color: var(--muted); }
.folder { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.folder svg { width: 22px; height: 22px; color: var(--muted); flex: none; }
.dim { opacity: .55; }

.skeleton { color: transparent !important; background: var(--surface-2); border-radius: 6px; }

/* Info: tovar kartochkalari */
.chip .n { opacity: .7; font-variant-numeric: tabular-nums; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 10px; }
.pcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; min-width: 0; box-shadow: var(--shadow); }
.pcard:active { background: var(--surface-2); }
.pimg { position: relative; aspect-ratio: 1 / 1; background: var(--surface-2); display: grid; place-items: center; }
.pimg img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pimg .ph { width: 44px; height: 44px; color: var(--muted); opacity: .6; }
.pimg .pqty { position: absolute; top: 8px; right: 8px; background: var(--text); color: var(--bg); font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.pbody { padding: 10px; display: grid; gap: 3px; min-width: 0; }
.pprice { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pname { font-size: 13.5px; line-height: 1.3; overflow-wrap: anywhere; }
.pmeta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pwh { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.pwh span { background: var(--surface-2); border-radius: 6px; padding: 2px 6px; font-size: 11.5px; color: var(--text-2); overflow-wrap: anywhere; max-width: 100%; }
.pwh b { color: var(--text); font-variant-numeric: tabular-nums; }
.btn.more { width: 100%; }
.check-line { margin-top: 6px; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); color: var(--text-2); font-size: 12.5px; line-height: 1.4; }
.check-line b { color: var(--text); font-variant-numeric: tabular-nums; }
.check-line .tag { margin-left: 0; }
.check-line[data-check] { cursor: pointer; position: relative; padding-right: 22px; }
.check-line[data-check]::after { content: '›'; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 18px; color: var(--text-3, var(--text-2)); }
.check-line[data-check]:active { filter: brightness(0.95); }
