:root {
  --bg: #f3f5f4; --panel: #ffffff; --fg: #18211e; --muted: #66736e; --line: #e1e6e3;
  --accent: #1f6f5c; --accent-fg: #ffffff; --in: #ffffff; --out: #d9efe6; --badge: #e0583a;
  --c0: #c2410c; --c1: #047857; --c2: #7c3aed; --c3: #b45309; --c4: #0369a1;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412; --panel: #171e1b; --fg: #e6ece9; --muted: #93a19b; --line: #26302c;
    --accent: #3fae90; --accent-fg: #06130e; --in: #1d2622; --out: #1f4a3d; --badge: #f07152;
    --c0: #fb923c; --c1: #34d399; --c2: #a78bfa; --c3: #fbbf24; --c4: #38bdf8;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.4 var(--font); -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
.screen { height: 100%; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; background: var(--panel); }

/* вход */
#login { justify-content: center; padding: 24px 16px; background: var(--bg); }
.login-card { background: var(--panel); border-radius: 16px; padding: 28px 20px; display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 0 0 8px; color: var(--muted); }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card input { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.login-card button, .composer button { background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 10px; padding: 12px; font-weight: 600; cursor: pointer; }
.error { color: var(--badge); margin: 0; font-size: 14px; }

/* шапка */
.bar { display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 2; }
.bar h1 { font-size: 20px; margin: 0; flex: 1; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--fg); text-decoration: none; }
.ghost.small { padding: 4px 10px; font-size: 12px; }
.tools { padding: 10px 14px 6px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
#search { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); width: 100%; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

/* список */
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; text-decoration: none; color: inherit; }
.conv:active { background: var(--bg); }
.ava { width: 48px; height: 48px; border-radius: 50%; flex: none; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; overflow: hidden; }
.ava img { width: 100%; height: 100%; object-fit: cover; }
.conv .mid { flex: 1; min-width: 0; }
.conv .top { display: flex; gap: 8px; align-items: baseline; }
.conv .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv time { font-size: 12px; color: var(--muted); flex: none; }
.conv .src { font-size: 12px; font-weight: 600; }
.conv .bottom { display: flex; gap: 8px; align-items: center; }
.conv .last { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .name, .conv.unread .last { color: var(--fg); }
.badge { background: var(--badge); color: #fff; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 1px 8px; flex: none; }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }
.src.c0 { color: var(--c0); } .src.c1 { color: var(--c1); } .src.c2 { color: var(--c2); } .src.c3 { color: var(--c3); } .src.c4 { color: var(--c4); }

/* чат */
.chat-bar .back { font-size: 30px; line-height: 1; text-decoration: none; color: var(--accent); padding: 0 6px 0 0; }
.chat-bar .ava { width: 38px; height: 38px; font-size: 14px; }
.chat-bar .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-bar .who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-bar .who small { font-size: 12px; font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 2px 10px; border-radius: 999px; margin: 6px 0; }
.msg { max-width: 82%; padding: 7px 10px 5px; border-radius: 14px; background: var(--in); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--out); border-bottom-right-radius: 4px; }
.msg.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg time { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg .att img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: 2px 0; }
.msg .att img.sticker { max-width: 128px; }
.msg .att a, .msg a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.msg .att audio { max-width: 100%; }
.msg.pending { opacity: .6; }
.composer { display: flex; gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--panel); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 18px; padding: 9px 14px; background: var(--bg); max-height: 140px; }
.composer button { border-radius: 50%; width: 42px; height: 42px; padding: 0; font-size: 18px; flex: none; }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; max-width: 90%; }

