:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #7a8699;
  --border: #dfe5ee;
  --border-soft: #edf1f6;
  --blue: #2384ff;
  --blue-soft: #edf5ff;
  --cyan: #12c8be;
  --orange: #ffb21a;
  --red: #ef6262;
  --navy: #11194a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f7f9fc;
}

.login-shell {
  width: min(100%, 360px);
}

.login-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(34, 47, 75, 0.08);
}

.brand-row,
.logo-lockup,
.app-topbar,
.top-nav,
.top-actions,
.filter-bar,
.filter-controls,
.tabs,
.section-title,
.section-toolbar,
.toolbar-actions {
  display: flex;
  align-items: center;
}

.brand-row,
.logo-lockup {
  gap: 10px;
}

.brand-mark {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 6px;
  color: #ffffff;
  background: var(--blue);
  font-size: 15px;
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: #596579;
  font-size: 12px;
  font-weight: 700;
}

.login-form input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 10px;
  color: var(--text);
  background: #ffffff;
}

.login-form input:focus,
.toolbar-actions input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(35, 132, 255, 0.12);
  outline: none;
}

.login-form button {
  height: 38px;
  border: 0;
  border-radius: 5px;
  color: #ffffff;
  background: var(--blue);
  font-weight: 800;
}

.form-error {
  margin: -2px 0 0;
  color: #c03636;
  font-size: 12px;
  font-weight: 700;
}

.app-frame {
  min-height: 100vh;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 60px;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  background: #ffffff;
}

.logo-lockup strong {
  color: #142033;
  font-size: 15px;
}

.top-nav {
  height: 100%;
  gap: 2px;
  margin-right: auto;
  margin-left: 26px;
}

.top-nav a {
  display: inline-flex;
  height: 100%;
  align-items: center;
  border-bottom: 2px solid transparent;
  padding: 0 16px;
  color: #3d4656;
  font-weight: 700;
}

.top-nav a.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

.top-actions {
  gap: 10px;
}

.primary-action,
.icon-button,
.filter-controls button,
.tabs button,
.toolbar-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 12px;
  color: #263245;
  background: #ffffff;
  font-weight: 700;
}

.primary-action {
  border-color: var(--blue);
  color: #ffffff;
  background: var(--blue);
}

.small-action {
  display: inline-flex;
  height: 32px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 10px;
  color: #2a5fb8;
  background: #ffffff;
  font-size: 13px;
  font-weight: 800;
}

.balance {
  display: inline-flex;
  height: 36px;
  align-items: center;
  border-radius: 5px;
  padding: 0 12px;
  color: #0f243a;
  background: #dff8f5;
  font-weight: 900;
}

.user-chip {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  color: #4f5b70;
  background: #eef2f7;
  font-size: 12px;
  font-weight: 900;
}

.icon-button {
  width: 42px;
  padding: 0;
}

.page {
  padding: 20px 24px 28px;
}

.context-bar {
  display: flex;
  min-height: 32px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  background: #f5f7fb;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: #6e7a8f;
  font-size: 12px;
  font-weight: 800;
}

.breadcrumbs a {
  color: var(--blue);
}

.breadcrumbs span {
  color: #4b5668;
}

.breadcrumbs b {
  color: #a8b1c0;
  font-weight: 800;
}

.back-button {
  display: inline-flex;
  height: 24px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 9px;
  color: #3f4c5f;
  background: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.filter-bar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.tabs button {
  min-width: 78px;
  border-radius: 0;
}

.tabs button:first-child {
  border-radius: 5px 0 0 5px;
}

.tabs button:last-child {
  border-radius: 0 5px 5px 0;
}

.tabs button.active,
.filter-controls button.active {
  color: var(--blue);
  border-color: var(--blue);
  background: var(--blue-soft);
}

.filter-controls {
  gap: 8px;
}

.panel-compact {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.section-title {
  justify-content: space-between;
  gap: 12px;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.insights {
  margin-bottom: 18px;
}

.insights > .section-title {
  height: 44px;
  border-bottom: 1px solid var(--border-soft);
  padding: 0 20px;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.insight-item {
  min-height: 82px;
  border-right: 1px solid var(--border-soft);
  padding: 16px 20px 10px;
  position: relative;
}

.insight-item:last-child {
  border-right: 0;
}

.metric-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--blue);
  font-weight: 700;
}

.metric-label i {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--blue);
}

.insight-item strong {
  display: block;
  margin-top: 10px;
  color: var(--navy);
  font-size: 22px;
  line-height: 1;
}

.spark {
  position: absolute;
  right: 20px;
  bottom: 12px;
  width: 92px;
  height: 26px;
  border-bottom: 2px solid #f2c785;
}

.spark::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: -2px;
  width: 28px;
  height: 24px;
  border-top: 2px solid currentColor;
  border-radius: 40% 30% 0 0;
  transform: rotate(28deg);
}

.spark-warm {
  color: var(--red);
}

