:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c1f24;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --accent-soft: #e8efff;
  --green: #16a34a;
  --green-soft: #e6f6ec;
  --amber: #b45309;
  --amber-soft: #fdf3e2;
  --red: #dc2626;
  --red-soft: #fdecec;
  --bubble-in: #ffffff;
  --bubble-out: #dfeaff;
  --bubble-op: #e3f5e8;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  color-scheme: light;
}

/* the panel is always light (white), whatever the computer's theme */

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- layout ---------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 12px; font-weight: 800;
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; color: var(--text);
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--border); font-size: 13px; }
.sidebar-foot .who { font-weight: 600; }

.main { flex: 1; min-width: 0; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

.topbar { display: none; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 5;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px;
  }
  .topbar select { flex: 1; }
  .main { padding: 16px; }
}

/* ---------- building blocks ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card, .chats > .card + .card { margin-top: 0; }
a.card { color: inherit; display: block; }
a.card:hover { text-decoration: none; border-color: var(--accent); }

.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 2px; }
.stat .hint { color: var(--muted); font-size: 12px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.spacer { flex: 1; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; word-break: break-word; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }

input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"], input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.row > select, .row > input[type="number"], .row > input[type="datetime-local"] { width: auto; }

label.field { display: block; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }

.alert { padding: 10px 12px; border-radius: 8px; background: var(--amber-soft); color: var(--amber); }
.alert.red { background: var(--red-soft); color: var(--red); }
.alert.blue { background: var(--accent-soft); color: var(--accent); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---------- login ---------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login .brand { padding: 0 0 16px; }

/* ---------- chats ---------- */