/* ---------- версия 2: карточка клиента, шаблоны, фото, статистика ---------- */
:root { --st-new: #2563eb; --st-wait: #b45309; --st-paid: #047857; --st-ship: #7c3aed; --st-done: #4b5563; --st-cancel: #b91c1c; --warn: #c2410c; }
@media (prefers-color-scheme: dark) { :root { --st-new: #60a5fa; --st-wait: #fbbf24; --st-paid: #34d399; --st-ship: #a78bfa; --st-done: #9ca3af; --st-cancel: #f87171; --warn: #fb923c; } }
.scroll { flex: 1; overflow-y: auto; }
.pad { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 999px; width: 36px; height: 36px; display: grid; place-items: center; text-decoration: none; font-size: 16px; cursor: pointer; flex: none; }
.bar .back { font-size: 30px; line-height: 1; text-decoration: none; color: var(--accent); padding: 0 6px 0 0; }
.selects { display: flex; gap: 8px; }
.selects select { flex: 1; min-width: 0; padding: 7px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); font-size: 13px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 14px 6px; }
.pad .section-title { margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.muted { color: var(--muted); }
.conv .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.conv .meta .src { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .rem { font-size: 12px; }
.conv time.wait { color: var(--warn); font-weight: 600; }
.amount { font-size: 12px; color: var(--muted); }
.pill { font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 8px; border: 1px solid currentColor; white-space: nowrap; }
.st-new { color: var(--st-new); } .st-wait_pay { color: var(--st-wait); } .st-paid { color: var(--st-paid); }
.st-shipped { color: var(--st-ship); } .st-done { color: var(--st-done); } .st-cancel { color: var(--st-cancel); }
.chip.st-new[aria-pressed="true"] { background: var(--st-new); border-color: var(--st-new); color: #fff; }
.chip.st-wait_pay[aria-pressed="true"] { background: var(--st-wait); border-color: var(--st-wait); color: #fff; }
.chip.st-paid[aria-pressed="true"] { background: var(--st-paid); border-color: var(--st-paid); color: #fff; }
.chip.st-shipped[aria-pressed="true"] { background: var(--st-ship); border-color: var(--st-ship); color: #fff; }
.chip.st-done[aria-pressed="true"] { background: var(--st-done); border-color: var(--st-done); color: #fff; }
.chip.st-cancel[aria-pressed="true"] { background: var(--st-cancel); border-color: var(--st-cancel); color: #fff; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.ghost.danger { color: var(--st-cancel); }
#card-toggle { font-weight: 600; }

/* карточка */
.card { border-bottom: 1px solid var(--line); padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 10px; background: var(--panel); max-height: 45vh; overflow-y: auto; }
.card .row { display: flex; flex-direction: column; gap: 5px; }
.card .row.two { flex-direction: row; gap: 10px; }
.card .row.two > label:first-child { flex: 0 0 34%; }
.card .row.two > label { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; }
.lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.lbl small { font-weight: 400; }
.card input, .card textarea, .tpl-form input, .tpl-form textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); width: 100%; min-width: 0; }
.card textarea { resize: vertical; }
.inline { display: flex; gap: 6px; align-items: center; min-width: 0; }
.inline.wrap { flex-wrap: wrap; }
.inline input { flex: 1; }
.inline.wrap input { flex: 1 1 140px; }
.small-btn { background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 600; cursor: pointer; white-space: nowrap; flex: none; }
.remind-current { display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: 14px; background: var(--bg); border-radius: 10px; padding: 6px 10px; }

/* панель ввода */
.composer .tool { background: none; border: 0; font-size: 20px; width: 34px; height: 42px; padding: 0; cursor: pointer; flex: none; }
.composer .send { border-radius: 50%; width: 42px; height: 42px; padding: 0; font-size: 18px; flex: none; background: var(--accent); color: var(--accent-fg); border: 0; cursor: pointer; }
.photo-strip { display: flex; gap: 8px; padding: 8px 10px 0; overflow-x: auto; background: var(--panel); border-top: 1px solid var(--line); }
.thumb { position: relative; flex: none; }
.thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; display: block; }
.thumb .x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--fg); color: var(--panel); cursor: pointer; line-height: 1; }
.sheet { background: var(--panel); border-top: 1px solid var(--line); max-height: 45vh; overflow-y: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; position: sticky; top: 0; background: var(--panel); }
.tpl-list { list-style: none; margin: 0; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 6px; }
.tpl { width: 100%; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.tpl span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* экран шаблонов */
.tpl-edit-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tpl-edit-list li { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.tpl-view { display: flex; flex-direction: column; gap: 3px; }
.tpl-view span { white-space: pre-wrap; color: var(--muted); font-size: 14px; }
.tpl-form { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.tpl-form h2 { font-size: 16px; margin: 0; }

/* статистика */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.tile b { font-size: 24px; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 13px; }
.tile.warn b { color: var(--warn); }
.tile.accent b { color: var(--st-paid); }
.stat-rows { list-style: none; margin: 0; padding: 0; }
.stat-rows li { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.stat-rows li > :first-child { justify-self: start; }
.toast { cursor: pointer; z-index: 10; }

/* ---------- сборщик заказа ---------- */
.order-btn { display: block; text-align: center; text-decoration: none; }
.order-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.order-item { display: flex; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.order-item.incomplete { border-color: var(--warn); border-style: dashed; }
.order-img { width: 84px; height: 84px; flex: none; border-radius: 10px; overflow: hidden; background: var(--bg); display: grid; place-items: center; font-size: 26px; text-decoration: none; }
.order-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.order-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.order-fields input { padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); min-width: 0; width: 100%; }
.order-fields .caption { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qty-row input { width: 64px; flex: 0 0 64px; text-align: right; font-variant-numeric: tabular-nums; }
.line-sum { margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.x-btn { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: none; cursor: pointer; color: var(--muted); }
.order-foot { border-top: 1px solid var(--line); padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; background: var(--panel); }
.order-total { display: flex; align-items: baseline; gap: 10px; }
.order-total b { font-size: 22px; font-variant-numeric: tabular-nums; }
.order-warn { margin: 0; color: var(--warn); font-size: 13px; font-weight: 600; }
.order-preview { margin: 0; white-space: pre-wrap; font: 13px/1.4 var(--font); background: var(--bg); border-radius: 10px; padding: 8px 10px; max-height: 30vh; overflow-y: auto; }
#order .who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
#order .who small { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* компактная нижняя панель заказа */
.order-foot { gap: 6px; padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
.order-bar { display: flex; align-items: center; gap: 8px; }
.order-bar .order-total { flex: 1; min-width: 0; flex-direction: column; gap: 0; align-items: flex-start; }
.order-bar .order-total b { font-size: 19px; line-height: 1.1; }
.order-bar .order-total span { font-size: 12px; }
.foot-btn { padding: 8px 12px; }
.send-panel { display: flex; flex-direction: column; gap: 8px; }
.order-foot.typing { padding-top: 4px; padding-bottom: 4px; }
.order-foot.typing .foot-btn, .order-foot.typing .send-panel, .order-foot.typing .order-warn { display: none !important; }
.order-foot.typing .order-total { flex-direction: row; align-items: baseline; gap: 8px; }
.order-foot.typing .order-total b { font-size: 15px; }

/* карточка: компактнее, с кнопкой «Свернуть» */
.card { max-height: 34vh; padding-top: 8px; padding-bottom: 8px; gap: 8px; }
.card-close { align-self: center; }

/* названия сообществ — голубым во всём списке и в шапке чата */
:root { --community: #2787f5; }
@media (prefers-color-scheme: dark) { :root { --community: #5aa9ff; } }
.src, .src.c0, .src.c1, .src.c2, .src.c3, .src.c4 { color: var(--community); }

/* ---------- чат: кнопка вниз, цитаты, отметки, меню сообщения ---------- */
.messages-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.messages-wrap .messages { flex: 1; }
.down-btn { position: absolute; right: 12px; bottom: 12px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--accent); font-size: 22px; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,.18); z-index: 3; }
.down-count { position: absolute; top: -6px; right: -4px; background: var(--badge); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 6px; }
.msg { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.msg time { display: flex; justify-content: flex-end; align-items: center; gap: 4px; }
.mark { font-size: 11px; letter-spacing: -2px; color: var(--muted); }
.mark.read { color: #2787f5; }
.quote { border-left: 3px solid var(--accent); padding: 2px 8px; margin: 0 0 4px; font-size: 12.5px; display: flex; flex-direction: column; background: rgba(0,0,0,.04); border-radius: 0 8px 8px 0; }
.quote b { color: var(--accent); font-size: 12px; }
.quote span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; }
.compose-bar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.cb-text { flex: 1; min-width: 0; display: flex; flex-direction: column; border-left: 3px solid var(--accent); padding-left: 8px; }
.cb-text b { font-size: 12px; color: var(--accent); }
.cb-text span { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-menu { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.msg-actions { background: var(--panel); width: 100%; max-width: 720px; border-radius: 16px 16px 0 0; padding: 8px 8px calc(10px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 2px; }
.act-preview { font-size: 13px; color: var(--muted); padding: 8px 12px 10px; border-bottom: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act { background: none; border: 0; text-align: left; padding: 13px 12px; font-size: 16px; border-radius: 10px; cursor: pointer; color: var(--fg); }
.act:active { background: var(--bg); }
.act.danger { color: var(--st-cancel); }
.act.muted { color: var(--muted); text-align: center; }

/* напоминание: кнопка в шапке и окно */
.small-icon { width: 34px; height: 34px; font-size: 15px; }
#remind-btn.on { background: var(--st-wait); border-color: var(--st-wait); }
.remind-line { background: var(--bg); border: 0; border-radius: 10px; padding: 8px 10px; text-align: left; font-size: 14px; cursor: pointer; color: var(--fg); }
.remind-sheet { gap: 10px; padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px)); }
.remind-sheet .sheet-head { padding: 0; position: static; }
.remind-sheet input { padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); width: 100%; }
.quick-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.quick-grid .chip { padding: 9px 4px; text-align: center; white-space: normal; }
.chat-bar .who small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* мои сообщения клиенту — фиолетовый фон */
:root { --out: #e3d5fb; }
@media (prefers-color-scheme: dark) { :root { --out: #4a3878; } }
.msg.out .quote { border-left-color: #7c4dff; }
.msg.out .quote b { color: #6a3fd8; }
@media (prefers-color-scheme: dark) { .msg.out .quote b { color: #c4a8ff; } }
