/* Админ-панель */
:root {
  --brand: #4F46E5; --bg: #f4f5f9; --card: #fff; --text: #1c1f2a; --muted: #6b7083; --line: #e3e5ee;
  --soft: #f7f8fb; --ok-bg: #e9f7ee; --ok: #1f6b3b; --err-bg: #fdecea; --err: #b4352a; --warn-bg: #fff6e5;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 24px; margin: 4px 0 6px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.danger { color: var(--err); }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.side { background: #161827; color: #d6d8e5; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.side-head { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; padding: 0 8px 18px; }
.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px rgba(79,70,229,.3); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: #c3c6d8; text-decoration: none; padding: 9px 12px; border-radius: 8px; }
.nav a:hover { background: #22253a; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.side-menu { flex: 1; display: flex; flex-direction: column; }
.side-foot { margin-top: auto; padding: 0 8px; }
.side-foot .link { color: #c3c6d8; }
.nav-toggle { display: none; }
.main { padding: 24px 28px 60px; max-width: 1200px; width: 100%; min-width: 0; }

/* Телефон и узкий планшет: шапка с кнопкой меню, разделы раскрываются списком */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; z-index: 20; height: auto; padding: 8px 12px; flex-direction: row; flex-wrap: wrap;
    align-items: center; gap: 8px; }
  .side-head { padding: 0 4px; flex: 1 1 auto; }
  .nav-toggle { display: inline-flex; align-items: center; gap: 10px; min-height: 40px; max-width: 60%; padding: 6px 12px;
    border: 1px solid #34374d; border-radius: 9px; background: #22253a; color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
  .nav-toggle > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .burger, .burger::before, .burger::after { display: block; width: 16px; height: 2px; border-radius: 2px; background: currentColor; flex: none; }
  .burger { position: relative; }
  .burger::before, .burger::after { content: ""; position: absolute; left: 0; }
  .burger::before { top: -5px; }
  .burger::after { top: 5px; }
  .side-menu { display: none; flex: 1 1 100%; padding: 4px 0 8px; max-height: calc(100vh - 60px); overflow-y: auto; }
  .side.open .side-menu { display: flex; }
  .nav a { padding: 12px; font-size: 16px; }
  .side-foot { margin: 8px 0 0; padding: 12px 12px 0; border-top: 1px solid #2c2f45; display: flex; justify-content: space-between;
    align-items: center; }
  .side-foot .link { padding: 8px 0; font-size: 16px; }
  .main { padding: 16px 16px 60px; }
  h1 { font-size: 21px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 36px; }
  .input { min-height: 42px; font-size: 16px; } /* 16px — iPhone не увеличивает страницу при вводе */
  .check input, .seg input[type="checkbox"] { width: 18px; height: 18px; }
  .page-head > .row { flex-wrap: wrap; }
  .filters .input, .filters .date { flex: 1 1 100%; }
  .filters .date .input { flex: 1; }
  .filters .btn { flex: 1 1 auto; }
  .card { padding: 14px; }
  .table th, .table td { padding: 10px; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.warn { background: var(--warn-bg); border-color: #f1d9a6; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head p { margin: 4px 0 0; max-width: 720px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 + section { margin-top: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 14px; }
.input { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font: inherit; background: #fff; color: var(--text); }
.input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
.input.short { max-width: 140px; }
.input.color { padding: 2px; height: 40px; max-width: 120px; }
.input.strong { font-weight: 700; }
textarea.input { resize: vertical; }
.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; cursor: pointer; }
.check input { margin-top: 3px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 9px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger-outline { color: var(--err); border-color: #f0c7c2; }
.link { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font: inherit; text-decoration: none; }
.link.danger { color: var(--err); }
.inline { display: inline; }

.flash { border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: #fff; color: var(--text); text-decoration: none; font-size: 14px; }
.chip b { color: var(--muted); font-weight: 600; margin-left: 4px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.on b { color: #e3e1ff; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px; }
.filters .input { width: auto; flex: 1 1 160px; }
.filters .date { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }

.table-wrap { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--soft); }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #fafaff; }
.status { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; vertical-align: middle; }
.s-new { background: #e7e9ff; color: #3730a3; }
.s-in_work { background: #fff3d6; color: #8a5a00; }
.s-contacted { background: #e2f5ea; color: #1f6b3b; }
.s-closed { background: #ececf1; color: #555a6e; }
.tag { display: inline-block; background: var(--soft); border: 1px solid var(--line); border-radius: 6px; padding: 0 7px; font-size: 13px; }
/* На телефоне строки таблиц заявок — карточками, подписи колонок из data-label */
@media (max-width: 700px) {
  .table-wrap:has(.cards) { background: none; border: 0; overflow: visible; }
  .table.cards thead { display: none; }
  .table.cards, .table.cards tbody, .table.cards tr, .table.cards td { display: block; width: 100%; }
  .table.cards tr { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px;
    margin-bottom: 10px; }
  .table.cards td { position: relative; padding: 5px 0 5px 118px; min-height: 32px; border-bottom: 1px dashed var(--line);
    white-space: normal; overflow-wrap: anywhere; }
  .table.cards tr td:last-child { border-bottom: 0; }
  .table.cards td::before { content: attr(data-label); position: absolute; left: 0; top: 6px; width: 108px; color: var(--muted);
    font-size: 13px; }
}
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-line; }
.answers dt { font-weight: 600; color: var(--text); }
@media (max-width: 600px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 8px; } }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { flex-direction: row; font-weight: 500; }
.seg input { position: absolute; opacity: 0; }
.seg span { padding: 7px 12px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.seg input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); }
.seg input:focus-visible + span { outline: 2px solid var(--brand); }
.files { padding-left: 0; list-style: none; margin: 0; }

.tree { padding: 10px 10px 6px; }
.tree h2 { padding: 6px 8px 2px; }
.tree-item { display: grid; grid-template-columns: 220px 1fr auto; gap: 12px; align-items: center; padding: 10px 8px;
  border-radius: 8px; color: var(--text); text-decoration: none; border-top: 1px solid var(--line); }
.tree-item:hover { background: #fafaff; }
.tree-title { font-weight: 600; }
.tree-text { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) { .tree-item { grid-template-columns: 1fr; gap: 2px; } .tree-text { white-space: normal; } }

.edit-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; margin-top: 8px; }
@media (max-width: 1000px) { .edit-grid { grid-template-columns: 1fr; } }
.opt-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.opt-row:last-child { border-bottom: 0; }
.opt-row .sub { grid-column: 1 / -1; font-weight: 400; color: var(--muted); padding-left: 14px; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 16px 0 6px; }

.preview-wrap { position: sticky; top: 20px; }
.tg-chat { background: #c9d9e8 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='20' cy='20' r='1.5' fill='%23b4c7da'/%3E%3C/svg%3E"); border-radius: 14px; padding: 16px 12px; margin-top: 6px; }
.tg-bubble { background: #fff; border-radius: 14px 14px 14px 4px; padding: 9px 12px; white-space: pre-line; font-size: 14px; box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; }
.tg-bubble a { color: #2a7ab0; }
.tg-buttons { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.tg-buttons span { background: rgba(80, 110, 140, .55); color: #fff; text-align: center; border-radius: 8px; padding: 7px 8px; font-size: 13px; }

.example-row { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 14px; padding: 12px 0; border-top: 1px solid var(--line); }
.example-row.is-hidden { opacity: .55; }
.thumb { width: 96px; height: 64px; border-radius: 8px; overflow: hidden; background: var(--soft); display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.example-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.example-form .row, .example-form .file-pick { grid-column: 1 / -1; }
@media (max-width: 700px) { .example-form { grid-template-columns: minmax(0, 1fr); } .example-row { grid-template-columns: 64px minmax(0, 1fr); gap: 10px; } .thumb { width: 64px; height: 44px; } }
.file-pick { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--brand); cursor: pointer; flex-wrap: wrap; }
.file-pick input { font-size: 13px; color: var(--muted); min-width: 0; max-width: 100%; }
.add-box { margin-top: 12px; }
.add-box summary { cursor: pointer; color: var(--brand); font-weight: 600; padding: 6px 0; }
.add-box form { margin-top: 10px; max-width: 520px; }
.hint-box { background: var(--soft); border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.logo-preview { height: 48px; border-radius: 8px; border: 1px solid var(--line); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 6px 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stats .card { margin: 0; }
.stat .num { font-size: 30px; font-weight: 800; line-height: 1.1; }
@media (max-width: 700px) { .stats { grid-template-columns: 1fr 1fr; } }
.legend { display: flex; gap: 6px 14px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: -8px; }
.sw.started, .bar.started { background: #c7cbff; }
.sw.contacts, .bar.contacts { background: #8b8ff7; }
.sw.submitted, .bar.submitted { background: var(--brand); }
.days { display: flex; gap: 3px; align-items: flex-end; height: 180px; overflow-x: auto; }
.day { flex: 1 0 14px; display: flex; flex-direction: column; height: 100%; }
.bars { flex: 1; display: flex; gap: 1px; align-items: flex-end; }
.bar { flex: 1; border-radius: 3px 3px 0 0; min-height: 0; }
.day-label { font-size: 11px; color: var(--muted); height: 16px; white-space: nowrap; }
.hbar-wrap { flex: 1; background: var(--soft); border-radius: 99px; height: 10px; overflow: hidden; }
.hbar { display: block; height: 10px; background: var(--brand); border-radius: 99px; min-width: 2px; }
.bar-cell { width: 35%; }
.hrow { display: grid; grid-template-columns: 150px 1fr auto; gap: 10px; align-items: center; padding: 6px 0; }
.heat { border-collapse: separate; border-spacing: 2px; font-size: 11px; }
.heat th { color: var(--muted); font-weight: 500; padding: 0 3px; }
.heat td { width: 26px; height: 24px; text-align: center; border-radius: 4px; color: #fff;
  background: color-mix(in srgb, var(--brand) calc(var(--v) * 100%), #eef0f7); }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login h1 { font-size: 21px; }

/* Аналитика на телефоне: 30 дней помещаются без прокрутки, воронка без колонки с полосой */
@media (max-width: 700px) {
  .days { gap: 2px; }
  .day { flex: 1 0 5px; }
  .day-label { font-size: 10px; overflow: visible; }
  .funnel th:nth-child(3), .funnel td.bar-cell { display: none; }
  .funnel th, .funnel td { padding: 8px 6px; }
  .hrow { grid-template-columns: 100px minmax(0, 1fr) auto; }
}
