:root {
  --bg: #e9edf4; --panel: #ffffff; --panel2: #f3f5f9; --text: #101b2d; --muted: #6b7686; --line: #dfe4ec;
  --navy: #12233f; --navy-text: #ffffff; --accent: #12233f; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --ok-soft: #dcfce7; --warn-soft: #fef3c7; --info-soft: #e0e7ff; --info: #3730a3;
  --shadow: 0 1px 2px rgba(16, 27, 45, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1522; --panel: #182133; --panel2: #1f2a3f; --text: #e8ecf4; --muted: #93a0b5; --line: #2a3650;
    --navy: #e8ecf4; --navy-text: #101b2d; --accent: #e8ecf4;
    --ok-soft: #14351f; --warn-soft: #3b2f10; --info-soft: #232a55; --info: #b6bdff;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .grow { flex: 1; }
.ok { color: var(--ok); } .err { color: var(--bad); }

/* --- формы --- */
label { display: grid; gap: 4px; font-weight: 600; font-size: 14px; }
label .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
input, textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); font: inherit; font-weight: 400;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--navy); outline-offset: -1px; }
input[type=checkbox] { width: auto; }
button {
  padding: 9px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
button:hover { border-color: var(--navy); }
button.primary { background: var(--navy); border-color: var(--navy); color: var(--navy-text); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; } .row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.stack { display: grid; gap: 14px; }

/* --- карточки, таблицы, бейджи --- */
.card { background: var(--panel); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); }
.card.flush { padding: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th { text-align: left; padding: 12px 16px; background: var(--panel2); font-weight: 700; white-space: nowrap; }
th:first-child { border-radius: 12px 0 0 12px; } th:last-child { border-radius: 0 12px 12px 0; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.empty { text-align: center; color: var(--muted); padding: 22px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600; background: var(--info-soft); color: var(--info); }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn, .badge.handoff { background: var(--warn-soft); color: var(--warn); }
.badge.gray, .badge.closed { background: var(--panel2); color: var(--muted); } .badge.bad { background: #fee2e2; color: var(--bad); }
.stat { font-size: 28px; font-weight: 800; line-height: 1.2; }
code { background: var(--panel2); padding: 2px 6px; border-radius: 6px; word-break: break-all; font-size: 13px; }
pre { background: var(--panel2); padding: 12px; border-radius: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; font-size: 13px; margin: 0; }
.list > * { padding: 12px 0; border-bottom: 1px solid var(--line); } .list > *:last-child { border-bottom: 0; }

/* --- каркас --- */
.shell { display: grid; grid-template-columns: 296px 1fr; min-height: 100vh; }
.shell.collapsed { grid-template-columns: 84px 1fr; }
.side { background: var(--panel); padding: 20px 24px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { display: flex; align-items: center; justify-content: space-between; font-weight: 800; font-size: 22px; margin-bottom: 8px; }
.side .brand button { border: 0; background: none; padding: 4px 8px; font-size: 18px; }
.balance { border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; margin-bottom: 12px; background: var(--panel2); }
.balance .top { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; }
.balance .chip { background: var(--panel); border-radius: 8px; padding: 1px 8px; font-size: 12.5px; color: var(--text); }
.balance .sum { font-size: 22px; font-weight: 800; }
.balance .left { font-size: 13px; color: var(--ok); font-weight: 600; } .balance .left.low { color: var(--warn); }
.nav a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.nav a:hover { background: var(--panel2); }
.nav a.active { background: var(--navy); color: var(--navy-text); }
.nav a.admin { background: var(--info-soft); color: var(--info); } .nav a.admin.active { background: var(--navy); color: var(--navy-text); }
.nav svg, .side svg { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side .links { margin-top: auto; padding-top: 14px; display: grid; gap: 8px; }
.side .links a.mini { color: var(--muted); font-size: 14px; padding: 4px 2px; }
.side .links button { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; }
.online { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.collapsed .side { padding: 20px 12px; align-items: center; }
.collapsed .side .label, .collapsed .balance, .collapsed .brand .name, .collapsed .side .links a.mini { display: none; }
.collapsed .nav a { padding: 12px; }
.collapsed .side .links button .label { display: none; }

.content { padding: 24px 32px 40px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar .page-icon { width: 54px; height: 54px; border-radius: 16px; background: var(--panel); display: grid; place-items: center; }
.topbar .page-icon svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.agentbox { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 16px; padding: 8px 14px; min-width: 210px; }
.agentbox select { border: 0; background: none; padding: 6px 4px; font-weight: 600; }
.agentbox select:focus { outline: none; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #cbd5e1; border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: #22c55e; } .switch input:checked + span::after { transform: translateX(20px); }
.usercard { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 16px; padding: 8px 14px; cursor: pointer; position: relative; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: #86efac; color: #14532d; display: grid; place-items: center; font-weight: 800; }
.usercard .who { min-width: 0; } .usercard .who b { display: block; line-height: 1.2; }
.usercard .who span { display: block; font-size: 12.5px; color: var(--muted); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar h1 { white-space: nowrap; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px; min-width: 180px; z-index: 30; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 8px 12px; border: 0; background: none; border-radius: 8px; font-weight: 600; }
.menu a:hover, .menu button:hover { background: var(--panel2); }
.filters { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.filters label { min-width: 220px; }

@media (max-width: 900px) {
  .shell, .shell.collapsed { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; }
  .side .brand { margin: 0 12px 0 0; } .balance { margin: 0; flex: 1; min-width: 190px; }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; } .nav a { margin: 0; padding: 8px 12px; }
  .side .links { display: none; }
  .content { padding: 16px; } .agentbox { min-width: 0; flex: 1; }
}

/* --- вкладки агента --- */
.tabs { display: flex; gap: 4px; margin: 0 0 18px; overflow-x: auto; background: var(--panel); border-radius: 14px; padding: 5px; }
.tabs a { padding: 9px 14px; color: var(--muted); border-radius: 10px; white-space: nowrap; font-weight: 600; }
.tabs a.active { background: var(--navy); color: var(--navy-text); }

/* --- чат --- */
.chat { display: grid; grid-template-rows: 1fr auto; height: 62vh; min-height: 360px; }
.msgs { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 2px 12px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.msg.client { align-self: flex-start; background: var(--panel2); }
.msg.bot { align-self: flex-end; background: var(--navy); color: var(--navy-text); }
.msg.manager { align-self: flex-end; background: var(--ok); color: #fff; }
.msg .who { display: block; font-size: 11px; opacity: .75; }
.dialogs { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
@media (max-width: 960px) { .dialogs { grid-template-columns: 1fr; } }
.conv { padding: 12px; border-radius: 12px; cursor: pointer; }
.conv:hover, .conv.active { background: var(--panel2); }
.conv .unread { background: var(--navy); color: var(--navy-text); border-radius: 99px; padding: 0 7px; font-size: 11px; }

/* --- модальные окна, тосты --- */
.overlay { position: fixed; inset: 0; background: rgba(8, 15, 30, .55); display: grid; place-items: center; padding: 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 20px; padding: 24px; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; }
.modal .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal .head button { border: 0; background: none; font-size: 22px; padding: 0 6px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; }

/* --- аналитика --- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 180px; padding-top: 8px; }
.bars .bar { flex: 1; background: var(--navy); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; position: relative; }
.bars .bar:hover { opacity: 1; }
.bars .bar.zero { background: var(--line); opacity: 1; }
.legend { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 4px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.guide h2 { margin-top: 22px; } .guide p, .guide li { color: var(--text); } .guide ol, .guide ul { padding-left: 22px; }

/* --- маркет --- */
.mtabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.mtabs a { padding: 12px 14px; color: var(--muted); font-weight: 600; white-space: nowrap; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.mtabs a:hover { color: var(--text); } .mtabs a.active { color: var(--text); border-color: var(--navy); }
.market { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.appcard { display: flex; flex-direction: column; gap: 6px; cursor: pointer; transition: box-shadow .12s, transform .12s; min-height: 210px; }
.appcard:hover { box-shadow: 0 6px 20px rgba(16, 27, 45, .12); transform: translateY(-2px); }
.appcard h3 { margin: 6px 0 0; font-size: 16px; } .appcard p { margin: 0; flex: 1; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.appicon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; flex: none; }
.appfoot { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 6px; }
.pricechip { background: var(--panel2); padding: 4px 10px; border-radius: 8px; font-weight: 600; font-size: 13.5px; }
.pricechip.free { background: var(--ok-soft); color: var(--ok); }
.swatch { display: inline-block; cursor: pointer; } .swatch input { position: absolute; opacity: 0; width: 0; height: 0; }
.swatch span { display: block; width: 28px; height: 28px; border-radius: 8px; border: 2px solid transparent; }
.swatch input:checked + span { border-color: var(--navy); }
details summary { cursor: pointer; }
