/* ============================================================
   AdControl — operations console
   Palette: ink navy sidebar, paper workspace, cobalt actions,
   status colors reserved for state. IDs and metrics set in mono.
   ============================================================ */

:root {
  --ink: #141926;          /* sidebar / primary text on light */
  --ink-soft: #232a3d;     /* sidebar hover */
  --paper: #f5f6f8;        /* workspace background */
  --card: #ffffff;
  --line: #e3e6ec;
  --text: #1c2230;
  --text-muted: #6b7284;
  --cobalt: #2b5ce6;       /* actions */
  --cobalt-deep: #1e46bd;
  --ok: #1f9d5b;
  --warn: #b7791f;
  --err: #c0392b;
  --err-deep: #a02c20;
  --radius: 8px;
  --sidebar-w: 226px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--paper);
}
a { color: var(--cobalt); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 14px; font-weight: 650; margin: 0; }
h3.form-title { font-size: 13px; font-weight: 650; margin: 0 0 12px; }
.mono { font-family: var(--mono); font-size: 0.93em; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.link { font-size: 13px; }

/* ---- Application frame ---- */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 24px 28px 48px; max-width: 1280px; width: 100%; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--ink);
  color: #c6ccdb;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
}
.brand-mark, .auth-mark {
  width: 22px; height: 22px; border-radius: 6px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--cobalt) 0%, #6f8ff0 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
}
.brand-name, .auth-name { color: #fff; font-weight: 650; letter-spacing: 0.01em; }
.nav { padding: 6px 10px 24px; display: flex; flex-direction: column; }
.nav-section {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.09em;
  color: #7c85a0; padding: 16px 10px 5px;
}
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  color: #c6ccdb; padding: 7px 10px; border-radius: 6px; font-size: 13.5px;
}
.nav-item:hover { background: var(--ink-soft); color: #fff; text-decoration: none; }
.nav-item.is-active { background: var(--cobalt); color: #fff; font-weight: 600; }
.nav-item.is-muted { color: #5b6479; cursor: default; }
.nav-item.is-muted:hover { background: none; }
.nav-phase {
  font-family: var(--mono); font-size: 10px; color: #5b6479;
  border: 1px solid #333c52; border-radius: 4px; padding: 0 5px; line-height: 1.6;
}

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 28px; gap: 16px;
}
.switcher { display: flex; align-items: center; gap: 8px; }
.switcher-label { font-size: 12px; color: var(--text-muted); }
.switcher-select, select {
  font: inherit; padding: 6px 28px 6px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; color: var(--text);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7284' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.select--sm { padding: 4px 24px 4px 8px; font-size: 12.5px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip { font-size: 13px; display: flex; align-items: center; gap: 8px; }

/* ---- Cards, grids ---- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px;
}
.card--narrow { max-width: 560px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.card-intro { color: var(--text-muted); font-size: 13px; margin: -4px 0 14px; max-width: 72ch; }
.grid { display: grid; gap: 14px; }
.grid--2 { grid-template-columns: 1fr 1fr; }
.grid--4 { grid-template-columns: repeat(4, 1fr); margin-bottom: 18px; }
.grid--4 .card { margin-bottom: 0; }
.grid--main-side { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 18px; }

/* ---- KPI ---- */
.kpi { padding: 14px 16px; }
.kpi-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); }
.kpi-value { font-size: 26px; font-weight: 650; margin-top: 2px; display: flex; align-items: center; gap: 8px; }
.kpi-foot { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---- Status system: dots + badges ---- */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot--ok { background: var(--ok); }
.dot--warn { background: var(--warn); }
.dot--err { background: var(--err); }
.dot--muted { background: #aab1c2; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; border-radius: 999px;
  padding: 2px 9px; vertical-align: middle; white-space: nowrap;
}
.badge--ok { background: #e7f5ee; color: #14683c; }
.badge--warn { background: #f9f1e2; color: #8a5a14; }
.badge--err { background: #f9e9e7; color: #93291e; }
.badge--muted { background: #eef0f4; color: #5a6172; }
.badge--admin { background: var(--ink); color: #cdd6f0; font-family: var(--mono); font-weight: 500; font-size: 10.5px; }

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-muted); font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--line);
}
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafbfd; }
.table--nested { margin-top: 12px; }
.table--nested th { font-size: 10.5px; }
.actions { text-align: right; white-space: nowrap; }
.actions form { display: inline-block; margin-left: 6px; }
.error-cell { color: var(--err); font-family: var(--mono); font-size: 11.5px; max-width: 260px; }
.change-cell { font-size: 11.5px; max-width: 320px; overflow-wrap: anywhere; }
.empty { color: var(--text-muted); padding: 14px 0; text-align: center; }

/* ---- Forms ---- */
.stack { display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="url"], .field textarea {
  width: 100%; font: inherit; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text);
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus, select:focus, .btn:focus-visible {
  outline: 2px solid var(--cobalt); outline-offset: 1px; border-color: var(--cobalt);
}
.field-hint { font-size: 12px; color: var(--text-muted); margin: 4px 0 0; }
.field-error { font-size: 12px; color: var(--err); margin: 4px 0 0; font-weight: 600; }
.inline-form { display: inline-block; }

/* ---- Buttons ---- */
.btn {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border-radius: 6px; padding: 8px 14px; border: 1px solid transparent;
  display: inline-flex; align-items: center; gap: 6px; line-height: 1.3;
}
.btn--primary { background: var(--cobalt); color: #fff; }
.btn--primary:hover { background: var(--cobalt-deep); }
.btn--ghost { background: #fff; border-color: var(--line); color: var(--text); }
.btn--ghost:hover { border-color: #c4cad6; background: #fafbfd; }
.btn--danger { background: #fff; border-color: #ecc8c3; color: var(--err); }
.btn--danger:hover { background: #fdf4f3; }
.btn--danger-solid { background: var(--err); color: #fff; }
.btn--danger-solid:hover { background: var(--err-deep); }
.btn--sm { padding: 4px 10px; font-size: 12px; }
.btn--block { width: 100%; justify-content: center; }

/* ---- Banners & flash ---- */
.banner { border-radius: var(--radius); padding: 11px 14px; font-size: 13px; margin-bottom: 18px; border: 1px solid; }
.banner--warn { background: #fbf5e8; border-color: #ecd9ae; color: #6d4a12; }
.banner--danger { background: #fbeae8; border-color: #efc6c0; color: #7c1f16; font-weight: 600; }
.flash {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-radius: var(--radius); padding: 11px 14px; margin-bottom: 16px;
  font-size: 13.5px; border: 1px solid;
}
.flash--success { background: #e9f6ef; border-color: #bfe3cf; color: #135c36; }
.flash--error { background: #fbeae8; border-color: #efc6c0; color: #7c1f16; }
.flash-close { background: none; border: none; font-size: 18px; cursor: pointer; color: inherit; opacity: 0.6; padding: 0 2px; }
.flash-close:hover { opacity: 1; }

/* ---- Connections ---- */
.connection { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.connection-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.connection-head strong { margin-right: 6px; }
.connection-actions { display: flex; gap: 0; }
.connection-meta { font-size: 11.5px; margin-top: 5px; }
.connection-error {
  margin-top: 8px; font-size: 12px; color: var(--err);
  background: #fdf4f3; border: 1px solid #f0d4d0; border-radius: 6px; padding: 7px 10px;
}
.divider { border-top: 1px solid var(--line); margin: 18px 0 16px; }

/* ---- Auth ---- */
.auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--ink); }
.auth-wrap { width: 100%; max-width: 380px; padding: 24px; }
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 22px; }
.auth-card { padding: 26px; }
.auth-title { font-size: 18px; margin-bottom: 2px; }
.auth-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 18px; }
.error-detail {
  background: #f4f5f8; border: 1px solid var(--line); border-radius: 6px;
  padding: 10px; font-family: var(--mono); font-size: 11px;
  overflow-x: auto; max-height: 300px; text-align: left;
}

/* ---- Responsive ---- */
@media (max-width: 1080px) {
  .grid--4 { grid-template-columns: 1fr 1fr; }
  .grid--main-side { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 2px; }
  .nav-section { display: none; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .grid--2, .grid--4 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- Phase 1-9 additions ---------------------------------------- */
.banner--err { background: #fbeae8; border-color: #efc6c0; color: #7c1f16; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab { padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--muted); border-radius: 8px 8px 0 0; border: 1px solid transparent; border-bottom: none; }
.tab:hover { color: var(--ink); text-decoration: none; }
.tab--active { color: var(--cobalt); background: #fff; border-color: var(--line); margin-bottom: -1px; }

.grid--two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .grid--two { grid-template-columns: 1fr; } }

/* Angle board */
.board { display: grid; grid-template-columns: repeat(4, minmax(230px, 1fr)); gap: 14px; margin-bottom: 18px; overflow-x: auto; }
.board-col { background: #eef0f4; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.board-col-head { display: flex; justify-content: space-between; align-items: center; margin: 2px 4px 10px; }
.board-col-head h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.angle-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(20,25,38,.05); }
.angle-title { font-weight: 650; font-size: 13.5px; margin-bottom: 2px; }
.angle-meta { color: var(--muted); margin: 6px 0 8px; }
.angle-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.angle-actions form { display: inline; }

/* Asset library */
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; }
.asset { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.asset img { width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block; }
.asset-video { width: 100%; aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center; background: #1d2333; color: #cfd6e4; font-size: 12px; }
.asset-meta { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 6px 8px; }
.asset--pick { cursor: pointer; position: relative; }
.asset--pick input { position: absolute; opacity: 0; }
.asset--pick:has(input:checked) { outline: 3px solid var(--cobalt); outline-offset: -1px; }
.swipe-thumb { height: 48px; border-radius: 6px; border: 1px solid var(--line); display: block; margin-bottom: 4px; }

/* Filters / condition rows */
.filter-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.filter-row select, .filter-row input { width: auto; }
.cond-row .field { margin: 0; }
.cond-row { gap: 8px; margin-bottom: 6px; }
details.add-rule > summary { list-style: none; cursor: pointer; display: inline-block; }
details.add-rule > summary::-webkit-details-marker { display: none; }
details > summary.btn { user-select: none; }

/* Funnel waterfall */
.funnel-step { display: grid; grid-template-columns: 110px 1fr 190px; gap: 12px; align-items: center; margin-bottom: 10px; }
.funnel-label { color: var(--muted); font-weight: 600; }
.funnel-track { background: #eef0f4; border-radius: 6px; height: 22px; overflow: hidden; }
.funnel-bar { background: var(--cobalt); height: 100%; border-radius: 6px; min-width: 2px; }
.range-pills { display: flex; gap: 6px; }
.table.perf td, .table.perf th { text-align: right; }
.table.perf td:first-child, .table.perf th:first-child { text-align: left; }
.table.ops td:last-child { max-width: 520px; }