.spark-cool,
.spark-cyan {
  color: var(--cyan);
  border-bottom-color: #bff1ee;
}

.spark-gray {
  color: #b4bac5;
  border-bottom-color: #eef1f5;
}

.data-section {
  overflow: hidden;
}

.section-toolbar {
  justify-content: space-between;
  min-height: 58px;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
}

.toolbar-actions {
  gap: 8px;
}

.toolbar-actions input {
  width: 190px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 10px;
  background: #ffffff;
}

.table-wrap {
  overflow: auto;
}

.table-wrap.dense {
  max-height: calc(100vh - 334px);
}

.data-table {
  width: 100%;
  min-width: 1280px;
  border-collapse: separate;
  border-spacing: 0;
  background: #ffffff;
}

.data-table th,
.data-table td {
  height: 42px;
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: #202938;
  background: #ffffff;
  font-size: 13px;
  font-weight: 900;
}

.sort-link {
  color: inherit;
  text-decoration: none;
}

.sort-link:hover {
  color: #2b7cff;
}

.data-table td {
  color: #243040;
  font-size: 13px;
}

.data-table select,
.data-table input[type="text"],
.data-table input:not([type]) {
  width: 100%;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 8px;
  color: #243040;
  background: #ffffff;
}

.data-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--blue);
}

code {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  color: #1f4fb0;
  background: #f6f8fc;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.roi {
  font-weight: 900;
}

.roi.neutral {
  color: #687386;
}

.value-positive {
  color: #12824c;
  font-weight: 800;
}

.value-negative {
  color: #c9382c;
  font-weight: 800;
}

.data-table .total-row td {
  background: #f5f8fb;
  border-bottom-color: #d6dee8;
  color: #202938;
  font-weight: 800;
}

.action-pill {
  display: inline-flex;
  min-width: 56px;
  height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 900;
}

.action-keep {
  color: #0b6d40;
  background: #e8f7ee;
}

.action-watch {
  color: #8a5a00;
  background: #fff3cf;
}

.action-block {
  color: #a3261d;
  background: #ffe5e1;
}

.badge {
  display: inline-flex;
  min-width: 76px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  padding: 0 10px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.badge.testing {
  background: var(--cyan);
}

.badge.watch {
  background: var(--orange);
}

.badge.blocked {
  background: #738095;
}

.table-link {
  color: var(--blue);
  font-weight: 800;
}

.source-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 18px 20px;
}

.source-head span,
.stat-panel p {
  color: var(--muted);
}

.source-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-actions button {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 12px;
  color: #263245;
  background: #ffffff;
  font-weight: 700;
}

.stat-panel {
  padding: 18px 20px;
}

.stat-panel > strong {
  display: block;
  margin: 20px 0 8px;
  color: var(--navy);
  font-size: 28px;
}

.stat-panel p {
  margin: 0;
  line-height: 1.6;
}

.empty-state {
  display: grid;
  min-height: 280px;
  place-items: center;
  padding: 34px 20px;
  text-align: center;
}

.empty-state h2 {
  margin-top: 14px;
}

.empty-state p {
  max-width: 420px;
  margin: 8px 0 0;
  color: var(--muted);
}

.empty-plus {
  display: inline-grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 1px solid var(--blue);
  border-radius: 50%;
  color: var(--blue);
  background: var(--blue-soft);
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
}

.editor-form {
  overflow: hidden;
}

.editor-error {
  margin: 14px 20px 0;
}

.form-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(240px, 0.8fr) minmax(360px, 1.2fr);
  padding: 18px 20px;
}

.form-grid.single {
  grid-template-columns: minmax(360px, 720px);
}

.form-grid.campaign-grid {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.form-grid label {
  display: grid;
  gap: 7px;
  color: #596579;
  font-size: 12px;
  font-weight: 800;
}

.form-grid input {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 10px;
  color: var(--text);
  background: #ffffff;
}

.form-grid select {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 10px;
  color: var(--text);
  background: #ffffff;
}

.form-grid select[multiple] {
  height: auto;
  min-height: 124px;
  padding: 6px;
}

.form-grid select[multiple] option {
  padding: 4px 6px;
}

.form-grid textarea {
  width: 100%;
  min-height: 124px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
}

.form-grid small,
.form-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.picker {
  display: grid;
  gap: 8px;
}

.picker-search {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 10px;
}

.picker-list {
  display: grid;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #ffffff;
}

.picker-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-soft);
  padding: 7px 9px;
  color: #2f3b4d;
  font-size: 13px;
  font-weight: 700;
}

.picker-option:last-child {
  border-bottom: 0;
}

.picker-option b {
  color: var(--muted);
  text-align: right;
  font-size: 12px;
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus,
.picker-search:focus,
.data-table input:focus,
.data-table select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(35, 132, 255, 0.12);
  outline: none;
}

.form-success {
  margin: 0;
  color: #16845f;
  font-size: 12px;
  font-weight: 800;
}

