:root {
  color-scheme: light dark;
  --bg: light-dark(#f3f5f8, #0b0f14);
  --surface: light-dark(#ffffff, #141a22);
  --surface-soft: light-dark(#f8fafc, #1a222d);
  --text: light-dark(#111827, #f3f4f6);
  --muted: light-dark(#667085, #9ba6b5);
  --line: light-dark(#e4e7ec, #2a3442);
  --blue: light-dark(#2563eb, #65a3ff);
  --blue-soft: light-dark(#eaf1ff, #142a4d);
  --green: light-dark(#15803d, #4ade80);
  --green-soft: light-dark(#eaf8ef, #133621);
  --amber: light-dark(#a15c00, #fbbf24);
  --amber-soft: light-dark(#fff5e2, #3b2a0d);
  --red: light-dark(#b42318, #fb7185);
  --red-soft: light-dark(#fff0ee, #3c171d);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.app-shell { max-width: 1480px; margin: 0 auto; min-height: 100vh; }
.topbar { min-height: 72px; padding: 14px 28px; display: flex; align-items: center; justify-content: space-between; gap: 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: #3478f6; color: white; font-weight: 800; box-shadow: 0 8px 22px rgb(52 120 246 / 25%); }
.brand-title { font-weight: 750; letter-spacing: -0.02em; }
.brand-subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.topbar-actions, .action-row, .form-footer { display: flex; align-items: center; gap: 10px; }
.mode-badge { display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; border-radius: 999px; background: var(--amber-soft); color: var(--amber); font-size: 13px; font-weight: 700; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.tabs { display: flex; gap: 4px; padding: 10px 28px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border: 0; border-radius: 9px; padding: 9px 13px; color: var(--muted); background: transparent; cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--text); background: var(--surface-soft); font-weight: 700; }
main { padding: 28px; }
.panel { display: none; }
.panel.active { display: block; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 20px; }
.page-heading.compact { align-items: center; }
.eyebrow { margin: 0 0 6px; color: var(--blue); text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 800; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(25px, 4vw, 38px); letter-spacing: -0.04em; line-height: 1.1; }
h2 { margin-bottom: 5px; font-size: 18px; letter-spacing: -0.02em; }
.muted { color: var(--muted); margin-bottom: 0; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 9px 14px; border: 1px solid #2563eb; border-radius: 10px; background: #2563eb; color: white; text-decoration: none; font-weight: 700; cursor: pointer; }
.button.secondary { border-color: var(--line); background: var(--surface); color: var(--text); }
.button:disabled { opacity: .55; cursor: wait; }
.text-button { border: 0; background: transparent; color: var(--blue); font-weight: 700; cursor: pointer; }
.text-button:disabled { color: var(--muted); cursor: not-allowed; opacity: .65; }
.notice { margin-bottom: 16px; padding: 12px 14px; border-radius: 10px; background: var(--blue-soft); color: var(--blue); }
.notice.error { background: var(--red-soft); color: var(--red); }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card, .account-card, .surface { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.stat-card { padding: 16px; }
.stat-label, .stat-note { color: var(--muted); font-size: 12px; }
.stat-value { display: block; margin: 7px 0 4px; font-size: 24px; line-height: 1; font-variant-numeric: tabular-nums; }
.accounts-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.account-card { padding: 18px; }
.account-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.account-name { font-weight: 800; }
.account-type { color: var(--muted); font-size: 12px; margin-top: 3px; }
.currency-pill, .status-pill, .evaluation { display: inline-flex; align-items: center; min-height: 26px; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 750; white-space: nowrap; }
.currency-pill { color: var(--blue); background: var(--blue-soft); }
.account-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.account-metric span { display: block; color: var(--muted); font-size: 11px; }
.account-metric strong { display: block; margin-top: 5px; font-variant-numeric: tabular-nums; }
.surface { overflow: hidden; }
.surface-header { padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
.attention-list:empty::after, .timeline:empty::after { content: "Пока ничего нет"; display: block; padding: 26px 18px; color: var(--muted); }
.attention-item { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 16px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.attention-item:last-child { border-bottom: 0; }
.budget-alert-section { margin-bottom: 18px; border-color: color-mix(in srgb, var(--red) 34%, var(--line)); }
.alert-header { background: var(--red-soft); }
.budget-alert-list { display: grid; }
.budget-alert-item { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(260px, 1.2fr) auto; align-items: center; gap: 18px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.budget-alert-item:last-child { border-bottom: 0; }
.budget-alert-reason { color: var(--muted); font-size: 12px; }
.attention-title { font-weight: 700; }
.attention-meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.cpa-value { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--red); }
.evaluation.good, .status-pill.active { color: var(--green); background: var(--green-soft); }
.evaluation.warn { color: var(--amber); background: var(--amber-soft); }
.evaluation.bad { color: var(--red); background: var(--red-soft); }
.status-pill.stopped { color: var(--muted); background: var(--surface-soft); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 14px; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button { min-height: 38px; border: 1px solid var(--line); border-radius: 9px; padding: 7px 11px; background: var(--surface); color: var(--text); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); font-weight: 700; }
.search-field input, .settings-form input, .campaign-builder input, .campaign-builder textarea, .campaign-builder select, .period-select select, .metrics-toolbar input, .metrics-toolbar select, dialog input, dialog select { min-height: 40px; border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; background: var(--surface); color: var(--text); }
.search-field input { width: min(280px, 100%); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1340px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
th { color: var(--muted); background: var(--surface-soft); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.sort-button { display: inline-flex; align-items: center; gap: 5px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; }
.sort-button.active { color: var(--blue); }
.numeric .sort-button { margin-left: auto; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-soft); }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.campaign-name { max-width: 290px; font-weight: 700; }
.campaign-sub { color: var(--muted); font-size: 11px; margin-top: 3px; font-weight: 500; }
.timeline-item { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 18px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.timeline-item:last-child { border-bottom: 0; }
.timeline-time { color: var(--muted); font-size: 12px; }
.timeline-message { font-weight: 650; }
.timeline-action { margin-top: 4px; color: var(--muted); font-size: 12px; }
.settings-form, .campaign-builder { padding: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.settings-form label, .campaign-builder label, .period-select, dialog label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.settings-form input, .campaign-builder input, .campaign-builder textarea, .campaign-builder select { width: 100%; color: var(--text); font-size: 16px; }
.rate-preview { margin-bottom: 18px; }
.metrics-section, .recommendation-section { margin-bottom: 16px; }
.metrics-toolbar { display: grid; grid-template-columns: 1fr 1fr minmax(240px, 1.5fr) 140px auto; gap: 12px; align-items: end; padding: 16px 18px 12px; }
.metrics-toolbar label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.metrics-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; margin: 0 18px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--line); }
.metrics-summary > div { padding: 12px 14px; background: var(--surface-soft); }
.metrics-summary span { display: block; color: var(--muted); font-size: 11px; }
.metrics-summary strong { display: block; margin-top: 4px; font-size: 18px; }
.metrics-legend { display: flex; justify-content: flex-end; gap: 18px; padding: 12px 18px 0; color: var(--muted); font-size: 12px; }
.metrics-quick-ranges { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 18px 14px; }
.metrics-quick-ranges button { min-height: 34px; padding: 6px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text); cursor: pointer; }
.metrics-quick-ranges button:hover { border-color: var(--blue); color: var(--blue); }
.metrics-legend span::before { content: ""; display: inline-block; width: 18px; height: 3px; margin-right: 6px; border-radius: 99px; vertical-align: middle; }
.legend-views::before { background: var(--blue); }
.legend-spend::before { background: var(--amber); }
.metrics-chart { position: relative; min-height: 330px; padding: 4px 18px 18px; }
.metrics-svg { min-height: 320px; }
.metrics-line { fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.metrics-line.views { stroke: var(--blue); }
.metrics-line.spend { stroke: var(--amber); }
.metric-dot { stroke: var(--surface); stroke-width: 2; }
.metric-dot.views { fill: var(--blue); }
.metric-dot.spend { fill: var(--amber); }
.active-metric-dot { stroke: var(--surface); stroke-width: 3; transition: cx 140ms ease, cy 140ms ease; }
.active-metric-dot.views { fill: var(--blue); }
.active-metric-dot.spend { fill: var(--amber); }
.metrics-crosshair { stroke: color-mix(in srgb, var(--muted) 65%, transparent); stroke-width: 1.5; stroke-dasharray: 5 5; transition: x1 140ms ease, x2 140ms ease; }
.metrics-hit-area { fill: transparent; pointer-events: all; cursor: crosshair; }
.metrics-tooltip { position: absolute; z-index: 4; display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; width: 210px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 11px; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: 0 14px 38px rgb(0 0 0 / 22%); pointer-events: none; transform: translate(-50%, -100%); transition: left 140ms ease, top 140ms ease, opacity 180ms ease; backdrop-filter: blur(10px); font-size: 12px; }
.metrics-tooltip[hidden] { display: none; }
.metrics-tooltip strong { grid-column: 1 / -1; margin-bottom: 2px; font-size: 13px; }
.metrics-tooltip span { display: contents; color: var(--muted); }
.metrics-tooltip b { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.spend-label { fill: var(--amber); }
.empty-chart { min-height: 300px; display: grid; place-items: center; color: var(--muted); text-align: center; }
.recommendation-list:empty::after { content: "Рекомендации появятся после трёх разнесённых по времени замеров"; display: block; padding: 26px 18px; color: var(--muted); }
.recommendation-card { padding: 15px 18px; border-bottom: 1px solid var(--line); }
.recommendation-card:last-child { border-bottom: 0; }
.recommendation-main { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.recommendation-main > div { display: flex; align-items: center; gap: 10px; min-width: 0; }
.recommendation-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recommendation-card p { margin: 10px 0; color: var(--muted); font-size: 13px; }
.recommendation-metrics { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); font-size: 12px; }
.recommendation-metrics strong { color: var(--text); }
.recommendation-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 12px; }
.rate-big { font-size: 24px; color: var(--blue); white-space: nowrap; }
.mini-chart { min-height: 88px; padding: 8px 14px 14px; }
.rate-chart-card { min-height: 360px; }
.rate-chart { min-height: 300px; padding: 18px; }
.chart-svg { display: block; width: 100%; height: 100%; min-height: inherit; overflow: visible; }
.chart-line { fill: none; stroke: var(--blue); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: color-mix(in srgb, var(--blue) 16%, transparent); }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 11px; }
.period-select { min-width: 150px; }
.rate-up { color: var(--red); }
.rate-down { color: var(--green); }
.campaign-builder { margin-bottom: 18px; }
.wide-label { display: grid; margin-top: 16px; }
.wide-label textarea { resize: vertical; }
.wide-label small { justify-self: end; }
.keyword-categories { display: flex; flex-wrap: wrap; gap: 10px 18px; margin: 18px 0 0; padding: 15px; border: 1px solid var(--line); border-radius: 11px; }
.keyword-categories legend { color: var(--text); font-weight: 750; padding: 0 6px; }
.keyword-categories label { display: flex; align-items: center; grid-template-columns: auto 1fr; gap: 7px; color: var(--text); }
.keyword-categories input { width: auto; min-height: auto; }
.builder-footer { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-top: 18px; }
.safety-inline { color: var(--muted); font-size: 12px; max-width: 720px; }
.draft-section { margin-top: 18px; }
.draft-list:empty::after { content: "Черновики появятся после сбора семантики"; display: block; padding: 26px 18px; color: var(--muted); }
.draft-card { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.draft-card:last-child { border-bottom: 0; }
.draft-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.draft-title { font-weight: 800; }
.draft-meta, .draft-link { color: var(--muted); font-size: 12px; margin-top: 4px; overflow-wrap: anywhere; }
.keyword-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.keyword-chip { padding: 5px 8px; border-radius: 999px; background: var(--surface-soft); border: 1px solid var(--line); font-size: 12px; }
.draft-actions { display: flex; align-items: center; gap: 8px; }
.button.small { min-height: 34px; padding: 6px 10px; font-size: 12px; }
code { padding: 2px 5px; border-radius: 5px; background: var(--surface-soft); color: var(--text); }
.safety-box { margin: 18px 0; padding: 14px 16px; border-radius: 11px; background: var(--amber-soft); color: var(--amber); }
.safety-box p { margin: 5px 0 0; }
.safety-box.manual-enabled { background: var(--green-soft); color: var(--green); }
.form-footer { justify-content: space-between; }
dialog { width: min(440px, calc(100% - 28px)); border: 1px solid var(--line); border-radius: 15px; padding: 20px; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 55%); }
.dialog-warning { margin: 14px 0 0; padding: 10px 12px; border-radius: 9px; background: var(--amber-soft); color: var(--amber); font-size: 12px; }
dialog form { display: grid; gap: 14px; }
.login-error { margin: 0; padding: 10px 12px; border-radius: 9px; background: var(--red-soft); color: var(--red); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 16px; }

body.auth-locked { overflow: hidden; background: light-dark(#f4f5f7, #090b0f); }
body.auth-locked .app-shell { visibility: hidden; }
#loginDialog {
  width: min(408px, calc(100% - 32px));
  border: 1px solid light-dark(#e4e7ec, #252b35);
  border-radius: 22px;
  padding: 30px;
  background: light-dark(#ffffff, #13171d);
  box-shadow: 0 30px 90px rgb(15 23 42 / 18%);
}
#loginDialog::backdrop { background: light-dark(#f4f5f7, #090b0f); }
#loginDialog form { gap: 18px; }
.login-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.login-mark {
  width: 50px;
  height: 50px;
  display: grid;
  flex: 0 0 50px;
  place-items: center;
  border-radius: 14px;
  background: #2563eb;
  color: white;
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 10px 26px rgb(37 99 235 / 24%);
}
.login-heading h2 { margin: 0 0 3px; font-size: 25px; letter-spacing: -0.035em; }
.login-heading p { margin: 0; color: var(--muted); font-size: 13px; }
#loginDialog label { gap: 8px; color: var(--text); font-size: 13px; font-weight: 650; }
#loginDialog input {
  width: 100%;
  min-height: 48px;
  border-radius: 11px;
  padding-inline: 13px;
  background: light-dark(#fafbfc, #0e1217);
  font-size: 15px;
}
#loginDialog input::placeholder { color: light-dark(#98a2b3, #717b8b); }
#loginDialog .dialog-actions { margin-top: 2px; }
#loginDialog .dialog-actions .button { width: 100%; min-height: 48px; border-radius: 11px; }
.login-security { margin: -2px 0 0; color: var(--muted); font-size: 11px; text-align: center; }
.login-security span { margin-right: 4px; color: var(--green); font-size: 8px; vertical-align: 1px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .metrics-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .topbar, .topbar-actions, .toolbar, .form-footer, .builder-footer, .draft-head { align-items: stretch; flex-direction: column; }
  .topbar { padding: 14px 16px; }
  .topbar-actions { width: 100%; }
  .tabs { padding-inline: 16px; }
  main { padding: 18px 14px; }
  .stats-grid, .accounts-grid, .form-grid, .metrics-toolbar, .metrics-summary { grid-template-columns: 1fr; }
  .attention-item { grid-template-columns: 1fr; gap: 8px; }
  .budget-alert-item { grid-template-columns: 1fr; gap: 9px; }
  .timeline-item { grid-template-columns: 1fr; gap: 5px; }
  .action-row { width: 100%; flex-wrap: wrap; }
  .button { min-height: 44px; }
  .search-field input { width: 100%; }
  .recommendation-main, .recommendation-main > div, .recommendation-actions { align-items: flex-start; flex-direction: column; }
  #loginDialog { padding: 24px; border-radius: 18px; }
}
