:root {
  --accent: #D9661F;
  --accent-text: #FFFFFF;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --brand: #1F4E79;
  --bg: #F3F5F7;
  --surface: #FFFFFF;
  --surface-2: #F7F9FA;
  --text: #18212B;
  --hint: #5A6672;
  --line: #E1E6EB;
  --field: #C9D2DB;
  --danger: #B3261E;
  --danger-soft: #FBE9E7;
  --ok: #1E6B34;
  --ok-soft: #E3F2E6;
  --warn: #8A4510;
  --warn-soft: #FCEBD9;
  --radius: 14px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: Manrope, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
:root[data-mode="dark"] {
  --bg: #121820; --surface: #1C2530; --surface-2: #222D3A; --text: #E8EDF2; --hint: #A3B0BD;
  --line: #2C3846; --field: #3A4858; --brand: #6FA3D6;
  --danger: #F2B8B5; --danger-soft: #3B1F1E; --ok: #9FD8AE; --ok-soft: #1D3324;
  --warn: #F5C08F; --warn-soft: #3A2A1A;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
svg.i { width: 20px; height: 20px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 16px); max-width: 720px; margin: 0 auto; }
body.no-tabs #app { padding-bottom: calc(var(--safe-b) + 96px); }
.boot { display: grid; place-items: center; min-height: 60vh; }
.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); } }

/* верхня панель */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; align-items: center; gap: 4px; min-height: 56px; padding: 6px 8px; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 18px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 8px; }
.topbar .actions { display: flex; gap: 2px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--text); }
.icon-btn:active { background: var(--surface-2); }

.hero { background: var(--brand); color: #fff; padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 14px; }
:root[data-mode="dark"] .hero { background: #183A5A; }
.hero .sub { color: #C9DAEA; font-size: 13px; }
.hero h1 { font-size: 24px; font-weight: 700; }
.hero .stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hero .stat { background: rgba(255,255,255,.12); border-radius: 12px; padding: 12px; }
.hero .stat b { display: block; font-size: 24px; }
.hero .stat span { font-size: 12px; color: #C9DAEA; }

.content { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; }
.section-title h2 { font-size: 17px; font-weight: 700; }
.section-title a, .section-title button { font-size: 13px; color: var(--hint); background: none; border: 0; cursor: pointer; }
.muted { color: var(--hint); font-size: 13px; }

/* картки та списки */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card.flat { padding: 0; gap: 0; overflow: hidden; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 56px; width: 100%; border: 0; background: transparent; text-align: left; border-bottom: 1px solid var(--line); cursor: pointer; color: var(--text); }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--surface-2); }
.row .ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex-shrink: 0; font-weight: 700; font-size: 13px; }
.row .body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .title { font-weight: 600; font-size: 15px; }
.row .subtitle { font-size: 13px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; }
.row .right { color: var(--hint); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.row.static { cursor: default; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile { min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; font-size: 14px; cursor: pointer; padding: 8px 10px; text-align: center; color: var(--text); }
.tile.primary { grid-column: 1 / -1; background: var(--accent); color: var(--accent-text); border: 0; font-size: 16px; min-height: 54px; }

.badge { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 10px; background: var(--surface-2); color: var(--hint); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }

/* форми */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-size: 13px; font-weight: 600; color: var(--hint); }
.field .help { font-size: 12px; color: var(--hint); }
.input, .select, textarea.input { width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--field); background: var(--surface); padding: 10px 12px; font-size: 16px; outline: none; }
textarea.input { min-height: 84px; resize: vertical; }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.picker { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--field); background: var(--surface); padding: 10px 12px; font-size: 16px; text-align: left; cursor: pointer; color: var(--text); }
.picker .placeholder { color: var(--hint); }
.picker .val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.check { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; width: 100%; background: transparent; border-left: 0; border-right: 0; border-top: 0; text-align: left; color: var(--text); }
.check:last-child { border-bottom: 0; }
.box { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--field); flex-shrink: 0; display: grid; place-items: center; margin-top: 1px; }
.check.on .box { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.check .box svg { width: 14px; height: 14px; stroke-width: 3; opacity: 0; }
.check.on .box svg { opacity: 1; }
.switch { position: relative; width: 50px; height: 30px; border-radius: 15px; background: var(--field); border: 0; cursor: pointer; flex-shrink: 0; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; overflow-x: auto; }
.segmented button { flex: 1; min-height: 40px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; font-size: 13px; cursor: pointer; padding: 0 10px; white-space: nowrap; color: var(--hint); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.swatch.on { border-color: var(--text); }
.swatch.sq { border-radius: 12px; width: 64px; height: 52px; }

/* кнопки */
.btn { min-height: 50px; border-radius: 14px; border: 1px solid var(--field); background: var(--surface); font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; cursor: pointer; color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-text); border: 0; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line); padding: 10px 16px calc(10px + var(--safe-b)); display: flex; gap: 10px; }
.bottom-bar-wrap > * { flex: 1; }
.bottom-bar-wrap { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; width: 100%; }

