/* Тёмная тема «Midnight»: строгие тона, минимальные скругления */
:root {
  --bg: #0a0d14;
  --surface: #121722;
  --surface-2: #1a2130;
  --line: #252d3d;
  --text: #e9edf4;
  --muted: #8b95a8;
  --primary: #e9edf4;
  --on-primary: #0a0d14;
  --accent: #8aa4d6;
  --danger: #e5534b;
  --success: #4cae7f;
  --warn: #d9a441;
  --info: #6f9de0;
  --r: 6px;      /* кнопки, поля */
  --r-card: 10px;
  --tabbar-h: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
body.no-tabbar { padding-bottom: 0; }
body.no-tabbar #tabbar { display: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 26px; font-weight: 600; margin: 4px 0 14px; letter-spacing: -0.02em; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 24px 2px 8px; }
#view { padding: 14px 16px 24px; max-width: 720px; margin: 0 auto; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nowrap { white-space: nowrap; }
.price { font-weight: 600; }
.old-price { color: var(--muted); text-decoration: line-through; font-size: 13px; margin-left: 6px; }
.hidden { display: none !important; }

/* Tab bar */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(10, 13, 20, .92);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 10.5px; letter-spacing: .02em; color: var(--muted); position: relative; cursor: pointer;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--text); }
.badge {
  position: absolute; top: 5px; left: calc(50% + 5px); min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 4px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.count { min-width: 20px; height: 20px; border-radius: 4px; background: var(--primary); color: var(--on-primary); font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; }

/* Cards & lists */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; }
.card + .card { margin-top: 10px; }
.pad { padding: 14px 16px; }
.list > * { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list > *:last-child { border-bottom: 0; }
.list-item { display: flex; align-items: center; gap: 12px; cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.list-item:active { background: var(--surface-2); }
.chev::after { content: '›'; color: var(--muted); font-size: 22px; line-height: 1; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 48px; margin-bottom: 8px; opacity: .8; }
.note { font-size: 13px; color: var(--muted); margin: 8px 2px 0; }

/* Buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  border: 1px solid transparent; border-radius: var(--r); padding: 13px 14px; font-weight: 600; cursor: pointer;
  background: var(--primary); color: var(--on-primary); letter-spacing: .01em;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: transparent; border-color: var(--line); color: var(--text); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.btn.sm { width: auto; padding: 7px 12px; font-size: 13px; }
.btn + .btn { margin-top: 8px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin: 0; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.icon-btn { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon-btn:disabled { opacity: .35; }

/* Segmented control */
.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 4px; padding: 9px 6px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 14px; }
.seg button.active { background: var(--surface-2); color: var(--text); }

/* Catalog */
.search { width: 100%; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; background: var(--surface); outline: none; }
.search:focus { border-color: var(--accent); }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 12px -16px; padding: 0 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); border-radius: var(--r); padding: 6px 12px; background: var(--surface); cursor: pointer; white-space: nowrap; font-size: 14px; color: var(--muted); }
.chip.active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.chip .cnt { opacity: .6; margin-left: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.product { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 8px; display: flex; flex-direction: column; cursor: pointer; text-align: left; }
.product.na .thumb { opacity: .5; }
.thumb {
  aspect-ratio: 1; border-radius: var(--r); display: flex; align-items: center; justify-content: center; font-size: 60px;
  background: radial-gradient(circle at 50% 35%, #1f2738, #121722 70%); overflow: hidden; position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.sm { width: 48px; height: 48px; font-size: 24px; flex: none; }
.thumb.lg { font-size: 130px; border-radius: var(--r-card); border: 1px solid var(--line); }
.product .title { margin: 8px 2px 4px; font-size: 14px; line-height: 1.3; flex: 1; }
.product .price-line { margin: 0 2px; }
.tag { display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 11px; font-weight: 600; letter-spacing: .02em; }
.tag.na { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.tag.off { background: var(--surface-2); color: var(--muted); }
.tag.usd { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }

/* Qty */
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.qty button { border: 0; background: none; width: 34px; height: 34px; font-size: 18px; color: var(--text); cursor: pointer; }
.qty span { min-width: 22px; text-align: center; font-weight: 600; }

/* Forms */
.field { display: block; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.field input, .field select, .field textarea { width: 100%; border: 0; background: none; outline: none; padding: 2px 0; resize: vertical; }
.field select option { background: var(--surface); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; }
.field-grid .field:nth-child(odd) { border-right: 1px solid var(--line); }
.input { width: 100%; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; background: var(--surface); outline: none; }
.input:focus { border-color: var(--accent); }
.radio { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.radio input, .check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; margin: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.switch { appearance: none; width: 42px; height: 24px; border-radius: 5px; background: var(--line); position: relative; cursor: pointer; flex: none; transition: .2s; margin: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 3px; background: #c9d0dc; transition: .2s; }
.switch:checked { background: var(--success); }
.switch:checked::after { left: 21px; background: #fff; }
.plain { border: 0; background: none; outline: none; width: 100%; padding: 0; }

/* Status */
.status { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-pending { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.st-assembling { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.st-ready, .st-shipped { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.st-completed { background: var(--surface-2); color: var(--muted); }
.st-cancelled { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.steps { display: flex; gap: 4px; margin: 4px 0 6px; }
.steps i { flex: 1; height: 3px; border-radius: 1px; background: var(--line); }
.steps i.on { background: var(--primary); }
.steps-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); gap: 4px; }
.status-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.status-actions .btn { margin: 0; padding: 9px; font-size: 13px; font-weight: 500; }
.status-actions .btn.current { border-color: var(--primary); }

/* Profile */
.avatar { width: 60px; height: 60px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 600; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 40px; height: 40px; font-size: 15px; border-radius: 6px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 12px 14px; }
.stat b { display: block; font-size: 20px; font-weight: 600; margin-top: 2px; }
.role { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
details.faq { border-bottom: 1px solid var(--line); padding: 0; }
details.faq:last-child { border-bottom: 0; }
details.faq summary { padding: 13px 16px; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
details.faq summary::after { content: '+'; color: var(--muted); }
details.faq[open] summary::after { content: '−'; }
details.faq p { margin: 0; padding: 0 16px 14px; color: var(--muted); font-size: 14px; }

/* Chat */
.chat { display: flex; flex-direction: column; min-height: calc(100vh - 120px); }
.chat-topic { font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; margin-bottom: 10px; background: var(--surface); }
.messages { flex: 1; display: flex; flex-direction: column; gap: 6px; padding-bottom: 12px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; }
.msg time { display: block; font-size: 11px; opacity: .55; text-align: right; margin-top: 2px; }
.msg.me { align-self: flex-end; background: var(--primary); color: var(--on-primary); border-bottom-right-radius: 3px; }
.msg.them { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 3px; }
.topic-divider { align-self: center; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 8px 0 2px; }
.composer {
  position: sticky; bottom: 0; display: flex; gap: 8px; padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.composer textarea { flex: 1; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; background: var(--surface); outline: none; resize: none; max-height: 120px; }
.composer button { width: 42px; height: 42px; border-radius: var(--r); border: 0; background: var(--primary); color: var(--on-primary); font-size: 18px; cursor: pointer; flex: none; align-self: flex-end; }

/* Misc */
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.header-row h1 { margin-bottom: 14px; }
.sticky-bottom { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); margin-top: 16px; z-index: 2; }
body.no-tabbar .sticky-bottom { bottom: calc(env(safe-area-inset-bottom) + 8px); }
.summary-line { display: flex; justify-content: space-between; padding: 4px 0; }
#toast {
  position: fixed; left: 50%; top: 14px; transform: translate(-50%, -160%); z-index: 100;
  background: #e9edf4; color: #0a0d14; padding: 10px 16px; border-radius: var(--r); font-size: 14px; font-weight: 500;
  transition: transform .25s; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
#toast.show { transform: translate(-50%, 0); }
.loader { width: 26px; height: 26px; margin: 80px auto; border: 2px solid var(--line); border-top-color: var(--text); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.mode-banner { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 9px 12px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.photo-edit { display: flex; gap: 12px; align-items: center; }
.photo-edit .thumb { width: 88px; height: 88px; flex: none; font-size: 40px; }
.file-label { position: relative; overflow: hidden; }
.file-label input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.result { border-left: 3px solid var(--success); }
.result.err { border-left-color: var(--danger); }

/* Выбор варианта (память) и способа оплаты в карточке товара */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 10px 14px; cursor: pointer; min-width: 84px; text-align: center; }
.opt small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.opt.active { border-color: var(--primary); background: var(--surface-2); }
.opt.na { color: var(--muted); }
.opt.na b { text-decoration: line-through; font-weight: 500; }
.pay-opt { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.pay-opt .sum { font-weight: 600; white-space: nowrap; }
.tag.plus { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }

/* Варианты в редакторе товара */
.var-row { display: grid; grid-template-columns: 1fr 1fr 32px; gap: 8px; align-items: center; }
.var-row .input { padding: 8px 10px; }
.var-row .check { grid-column: span 2; }
#pedit.has-variants .single-only { display: none !important; }

/* Обращения */
.ctx { border-left: 3px solid var(--accent); }
.ctx .ctx-items { font-size: 14px; margin: 6px 0; }
.ticket-closed { border: 1px dashed var(--line); border-radius: var(--r); padding: 12px; text-align: center; color: var(--muted); font-size: 14px; margin: 8px 0; }
.st-open { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.st-closed { background: var(--surface-2); color: var(--muted); }
.tnum { font-variant-numeric: tabular-nums; font-weight: 600; }
