/* qwind.tech — оформление сайта.
   Чтобы поменять цвета, шрифт или отступы, достаточно поправить переменные ниже. */

:root {
  color-scheme: light;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #f4f6fa;            /* фон страницы */
  --surface: #ffffff;       /* карточки и таблицы */
  --surface-2: #f8f9fc;     /* шапки таблиц, подсветка строк */
  --border: #e3e7ef;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #64748b;
  --accent: #2a78d6;        /* основной синий */
  --accent-soft: #e8f1fc;
  --sidebar: #0f1b2d;
  --sidebar-text: #c7d2e3;
  --sidebar-active: #1d2d47;
  --good: #0a8a0a;  --good-bg: #e7f6e7;
  --warn: #9a6400;  --warn-bg: #fff4dc;  --warn-mark: #fab219;
  --bad: #c62f2f;   --bad-bg: #fdeaea;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100; --series-5: #e87ba4; --series-6: #008300;
  --series-neutral: #94a3b8;
  --grid: #e9edf3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121417; --surface: #1a1a19; --surface-2: #222321; --border: #30312e;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #9a998f;
    --accent: #3987e5; --accent-soft: #1d2a3c;
    --sidebar: #0c0d0f; --sidebar-text: #b9c2cf; --sidebar-active: #1f2733;
    --good: #4cc94c; --good-bg: #16301a; --warn: #fab219; --warn-bg: #33290f;
    --bad: #f07a7a; --bad-bg: #3a1c1c;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #0ca30c;
    --series-neutral: #6b7280;
    --grid: #2a2b28; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121417; --surface: #1a1a19; --surface-2: #222321; --border: #30312e;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9a998f;
  --accent: #3987e5; --accent-soft: #1d2a3c;
  --sidebar: #0c0d0f; --sidebar-text: #b9c2cf; --sidebar-active: #1f2733;
  --good: #4cc94c; --good-bg: #16301a; --warn: #fab219; --warn-bg: #33290f;
  --bad: #f07a7a; --bad-bg: #3a1c1c;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #0ca30c;
  --series-neutral: #6b7280;
  --grid: #2a2b28; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- каркас: меню слева, содержимое справа ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 20px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 18px; padding: 4px 10px 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; font-size: 16px; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--sidebar-text); opacity: .8; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--sidebar-text); padding: 9px 10px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav-count { margin-left: auto; font-size: 11px; background: rgba(255,255,255,.1); padding: 1px 7px; border-radius: 10px; }
.sidebar-foot { margin-top: auto; padding: 10px; font-size: 12px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot button { background: none; border: 1px solid #2c3b55; color: var(--sidebar-text); border-radius: 8px; padding: 6px 10px; cursor: pointer; font: inherit; }

.main { min-width: 0; padding: 24px 28px 48px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.topbar .sub { color: var(--muted); margin-top: 4px; }
.day-picker { display: flex; align-items: center; gap: 8px; }
select, input[type=text], input[type=search], input[type=password] {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-height: 36px; }
select:focus, input:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; min-height: 36px; }
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

/* ---------- карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); margin-bottom: 16px; }
.kpi { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.kpi a { color: inherit; }
.kpi-label { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: 12px; color: var(--muted); }
.kpi-delta.up-bad, .kpi-delta.down-good { font-weight: 600; }
.kpi-delta.up-bad { color: var(--bad); }
.kpi-delta.down-good { color: var(--good); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.two { grid-template-columns: 3fr 2fr; margin-bottom: 16px; }
.two-even { grid-template-columns: 1fr 1fr; margin-bottom: 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.chart-box { position: relative; height: 260px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.box { height: 10px; width: 10px; border-radius: 3px; }
.takeaway { background: var(--accent-soft); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; color: var(--text); }

/* полосы долей (структура расходов) */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 56px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }

/* разбор цены товара */
.stack { display: flex; height: 18px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--surface); }
.stack div { height: 100%; }
.c-cost { background: #2a78d6; } .c-commission { background: #eb6834; } .c-logistics { background: #1baf7a; }
.c-services { background: #eda100; } .c-ads { background: #e87ba4; } .c-tax { background: #94a3b8; } .c-profit { background: #008300; }
.parts { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 16px; margin-top: 14px; font-size: 13px; }
.parts .total { font-weight: 700; border-top: 1px solid var(--border); padding-top: 6px; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 12px; position: sticky; top: 0; white-space: nowrap; }
th a { color: inherit; }
th.sorted a { color: var(--accent); }
td.r, th.r { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.product-cell { min-width: 260px; max-width: 420px; }
.product-cell .title { color: var(--text); font-weight: 500; display: block; }
.product-cell .meta { color: var(--muted); font-size: 12px; }
.neg { color: var(--bad); }
.pos { color: var(--good); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-bad { color: var(--bad); background: var(--bad-bg); }
.badge-warn { color: var(--warn); background: var(--warn-bg); }
.badge-good { color: var(--good); background: var(--good-bg); }

/* фильтры над таблицей */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.tabs a { padding: 6px 12px; border-radius: 7px; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.tabs a:hover { text-decoration: none; background: var(--surface-2); }
.tabs a.on { background: var(--accent); color: #fff; }
.tabs a .cnt { opacity: .75; font-size: 12px; margin-left: 4px; }
.check { display: inline-flex; gap: 6px; align-items: center; color: var(--text-2); }
.pager { display: flex; gap: 6px; align-items: center; justify-content: space-between; margin-top: 12px; color: var(--muted); }
.pager .btns { display: flex; gap: 6px; }

/* формы */
.form { display: grid; gap: 14px; max-width: 520px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 3px; }
.field input[type=text] { width: 160px; }
.alert { border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; }
.alert-ok { background: var(--good-bg); color: var(--good); }
.alert-err { background: var(--bad-bg); color: var(--bad); }
details.method summary { cursor: pointer; color: var(--text-2); font-weight: 600; }
details.method { margin-top: 16px; }
details.method p, details.method li { color: var(--text-2); }

/* вход */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { color: var(--text); padding: 0 0 16px; }
.login-card input { width: 100%; }

/* ---------- узкие экраны ---------- */
@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 10px 12px; gap: 8px; }
  .brand { padding: 0 8px 0 0; }
  .brand small { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { padding: 8px 10px; white-space: nowrap; }
  .nav a.active { box-shadow: inset 0 -3px 0 var(--accent); }
  .nav-count { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; flex-direction: row; align-items: center; }
  .sidebar-foot .who { display: none; }
  .main { padding: 16px 16px 40px; }
  .two, .two-even { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bar-row { grid-template-columns: 110px 1fr 48px; }
}
.form-group { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 10px 0 -4px; }
.form-group:first-of-type { margin-top: 4px; }
.field select { min-width: 160px; }

/* Юнит-экономика */
.badge-muted { color: var(--text-2); background: var(--surface-2); }
.unit-table tr.zone-loss > td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.unit-table tr.zone-below > td:first-child { box-shadow: inset 3px 0 0 var(--warn-mark); }
.advice-cell { min-width: 200px; max-width: 280px; }
.advice { font-weight: 600; display: block; cursor: help; }
.advice-cell .meta, .actions-list .meta { display: block; color: var(--muted); font-size: 12px; }
.actions-list { margin: 0; padding-left: 22px; display: grid; gap: 12px; }
.actions-list li { padding-left: 4px; }
.act-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.act-effect { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.risk-row { display: grid; grid-template-columns: minmax(140px, 1fr) 2fr 64px; gap: 10px; align-items: center; padding: 4px 0; }
.risk-row .note { grid-column: 1 / -1; color: var(--muted); font-size: 12px; margin-top: -4px; }
.compare td.r, .compare th.r { width: 110px; }
.rec-box { border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; margin: 6px 0 12px; }
.rec-box .act { font-size: 18px; font-weight: 700; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters .tabs { max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
.options { display: grid; gap: 12px; }
.option { padding: 10px 12px; background: var(--surface-2); border-radius: 8px; }
@media (max-width: 900px) {
  .layout { min-width: 0; max-width: 100vw; overflow-x: clip; }
  .sidebar { min-width: 0; max-width: 100vw; }
  .main { min-width: 0; }
}
.share { display: grid; grid-template-columns: 60px auto; gap: 8px; align-items: center; justify-content: end; }
.share .bar-track { height: 6px; }
tr.total td { border-top: 2px solid var(--border); font-weight: 600; }
.steps { margin: 6px 0 0; padding-left: 22px; display: grid; gap: 8px; }
tr.done-row td { opacity: .45; }
tr.done-row td:first-child { opacity: 1; }
a.option { display: block; color: inherit; text-decoration: none; border: 1px solid transparent; transition: border-color .15s; }
a.option:hover { border-color: var(--accent); text-decoration: none; }
a.option .more { color: var(--accent); font-size: 12px; margin-top: 4px; display: inline-block; }
.kpi a.kpi-link { color: inherit; }
.bar-row a { color: inherit; }
.diag-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
a.option.on { border-color: var(--accent); background: var(--accent-soft); }
details.sol summary { cursor: pointer; list-style: none; }
details.sol summary::-webkit-details-marker { display: none; }
details.sol .steps { margin-top: 8px; font-size: 13px; }

/* ---------- агенты ---------- */
textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; resize: vertical; }
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-bottom: 16px; }
.agent-card { display: grid; gap: 8px; align-content: start; }
.agent-card.off { opacity: .6; }
.agent-card h3 { margin: 0; font-size: 16px; }
.agent-stats { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-2); }
.agent-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.q-list { display: grid; gap: 12px; }
.q-item { padding: 12px 14px; background: var(--surface-2); border-radius: 8px; display: grid; gap: 8px; }
.q-item.open { border-left: 3px solid var(--warn); }
.q-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.q-answer { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; }
.q-answer textarea { flex: 1 1 260px; min-height: 38px; }
.wide-form { display: grid; gap: 12px; max-width: 760px; }
.wide-form input[type=text] { width: 100%; }
.row-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.copy-box { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; user-select: all; }
.log-table td { vertical-align: top; }
.log-table .change { color: var(--text-2); font-size: 13px; }

/* ---------- развёрнутый ответ агента (Markdown) ---------- */
.md { line-height: 1.6; overflow-wrap: anywhere; max-width: 900px; }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.3em 0 .5em; line-height: 1.3; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 16px; } .md h4 { font-size: 15px; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 .9em; }
.md ul, .md ol { padding-left: 22px; }
.md li + li { margin-top: 3px; }
.md blockquote { border-left: 3px solid var(--border); padding: 2px 12px; color: var(--text-2); }
.md code { background: var(--surface-2); border-radius: 4px; padding: 1px 5px; font-size: .92em; }
.md pre { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }
@media print {
  .sidebar, .no-print, .topbar .btn, .alert { display: none !important; }
  .layout { display: block; } .main { padding: 0; } .card { box-shadow: none; border: 0; padding: 0; }
}

/* ---------- графики ---------- */
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.chart-grid .wide { grid-column: 1 / -1; }
@media (max-width: 1100px) { .chart-grid { grid-template-columns: minmax(0, 1fr); } }
.chart-card { display: grid; gap: 6px; align-content: start; min-width: 0; }
.chart-card .card-head { margin-bottom: 2px; }
.chart-card .note { font-size: 12px; color: var(--muted); }
details.data-table summary { cursor: pointer; font-size: 12px; color: var(--text-2); margin-top: 6px; }
details.data-table .table-wrap { margin-top: 8px; max-height: 360px; overflow: auto; }
details.data-table table { font-size: 12px; }
.legend i.dash { background: none; border-top: 2px dashed var(--muted); height: 0; }
.legend i.dot2 { background: none; border-top: 2px dotted var(--text-2); height: 0; }
.kpi-delta.up { color: var(--good); } .kpi-delta.down { color: var(--bad); }
@media (max-width: 520px) { .kpi-value { font-size: 21px; } }
a.kpi.on { outline: 2px solid var(--accent); outline-offset: -2px; }
a.kpi:hover { background: var(--surface-2); }

/* ---------- калькулятор ---------- */
.calc-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .calc-layout { grid-template-columns: minmax(0, 1fr); } }
.calc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 14px; margin: 8px 0 6px; }
.calc-field label { font-weight: 600; font-size: 13px; margin-bottom: 4px; display: block; }
.calc-input { display: flex; align-items: center; gap: 6px; }
.calc-input input { width: 100%; min-width: 0; text-align: right; font-variant-numeric: tabular-nums; }
.calc-input span { color: var(--muted); min-width: 14px; }
.calc-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.calc-kpis > div { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; background: var(--surface-2); border-radius: 10px; }