/* нижня навігація */
#tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; background: var(--surface); border-top: 1px solid var(--line); padding: 4px 6px calc(4px + var(--safe-b)); display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
#tabbar:empty, body.no-tabs #tabbar { display: none; }
#tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; font-size: 11px; color: var(--hint); }
#tabbar a.on { color: var(--accent); font-weight: 700; }

/* шторки (випадаючі вікна знизу) */
#layer:empty { display: none; }
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(10, 15, 20, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 720px; max-height: 88vh; background: var(--surface); border-radius: 18px 18px 0 0; display: flex; flex-direction: column; animation: up .2s ease-out; padding-bottom: var(--safe-b); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 6px 18px; }
.sheet-head h3 { flex: 1; font-size: 17px; font-weight: 700; }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; }
.sheet-body { overflow-y: auto; padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.sheet-foot { padding: 10px 16px 14px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.sheet-foot > * { flex: 1; }
.option { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 4px; border: 0; border-bottom: 1px solid var(--line); background: transparent; width: 100%; text-align: left; cursor: pointer; color: var(--text); }
.option .t { flex: 1; min-width: 0; }
.option .t small { display: block; color: var(--hint); font-size: 12px; }
.option.on { color: var(--accent); font-weight: 600; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 24px); transform: translateX(-50%); z-index: 30; background: #18212B; color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); animation: up .2s; }
.toast.error { background: var(--danger); color: #fff; }
:root[data-mode="dark"] .toast.error { background: #8C1D18; }

.empty { text-align: center; padding: 32px 16px; color: var(--hint); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty svg { width: 40px; height: 40px; stroke-width: 1.5; }
.empty b { color: var(--text); font-size: 16px; }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 600; }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.drop { border: 2px dashed var(--field); border-radius: var(--radius); padding: 28px 16px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; background: var(--surface); }
.drop svg { width: 36px; height: 36px; color: var(--accent); }
.kv { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--hint); }
.kv dd { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* заявки: великі кнопки постачальників */
.sup-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.sup-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; min-height: 128px; padding: 16px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; color: var(--text); }
.sup-btn:active { transform: scale(.98); }
.sup-btn .sup-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.sup-btn .sup-ic svg { width: 24px; height: 24px; }
.sup-btn b { font-size: 17px; }
.sup-btn .muted { margin-top: auto; }
.sup-btn.alt .sup-ic { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.group-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; margin-top: 6px; }
.group-head .badge { margin-left: auto; }
.qty { font-weight: 700; white-space: nowrap; text-align: right; }
.qty small { display: block; font-weight: 500; color: var(--hint); font-size: 11px; }
/* непарна остання плитка — на всю ширину, щоб не стояла сама */
.tiles .tile.primary ~ .tile:last-child:nth-child(even) { grid-column: 1 / -1; }

/* головний екран */
:root { --h1b: #E6F1FB; --h1t: #0C447C; --h2b: #E1F5EE; --h2t: #085041; --h3b: #FAEEDA; --h3t: #633806;
  --h4b: #EEEDFE; --h4t: #3C3489; --h5b: #FAECE7; --h5t: #712B13; --h6b: #F1EFE8; --h6t: #444441; }
:root[data-mode="dark"] { --h1b: #0C447C; --h1t: #B5D4F4; --h2b: #085041; --h2t: #9FE1CB; --h3b: #633806; --h3t: #FAC775;
  --h4b: #3C3489; --h4t: #CECBF6; --h5b: #712B13; --h5t: #F5C4B3; --h6b: #444441; --h6t: #D3D1C7; }
.home-hero { background: var(--brand); color: #fff; padding: 16px 18px 46px; border-radius: 0 0 24px 24px; display: flex; flex-direction: column; gap: 14px; }
:root[data-mode="dark"] .home-hero { background: #183A5A; }
.home-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.home-top .sub { color: #C9DAEA; font-size: 12px; }
.home-top h1 { font-size: 20px; font-weight: 700; margin-top: 2px; }
.home-gear { color: #fff; opacity: .9; margin: -6px -8px 0 0; }
.home-gear:active { background: rgba(255,255,255,.14); }
.home-nums { display: flex; gap: 28px; flex-wrap: wrap; }
.home-nums b { display: block; font-size: 24px; font-weight: 700; }
.home-nums span, .home-cap { font-size: 12px; color: #C9DAEA; }
.home-bar { height: 6px; border-radius: 3px; background: rgba(255,255,255,.25); overflow: hidden; margin-bottom: 6px; }
.home-bar > div { height: 100%; background: #fff; border-radius: 3px; }
.home-search { margin: -26px 16px 0; background: var(--surface); border: 1px solid var(--field); border-radius: 16px; padding: 0 14px; min-height: 50px; display: flex; align-items: center; gap: 10px; color: var(--hint); position: relative; }
.home-search-input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 15px; color: var(--text); }
.home-body { padding: 14px 16px 84px; display: flex; flex-direction: column; gap: 12px; }
.home-last { display: flex; align-items: center; gap: 12px; border: 0; border-radius: 16px; background: var(--surface); box-shadow: 0 0 0 1px var(--line); padding: 11px 14px; text-align: left; cursor: pointer; color: var(--text); }
.home-last > div { flex: 1; min-width: 0; }
.home-last b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-last small { display: block; font-size: 12px; color: var(--hint); }
.home-last svg { color: var(--hint); }
.home-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.home-tile { position: relative; border: 0; border-radius: 18px; padding: 14px; min-height: 116px; display: flex; flex-direction: column; justify-content: space-between; text-align: left; cursor: pointer; background: var(--tb); color: var(--tt); }
.home-tile:active { filter: brightness(.96); }
.home-tile.small { min-height: 90px; }
.home-tile .n { display: block; font-size: 26px; font-weight: 700; line-height: 1; margin-bottom: 3px; }
.home-tile b { display: block; font-size: 15px; font-weight: 700; }
.home-tile small { display: block; font-size: 12px; opacity: .85; }
.home-tile svg.big { width: 26px; height: 26px; }
.home-tile svg.ch { position: absolute; top: 14px; right: 12px; width: 16px; height: 16px; opacity: .55; }
.home-tile.c1 { --tb: var(--h1b); --tt: var(--h1t); }
.home-tile.c2 { --tb: var(--h2b); --tt: var(--h2t); }
.home-tile.c3 { --tb: var(--h3b); --tt: var(--h3t); }
.home-tile.c4 { --tb: var(--h4b); --tt: var(--h4t); }
.home-tile.c5 { --tb: var(--h5b); --tt: var(--h5t); }
.home-tile.c6 { --tb: var(--h6b); --tt: var(--h6t); }
.home-fab { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--safe-b) + 14px); z-index: 3; background: var(--accent); color: var(--accent-text); border: 0; border-radius: 28px; padding: 14px 26px; font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.28); cursor: pointer; }
