/* DROGAN AI — админ-панель. Тёмная тема по умолчанию, светлая по переключателю. */
:root {
  --bg: #0b0f17;
  --panel: #121826;
  --panel-2: #182032;
  --line: #232c40;
  --text: #e6ebf4;
  --muted: #8b97ad;
  --accent: #3b9eff;
  --accent-soft: rgba(59, 158, 255, .14);
  --ok: #34c77b;
  --warn: #f5b041;
  --bad: #f25f5c;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f0f3f8;
  --line: #e1e6ef;
  --text: #141a26;
  --muted: #5d6a80;
  --accent: #1a73e8;
  --accent-soft: rgba(26, 115, 232, .1);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
a { color: var(--accent); }

/* ---------- Кнопки и поля ---------- */
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 9px 16px; border-radius: 9px; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px; padding: 0; }
.link:hover { color: var(--text); }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.error { color: var(--bad); font-size: 14px; margin: 0; }

/* ---------- Бренд ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; letter-spacing: .02em; }
.brand b { color: var(--accent); }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 700; }

/* ---------- Вход ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.login-card h1 { font-size: 20px; }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100%;
  background: linear-gradient(to right, var(--panel) 232px, var(--line) 232px, var(--line) 233px, var(--bg) 233px); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 24px;
  padding: 20px 14px; background: var(--panel); border-right: 1px solid var(--line); }
#nav { display: grid; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: var(--muted); text-decoration: none; font-weight: 500; }
.nav-item:hover { color: var(--text); background: var(--panel-2); }
.nav-item.active { color: var(--text); background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.nav-item .count { margin-left: auto; background: var(--bad); color: #fff; font-size: 12px; border-radius: 10px;
  padding: 0 7px; line-height: 20px; }
.sidebar-foot { margin-top: auto; display: grid; gap: 12px; }
.user { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted);
  padding: 0 4px; }
.main { min-width: 0; }
.view { padding: 28px 32px 48px; max-width: 1280px; }
.view-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  margin-bottom: 24px; }
.view-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.banner { padding: 10px 32px; background: rgba(245, 176, 65, .12); border-bottom: 1px solid rgba(245, 176, 65, .3);
  color: var(--warn); font-size: 14px; }
.banner.bad { background: rgba(242, 95, 92, .12); border-color: rgba(242, 95, 92, .3); color: var(--bad); }

/* ---------- Переключатель периода ---------- */
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { font: inherit; font-size: 13px; border: 0; background: none; color: var(--muted); padding: 6px 12px;
  border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--panel-2); color: var(--text); }

/* ---------- Показатели ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 32px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.alert .value { color: var(--bad); }
.kpi.primary { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; gap: 12px; }
.card-head span { color: var(--muted); font-size: 13px; }

/* ---------- Воронка ---------- */
.funnel { display: grid; gap: 8px; }
.funnel-row { display: grid; grid-template-columns: 200px 1fr 48px; gap: 12px; align-items: center; font-size: 14px; }
.funnel-row .bar { height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.funnel-row .bar i { display: block; height: 100%; background: var(--accent); border-radius: 5px; min-width: 2px; }
.funnel-row.muted .bar i { background: var(--muted); }
.funnel-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.funnel-row.has .n { color: var(--text); font-weight: 600; }

.empty { color: var(--muted); text-align: center; padding: 28px 12px; font-size: 14px; }

/* ---------- Интеграции ---------- */
.integrations { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.integration { display: grid; gap: 10px; align-content: start; }
.integrations .card + .card { margin-top: 0; }
.integration .top { display: flex; justify-content: space-between; align-items: center; }
.integration p { margin: 0; color: var(--muted); font-size: 13px; }
.integration code { font-size: 12px; background: var(--bg); border: 1px solid var(--line); padding: 6px 8px;
  border-radius: 7px; overflow-wrap: anywhere; display: block; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; white-space: nowrap; }
.badge.ok { background: rgba(52, 199, 123, .14); color: var(--ok); }
.badge.off { background: var(--panel-2); color: var(--muted); }
.badge.bad { background: rgba(242, 95, 92, .14); color: var(--bad); }
.badge.warn { background: rgba(245, 176, 65, .14); color: var(--warn); }

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px;
  justify-items: center; width: max-content; max-width: calc(100% - 32px); }
.toast { background: var(--panel-2);
  border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.3); }

