:root {
  --ink: #15223b;
  --ink-2: #2c3b57;
  --ink-soft: #8d9bb3;
  --paper: #f4f6f8;
  --surface: #ffffff;
  --line: #dde3ea;
  --line-strong: #c9d2dd;
  --text: #1b2433;
  --text-2: #4c5a70;
  --muted: #7a879b;
  --action: #2457d6;
  --action-hover: #1c47b4;
  --action-soft: #e8eefc;
  --open: #0f9d74;
  --open-soft: #e3f4ee;
  --closing: #d99a00;
  --closing-soft: #fbf1d9;
  --closed: #c2413a;
  --closed-soft: #f9e5e3;
  --series-in: #2f6bdb;
  --series-out: #b85c1e;
  --out-bubble: #e9effb;
  --radius-s: 6px;
  --radius-m: 10px;
  --shadow-pop: 0 12px 32px rgba(21, 34, 59, 0.18);
  font-family: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--action); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* --- shell ---------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--ink);
  color: #e7ecf4;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { padding: 0 8px 18px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); margin-bottom: 14px; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; color: #fff; }
.brand-line { display: flex; align-items: center; gap: 8px; margin-top: 6px; color: var(--ink-soft); font-size: 13px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-soft); flex: none; }
.pulse.ok { background: #3ad19c; }
.pulse.warn { background: #f2b931; }
.pulse.bad { background: #ff6a5e; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: var(--radius-s); color: #c6d0df; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255, 255, 255, 0.12); color: #fff; }
.nav .badge { background: #ff6a5e; color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.nav-sep { height: 1px; background: rgba(255, 255, 255, 0.08); margin: 10px 4px; }
.side-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, 0.08); font-size: 13px; color: var(--ink-soft); }
.side-foot button { background: none; border: 0; padding: 0; color: #c6d0df; cursor: pointer; }
.side-foot button:hover { color: #fff; }

.main { min-width: 0; padding: 28px 36px 48px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.015em; margin: 0; color: var(--ink); }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; color: var(--ink); }
.sub { color: var(--text-2); margin: 4px 0 0; }

/* --- building blocks ------------------------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px 20px; }
.stack > * + * { margin-top: 18px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: var(--radius-s); padding: 7px 14px; cursor: pointer; font-weight: 500;
}
.btn:hover { border-color: var(--ink-soft); }
.btn.primary { background: var(--action); border-color: var(--action); color: #fff; }
.btn.primary:hover { background: var(--action-hover); }
.btn.danger { color: var(--closed); border-color: #e7b7b3; }
.btn:disabled { opacity: 0.5; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-s); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.on { background: var(--ink); color: #fff; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-weight: 500; color: var(--text-2); font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
input[type="text"], input[type="password"], input[type="search"], select, textarea {
  border: 1px solid var(--line-strong); border-radius: var(--radius-s); padding: 8px 10px; background: #fff; width: 100%;
}
textarea { resize: vertical; min-height: 44px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; background: #eef1f5; color: var(--text-2); }
.chip.open { background: var(--open-soft); color: #0b7356; }
.chip.closing { background: var(--closing-soft); color: #8a6200; }
.chip.closed { background: var(--closed-soft); color: #9a2f29; }
.chip.info { background: var(--action-soft); color: var(--action); }
.toast {
  position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius-m);
  box-shadow: var(--shadow-pop); max-width: 420px; z-index: 50;
}
.toast.bad { background: var(--closed); }
.empty { color: var(--muted); padding: 24px 0; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid td.r, table.grid th.r { text-align: right; }

/* --- overview -------------------------------------------------------------------- */
.status-line { font-size: 26px; font-weight: 600; letter-spacing: -0.015em; color: var(--ink); line-height: 1.25; max-width: 30ch; }
.status-line .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 10px; vertical-align: 3px; }
.status-sub { color: var(--text-2); margin-top: 8px; }
.issues { border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--surface); }
.issue { padding: 10px 14px 10px 16px; border-left: 4px solid var(--closing); }
.issue + .issue { border-top: 1px solid var(--line); }
.issue.bad { border-left-color: var(--closed); }
.today { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--surface); }
.today > div { padding: 14px 16px; }
.today > div + div { border-left: 1px solid var(--line); }
.today .v { font-size: 22px; font-weight: 600; color: var(--ink); }
.today .k { color: var(--muted); font-size: 13px; }
.today .v.bad { color: var(--closed); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.tip {
  position: absolute; pointer-events: none; background: var(--ink); color: #fff; padding: 6px 10px; border-radius: var(--radius-s);
  font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); box-shadow: var(--shadow-pop);
}
.waitlist a.wrow { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 10px 4px; color: inherit; border-bottom: 1px solid var(--line); }
.waitlist a.wrow:last-child { border-bottom: 0; }
.waitlist a.wrow:hover { background: #f8fafc; text-decoration: none; }
.wname { font-weight: 500; }
.wtext { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wtime { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* --- dialogs --------------------------------------------------------------------- */
.dialogs { display: grid; grid-template-columns: 320px minmax(0, 1fr) 280px; height: calc(100vh - 56px); border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--surface); overflow: hidden; }
.dlist { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.dlist-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.dlist-items { overflow-y: auto; flex: 1; }
.ditem { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; color: inherit; }
.ditem:hover { background: #f8fafc; text-decoration: none; }
.ditem.active { background: var(--action-soft); }
.ditem .dn { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ditem .dt { color: var(--text-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ditem .dm { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.ditem .waiting { display: block; width: 8px; height: 8px; border-radius: 50%; background: var(--closed); margin: 4px 0 0 auto; }
.conv { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #f7f9fb; }
.conv-head { padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; gap: 12px; }
.conv-head .who { font-weight: 600; }
.msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); padding: 8px 0; }
.bubble { max-width: min(560px, 78%); padding: 8px 12px 6px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.bubble.out { align-self: flex-end; background: var(--out-bubble); border-color: #d3def5; }
.bubble.tpl { border-style: dashed; }
.bubble .meta { display: flex; gap: 8px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--muted); margin-top: 3px; }
.bubble .who { font-size: 11px; color: var(--text-2); font-weight: 500; margin-bottom: 2px; }
.ticks.read { color: var(--action); }
.ticks.failed { color: var(--closed); }
.bubble .err { color: var(--closed); font-size: 12px; margin-top: 4px; }
.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 12px 14px; }
.composer .note { font-size: 12px; margin-bottom: 8px; color: var(--text-2); }
.composer .note.closed { color: #9a2f29; }
.composer .bar { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 180px; }
.cpanel { border-left: 1px solid var(--line); padding: 18px; overflow-y: auto; }
.cpanel .big-ring { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.cpanel dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.cpanel dt { color: var(--muted); }
.cpanel dd { margin: 0; overflow-wrap: anywhere; }
.cpanel h3 { font-size: 13px; color: var(--muted); font-weight: 500; margin: 18px 0 8px; }
.pick { position: absolute; bottom: 64px; left: 14px; right: 14px; max-height: 320px; overflow-y: auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-m); box-shadow: var(--shadow-pop); z-index: 5; }
.pick button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 10px 12px; cursor: pointer; }
.pick button:hover { background: #f8fafc; }
.composer { position: relative; }

/* --- templates ------------------------------------------------------------------- */
.tfam { display: grid; grid-template-columns: 220px 1fr auto; gap: 16px; padding: 14px 4px; border-bottom: 1px solid var(--line); align-items: start; }
.tfam:last-child { border-bottom: 0; }
.tfam .tn { font-weight: 600; overflow-wrap: anywhere; }
.tbody { color: var(--text-2); white-space: pre-wrap; max-height: 4.4em; overflow: hidden; }
.tform { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; }
.wa-preview { background: #ece5dd; border-radius: var(--radius-m); padding: 18px; }
.wa-preview .bubble { max-width: 100%; }
.wa-preview .qr { background: #fff; border-radius: 10px; text-align: center; padding: 8px; margin-top: 6px; color: #3b7cc6; font-weight: 500; }

/* --- switches ------------------------------------------------------------------- */
.switch-row { display: grid; grid-template-columns: 1fr auto; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); align-items: center; }
.switch-row:last-child { border-bottom: 0; }
.switch-row .t { font-weight: 500; }
.switch-row .d { color: var(--muted); font-size: 13px; }
.toggle { position: relative; width: 42px; height: 24px; border-radius: 12px; background: var(--line-strong); border: 0; cursor: pointer; flex: none; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left 0.15s; }
.toggle.on { background: var(--open); }
.toggle.on::after { left: 21px; }
dl.kv { display: grid; grid-template-columns: 220px 1fr; gap: 8px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* --- login ------------------------------------------------------------------------- */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 16px; }
.login form { width: min(360px, 100%); background: var(--surface); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login .brand-name { color: var(--ink); font-size: 22px; }
.login .err { color: var(--closed); min-height: 1.2em; font-size: 13px; }

/* --- small screens ------------------------------------------------------------------ */
@media (max-width: 1100px) {
  .dialogs { grid-template-columns: 280px minmax(0, 1fr); }
  .cpanel { display: none; }
  .today { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .today > div:nth-child(5) { border-left: 0; }
  .today > div:nth-child(n + 5) { border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 12px 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { display: none; }
  .main { padding: 18px 16px 40px; }
  .dialogs { grid-template-columns: 1fr; height: auto; min-height: 70vh; }
  .dialogs.has-active .dlist { display: none; }
  .dialogs:not(.has-active) .conv { display: none; }
  .today { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .today > div { border-left: 0 !important; border-top: 1px solid var(--line); }
  .tfam, .tform { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; }
  .status-line { font-size: 21px; }
}
@media (prefers-reduced-motion: reduce) {
  .toggle::after { transition: none; }
}
