/* Робочий кабінет агента · Telegram Mini App. Mobile-first (320–430 px), тема Telegram (світла/темна) повним набором.
   Ритм 4 pt, один радіус, без декоративних тіней і градієнтів. Цілі дотику ≥ 44 px. */

:root {
	--bg: var(--tg-theme-secondary-bg-color, #f2f3f5);
	--surface: var(--tg-theme-bg-color, #ffffff);
	--text: var(--tg-theme-text-color, #16181d);
	--muted: var(--tg-theme-hint-color, #6b7280);
	--line: var(--tg-theme-section-separator-color, #e3e5e8);
	--brand: var(--tg-theme-button-color, #1f4e8c);
	--brand-text: var(--tg-theme-button-text-color, #ffffff);
	--link: var(--tg-theme-link-color, #1f4e8c);
	--danger: var(--tg-theme-destructive-text-color, #c62828);
	--ok: #1e7d43;
	--warn: #9a6100;
	--warn-bg: rgba(214, 152, 0, .12);
	--danger-bg: rgba(198, 40, 40, .10);
	--ok-bg: rgba(30, 125, 67, .10);
	--brand-soft: rgba(31, 78, 140, .10);
	--r: 12px;
	--safe-top: var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px));
	--safe-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}
@media (prefers-color-scheme: dark) {
	:root:not([data-tg]) { --bg: #0f1115; --surface: #181b21; --text: #eceef2; --muted: #9aa1ad; --line: #2a2f38; --brand: #5b8fd6; --link: #7aa7e6; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* інакше display:flex/grid класів перебиває атрибут hidden */
html, body { margin: 0; padding: 0; }
body {
	background: var(--bg); color: var(--text);
	font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	-webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
	overflow-x: hidden;
}
.ac { min-height: 100vh; padding-bottom: calc(96px + var(--safe-bottom)); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
button { font: inherit; color: inherit; }
a { color: var(--link); }

/* ---------- верх ---------- */
.ac-top {
	position: sticky; top: 0; z-index: 5;
	display: flex; align-items: center; gap: 8px; min-height: 52px;
	padding: calc(8px + var(--safe-top)) 16px 8px;
	background: var(--surface); border-bottom: 1px solid var(--line);
}
.ac-back { flex: none; width: 40px; height: 40px; margin-left: -8px; display: grid; place-items: center; border: 0; background: transparent; border-radius: var(--r); color: var(--brand); }
.ac-back svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.ac-top-text { min-width: 0; flex: 1; }
.ac-title { font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-sub:empty { display: none; }
.ac-offline { position: sticky; top: 52px; z-index: 4; padding: 8px 16px; background: var(--danger-bg); color: var(--danger); font-size: 13px; text-align: center; }

.ac-main { padding: 12px 16px; display: grid; gap: 12px; min-width: 0; }
.ac-main > * { min-width: 0; }
.ac-empty { color: var(--muted); text-align: center; padding: 28px 8px; margin: 0; }
.ac-empty b { display: block; color: var(--text); margin-bottom: 4px; }
.ac-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 4px 0 0; font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.ac-h a, .ac-h button { text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 14px; background: none; border: 0; color: var(--link); padding: 0; min-height: 32px; }

/* ---------- картки, списки ---------- */
.ac-card { background: var(--surface); border-radius: var(--r); padding: 14px; display: grid; gap: 10px; min-width: 0; }
.ac-card h1 { margin: 0; font-size: 18px; line-height: 1.3; overflow-wrap: anywhere; }
.ac-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin: 0; }
.ac-kv > div { min-width: 0; }
.ac-kv dt { font-size: 12px; color: var(--muted); }
.ac-kv dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.ac-kv .wide { grid-column: 1 / -1; }
.ac-kv .is-debt { color: var(--danger); }
.ac-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--r); overflow: hidden; }
.ac-list > li + li { border-top: 1px solid var(--line); }
.ac-row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 56px; padding: 10px 14px; border: 0; background: transparent; text-align: left; min-width: 0; }
button.ac-row:active { background: var(--brand-soft); }
.ac-row-main { flex: 1; min-width: 0; }
.ac-row-title { font-weight: 600; overflow-wrap: anywhere; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.ac-row-meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; margin-top: 2px; }
.ac-row-side { flex: none; text-align: right; font-weight: 650; }
.ac-row-side small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.ac-chev { flex: none; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); opacity: .6; }

/* ---------- кнопки ---------- */
.ac-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 600; text-align: center; cursor: pointer; }
.ac-btn:disabled { opacity: .5; }
.ac-btn--primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.ac-btn--danger { color: var(--danger); }
.ac-btn--ghost { background: transparent; border-style: dashed; }
.ac-btn--wide { width: 100%; }
.ac-btn--hero { width: 100%; min-height: 56px; font-size: 17px; }
.ac-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ac-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ac-grid2 > .ac-btn { min-width: 0; white-space: normal; }
.ac-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ac-actions .ac-btn { flex-direction: column; min-height: 76px; gap: 6px; font-size: 14px; }
.ac-actions .ac-btn svg { width: 24px; height: 24px; color: var(--brand); }

/* ---------- плитки показників ---------- */
.ac-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ac-tile { background: var(--surface); border-radius: var(--r); padding: 12px; min-width: 0; border: 0; text-align: left; }
.ac-tile b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ac-tile span { font-size: 12px; color: var(--muted); }
.ac-tile.is-warn b { color: var(--warn); }
.ac-hello { display: grid; gap: 2px; }
.ac-hello b { font-size: 20px; }
.ac-hello span { color: var(--muted); font-size: 13px; }

/* ---------- поля ---------- */
.ac-input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--text); font: inherit; font-size: 16px; }
.ac-input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
textarea.ac-input { min-height: 72px; resize: vertical; }
.ac-field { display: grid; gap: 6px; }
.ac-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.ac-search { position: relative; }
.ac-search svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; }
.ac-search .ac-input { padding-left: 38px; }
.ac-seg { display: flex; gap: 4px; padding: 4px; background: var(--surface); border-radius: var(--r); }
.ac-seg button { flex: 1; min-height: 36px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: 14px; color: var(--muted); }
.ac-seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-text); }
.ac-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.ac-chip { flex: none; min-height: 36px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; }
.ac-ddate { gap: 8px; }
.ac-ddate-label { font-size: 17px; font-weight: 600; line-height: 1.3; }
.ac-ddate-input { max-width: 100%; }
.ac-chip[aria-pressed="true"] { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); font-weight: 600; }