/* ---------- Телефон ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; background: var(--bg); }
  .card-head { flex-direction: column; gap: 2px; }
  .sidebar { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center;
    padding: 10px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .sidebar .brand span:last-child, .sidebar-foot .user span, #theme-toggle { display: none; }
  #nav { display: flex; gap: 4px; }
  .nav-item { white-space: nowrap; padding: 7px 10px; }
  .nav-item.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .sidebar-foot { margin: 0 0 0 auto; }
  .view { padding: 20px 16px 40px; }
  .banner { padding: 10px 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 26px; }
  .funnel-row { grid-template-columns: 130px 1fr 36px; font-size: 13px; }
}

/* ---------- AI-тренер ---------- */
.trainer { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.trainer .card + .card { margin-top: 0; }
.tr-chat { display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 480px; padding: 0; overflow: hidden; }
.msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.msg.thinking { color: var(--muted); }
.proposal { border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 12px 14px;
  background: var(--bg); display: grid; gap: 8px; max-width: 95%; }
.proposal-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: 14px; }
.proposal p { margin: 0; font-size: 13px; }
.proposal pre { margin: 0; padding: 8px 10px; border-radius: 7px; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 220px; overflow-y: auto; }
.proposal pre.del, .diff-inline .del { background: rgba(242, 95, 92, .12); color: var(--bad); }
.proposal pre.add, .diff-inline .add { background: rgba(52, 199, 123, .12); color: var(--ok); }
.diff-inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.diff-inline span.del, .diff-inline span.add { padding: 3px 8px; border-radius: 6px; font-weight: 600; text-decoration: none; }
.diff-inline .del { text-decoration: line-through; }
.diff-inline .arrow { color: var(--muted); }
.warn-line { color: var(--warn); }
.muted { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.composer { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 8px; background: var(--panel); }
.composer textarea { resize: vertical; min-height: 48px; }
.composer-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.composer-row .btn.primary { margin-left: auto; }
.file-btn { cursor: pointer; }
.banner-inline { background: rgba(245, 176, 65, .12); color: var(--warn); font-size: 13px; padding: 10px 18px; }
.tr-side { display: grid; gap: 12px; height: calc(100vh - 170px); min-height: 480px; grid-template-rows: auto 1fr; }
.side-body { overflow-y: auto; min-height: 0; }
.side-meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.doc { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 12.5px/1.55 ui-monospace, Menlo, Consolas, monospace; color: var(--text); }
.kn { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.kn p { margin: 4px 0 0; color: var(--muted); white-space: pre-wrap; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ver { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
@media (max-width: 860px) {
  .trainer { grid-template-columns: 1fr; }
  .tr-chat { height: 70vh; }
  .tr-side { height: auto; max-height: 70vh; }
  .msg { max-width: 92%; }
}

/* ---------- Диалоги ---------- */
.conversations { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 16px; align-items: start; }
.conversations .card + .card, .settings-panel + .conversations .card { margin-top: 0; }
.settings-panel { display: grid; gap: 12px; margin-bottom: 16px; max-width: 720px; }
.settings-panel p { margin: 0; }
.conv-list-card { display: grid; gap: 10px; padding: 14px; height: calc(100vh - 170px); min-height: 480px; grid-template-rows: auto auto 1fr; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 12px; border: 1px solid var(--line); background: none; color: var(--muted); padding: 5px 10px; border-radius: 20px; cursor: pointer; }
.chip.on { background: var(--accent-soft); color: var(--text); border-color: var(--accent); }
.conv-list { overflow-y: auto; min-height: 0; margin: 0 -6px; }
.conv-row { display: grid; gap: 4px; padding: 10px; border-radius: 10px; color: inherit; text-decoration: none; border: 1px solid transparent; }
.conv-row:hover { background: var(--panel-2); }
.conv-row.active { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.conv-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.conv-text { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-tags { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.conv-detail { display: flex; flex-direction: column; padding: 0; height: calc(100vh - 170px); min-height: 480px; overflow: hidden; }
.conv-detail > .empty { margin: auto; }
.conv-head { display: grid; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.conv-title { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.back { display: none; }
.handoff { margin: 10px 18px 0; padding: 10px 12px; border-radius: 9px; background: rgba(245, 176, 65, .1); color: var(--warn); font-size: 13px; }
.handoff.urgent { background: rgba(242, 95, 92, .12); color: var(--bad); }
.handoff div { color: var(--text); margin-top: 2px; }
.memory { display: flex; gap: 6px 14px; flex-wrap: wrap; padding: 10px 18px 0; font-size: 13px; }
.thread { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.bubble.in { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.bubble.out.staff { background: rgba(245, 176, 65, .14); }
.bubble.system { align-self: center; background: none; color: var(--muted); font-size: 12px; }
.bubble-meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg-err { color: var(--bad); font-size: 12px; margin-top: 4px; }
@media (max-width: 860px) {
  .conversations { grid-template-columns: 1fr; }
  .conversations.has-active .conv-list-card { display: none; }
  .conversations:not(.has-active) .conv-detail { display: none; }
  .conv-list-card, .conv-detail { height: calc(100vh - 150px); }
  .back { display: inline; }
  .bubble { max-width: 88%; }
}

/* ---------- Товары ---------- */
.products { display: grid; grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); gap: 16px; align-items: start; }
.products .card + .card { margin-top: 0; }
.prod-list-card { display: grid; gap: 10px; padding: 14px; height: calc(100vh - 170px); min-height: 480px; grid-template-rows: auto auto auto 1fr; }
.prod-list { overflow-y: auto; min-height: 0; margin: 0 -6px; }
.prod-row { display: grid; grid-template-columns: 40px 1fr auto; grid-template-areas: "thumb main price" "thumb tags tags";
  gap: 2px 10px; padding: 9px 10px; border-radius: 10px; color: inherit; text-decoration: none; border: 1px solid transparent; align-items: center; }
.prod-row:hover { background: var(--panel-2); }
.prod-row.active { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.prod-row.inactive { opacity: .6; }
.prod-thumb { grid-area: thumb; width: 40px; height: 40px; border-radius: 8px; background: var(--panel-2); display: grid; place-items: center; overflow: hidden; }
.prod-thumb img { width: 100%; height: 100%; object-fit: cover; }
.prod-main { grid-area: main; display: grid; min-width: 0; font-size: 14px; }
.prod-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prod-price { grid-area: price; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; display: grid; }
.prod-tags { grid-area: tags; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.prod-editor { padding: 0; height: calc(100vh - 170px); min-height: 480px; overflow-y: auto; }
.prod-editor > .empty { margin-top: 30vh; }
.prod-form { display: grid; gap: 18px; padding: 18px 20px 24px; }
.form-head { display: grid; gap: 4px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 16px; margin: 0; display: grid; gap: 12px; min-width: 0; }
legend { padding: 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.toggles { display: flex; gap: 18px; flex-wrap: wrap; }
label.check { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
label.check input { width: auto; }
.faq-row { display: grid; gap: 6px; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
.faq-row .link { justify-self: start; }
.photo-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-strip img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.form-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--panel); padding: 12px 0 2px; }
.warn-box { border: 1px solid rgba(245, 176, 65, .4); background: rgba(245, 176, 65, .08); border-radius: 10px; padding: 12px 14px; display: grid; gap: 6px; font-size: 14px; }
.warn-box p { margin: 0; }
.warn-box.bad { border-color: rgba(242, 95, 92, .4); background: rgba(242, 95, 92, .08); }
a.btn { text-decoration: none; display: inline-block; }
@media (max-width: 860px) {
  .products { grid-template-columns: 1fr; }
  .products.has-active .prod-list-card { display: none; }
  .products:not(.has-active) .prod-editor { display: none; }
  .prod-list-card, .prod-editor { height: auto; min-height: 0; max-height: none; }
  .prod-list { max-height: 65vh; }
  .grid2 { grid-template-columns: 1fr; }
  .prod-form { padding: 14px; }
}

.grid2 .span2 { grid-column: 1 / -1; }

/* ---------- AI-модель ---------- */
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.ai-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; margin-top: 16px; }
.ai-grid .card + .card { margin-top: 0; }
.ai-form { display: grid; gap: 14px; }
.ai-form fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0; display: grid; gap: 10px; }
.ai-form fieldset p { margin: 0; font-size: 13px; }
.check.inline { align-self: end; padding-bottom: 10px; }
.budget p { margin: 10px 0 0; }
.budget-bar { height: 10px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.budget-bar i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.budget.warn .budget-bar i { background: var(--warn); }
.budget.over .budget-bar i { background: var(--bad); }
.budget.over { border-color: rgba(242, 95, 92, .5); }
.spend-chart { display: flex; align-items: flex-end; gap: 2px; height: 140px; border-bottom: 1px solid var(--line); }
.sc-col { flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; }
.sc-col i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; }
.sc-col:hover i { filter: brightness(1.25); }
.sc-col:hover { background: var(--accent-soft); }
.sc-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; }
.sc-table { margin-top: 10px; }
.tc { display: flex; flex-direction: column; }
.tc > p { margin: 0 0 10px; font-size: 13px; }
.tc-msgs { min-height: 260px; max-height: 460px; border: 1px solid var(--line); border-radius: 10px; flex: none; }
.tc .composer { padding: 10px 0 0; border: 0; display: grid; gap: 8px; }
.msg-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.msg.err { color: var(--bad); }
@media (max-width: 900px) {
  .ai-grid { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr; }
}
.ai-form .form-actions { position: static; }
.msg-note { white-space: normal; }
