/* КВАДРАТ CRM — админ-панель заявок */
:root {
  --bg: #f5f4f1;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --line: rgba(11, 11, 11, .09);
  --side: #14171c;
  --side-2: #1f242c;
  --side-ink: #c9ced6;
  --accent: #ff5b1f;
  --accent-soft: #ffe9df;
  --good: #006300;
  --good-bg: #e4f3e4;
  --bad: #b3261e;
  --bad-bg: #fbe7e5;
  --warn-bg: #fff3d6;
  --s1: #2a78d6;
  --seq-250: #86b6ef;
  --seq-350: #5598e7;
  --seq-450: #2a78d6;
  --seq-550: #1c5cab;
  --seq-650: #104281;
  --r: 16px;
  --font: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* ---------- Кнопки и поля ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: rgba(11, 11, 11, .25); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #e84a10; border-color: #e84a10; }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-danger { color: var(--bad); }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-icon { width: 38px; padding: 0; }
.input, .select { height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 12px; outline: none; min-width: 0; }
.input:focus, .select:focus { border-color: var(--ink); }
textarea.input { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- Вход ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(800px 400px at 80% 0%, rgba(255, 91, 31, .08), transparent 60%), var(--bg); }
.login-box { width: 100%; max-width: 380px; background: var(--surface); border-radius: 20px; padding: 32px; border: 1px solid var(--line); box-shadow: 0 30px 60px rgba(20, 23, 28, .08); }
.login-box h1 { font-size: 22px; margin: 18px 0 6px; }
.login-box p { color: var(--muted); margin: 0 0 20px; }
.login-box form { display: grid; gap: 12px; }
.login-box .input { height: 46px; }
.login-box .btn { height: 46px; }
.login-err { color: var(--bad); font-size: 13px; min-height: 18px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .08em; font-size: 16px; text-decoration: none; }
.logo-mark { width: 28px; height: 28px; border: 3px solid currentColor; position: relative; flex: none; }
.logo-mark::after { content: ""; position: absolute; right: -3px; bottom: -3px; width: 11px; height: 11px; background: var(--accent); }

/* ---------- Каркас ---------- */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100%; }
.sidebar { background: var(--side); color: var(--side-ink); padding: 20px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.sidebar .logo { color: #fff; padding: 4px 8px; }
.sidebar .logo small { display: block; font-size: 11px; letter-spacing: 0; font-weight: 500; color: #7d8591; }
.side-nav { display: grid; gap: 2px; }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; text-decoration: none; font-weight: 500; }
.side-nav a:hover { background: var(--side-2); color: #fff; }
.side-nav a.active { background: var(--side-2); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.side-nav .count { margin-left: auto; font-size: 12px; font-weight: 700; background: var(--accent); color: #fff; border-radius: 99px; padding: 1px 7px; }
.side-foot { margin-top: auto; display: grid; gap: 8px; font-size: 12px; }
.mode { display: flex; gap: 8px; align-items: flex-start; padding: 10px; border-radius: 10px; background: var(--side-2); line-height: 1.35; }
.mode i { width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; flex: none; }
.mode b { color: #fff; display: block; }
.side-foot a, .side-foot button { color: var(--side-ink); background: none; border: 0; text-align: left; padding: 6px 10px; border-radius: 8px; text-decoration: none; display: flex; gap: 8px; align-items: center; }
.side-foot a:hover, .side-foot button:hover { background: var(--side-2); color: #fff; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 28px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.topbar h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.topbar .search { width: 280px; }
.menu-btn { display: none; }
.view { padding: 24px 28px 48px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; width: 250px; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; box-shadow: 20px 0 60px rgba(0, 0, 0, .3); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .topbar .search { display: none; }
  .view { padding: 16px; }
}

/* ---------- Карточки и сетки ---------- */
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 1200px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-main { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .g4, .g2 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.card-head span { font-size: 12px; color: var(--muted); }

.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin: 6px 0 4px; line-height: 1.1; }
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.delta .i { width: 14px; height: 14px; }
.delta.up .i { color: var(--good); }
.delta.down .i { color: var(--bad); }
.tile .spark { display: block; width: 100%; height: 34px; margin-top: 10px; }

/* ---------- Графики ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--s1); transition: opacity .15s; }
.chart .bar.dim { opacity: .35; }
.chart .hit { fill: transparent; cursor: default; }
.chart .val { fill: var(--ink-2); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .lbl { fill: var(--ink); font-size: 13px; }
.tooltip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 7px 10px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); opacity: 0; transition: opacity .12s; z-index: 5; }
.tooltip.show { opacity: 1; }
.tooltip b { font-size: 13px; }
.table-toggle { font-size: 12px; color: var(--muted); background: none; border: 0; padding: 0; text-decoration: underline; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tbody tr { cursor: pointer; }
.t tbody tr:hover { background: #f4f3ef; }
.t .r { text-align: right; }
.t td.name b { display: block; }
.t td.name span { font-size: 12px; color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 50%; }
.sla { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--bad-bg); color: var(--bad); margin-left: 6px; }
.sla.ok { background: var(--good-bg); color: var(--good); }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 6px; background: #efeee9; color: var(--ink-2); white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

/* ---------- Панель фильтров ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-weight: 500; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .c { font-size: 11px; opacity: .7; }
.pager { display: flex; justify-content: space-between; align-items: center; padding-top: 14px; color: var(--muted); font-size: 13px; }

/* ---------- Канбан ---------- */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(230px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.col { background: #ebe9e4; border-radius: 14px; padding: 10px; min-height: 240px; transition: background .15s; }
.col.over { background: #e1ded6; box-shadow: inset 0 0 0 2px var(--ink); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 10px; font-weight: 700; }
.col-head i { width: 8px; height: 8px; border-radius: 50%; }
.col-head .c { color: var(--muted); font-weight: 600; }
.col-head .sum { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 500; }
.k-card { background: var(--surface); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; border: 1px solid var(--line); cursor: grab; box-shadow: 0 1px 2px rgba(0, 0, 0, .04); }
.k-card:active { cursor: grabbing; }
.k-card.dragging { opacity: .4; }
.k-card b { display: block; }
.k-card .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.k-card .foot { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12px; }

/* ---------- Карточка заявки (drawer) ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-bg { position: absolute; inset: 0; background: rgba(11, 11, 11, .35); }
.drawer-box { position: absolute; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--surface); display: flex; flex-direction: column; animation: slide .22s ease; box-shadow: -20px 0 60px rgba(0, 0, 0, .15); }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.drawer-head h2 { margin: 0; font-size: 20px; }
.drawer-body { padding: 18px 22px 28px; overflow-y: auto; display: grid; gap: 18px; align-content: start; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 13px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.sec-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.est-box { background: #f4f3ef; border-radius: 12px; padding: 12px 14px; }
.est-box b { font-size: 20px; }
.notes { display: grid; gap: 8px; }
.note { border-left: 2px solid var(--grid); padding: 2px 0 2px 12px; font-size: 13px; }
.note time { display: block; font-size: 11px; color: var(--muted); }
.contact-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Telegram ---------- */
.tg-preview { background: #dfe8ef; border-radius: 14px; padding: 18px; min-height: 200px; background-image: radial-gradient(rgba(255, 255, 255, .5) 1px, transparent 1px); background-size: 14px 14px; }
.bubble { background: #fff; border-radius: 12px 12px 12px 4px; padding: 10px 12px 18px; max-width: 360px; font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; position: relative; box-shadow: 0 1px 1px rgba(0, 0, 0, .08); word-break: break-word; }
.bubble .time { position: absolute; right: 10px; bottom: 4px; font-size: 11px; color: #8a9aa8; }
.bubble-from { font-size: 13px; font-weight: 700; color: #2a78d6; margin-bottom: 4px; }
.bubble-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 4px; max-width: 360px; }
.bubble-btns span { background: rgba(255, 255, 255, .75); border-radius: 8px; text-align: center; font-size: 13px; font-weight: 600; padding: 7px; color: #2a6aa8; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: #d7d5ce; transition: background .2s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + i { background: var(--ink); }
.switch input:checked + i::after { transform: translateX(18px); }
.steps-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; color: var(--ink-2); }
.vars { display: flex; flex-wrap: wrap; gap: 6px; }
.vars button { font-family: ui-monospace, Consolas, monospace; font-size: 12px; padding: 3px 7px; border-radius: 6px; border: 1px solid var(--line); background: #f4f3ef; }
.alert { padding: 10px 12px; border-radius: 10px; font-size: 13px; background: var(--warn-bg); color: #6b4d00; }
.alert.ok { background: var(--good-bg); color: var(--good); }
.alert.err { background: var(--bad-bg); color: var(--bad); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
