:root {
  --canvas: #FFFFFF; --surface: #F9F8F7; --surface2: #F0EFED; --border: #E6E5E3;
  --text: #2C2C2B; --text2: #6F6C67; --accent: #1F6FC0; --accent-soft: #E5F2FC;
  --primary: #1F6FC0; --primary-hover: #185A9E;
  --green: #3D8C62; --green-soft: #E8F1EC; --orange: #B8692B; --orange-soft: #FBEBDE;
  --red: #D0493D; --red-soft: #FCE9E7;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #191919; --surface: #202020; --surface2: #2C2C2B; --border: rgba(255,255,255,.16);
    --text: #FFFFFF; --text2: rgba(255,255,255,.66); --accent: #8DBDF2; --accent-soft: #1E2A38;
    --primary: #2273C9; --primary-hover: #2E82DB;
    --green: #72BC8F; --green-soft: #1D2B23; --orange: #DE9255; --orange-soft: #33271D;
    --red: #E97366; --red-soft: #36211F;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--surface); color: var(--text); font-size: 16px; line-height: 1.5; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1, h2 { margin: 0; }
.muted { color: var(--text2); }

/* --- шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--canvas) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}
.topbar-row, .tools { max-width: 760px; margin: 0 auto; }
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 8px; }
.brand h1 { font-size: 20px; line-height: 1.2; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.count { font-size: 13px; font-weight: 600; color: var(--text2); background: var(--surface2); border-radius: 10px; padding: 0 8px; line-height: 20px; }
.sync { margin: 0; font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 44px; height: 44px; border-radius: 10px; border: 0; background: transparent; color: var(--text); display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--surface2); }
.icon-btn svg { width: 20px; height: 20px; }
.tools { margin-top: 12px; display: grid; gap: 10px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--surface2); border-radius: 10px; padding: 0 12px; color: var(--text2); }
.search input { flex: 1; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 16px; height: 42px; outline: none; min-width: 0; }
.segments { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.seg { flex: none; border: 1px solid var(--border); background: var(--canvas); color: var(--text); border-radius: 999px; padding: 0 14px; height: 34px; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; }
.seg.active { background: var(--text); color: var(--canvas); border-color: var(--text); }

/* --- контент --- */
main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(40px + env(safe-area-inset-bottom)); }
.list { display: grid; gap: 12px; }
.card { background: var(--canvas); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.login { display: grid; gap: 12px; margin-top: 24px; }
.login h2 { font-size: 22px; }
.login p { margin: 0; }
input[type=password] { width: 100%; height: 48px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--canvas); color: var(--text); font: inherit; font-size: 16px; }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.order { scroll-margin-top: 170px; transition: border-color .2s, box-shadow .2s; }
.order.highlight { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.order-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.title { font-size: 17px; line-height: 1.35; font-weight: 650; }
.status { flex: none; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 2px 8px; line-height: 20px; }
.status.new { background: var(--accent-soft); color: var(--accent); }
.status.ready { background: var(--green-soft); color: var(--green); }
.status.opened { background: var(--surface2); color: var(--text2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-size: 13px; border-radius: 6px; padding: 2px 8px; background: var(--surface2); color: var(--text); }
.chip:empty { display: none; }
.chip.accent { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.description { margin: 12px 0 0; white-space: pre-line; color: var(--text); font-size: 15px;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.description.open { -webkit-line-clamp: unset; display: block; }
.link-btn { border: 0; background: none; padding: 4px 0; color: var(--accent); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 10px; font-size: 13px; color: var(--text2); }
.site-link { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 600; text-decoration: none; min-height: 44px; }
.site-link svg { width: 15px; height: 15px; }
.response { margin-top: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.response-text { margin: 0; white-space: pre-line; font-size: 15px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--canvas); color: var(--text); font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--surface2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #FFFFFF; }
.btn.primary:hover { background: var(--primary-hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.wide { width: 100%; }
.actions .copy-open { flex: 1 1 220px; }
.banner { margin: 0 0 12px; padding: 12px 14px; border-radius: 10px; background: var(--orange-soft); color: var(--orange); font-size: 14px; }
.empty { text-align: center; padding: 64px 24px; }
.empty h2 { font-size: 18px; margin-bottom: 6px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--canvas); padding: 12px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 20; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (min-width: 700px) { .title { font-size: 18px; } .card { padding: 20px; } }

/* --- v5: вкладки, редактор отклика, образцы, настройки --- */
main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text2); margin-right: 6px; vertical-align: 1px; }
.dot.on { background: var(--green); }
.icon-btn { position: relative; }
.badge-dot { position: absolute; top: 10px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--orange); }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--canvas) 94%, transparent); backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px); border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
.tab { flex: 1; max-width: 200px; border: 0; background: none; color: var(--text2); display: grid; justify-items: center;
  gap: 2px; padding: 6px 0; font: inherit; font-size: 11px; font-weight: 600; cursor: pointer; position: relative; }
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }
.tab-badge { position: absolute; top: 2px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font-style: normal; font-size: 11px; line-height: 18px; }
.tab-badge.dot-only { min-width: 8px; width: 8px; height: 8px; padding: 0; background: var(--orange); }
.status.old { background: var(--surface2); color: var(--text2); }
.links { display: inline-flex; align-items: center; gap: 14px; }
.app-link { color: var(--text2); font-weight: 600; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.response-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
textarea.response-text { width: 100%; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 15px;
  line-height: 1.5; resize: none; padding: 0; outline: none; overflow: hidden; min-height: 72px; }
.regen { margin-top: 10px; display: grid; gap: 8px; }
.quick { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.quick button { flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px;
  height: 34px; padding: 0 12px; font: inherit; font-size: 14px; cursor: pointer; }
.quick button:disabled { opacity: .5; }
.regen-row, .custom { display: flex; gap: 8px; }
.regen-row .generate { flex: 1 1 auto; }
.sample-pick { flex: 0 1 46%; min-width: 0; height: 44px; border-radius: 10px; border: 1px solid var(--border); background: var(--canvas);
  color: var(--text); font: inherit; font-size: 14px; padding: 0 10px; }
.input { width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--canvas);
  color: var(--text); font: inherit; font-size: 16px; }
.input.area { resize: vertical; line-height: 1.45; }
.custom .input { flex: 1; min-width: 0; }
.btn.star { min-width: 44px; padding: 0 12px; color: var(--orange); }
.btn.small { min-height: 34px; font-size: 13px; padding: 0 12px; }
.view .card + .card, .view .card + .list, .view .list + .card { margin-top: 12px; }
.section-title { font-size: 16px; margin-bottom: 6px; }
.small { font-size: 14px; margin: 0 0 10px; }
.center { text-align: center; margin: 10px 0 0; }
#view-samples .card .input, #view-samples .card .btn { margin-top: 8px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 15px; }
.kv:first-of-type { border-top: 0; }
.kv b.ok { color: var(--green); } .kv b.bad { color: var(--orange); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.sample .description { -webkit-line-clamp: 6; }

.push-log { margin-top: 8px; font-size: 12px; line-height: 1.45; word-break: break-word; }
.push-log .ok { color: #2e7d4f; } .push-log .bad { color: #b3261e; }

/* v5.3 — mobile control panels */
.tabbar { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.tab { min-width: 0; min-height: 56px; padding: 8px 2px; font-size: 11px; }
.tab span { font-size: 11px; }
.btn, .icon-btn, summary, .seg, .check-field { min-height: 44px; }
.field-label { display: block; margin: 16px 0 6px; font-size: 14px; font-weight: 600; }
.settings-section { border-top: 1px solid var(--border); padding: 8px 0; }
.settings-section summary { display: list-item; cursor: pointer; padding: 12px 4px; font-weight: 600; }
.settings-section form .input { width: 100%; margin-bottom: 4px; }
.settings-section form button[type=submit] { margin-top: 20px; }
.check-field { display: flex; align-items: center; gap: 12px; margin: 12px 0; line-height: 1.4; }
.check-field input { width: 22px; height: 22px; flex-shrink: 0; }
.control-hero h2 { margin-top: 8px; font-size: 24px; }
.eyebrow { color: var(--text2); font-size: 12px; letter-spacing: .08em; font-weight: 700; }
.control-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.control-actions button:last-child { grid-column: 1 / -1; }
.error-text { color: var(--red); overflow-wrap: anywhere; }
.command-item { border-bottom: 1px solid var(--border); padding: 12px 0; }
.command-item>div { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.command-item p { margin: 4px 0; }
.command-state { font-size: 14px; }
.command-state.done { color: var(--green); }
.command-state.error, .command-state.expired { color: var(--red); }
.command-state.pending { color: var(--orange); }
.sample-preview { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 160px; overflow: hidden; line-height: 1.6; margin: 12px 0; }
.expanded .sample-preview { max-height: none; }
.sample .order-top { align-items: flex-start; flex-wrap: wrap; gap: 8px; }
.sample .title { flex: 1; min-width: 140px; }
.sample .row-btns { margin-top: 16px; }
.btn.danger { color: var(--red); }
.edit-dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--canvas); color: var(--text); padding: 20px; max-width: 640px; width: calc(100% - 24px); max-height: 90dvh; overflow-y: auto; }
.edit-dialog::backdrop { background: rgba(0,0,0,.5); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.edit-dialog .input { width: 100%; font-size: 16px; }
.instruction { margin-top: 16px; padding: 16px; background: var(--surface); border-radius: 8px; overflow-wrap: anywhere; font-size: 14px; }
.instruction ol { padding-left: 20px; }
.instruction li { margin: 12px 0; }
.tunnel-buttons { margin-top: 16px; }
.import-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
@media(max-width: 480px) {
  main { padding-left: 12px; padding-right: 12px; }
  .card { padding: 16px; }
  .row-btns { flex-wrap: wrap; gap: 8px; }
  .row-btns .btn { flex: 1 1 auto; }
  .regen-row { flex-wrap: wrap; }
  .sample-pick { min-width: 0; flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* Readable five-tab navigation, also on narrow phones. */
.tab span { font-size: 14px; line-height: 1.2; }
.small, .sync { font-size: 14px; }
/* Transient confirmations must not cover the bottom navigation. */
.toast { bottom: calc(88px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); }
/* Native select text must not set the grid's minimum card width. */
.list { grid-template-columns: minmax(0, 1fr); }
.card, .regen, .regen-row, .custom, .response { min-width: 0; max-width: 100%; }
.order .title, .description { overflow-wrap: anywhere; }
.order .meta { flex-wrap: wrap; }
.order .links { flex-wrap: wrap; min-width: 0; }
.quick { min-width: 0; max-width: 100%; }
.brand > div { min-width: 0; }
.top-actions { flex-shrink: 0; }
.quick button, .btn.small { min-height: 44px; }
.chip, .status, .meta, .response-head, .count { font-size: 14px; }
@media(max-width:360px) { .brand h1 { font-size: 18px; } }

:root { --green: #28734C; }
@media (prefers-color-scheme: dark) { :root { --green: #72BC8F; } }
.push-log { font-size: 14px; }

textarea.response-text { max-height: 55dvh; overflow-y: auto; }