.chats { display: grid; grid-template-columns: minmax(230px, 320px) 1fr; gap: 16px; height: calc(100vh - 190px); min-height: 420px; }
.mobile-only { display: none; }
@media (max-width: 860px) { .mobile-only { display: inline-flex; } }
.chat-list { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.chat-list .search { padding: 12px; border-bottom: 1px solid var(--border); }
.chat-items { overflow-y: auto; flex: 1; }
.chat-item { display: block; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.chat-item:hover { background: var(--surface-2); text-decoration: none; }
.chat-item.active { background: var(--accent-soft); }
.chat-item .top { display: flex; justify-content: space-between; gap: 8px; }
.chat-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }

.chat-pane { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.msg { max-width: min(78%, 620px); padding: 8px 12px; border-radius: 12px; background: var(--bubble-in); box-shadow: var(--shadow); }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg.op { background: var(--bubble-op); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.msg img.media { display: block; max-width: 100%; max-height: 320px; border-radius: 8px; margin-bottom: 4px; }
.msg audio.media { display: block; width: 260px; max-width: 100%; margin-bottom: 4px; }
.composer { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; }

@media (max-width: 860px) {
  .chats { grid-template-columns: 1fr; height: auto; }
  .chats.has-open .chat-list { display: none; }
  .chats:not(.has-open) .chat-pane { display: none; }
  .chat-pane { height: calc(100vh - 150px); }
}

.qr { background: #fff; padding: 12px; border-radius: 8px; width: 260px; max-width: 100%; }
.qr img { width: 100%; display: block; }

/* ---------- misc ---------- */

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }

.secret {
  font-family: ui-monospace, Consolas, monospace; font-size: 16px; padding: 10px 12px;
  background: var(--surface-2); border-radius: 8px; user-select: all; word-break: break-all;
}

.dialog-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.dialog { width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: calc(100% - 32px); z-index: 30;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red); color: #fff; }
#toast.action { pointer-events: auto; display: flex; align-items: center; gap: 12px; }
#toast.action .btn { color: var(--text); }

.icon-btn {
  border: none; background: none; cursor: pointer; color: var(--muted);
  padding: 4px 8px; border-radius: 6px; font-size: 13px;
}
.icon-btn:hover { background: var(--red-soft); color: var(--red); }

/* ---- broadcast builder: a colour per screen, buttons that look like buttons ---- */
.step-title { display: flex; align-items: center; gap: 10px; }
.step-num {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--accent); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700;
}
.flow-screen { border-left: 6px solid var(--sc); }
.flow-tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; cursor: pointer;
  color: var(--sc); background: color-mix(in srgb, var(--sc) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--sc) 45%, transparent);
}
.flow-tag.big { font-size: 14px; padding: 4px 14px; }
.flow-buttons { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.flow-btn { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.flow-btn-face {
  display: inline-block; padding: 6px 14px; border-radius: 8px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.flow-btn-face.small { padding: 2px 10px; font-size: 12px; }
.flow-btn-face.wide { display: block; text-align: center; }
.flow-map { display: flex; flex-direction: column; gap: 8px; }
.flow-map-screen { border-left: 4px solid var(--sc); background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.flow-map-btn { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 0 14px; font-size: 13px; }

/* ---- «Клиенты»: the funnel and the requests ---- */
.funnel-step { display: flex; flex-direction: column; gap: 4px; }
.funnel-bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.funnel-fill.amber { background: var(--amber); }
.funnel-fill.green { background: var(--green); }
.lead-card { border-left: 5px solid var(--border); }
.lead-card.red { border-left-color: var(--red); }
.lead-card.amber { border-left-color: var(--amber); }
.lead-card.blue { border-left-color: var(--accent); }
.lead-card.green { border-left-color: var(--green); }
.lead-questions { margin: 4px 0 0; padding-left: 18px; }

/* ---- «ИИ и характер»: the sandbox chat ---- */
.ai-sandbox { background: var(--surface-2); border-radius: 10px; padding: 12px; min-height: 80px; max-height: 480px; overflow-y: auto; }
.ai-msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; display: flex; flex-direction: column; gap: 4px; }
.ai-msg.dealer { align-self: flex-end; background: var(--accent-soft); }
.ai-msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }

/* ---- the menu in groups ---- */
.nav-group {
  margin: 14px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.nav a { justify-content: flex-start; gap: 10px; }
.nav-icon { width: 20px; text-align: center; flex: none; }
.nav-label { flex: 1; min-width: 0; }
.nav-count {
  min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff;
  font-size: 12px; font-weight: 700; text-align: center; line-height: 20px;
}
.sidebar { overflow-y: auto; width: 240px; }
.page-about { margin: -10px 0 18px; font-size: 14px; }

/* ---- AI spend by day, the overview's sections ---- */
.spend-days { display: flex; align-items: flex-end; gap: 3px; height: 90px; padding: 6px; background: var(--surface-2); border-radius: 8px; }
.spend-day { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.spend-bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; }
.funnel-fill.red { background: var(--red); }
.section-title { margin: 6px 0 10px; font-size: 16px; }
.grid + .section-title { margin-top: 22px; }
.card.stat.attention { border-color: var(--red); background: var(--red-soft); }

/* ---- the dossier: blocks and chips ---- */
.dossier-block { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: var(--surface-2); }
.dossier-head { display: flex; align-items: center; gap: 12px; }
.dossier-head h3 { margin: 0; }
.dossier-icon { font-size: 22px; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--surface); flex: none; }
.chips-field { gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.rows { flex-direction: column; align-items: stretch; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px 6px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  font-size: 14px; line-height: 1.3;
}
.chips.rows .chip { border-radius: 10px; justify-content: space-between; }
.chip-text { overflow-wrap: anywhere; }
.chip-x {
  border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px;
  width: 22px; height: 22px; border-radius: 50%; flex: none; padding: 0;
}
.chip-x:hover { background: var(--red-soft); color: var(--red); }
.chips-add input { flex: 1; min-width: 180px; }
.dossier-block textarea { min-height: 110px; }

/* ---- a list as one field: chips inside, «+» at the end ---- */
div.field > span:first-child { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.chip-box {
  display: flex; align-items: stretch; min-height: 38px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); overflow: hidden;
}
.chip-box:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip-box > .chips { flex: 0 1 auto; align-items: center; gap: 4px; padding: 4px 6px; }
.chip-box > .chips:empty { padding: 0; }
.chip-box > .chips > .muted { padding: 0 4px; }
.chip-box .chip { padding: 2px 4px 2px 10px; font-size: 13px; }
.chip-box .chip-x { width: 20px; height: 20px; font-size: 12px; }
.chip-box > input.chip-inline { flex: 1; min-width: 90px; border: none; outline: none; background: transparent; padding: 6px 8px; }
.chip-box > .chips:not(:empty) + input.chip-inline { padding-left: 2px; }
.chip-box-add {
  margin-left: auto; flex: none; width: 42px; border: none; border-left: 1px solid var(--border);
  background: transparent; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer;
}
.chip-box-add:hover { background: var(--accent-soft); color: var(--accent); }

/* ---- a list with «+ Добавить» on its title line, and the menu it opens ---- */
.field-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.field-head > span:first-child { font-size: 12px; color: var(--muted); }
.pick-menu {
  position: absolute; z-index: 25; width: 280px; max-height: 320px; overflow-y: auto; padding: 6px;
  display: flex; flex-direction: column; gap: 2px; box-shadow: 0 8px 24px rgba(16, 24, 40, 0.14);
}
.card.pick-menu + .card { margin-top: 0; }
.pick-item { text-align: left; border: none; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.pick-item:hover { background: var(--accent-soft); color: var(--accent); }

/* ---- «Бухгалтерия»: what the dealer pays each month, big and first ---- */
.pay-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.pay-tile {
  border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface);
  display: flex; flex-direction: column; gap: 8px; border-top: 4px solid var(--green);
}
.pay-tile.empty-sum { border-top-color: var(--border); background: var(--surface-2); }
.pay-tile-head { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.pay-tile-head .spacer { flex: 1; }
.pay-sum { display: flex; align-items: center; gap: 6px; }
.pay-sum input[type="number"] {
  font-size: 24px; font-weight: 700; padding: 4px 8px; width: 100%; min-width: 0;
  border-color: transparent; background: transparent;
}
.pay-sum input[type="number"]:hover:not(:disabled), .pay-sum input[type="number"]:focus { border-color: var(--border); background: var(--surface); }
.pay-sum select { width: auto; font-size: 16px; font-weight: 600; }
.pay-tile textarea { font-size: 13px; min-height: 0; }
.pay-add {
  border: 2px dashed var(--border); border-radius: 12px; background: transparent; cursor: pointer;
  color: var(--muted); font-weight: 600; min-height: 80px;
}
.pay-add:hover { border-color: var(--accent); color: var(--accent); }
.pay-total { font-size: 15px; }
.pay-total strong { font-size: 18px; }
details.acc-part { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
details.acc-part > summary {
  cursor: pointer; padding: 10px 14px; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px;
}
details.acc-part > summary::-webkit-details-marker { display: none; }
details.acc-part > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
details.acc-part[open] > summary::before { transform: rotate(90deg); }
details.acc-part > .acc-part-body { padding: 0 14px 14px; }

/* ---- «Напоминания Марины»: numbered steps and a preview of the message ---- */
.rem-summary { font-size: 15px; font-weight: 600; }
.rem-step { display: flex; gap: 12px; align-items: flex-start; }
.rem-step > .step-num { margin-top: 2px; width: 26px; height: 26px; font-size: 13px; }
.rem-step > .rem-step-body { flex: 1; min-width: 0; }
.rem-step-title { font-weight: 600; margin-bottom: 6px; }
.rem-preview {
  background: var(--green-soft); border-radius: 12px 12px 12px 4px; padding: 10px 14px; max-width: 520px;
  white-space: pre-wrap; border: 1px solid color-mix(in srgb, var(--green) 25%, transparent);
}
.card.rem-off { opacity: .65; }

/* ---- «Фильмы и AR» ---- */
.catalog-grid { align-items: start; }
.catalog-list { display: flex; flex-direction: column; gap: 4px; max-height: 520px; overflow-y: auto; }
.catalog-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
.catalog-title { font-weight: 600; }

.catalog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.catalog-projects { grid-column: 1 / -1; }
.catalog-projects .catalog-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; max-height: none; }
@media (max-width: 800px) { .catalog-grid { grid-template-columns: 1fr; } }
.catalog-name { gap: 4px; flex: 1; min-width: 0; }
.catalog-row > .muted { white-space: nowrap; }
.catalog-name .badge { font-size: 11px; }
.row.wrap { flex-wrap: wrap; }
.who-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; max-height: 360px; overflow-y: auto; }
.who-row { display: flex; flex-direction: column; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); text-decoration: none; color: inherit; }
.who-row:hover { outline: 1px solid var(--accent, #4f8cff); }

/* «Обзор»: what waits for you, one line each; the search at the top */
.page-head .search-box { position: relative; margin-left: auto; width: min(320px, 100%); }
.search-results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); display: flex; flex-direction: column; gap: 2px; padding: 6px; max-height: 360px; overflow: auto; }
.search-results a { padding: 6px 8px; border-radius: 6px; color: var(--text); }
.search-results a:hover { background: var(--surface-2); text-decoration: none; }
.todo-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-top: 1px solid var(--border); color: var(--text); }
.todo-row:hover { text-decoration: none; background: var(--surface-2); }
.todo-row .badge { min-width: 92px; text-align: center; }
.todo-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amber-text { color: var(--amber); }
@media (max-width: 860px) {
  .page-head .search-box { width: 100%; margin-left: 0; }
  .todo-text { white-space: normal; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
  .todo-row .badge { min-width: 0; }
}
