/* Metrika Menu Optimizer — design tokens (Nexus-inspired, custom) */
:root {
  --bg:        #F7F6F2;
  --surface:   #FFFFFF;
  --surface-2: #FAF9F5;
  --border:    #E4E1DA;
  --border-2:  #D4D1CA;
  --text:      #1E1C16;
  --text-mut:  #6F6E68;
  --text-faint:#A8A6A0;
  --primary:   #C8001E; /* красный Yandex Metrika */
  --primary-h: #9F0017;
  --accent:    #01696F;
  --success:   #2F7A2A;
  --warning:   #B05E1A;
  --error:     #A12C7B;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow-1:  0 1px 0 rgba(20, 18, 12, .03), 0 6px 18px -10px rgba(20, 18, 12, .12);
  --shadow-2:  0 12px 32px -16px rgba(20, 18, 12, .22);
  --mono: ui-monospace, 'JetBrains Mono', SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Satoshi', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11", "tnum";
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 32px; height: 32px; color: var(--primary); }
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-sub   { font-size: 12px; color: var(--text-mut); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-mut);
}
.pill-muted { color: var(--text-mut); }
.pill-ok    { color: var(--success); border-color: #c9e2c6; background:#eef7ec; }
.pill-warn  { color: var(--warning); border-color: #ecd6bd; background:#fbf2e6; }

/* Step nav */
.stepnav {
  display: flex; gap: 4px; padding: 16px 28px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.step {
  appearance: none; background: transparent; border: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  color: var(--text-mut);
  font: inherit; font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.step:hover { background: var(--surface-2); color: var(--text); }
.step.active {
  color: var(--text);
  background: var(--surface);
  border-bottom-color: var(--primary);
}
.step-num {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-mut);
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--border);
}
.step.active .step-num {
  background: var(--primary); color: white; border-color: var(--primary);
}

.container { max-width: 1180px; margin: 0 auto; padding: 28px; }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-1);
}
.panel-head { margin-bottom: 22px; }
.panel-head h1 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.01em; }
.panel-head p  { margin: 0; color: var(--text-mut); font-size: 14px; max-width: 70ch; }

.subhead {
  display: flex; align-items: center; justify-content: space-between;
  margin: 18px 0 10px;
}
.subhead h2 { margin: 0; font-size: 14px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; color: var(--text-mut); }

.divider { height: 1px; background: var(--border); margin: 22px 0; }

/* Forms */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-mut); letter-spacing: .02em; text-transform: uppercase; }
.field-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-mut); }
.hint { color: var(--text-mut); font-size: 12px; }

input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  font: inherit;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(200, 0, 30, .12);
}

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--border-2); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 500;
  padding: 9px 14px; border-radius: var(--radius-sm); cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-h); border-color: var(--primary-h); }
.btn-ghost { background: var(--surface); }
.btn-link { background: transparent; border-color: transparent; color: var(--accent); padding: 9px 0; }
.btn-link:hover { background: transparent; text-decoration: underline; }
.btn-danger { color: var(--error); border-color: #eccfe1; }
.btn-danger:hover { background: #fbeaf3; }
.btn-icon { padding: 6px 8px; font-size: 14px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.datatable { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 14px; }
.datatable th, .datatable td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.datatable thead th {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-mut);
  background: var(--surface-2); position: sticky; top: 0;
}
.datatable tbody tr:hover { background: var(--surface-2); }
.datatable td input { padding: 7px 9px; font-size: 13px; }
.datatable td.actions { width: 1%; white-space: nowrap; }
.tag-home { display: inline-block; padding: 2px 8px; border-radius: 999px; background:#fcebee; color: var(--primary); font-size: 11px; font-weight: 600; letter-spacing: .02em; }

@media (max-width: 640px) {
  .datatable { min-width: 680px; }
  #reco-table { min-width: 980px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .panel { padding: 22px 18px; }
  .container { padding: 28px 14px; }
}

/* Geo segments */
.geo-list { display: grid; gap: 14px; }
.geo-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: var(--surface);
  display: grid; gap: 10px;
}
.geo-card .row { justify-content: space-between; }
.geo-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.geo-tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border-2);
  font-size: 13px;
}
.geo-tag button { all: unset; cursor: pointer; color: var(--text-faint); }
.geo-tag button:hover { color: var(--primary); }

/* Cards */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 8px 0 16px; }
@media (max-width: 860px) { .cards { grid-template-columns: 1fr; } }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
}
.card h3 { margin: 0 0 6px; font-size: 15px; }

/* KPI */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 8px 0 18px; }
@media (max-width: 860px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-mut); font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border-2);
  font-size: 13px;
}
.chip .delta { font-variant-numeric: tabular-nums; color: var(--success); font-weight: 600; font-size: 12px; }
.chip .delta.neg { color: var(--error); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%);
  background: #1E1C16; color: white;
  padding: 10px 16px; border-radius: 8px;
  box-shadow: var(--shadow-2);
  font-size: 14px;
  z-index: 1000;
}
.toast.err { background: var(--primary); }

.hidden { display: none !important; }
.muted  { color: var(--text-mut); font-size: 13px; }
.codebox {
  background: #1A1A18; color: #F2EFEA;
  padding: 14px 16px; border-radius: var(--radius-sm);
  overflow: auto; max-height: 420px; font-size: 12.5px; line-height: 1.55;
  border: 1px solid #2A2925;
}
.actions { display: flex; gap: 10px; align-items: center; margin-top: 22px; flex-wrap: wrap; }

/* Logs requests list */
#log-requests { margin-top: 10px; display: grid; gap: 8px; }
.log-req {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 8px 10px; border: 1px dashed var(--border-2); border-radius: 6px; background: var(--surface-2);
  font-size: 13px;
}
.log-req .req-id { font-weight: 700; }
.log-req .req-actions { display: flex; gap: 6px; }