/* ---------- бейджі й нотатки ---------- */
.ac-badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.ac-badge--ok { background: var(--ok-bg); color: var(--ok); }
.ac-badge--warn { background: var(--warn-bg); color: var(--warn); }
.ac-badge--danger { background: var(--danger-bg); color: var(--danger); }
.ac-badge--muted { background: var(--line); color: var(--muted); }
.ac-note { padding: 10px 12px; border-radius: var(--r); background: var(--brand-soft); font-size: 14px; overflow-wrap: anywhere; }
.ac-note b { display: block; margin-bottom: 2px; }
.ac-note--warn { background: var(--warn-bg); }
.ac-note--danger { background: var(--danger-bg); }
.ac-note--ok { background: var(--ok-bg); }
.ac-note ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- товари, кошик ---------- */
.ac-item { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 10px 14px; align-items: center; }
.ac-item-name { font-weight: 600; overflow-wrap: anywhere; }
.ac-item-meta { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 12px; color: var(--muted); margin-top: 2px; }
.ac-item-hint { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.ac-item-hint b { color: var(--text); }
.ac-item-foot { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.ac-step { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.ac-step button { width: 44px; height: 44px; border: 0; background: transparent; font-size: 20px; font-weight: 600; color: var(--brand); }
.ac-step input { width: 64px; height: 44px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; font: inherit; font-size: 16px; background: transparent; color: var(--text); }
.ac-step.is-zero input { color: var(--muted); }
.ac-price { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.ac-price input { width: 96px; min-height: 44px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r); text-align: right; font: inherit; font-size: 16px; background: var(--surface); color: var(--text); }
.ac-price input.is-missing { border-color: var(--danger); background: var(--danger-bg); }
.ac-line-sum { font-weight: 650; text-align: right; }
.ac-totals { display: grid; gap: 6px; }
.ac-totals div { display: flex; justify-content: space-between; gap: 8px; }
.ac-totals .is-total { font-size: 18px; font-weight: 700; padding-top: 6px; border-top: 1px solid var(--line); }
.ac-big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ac-big.is-debt { color: var(--danger); }

/* ---------- нижня панель, тост, шторка ---------- */
.ac-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; align-items: center; gap: 10px; padding: 10px 16px calc(10px + var(--safe-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.ac-bar-sum { flex: 1; min-width: 0; display: grid; font-size: 13px; color: var(--muted); }
.ac-bar-sum span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-bar-sum b { color: var(--text); font-size: 16px; font-variant-numeric: tabular-nums; }
.ac-bar .ac-btn { flex: none; max-width: 60%; }
.ac-toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + var(--safe-bottom)); z-index: 9; padding: 12px 14px; border-radius: var(--r); background: rgba(22, 24, 29, .92); color: #fff; font-size: 14px; text-align: center; }
.ac-sheet-wrap { position: fixed; inset: 0; z-index: 8; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; }
.ac-sheet { width: 100%; max-height: 88vh; overflow-y: auto; background: var(--surface); border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + var(--safe-bottom)); display: grid; gap: 12px; }
.ac-sheet h2 { margin: 0; font-size: 17px; }
.ac-sheet p { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.ac-skel { height: 56px; border-radius: var(--r); background: var(--surface); opacity: .7; animation: ac-pulse 1.2s ease-in-out infinite; }
@keyframes ac-pulse { 50% { opacity: .35; } }
.ac-timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.ac-timeline li { display: flex; justify-content: space-between; gap: 8px; }
.ac-timeline li span:last-child { color: var(--muted); text-align: right; }

@media (min-width: 640px) {
	.ac-main { max-width: 640px; margin: 0 auto; }
	.ac-actions { grid-template-columns: repeat(4, 1fr); }
	.ac-tiles { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 340px) {
	.ac-main { padding: 10px 12px; }
	.ac-kv { grid-template-columns: 1fr; }
	.ac-step input { width: 52px; }
	.ac-step button { width: 40px; }
	.ac-price input { width: 84px; }
	.ac-tile b { font-size: 18px; }
}

/* ---- борги 1С і фото боргових накладних */
.ac-debt { gap: 8px; }
.ac-debt-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ac-debt-sum { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ac-debt-sum b { font-size: 24px; line-height: 1.2; }
.ac-debt-sum span { color: var(--muted); font-size: 14px; }
.ac-h .ac-row-meta { font-weight: 400; margin-left: 6px; text-transform: none; letter-spacing: 0; }
.ac-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.ac-photo { margin: 0; display: grid; gap: 4px; min-width: 0; }
.ac-photo.is-hidden { opacity: .55; }
.ac-photo-btn { padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); aspect-ratio: 3 / 4; }
.ac-photo-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ac-photo figcaption { display: grid; font-size: 12px; color: var(--muted); line-height: 1.25; overflow-wrap: anywhere; }
.ac-progress { display: inline-block; width: 120px; max-width: 50%; height: 6px; border-radius: 3px; background: var(--line); vertical-align: middle; overflow: hidden; }
.ac-progress span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.ac-viewer { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .92); display: flex; align-items: center; justify-content: center;
  padding: calc(48px + var(--safe-top)) 8px calc(16px + var(--safe-bottom)); }
.ac-viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.ac-viewer p { color: #ddd; }
.ac-viewer-close { position: absolute; top: calc(8px + var(--safe-top)); right: 8px; min-height: 40px; padding: 8px 14px; border-radius: 999px;
  border: 0; background: rgba(255, 255, 255, .16); color: #fff; font-size: 15px; }
.is-debt { color: var(--danger); }
.is-warn { color: var(--warn); }
