/* ============================================================================
   Bundle Admin — Dark theme (Phase 4.3, MetricFlow-inspired).

   Цветовая схема:
     bg          #0f172a (slate-900)
     bg-card     #1e293b (slate-800)
     bg-elev     #334155 (slate-700)
     border      #334155 (slate-700)
     text        #e2e8f0 (slate-200)
     text-muted  #94a3b8 (slate-400)
     text-dim    #64748b (slate-500)
     accent      #3b82f6 (blue-500)
     ok          #22c55e (green-500)
     warn        #f59e0b (amber-500)
     alert       #ef4444 (red-500)
   ============================================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Inter", sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  color: #e2e8f0;
  background: #0f172a;
  -webkit-font-smoothing: antialiased;
}

a { color: #60a5fa; text-decoration: none; }
a:hover { color: #93c5fd; text-decoration: underline; }

code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  background: #0f172a;
  border: 1px solid #334155;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11.5px;
  color: #cbd5e1;
}

.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 32px;
}

/* ============================================================================
   TopNav
   ============================================================================ */

.topnav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 32px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.topnav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.topnav a:hover {
  background: #334155;
  color: #f1f5f9;
}
.topnav .brand {
  font-weight: 700;
  font-size: 15px;
  color: #f1f5f9;
  letter-spacing: 0.3px;
  margin-right: 8px;
  padding: 6px 12px;
}
.topnav .brand:hover { background: transparent; }
.topnav .spacer { flex: 1; }
.topnav .user {
  color: #93c5fd;
  font-size: 12px;
  padding: 6px 10px;
}
.topnav .logout-form { display: inline; margin: 0; }
.topnav button.link {
  background: none;
  border: 1px solid #334155;
  color: #cbd5e1;
  cursor: pointer;
  padding: 6px 12px;
  font: inherit;
  font-size: 12px;
  border-radius: 6px;
}
.topnav button.link:hover { background: #334155; color: #f1f5f9; }

.mode {
  padding: 3px 9px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.mode--dry_run { background: rgba(59, 130, 246, 0.15); color: #93c5fd; border: 1px solid rgba(59,130,246,0.4); }
.mode--shadow  { background: rgba(245, 158, 11, 0.15); color: #fcd34d; border: 1px solid rgba(245,158,11,0.4); }
.mode--auto    { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border: 1px solid rgba(239,68,68,0.4); }
.mode--live    { background: rgba(34, 197, 94, 0.15); color: #86efac; border: 1px solid rgba(34,197,94,0.4); }
.mode--ready   { background: rgba(245, 158, 11, 0.15); color: #fcd34d; border: 1px solid rgba(245,158,11,0.4); }

/* ============================================================================
   Headings + header rows
   ============================================================================ */

h1 { font-size: 24px; font-weight: 700; margin: 0 0 4px; color: #f1f5f9; letter-spacing: -0.2px; }
h2 { font-size: 16px; font-weight: 600; margin: 24px 0 12px; color: #f1f5f9; }
h3 { font-size: 13px; font-weight: 600; margin: 16px 0 8px; color: #cbd5e1; }

.header-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.header-row h1 { flex: 1; min-width: 0; }
.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.header-row form.inline,
.header-row form.inline-form { margin: 0; display: inline-flex; }

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid #475569;
  border-radius: 6px;
  background: #334155;
  color: #e2e8f0;
  text-decoration: none;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  line-height: 1.3;
}
.btn:hover { background: #475569; border-color: #64748b; color: #f1f5f9; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #f1f5f9;
}
.btn--primary:hover { background: #1d4ed8; border-color: #1d4ed8; }

.btn--danger {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fef2f2;
}
.btn--danger:hover { background: #991b1b; border-color: #991b1b; }

.btn--warn {
  background: #b45309;
  border-color: #b45309;
  color: #fffbeb;
}
.btn--warn:hover { background: #92400e; border-color: #92400e; }

.btn--ok {
  background: #15803d;
  border-color: #15803d;
  color: #f0fdf4;
}
.btn--ok:hover { background: #166534; border-color: #166534; }

.btn--ghost {
  background: transparent;
  border-color: #334155;
  color: #94a3b8;
}
.btn--ghost:hover { background: #1e293b; color: #e2e8f0; }

.btn--active {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #f1f5f9;
}

/* Inline form on a row — кнопки flush */
.inline-form, form.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

/* ============================================================================
   Tables
   ============================================================================ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  overflow: hidden;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid #334155;
  font-size: 12.5px;
  vertical-align: middle;
}
.data-table th {
  font-weight: 600;
  background: #0f172a;
  color: #94a3b8;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #283548; }
.data-table td.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.data-table td.actions form { margin: 0; display: inline-flex; gap: 4px; align-items: center; }

.link-strong {
  color: #60a5fa;
  font-weight: 600;
  text-decoration: none;
}
.link-strong:hover { text-decoration: underline; }

/* ============================================================================
   Badges
   ============================================================================ */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: #334155;
  color: #cbd5e1;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  border: 1px solid transparent;
  vertical-align: middle;
}
.badge--ok    { background: rgba(34, 197, 94, 0.18); color: #86efac; border-color: rgba(34,197,94,0.35); }
.badge--off   { background: rgba(100, 116, 139, 0.25); color: #cbd5e1; border-color: rgba(100,116,139,0.35); }
.badge--warn  { background: rgba(245, 158, 11, 0.18); color: #fcd34d; border-color: rgba(245,158,11,0.4); }
.badge--alert { background: rgba(239, 68, 68, 0.2); color: #fca5a5; border-color: rgba(239,68,68,0.4); }

.action--stop      { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.action--scale_up  { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.action--scale_down{ background: rgba(168, 85, 247, 0.2); color: #d8b4fe; }
.action--restart, .action--start { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.action--hold      { background: rgba(100, 116, 139, 0.25); color: #cbd5e1; }

.verdict {
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.verdict--executed  { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.verdict--would_do  { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.verdict--escalated { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.verdict--failed    { background: rgba(239, 68, 68, 0.22); color: #fca5a5; }
.verdict--skipped   { background: rgba(100, 116, 139, 0.25); color: #cbd5e1; }
.verdict--rejected  { background: rgba(168, 85, 247, 0.2); color: #d8b4fe; }

/* ============================================================================
   Forms
   ============================================================================ */

.form-stack { display: flex; flex-direction: column; gap: 14px; max-width: 720px; }

.form, .form-wide { display: flex; flex-direction: column; gap: 14px; }
.form-wide fieldset, fieldset {
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 18px 20px;
  background: #1e293b;
  margin: 0 0 4px;
}
.form-wide legend, fieldset > legend {
  font-weight: 600;
  padding: 0 8px;
  font-size: 12px;
  color: #93c5fd;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: #cbd5e1;
  margin-bottom: 4px;
}
label span { font-weight: 500; color: #94a3b8; }

input[type="text"], input[type="number"], input[type="password"], input[type="email"],
select, textarea {
  padding: 8px 11px;
  border: 1px solid #475569;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  background: #0f172a;
  color: #e2e8f0;
  transition: border-color 0.15s, background 0.15s;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="password"]:focus,
input[type="email"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #3b82f6;
  background: #1e293b;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}
textarea { font-family: "SF Mono", Menlo, monospace; font-size: 12px; resize: vertical; }
.form-wide small, small.muted { color: #64748b; font-size: 11px; }
.form-wide .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }

label.checkbox, .checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  user-select: none;
}
label.checkbox input, .checkbox input { margin: 0; }

.form-actions {
  display: flex;
  gap: 12px;
  padding: 16px 0 0;
  align-items: center;
}

/* ============================================================================
   Login
   ============================================================================ */

.login-card {
  max-width: 400px;
  margin: 80px auto;
  padding: 36px;
  background: #1e293b;
  border-radius: 10px;
  border: 1px solid #334155;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.login-card h1 { margin-top: 0; font-size: 22px; }
.login-card .form-actions { padding-top: 8px; }

/* ============================================================================
   KV block (definitions / details)
   ============================================================================ */

.kv-block {
  margin: 16px 0;
  padding: 18px 20px;
  background: #1e293b;
  border-radius: 8px;
  border: 1px solid #334155;
}
.kv-block h2 { margin-top: 0; }

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 20px;
  margin: 0;
  align-items: start;
}
.kv dt {
  font-weight: 600;
  color: #94a3b8;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding-top: 2px;
}
.kv dd { margin: 0; font-size: 13px; color: #e2e8f0; }

section.kv-block + section { margin-top: 8px; }

/* Sections without kv-block wrapper */
section { margin: 24px 0; }
section h2:first-child { margin-top: 0; }

/* ============================================================================
   Alerts (inline)
   ============================================================================ */

.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin: 12px 0;
  font-size: 13px;
  border: 1px solid transparent;
}
.alert--error { background: rgba(239,68,68,0.12); color: #fca5a5; border-color: rgba(239,68,68,0.35); }
.alert--warn  { background: rgba(245,158,11,0.12); color: #fcd34d; border-color: rgba(245,158,11,0.35); }
.alert--ok    { background: rgba(34,197,94,0.12); color: #86efac; border-color: rgba(34,197,94,0.35); }
.alert ul { margin: 6px 0 0 16px; padding: 0; }

.muted { color: #94a3b8; }
.muted code { color: #cbd5e1; }
.empty {
  padding: 48px 24px;
  text-align: center;
  color: #94a3b8;
  background: #1e293b;
  border: 1px dashed #334155;
  border-radius: 8px;
}
.legend { color: #64748b; font-size: 12px; margin: 8px 0; }
.legend li { margin: 2px 0; }

.footer {
  padding: 24px 32px;
  color: #64748b;
  font-size: 11px;
  text-align: center;
  border-top: 1px solid #1e293b;
  margin-top: 48px;
}

/* ============================================================================
   Filter form (search + period)
   ============================================================================ */

.filter-form, .filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
}
.filter-bar { padding: 8px 16px; }
.filter-form input, .filter-form select { padding: 6px 10px; font-size: 12.5px; }
.filter-form .checkbox { color: #cbd5e1; }
.filter-form .right { margin-left: auto; }

/* ============================================================================
   KPI cards (dashboard / account_detail / analytics)
   ============================================================================ */

.kpi-row, .kpi-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.kpi, .kpi-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #94a3b8;
}
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: -0.4px;
  line-height: 1.1;
}
.kpi-card .muted { font-size: 11.5px; }

/* 2-col grid for top/bad creatives */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .grid-2col { grid-template-columns: 1fr; } }

/* ============================================================================
   Charts
   ============================================================================ */

.chart-block {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 16px 20px;
  margin: 16px 0;
}
.chart-block h3 {
  margin-top: 0;
  margin-bottom: 12px;
  color: #cbd5e1;
}
.chart-block canvas { background: transparent; }

/* ============================================================================
   Misc utility
   ============================================================================ */

[x-cloak] { display: none !important; }
.hidden { display: none !important; }

/* ============================================================================
   Drilldown card layout (bundle/account hierarchy)
   ============================================================================ */

.drill-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  margin: 4px 0;
}
.drill-card.drill-campaign { background: #1a2538; border-color: #334155; }
.drill-card.drill-adset { background: #15202e; border-color: #2c3a4f; }

.drill-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 12.5px;
  user-select: none;
}
.drill-row:hover { background: rgba(59, 130, 246, 0.06); }
.drill-row.drill-ad { cursor: default; }
.drill-row.drill-ad:hover { background: transparent; }

.drill-toggle {
  font-size: 10px;
  color: #64748b;
  min-width: 12px;
  text-align: center;
}

.drill-name {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 11.5px;
  color: #cbd5e1;
  flex: 1 1 200px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drill-stat {
  font-size: 11.5px;
  color: #94a3b8;
  white-space: nowrap;
}
.drill-stat strong {
  color: #e2e8f0;
  font-weight: 600;
}

.drill-children {
  padding: 4px 14px 10px 30px;
  border-top: 1px solid #2c3a4f;
}
.drill-card.drill-adset .drill-children {
  padding-left: 24px;
}

.bundle-drill {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 14px 18px;
  margin: 16px 0;
}

.bundle-list-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  margin: 8px 0;
  overflow: hidden;
}
.bundle-list-card:has(.bundle-list-header[data-row-open="true"]) {
  border-color: #3b82f6;
}
.bundle-list-header {
  padding: 12px 16px;
  font-size: 13px;
}
.bundle-list-body {
  padding: 14px 18px;
  border-top: 1px solid #2c3a4f;
  background: #0f172a;
}
.right { margin-left: auto; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.compact { font-size: 11.5px; }

/* Manual action buttons in drilldown rows */
.drill-actions {
  margin-left: auto;
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.btn-mini {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 3px;
  border: 1px solid #475569;
  background: #1e293b;
  color: #cbd5e1;
  cursor: pointer;
  line-height: 1.4;
  font-family: inherit;
}
.btn-mini:hover { background: #334155; }
.btn-mini--stop { color: #fca5a5; border-color: #7f1d1d; background: rgba(127, 29, 29, 0.15); }
.btn-mini--stop:hover { background: rgba(127, 29, 29, 0.35); }
.btn-mini--restart { color: #86efac; border-color: #14532d; background: rgba(20, 83, 45, 0.15); }
.btn-mini--restart:hover { background: rgba(20, 83, 45, 0.35); }
.btn-mini--on { color: #fbbf24; border-color: #92400e; background: rgba(146, 64, 14, 0.2); }
.is-stopped { color: #f87171; text-decoration: line-through; }
.dupe-wrap { display: inline-flex; gap: 4px; align-items: center; }
.dupe-form { display: inline-flex; gap: 4px; align-items: center; }
.dupe-input {
  width: 48px;
  padding: 2px 4px;
  font-size: 11px;
  border-radius: 3px;
  border: 1px solid #475569;
  background: #0f172a;
  color: #e2e8f0;
}
