/* 📊 Финанс Mini App — Telegram мавзуси (ёруғ/қоронғи) ранглари билан; бўлмаса — дизайн палитраси */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111214);
  --hint: var(--tg-theme-hint-color, #6b6a65);
  --sub: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #52514e));
  --link: var(--tg-theme-link-color, #256abf);
  --accent: var(--tg-theme-button-color, #256abf);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #c4302f);
  --pos: #1f7a3a;
  --neg: #c4302f;
  --warn-bg: #fff4d6;
  --warn-text: #7a5300;
  --line: rgba(17, 18, 20, 0.09);
  --soft: rgba(37, 106, 191, 0.10);
  --radius: 16px;
  --nav-h: 64px;
  /* iPhone'даги пастки чизиқ (home indicator): қурилма ёки Telegram берган жой — пастки меню шунча баланд */
  --safe-b: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  color-scheme: light;
}
[data-scheme="dark"] {
  --pos: #4cc26e;
  --neg: #ff6b61;
  --warn-bg: #3a2f12;
  --warn-text: #f5d58a;
  --line: rgba(255, 255, 255, 0.10);
  --soft: rgba(110, 168, 255, 0.16);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }
#app { max-width: 640px; margin: 0 auto; min-height: 100vh; }

/* Юкланиш ва хабарлар */
.boot, .state { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center; color: var(--sub); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Тепа */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 16px 6px; }
.cab { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0; border: 0; background: none; font-size: 20px; font-weight: 700; letter-spacing: -0.2px; text-align: left; }
.cab svg { flex: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--card); font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
select.chip { appearance: none; -webkit-appearance: none; padding-right: 14px; }

main { padding: 4px 16px calc(var(--nav-h) + var(--safe-b) + 24px); display: flex; flex-direction: column; gap: 12px; }
.head h1 { margin: 6px 0 0; font-size: 22px; letter-spacing: -0.3px; }
.head .dates { color: var(--hint); font-size: 13px; }
.note { padding: 10px 12px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.card h2 { margin: 0 0 8px; font-size: 15px; font-weight: 650; }

/* Ранглар */
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.unit { font-size: 13px; color: var(--sub); padding: 0 2px; }

/* Сотувдан фойдагача: ботдаги «Пул ҳисоби» қаторлари, тийинигача, ҳисоб тартибида */
.flow h2 { margin-bottom: 4px; }
.fl { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto 42px; gap: 8px; align-items: baseline; padding: 6px 0; font-size: 15px; }
.fl .op { color: var(--hint); font-weight: 700; text-align: center; }
.fl .nm { min-width: 0; }
.fs { font-size: 12px; color: var(--hint); }
.fl .fs { grid-column: 2 / -1; margin-top: -6px; }
.fl .v { font-weight: 650; white-space: nowrap; text-align: right; }
.fl .p { font-size: 12px; color: var(--hint); text-align: right; white-space: nowrap; }
.fl.part { padding: 1px 0 3px; font-size: 13px; color: var(--sub); }
.fl.part .nm { padding-left: 12px; }
.fl.part .v { font-weight: 500; }
.fl.plus .v { color: var(--pos); }
.fl.subtotal, .fl.result { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }
.fl.subtotal .nm, .fl.subtotal .v { font-weight: 700; }
.fl.result { font-size: 17px; }
.fl.result .nm { font-weight: 700; }
.fl.result .v { font-size: 22px; font-weight: 750; letter-spacing: -0.4px; }

/* Жадвал */
.rows { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto 52px; gap: 8px; padding: 6px 0; font-size: 14px; align-items: baseline; }
.row .v { text-align: right; font-weight: 600; white-space: nowrap; }
.row .p { text-align: right; color: var(--hint); font-size: 12px; white-space: nowrap; }
.rows.nopct .row { grid-template-columns: minmax(0, 1fr) auto; }
.row.sub { padding: 2px 0 2px 14px; font-size: 13px; color: var(--sub); }
.row.sub .v { font-weight: 500; }
.row.total { font-weight: 700; }
.sep { height: 1px; background: var(--line); margin: 4px 0; }
.toggle { width: 100%; min-height: 48px; border: 0; border-radius: var(--radius); background: var(--card); color: var(--link); font-weight: 600; }
.list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.list li { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.list .n { color: var(--hint); font-size: 12px; }
.btn { min-height: 46px; padding: 0 18px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 650; }
.btn.ghost { background: var(--soft); color: var(--link); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn:disabled { opacity: .55; }

/* Артикуллар */
.search { width: 100%; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); outline: none; }
.search:focus { border-color: var(--accent); }
.art { background: var(--card); border-radius: 14px; padding: 12px 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; }
.art .vendor { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art .title { color: var(--hint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art .meta { grid-column: 1 / -1; font-size: 12px; color: var(--sub); }
.art .profit { text-align: right; font-weight: 700; white-space: nowrap; }
.art .margin { text-align: right; font-size: 12px; color: var(--hint); }
.empty { text-align: center; color: var(--hint); padding: 24px 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.ic { display: inline-flex; }
.ic svg { display: block; }
.has-bulk main { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 230px); }
[hidden] { display: none !important; }

/* Таннарх */
.info { font-size: 12px; color: var(--sub); }
.prod { background: var(--card); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.prod.picked { box-shadow: inset 0 0 0 2px var(--accent); }
.prod-head { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 10px; align-items: start; }
.prod-head input[type=checkbox] { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--accent); }
.prod-name { display: flex; flex-direction: column; min-width: 0; }
.prod-name b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prod-name span { font-size: 12px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prod-total { font-weight: 650; white-space: nowrap; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn-text); font-size: 11px; font-weight: 600; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; padding: 6px; border: 1px solid var(--line); border-radius: 12px; }
.field.dirty { border-color: var(--accent); }
.field.need { border: 2px solid #eda100; padding: 5px; }
.field label { display: flex; flex-direction: column; gap: 1px; padding: 2px 2px 0; }
.field label span { font-size: 11px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field input { width: 100%; min-width: 0; padding: 0; border: 0; outline: none; background: transparent; font-size: 16px; font-weight: 600; }
.field input::placeholder, .bulk-row input::placeholder { color: var(--hint); font-weight: 400; }
.field select, .cur { width: 100%; height: 40px; padding: 0 8px; border: 0; border-radius: 8px; background: var(--soft); font-size: 15px; font-weight: 600; appearance: none; -webkit-appearance: none; text-align: center; }
.prod-actions { display: flex; gap: 8px; justify-content: flex-end; }
.bulk { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 6; background: var(--card); border-radius: 18px 18px 0 0; box-shadow: 0 -6px 20px rgba(0, 0, 0, .12); padding: 12px 16px 14px; max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.bulk-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 700; }
.bulk-row { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) 64px; gap: 8px; }
.bulk-row select, .bulk-row input { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); padding: 0 10px; min-width: 0; }
.bulk-row input { font-weight: 600; }
.linkbtn { border: 0; background: none; color: var(--link); font-weight: 600; padding: 6px 0; min-height: 36px; }

/* Пастки навигация */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; height: calc(var(--nav-h) + var(--safe-b)); background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(3, 1fr); max-width: 640px; margin: 0 auto; padding-bottom: var(--safe-b); }
nav.tabs button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--hint); }
nav.tabs button.on { color: var(--accent); font-weight: 650; }

/* Ойналар */
.sheet-bg { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; background: var(--card); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; max-height: 80vh; overflow-y: auto; }
.sheet h3 { margin: 0 0 4px; font-size: 17px; }
.sheet .opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; min-height: 52px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); text-align: left; }
.sheet .opt small { color: var(--hint); }
.sheet .opt.on { border-color: var(--accent); }
.sheet input[type=date] { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); padding: 0 10px; }
.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translateX(-50%); z-index: 30; max-width: 92vw; background: rgba(17, 18, 20, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 6px 18px rgba(0, 0, 0, .25); }
.toast.bad { background: var(--neg); }
