:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #efece6;
  --line: #e2ddd4;
  --text: #1c1b19;
  --muted: #6d685f;
  --accent: #1f3d34;
  --accent-ink: #ffffff;
  --accent-soft: #e3ece8;
  --danger: #a3302a;
  --danger-soft: #f8e7e5;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --ok: #276749;
  --ok-soft: #e2f1e8;
  --info-soft: #e8edf6;
  --info: #2f4d7a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 4px 16px rgb(0 0 0 / 5%);
  --tg-bubble: #ffffff;
  --tg-bg: #dfe6d9;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1d1d1b;
    --surface-2: #262623;
    --line: #34332f;
    --text: #efece6;
    --muted: #a19c92;
    --accent: #7fbfa6;
    --accent-ink: #10201a;
    --accent-soft: #1f3129;
    --danger: #f08b82;
    --danger-soft: #3a1f1c;
    --warn: #e8c071;
    --warn-soft: #362b16;
    --ok: #86d0a6;
    --ok-soft: #1c3226;
    --info-soft: #1f2838;
    --info: #9db8e3;
    --shadow: none;
    --tg-bubble: #2a2b28;
    --tg-bg: #1a211b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.boot { padding: 48px; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -0.01em; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; }
.brand-mark svg { width: 17px; height: 17px; }
.tabs { display: flex; gap: 4px; margin-left: 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; padding: 7px 12px; border-radius: 999px; cursor: pointer;
  color: var(--muted); white-space: nowrap; font-weight: 550;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-current="true"] { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.tab .count { display: inline-block; min-width: 20px; margin-left: 5px; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; line-height: 20px; text-align: center; }
.spacer { flex: 1; }
.icon-btn { border: 0; background: none; padding: 8px; border-radius: 10px; cursor: pointer; color: var(--muted);
  display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.banner { padding: 8px 16px; font-size: 13px; background: var(--info-soft); color: var(--info); border-bottom: 1px solid var(--line); }

.main { flex: 1; display: grid; grid-template-columns: minmax(300px, 380px) 1fr; min-height: 0; }
.list-pane { border-right: 1px solid var(--line); overflow-y: auto; height: calc(100vh - 57px); position: sticky; top: 57px; }
.detail-pane { min-width: 0; padding: 20px 28px 0; }
.empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty-title { color: var(--text); font-weight: 600; margin-bottom: 4px; }

@media (max-width: 899px) {
  .main { grid-template-columns: 1fr; }
  .list-pane { border-right: 0; height: auto; position: static; }
  .main.has-detail .list-pane { display: none; }
  .main:not(.has-detail) .detail-pane { display: none; }
  .detail-pane { padding: 12px 14px 140px; }
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .tabs { order: 10; flex: 1 1 100%; margin: 0 -16px; padding: 0 12px; mask-image: linear-gradient(90deg, #000 88%, transparent); }
  .brand-name { display: inline; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .tab { padding: 7px 10px; }
  .list-pane, .detail-pane { scroll-margin-top: 100px; }
}

/* ---------- list ---------- */
.list { list-style: none; margin: 0; padding: 8px; }
.item {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center;
  padding: 10px; border-radius: var(--radius); cursor: pointer; border: 1px solid transparent;
  width: 100%; text-align: left; background: none;
}
.item:hover { background: var(--surface-2); }
.item[aria-current="true"] { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--surface-2);
  display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.thumb svg { width: 22px; height: 22px; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-top: 4px; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.item-main { min-width: 0; }
.item-price { font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.item-issues { color: var(--danger); font-size: 12px; text-align: right; margin-top: 2px; white-space: nowrap; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.READY_FOR_REVIEW { background: var(--ok-soft); color: var(--ok); }
.pill.NEEDS_REVIEW { background: var(--warn-soft); color: var(--warn); }
.pill.PUBLISHED { background: var(--accent-soft); color: var(--accent); }
.pill.ERROR { background: var(--danger-soft); color: var(--danger); }

/* ---------- detail ---------- */
.detail { max-width: 980px; margin: 0 auto; display: grid; gap: 16px; }
.detail-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-head h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.detail-sub { color: var(--muted); font-size: 13px; width: 100%; }
.back { display: none; }
@media (max-width: 899px) { .back { display: inline-grid; margin-left: -6px; } }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1099px) {
  .grid-2 { grid-template-columns: 1fr; }
  /* На вузькому екрані картки йдуть у порядку роботи:
     прев'ю → ціна → фото → опис → призначення. */
  .grid-2 > .stack { display: contents; }
  .c-preview { order: 1; } .c-price { order: 2; } .c-photos { order: 3; }
  .c-description { order: 4; } .c-destination { order: 5; } .c-source { order: 6; }
}
.stack { display: grid; gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 0; }
.card-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0; }
.card-body { padding: 12px 16px 16px; display: grid; gap: 12px; }

.alerts { display: grid; gap: 8px; }
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert-detail { opacity: 0.8; font-size: 13px; }

/* Telegram-like preview */
.tg { background: var(--tg-bg); border-radius: var(--radius-sm); padding: 14px; }
.tg-bubble { background: var(--tg-bubble); border-radius: 12px; overflow: hidden; max-width: 460px; box-shadow: 0 1px 1px rgb(0 0 0 / 8%); }
.tg-media { display: grid; gap: 2px; grid-template-columns: repeat(2, 1fr); }
.tg-media.one { grid-template-columns: 1fr; }
.tg-media img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--surface-2); }
.tg-media.one img { aspect-ratio: 4 / 3; }
.tg-text { padding: 10px 12px 12px; white-space: pre-wrap; word-wrap: break-word; }
.tg-empty { padding: 14px; color: var(--muted); font-style: italic; }

/* values */
.values { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.value { padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius-sm); min-width: 0; }
.value-label { font-size: 12px; color: var(--muted); }
.value-main { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 1px; overflow-wrap: anywhere; }
.value-src { font-size: 12px; color: var(--muted); margin-top: 2px; }
.value.final { grid-column: 1 / -1; background: var(--accent-soft); }
.value.final .value-main { font-size: 26px; color: var(--accent); letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.editor { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  cursor: pointer; font-variant-numeric: tabular-nums; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip small { color: var(--muted); margin-left: 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 140px; }

.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
  padding: 10px 12px; min-height: 42px;
}
.select { width: auto; }
.textarea { min-height: 150px; resize: vertical; line-height: 1.45; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px; border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 42px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-danger { color: var(--danger); }
.btn-ghost { border-color: transparent; background: none; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-weight: 600; }

/* photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photo { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.photo.off img, .photo.off .noimg { opacity: 0.4; filter: grayscale(0.6); }
.photo img, .photo .noimg { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--surface-2); }
.photo .noimg { display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.photo-body { padding: 8px 10px 10px; display: grid; gap: 6px; }
.photo-reason { font-size: 12.5px; color: var(--muted); min-height: 2.6em; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 11px; font-weight: 650; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.tag.PRICE_TAG, .tag.RECEIPT, .tag.DOCUMENT { background: var(--danger-soft); color: var(--danger); }

.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 14px; font-weight: 550; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--line); position: relative;
  cursor: pointer; margin: 0; flex: none; transition: background 0.15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgb(0 0 0 / 20%); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

details.card > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; align-items: center; gap: 8px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "›"; margin-left: auto; color: var(--muted); font-size: 20px; transition: transform 0.15s; }
details.card[open] > summary::after { transform: rotate(90deg); }
.pre { font-family: inherit; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; background: var(--surface-2); padding: 12px; border-radius: var(--radius-sm); margin: 0; }
.audit { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.audit li { display: grid; grid-template-columns: 130px 1fr; gap: 10px; }
.audit time { color: var(--muted); font-variant-numeric: tabular-nums; }
.trace { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }

/* sticky actions */
.actionbar {
  position: sticky; bottom: 0; z-index: 10; margin: 8px -28px 0; padding: 12px 28px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.actionbar .hint { color: var(--muted); font-size: 13px; flex: 1 1 200px; }
@media (max-width: 899px) {
  .actionbar { position: fixed; left: 0; right: 0; margin: 0; padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .actionbar .btn-primary { flex: 1 1 100%; order: -1; }
  .actionbar .btn:not(.btn-primary) { flex: 1 1 0; }
  .actionbar .hint { flex-basis: 100%; order: -2; }
}

/* settings / login */
.page { max-width: 760px; margin: 0 auto; padding: 24px 16px 60px; display: grid; gap: 16px; }
.page h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.kv { display: grid; grid-template-columns: minmax(150px, 240px) 1fr; gap: 8px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
/* На телефоне длинные украинские значения не должны переноситься по слогам. */
@media (max-width: 600px) {
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; font-weight: 600; }
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.table td .row { gap: 6px; margin: 0 0 6px; }
.table td .input { max-width: 92px; min-height: 36px; }
/* Числовые поля (лимиты, срок, прозрачность) не растягиваются на всю ширину. */
.row .input[inputmode="numeric"], .row .input[type="number"] { max-width: 140px; }
.table td .btn { min-height: 36px; padding: 0 10px; }
/* На телефоне таблица пользователей прокручивается по горизонтали, а не ломает вёрстку. */
@media (max-width: 760px) {
  .page .table { display: block; overflow-x: auto; white-space: nowrap; }
  .page .table td, .page .table th { white-space: normal; }
}

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); padding: 28px; display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 21px; }
.error-text { color: var(--danger); font-size: 14px; min-height: 1.4em; }

/* toast & dialog */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; max-width: min(92vw, 520px);
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 30px rgb(0 0 0 / 25%); }
.toast.error { background: var(--danger); color: #fff; }
@media (max-width: 899px) { .toast { bottom: calc(150px + env(safe-area-inset-bottom)); } }

.dialog { border: 0; border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgb(0 0 0 / 30%); }
.dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog-body { padding: 20px; display: grid; gap: 14px; }
.dialog-title { margin: 0; font-size: 19px; }
.dialog-content { max-height: 55vh; overflow: auto; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