.backfill-progress {
  display: grid;
  gap: 8px;
  margin: 14px 20px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  background: #f8fbff;
}

.backfill-progress[hidden] {
  display: none;
}

.backfill-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #26364f;
  font-size: 12px;
  font-weight: 800;
}

.backfill-progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce8f7;
}

.backfill-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  transition: width 180ms ease;
}

.backfill-progress p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.backfill-progress.is-error {
  border-color: #f1b6b6;
  background: #fff8f8;
}

.backfill-progress.is-error .backfill-progress-track span {
  background: #d95454;
}

.form-options-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  color: #526074;
  font-size: 13px;
  font-weight: 800;
}

.form-options-row label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.payload-preview {
  margin-top: 18px;
  padding: 18px 20px;
}

.payload-preview pre {
  max-height: 460px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 14px 0 0;
  padding: 14px;
  color: #1d2736;
  background: #f8fafc;
  font-size: 12px;
  line-height: 1.55;
}

.material-output {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 18px 20px;
}

.copy-field {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 82px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfe;
}

.copy-field > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.copy-field code {
  overflow-x: auto;
  white-space: nowrap;
}

.copy-field button {
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: #2a5fb8;
  background: #ffffff;
  font-weight: 800;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.row-actions form {
  margin: 0;
}

.row-actions button,
.row-actions select {
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

.row-actions button {
  padding: 0 10px;
  cursor: pointer;
}

.inline-move-form {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.compact-date {
  height: 34px;
  min-width: 140px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #ffffff;
  color: var(--text);
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
}

.popup-page {
  min-height: 100vh;
  background: var(--page);
  padding: 14px;
}

.popup-page .data-table {
  min-width: 1080px;
}

.material-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.empty-state.compact {
  min-height: 220px;
}

.zones-editor {
  border-top: 1px solid var(--border);
}

.zones-title {
  padding: 16px 20px;
}

.auto-extract-note {
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  background: #fbfcfe;
}

.token-status {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(240px, 0.45fr) minmax(360px, 1fr);
  padding: 18px 20px;
}

.options-cache-banner {
  display: grid;
  align-items: center;
  gap: 14px;
  grid-template-columns: minmax(180px, 0.3fr) minmax(220px, 0.45fr) auto;
  border-top: 1px solid var(--border);
  padding: 14px 20px;
}

.options-cache-banner.ready {
  background: #f3fbf8;
}

.options-cache-banner.missing {
  background: #fff8ed;
}

.token-status div,
.options-cache-banner div {
  display: grid;
  gap: 7px;
}

.token-status span,
.options-cache-banner span {
  color: #596579;
  font-size: 12px;
  font-weight: 800;
}

.token-status strong,
.options-cache-banner strong {
  color: var(--navy);
  font-size: 15px;
}

.auto-extract-note h2 {
  margin: 0 0 8px;
}

.auto-extract-note p {
  max-width: 840px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.zones-details summary {
  color: var(--blue);
  cursor: pointer;
  font-weight: 800;
}

.zone-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 640px;
  margin-top: 8px;
}

.zone-chip-list span {
  display: inline-flex;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  color: #586478;
  background: #f7f9fc;
  font-size: 12px;
}

.zone-chip-list b {
  color: #20304a;
}

.split-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  margin-top: 18px;
}

.split-grid .panel-compact {
  padding: 18px 20px;
}

.path-row {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 9px 14px;
  margin-top: 16px;
}

.path-row span,
.rule-list span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.path-row b,
.rule-list b {
  color: #263245;
  font-size: 13px;
}

.rule-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.rule-list div {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  align-items: center;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 10px;
  background: #fbfcfe;
}

@media (max-width: 980px) {
  .app-topbar,
  .filter-bar,
  .section-toolbar {
    align-items: flex-start;
    flex-direction: column;
    height: auto;
  }

  .app-topbar {
    position: static;
    padding: 14px 16px;
  }

  .context-bar {
    padding: 8px 16px;
    align-items: flex-start;
    flex-direction: column;
  }

  .top-nav {
    width: 100%;
    height: auto;
    margin: 4px 0 0;
    overflow-x: auto;
  }

  .top-nav a {
    height: 36px;
  }

  .top-actions,
  .filter-controls,
  .toolbar-actions {
    flex-wrap: wrap;
  }

  .insight-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .insight-item {
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
  }
}

@media (max-width: 640px) {
  .page {
    padding: 14px;
  }

  .tabs,
  .filter-controls,
  .toolbar-actions {
    width: 100%;
  }

  .tabs button,
  .filter-controls button,
  .toolbar-actions button,
  .toolbar-actions input {
    flex: 1;
    min-width: 0;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-grid,
  .form-grid.single,
  .form-grid.campaign-grid {
    grid-template-columns: 1fr;
  }

  .copy-field {
    grid-template-columns: 1fr;
  }
}
