:root {
  --bg: #050607;
  --bg-soft: #0a0d10;
  --panel: #0d1117;
  --panel-2: #10151d;
  --line: rgba(191, 208, 255, 0.12);
  --text: #e9eef8;
  --muted: #7f8a9d;
  --accent: #c7f34f;
  --accent-2: #5ea2ff;
  --accent-3: #58d97c;
  --danger: #ff7575;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --mono: "IBM Plex Mono", "SFMono-Regular", "Menlo", monospace;
  --display: "Rajdhani", "Arial Narrow", sans-serif;
  --sans: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 85%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--sans);
  background:
    linear-gradient(180deg, rgba(199, 243, 79, 0.06), transparent 120px),
    linear-gradient(90deg, rgba(94, 162, 255, 0.04), transparent 40%),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

.shell {
  min-height: 100vh;
  padding: 8px;
  display: grid;
  gap: 0;
  align-content: start;
  grid-auto-rows: max-content;
}

.topbar,
.module-nav,
.toolbar,
.filters,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar {
  height: 32px;
  min-height: 32px;
  padding: 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  overflow: hidden;
}

.topbar-brand,
.topbar-stats,
.toolbar-actions,
.toolbar-meta,
.section-head-meta,
.modal-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-brand {
  gap: 8px;
  flex: 0 0 auto;
  height: 100%;
}

.brand-copy h1,
.section-head h3 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
}

.logo {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.62rem;
  color: var(--accent);
  background: linear-gradient(180deg, rgba(199, 243, 79, 0.14), rgba(94, 162, 255, 0.08));
  border: 1px solid rgba(199, 243, 79, 0.28);
}

.brand-copy {
  display: flex;
  align-items: center;
  height: 100%;
}

.brand-copy h1 {
  font-size: 0.78rem;
  line-height: 1;
  letter-spacing: 0.03em;
}

.module-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 0;
  min-height: auto;
  height: auto;
  align-items: center;
  padding: 2px 8px;
}

.shell > .topbar {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.shell > .module-nav,
.shell > .toolbar,
.shell > .filters {
  border-top: 0;
  border-radius: 0;
}

.shell > .filters {
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
}

.module-link,
.toolbar-btn,
.row-edit-btn,
.row-code-btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
}

.module-link {
  padding: 4px 12px;
  font-size: 11px;
  color: #11140d;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  min-height: 26px;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent), #a6ca3a);
  border-color: rgba(199, 243, 79, 0.45);
  border-radius: 9px;
}

.toolbar,
.filters {
  padding: 4px 6px;
}

.module-link.active {
  border-color: rgba(94, 162, 255, 0.45);
  box-shadow: inset 0 -2px 0 var(--accent-2), 0 0 0 1px rgba(94, 162, 255, 0.18);
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 2px 6px;
}

.compact-btn {
  padding: 5px 12px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-family: var(--mono);
  line-height: 1;
  min-height: 24px;
}

.primary {
  border: 0;
  color: #11140d;
  background: linear-gradient(135deg, var(--accent), #a6ca3a);
}

.toolbar-btn:disabled {
  color: rgba(233, 238, 248, 0.42);
}

.filters {
  display: grid;
  grid-template-columns: minmax(240px, 2fr) repeat(3, minmax(160px, 1fr));
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-family: var(--mono);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 8px;
  align-items: start;
}

.workspace.campaigns-full {
  grid-template-columns: minmax(0, 1fr);
}

.workspace.campaigns-full .workspace-side {
  display: none;
}

.workspace-main,
.workspace-side {
  display: grid;
  gap: 8px;
}

.panel {
  padding: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stat-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(9, 14, 16, 0.96), rgba(9, 11, 15, 0.96));
}

.stat-clicks {
  background: linear-gradient(180deg, #3a4048, #252b33);
  border-color: rgba(145, 156, 171, 0.34);
}

.stat-revenue {
  background: linear-gradient(135deg, #d8ff59, #bde94f);
  border-color: rgba(216, 255, 89, 0.52);
}

.stat-conversions {
  background: linear-gradient(135deg, #eaff38, #d4ef1b);
  border-color: rgba(234, 255, 56, 0.58);
}

.stat-profit {
  background: linear-gradient(135deg, #b7ea73, #9ddf5d);
  border-color: rgba(157, 223, 93, 0.54);
}

.stat-profit.negative {
  background: linear-gradient(135deg, #ff7f84, #ef5f68);
  border-color: rgba(255, 127, 132, 0.58);
}

.stat-card span,
.messages,
.selected-caption,
th,
td,
.readonly-box span,
.placeholder-panel p {
  color: var(--muted);
}

#data-body td {
  color: var(--text);
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 20px;
}

.stat-revenue span,
.stat-revenue strong,
.stat-conversions span,
.stat-conversions strong,
.stat-profit span,
.stat-profit strong {
  color: #11140d;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.selected-caption {
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid rgba(191, 208, 255, 0.08);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.01), rgba(255, 255, 255, 0));
}

.drilldown-toolbar {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.drilldown-row {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 8px;
}

.drilldown-toolbar select,
.drilldown-toolbar input {
  background: linear-gradient(135deg, rgba(58, 64, 72, 0.62), rgba(37, 43, 51, 0.62));
  color: #e9eef8;
  border-color: rgba(145, 156, 171, 0.35);
  font-family: var(--mono);
}

.drilldown-toolbar select:focus,
.drilldown-toolbar input:focus {
  outline: 1px solid rgba(145, 156, 171, 0.48);
}

.drilldown-shortcut {
  width: 100%;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid rgba(199, 243, 79, 0.55);
  background: linear-gradient(135deg, rgba(216, 255, 89, 0.9), rgba(189, 233, 79, 0.9));
  color: #11140d;
  font-family: var(--mono);
  text-align: left;
  cursor: pointer;
}

.drilldown-shortcut.active {
  box-shadow: inset 0 0 0 1px rgba(145, 156, 171, 0.45), 0 0 0 1px rgba(199, 243, 79, 0.25);
}

.drilldown-blue-btn {
  border-color: rgba(94, 162, 255, 0.5);
  background: linear-gradient(135deg, rgba(94, 162, 255, 0.34), rgba(70, 124, 204, 0.34));
  color: #dfe9ff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
}

th + th,
td + td {
  border-left: 1px solid rgba(191, 208, 255, 0.07);
}

.campaign-check-col {
  width: 32px;
  padding-left: 6px;
  padding-right: 6px;
  text-align: center;
}

.campaign-check {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--accent);
}

th {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 11px;
  background: linear-gradient(135deg, rgba(216, 255, 89, 0.82), rgba(189, 233, 79, 0.82));
  color: #11140d;
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.sort-arrow {
  font-size: 10px;
  opacity: 0.7;
}

.sort-btn.active .sort-arrow {
  opacity: 1;
}

tbody tr {
  cursor: pointer;
}

tbody tr.selected {
  background: rgba(94, 162, 255, 0.14);
  box-shadow: inset 3px 0 0 var(--accent-2);
}

.row-edit-btn,
.row-code-btn {
  padding: 6px 10px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.name-with-tags {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.campaign-name-cell {
  display: grid;
  gap: 6px;
}

.campaign-score {
  display: flex;
  align-items: center;
  gap: 8px;
}

.campaign-score-track {
  position: relative;
  width: 120px;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(191, 208, 255, 0.15);
}

.campaign-score-fill {
  height: 100%;
}

.campaign-score-fill.positive {
  background: linear-gradient(90deg, rgba(170, 255, 0, 0.75), rgba(199, 243, 79, 0.95));
}

.campaign-score-fill.negative {
  background: linear-gradient(90deg, rgba(255, 64, 96, 0.8), rgba(255, 90, 128, 0.96));
}

.campaign-score-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text);
  white-space: nowrap;
}

.name-text {
  color: var(--text);
}

.entity-id {
  display: inline-flex;
  align-items: center;
  margin-right: 8px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
}

.name-tags {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.table-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #11140d;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table-tag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: none;
}

.table-tag.tag-color-1 { background: #c7f34f; border-color: rgba(199, 243, 79, 0.48); }
.table-tag.tag-color-2 { background: #58d97c; border-color: rgba(88, 217, 124, 0.48); }
.table-tag.tag-color-3 { background: #5ea2ff; border-color: rgba(94, 162, 255, 0.48); }
.table-tag.tag-color-4 { background: #ffd166; border-color: rgba(255, 209, 102, 0.48); }
.table-tag.tag-color-5 { background: #ff9f43; border-color: rgba(255, 159, 67, 0.48); }
.table-tag.tag-color-6 { background: #ff8fab; border-color: rgba(255, 143, 171, 0.48); }
.table-tag.tag-color-7 { background: #7bdff2; border-color: rgba(123, 223, 242, 0.48); }
.table-tag.tag-color-8 { background: #b8f2e6; border-color: rgba(184, 242, 230, 0.48); }
.table-tag.tag-color-9 { background: #f9c74f; border-color: rgba(249, 199, 79, 0.48); }
.table-tag.tag-color-10 { background: #90be6d; border-color: rgba(144, 190, 109, 0.48); }

.side-panel {
  position: sticky;
  top: 10px;
}

.form-grid {
  display: grid;
  gap: 8px;
}

.source-short-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.source-advanced {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.source-advanced-title {
  font-family: var(--display);
  font-weight: 700;
  margin-bottom: 6px;
}

.source-token-head,
.source-token-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  align-items: center;
}

.source-token-head {
  margin-bottom: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.source-token-rows {
  display: grid;
  gap: 6px;
}

.source-token-row label {
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
}

.readonly-box {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
}

.readonly-box strong {
  display: block;
  margin-top: 6px;
  font-family: var(--mono);
  color: var(--text);
}

.campaign-link-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.placeholder-panel {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, 0.02);
}

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

.message {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
}

.message.success {
  border-color: rgba(88, 217, 124, 0.45);
}

.message.error {
  border-color: rgba(255, 117, 117, 0.45);
}

.toast-stack {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: grid;
  gap: 8px;
  width: min(540px, calc(100vw - 24px));
}

.toast {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(13, 17, 23, 0.96);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  box-shadow: var(--shadow);
  opacity: 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.success {
  border-color: rgba(88, 217, 124, 0.45);
}

.toast.error {
  border-color: rgba(255, 117, 117, 0.45);
}

.toast.hide {
  opacity: 0;
  transform: translateY(-4px);
}

.mini-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
}

.mini-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.mini-chip.blue::before {
  background: var(--accent-2);
}

.mini-chip.green::before {
  background: var(--accent-3);
}

.mini-chip.yellow::before {
  background: var(--accent);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 20;
}

.hidden,
.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(900px, calc(100vw - 32px));
}

.campaign-modal-card {
  width: min(980px, calc(100vw - 32px));
}

.source-modal-card {
  width: min(1120px, calc(100vw - 32px));
}

.offer-modal-card,
.landing-modal-card {
  width: min(760px, calc(100vw - 32px));
}

.conversion-logs-modal-card {
  width: min(1320px, calc(100vw - 32px));
}

.monitor-modal-card {
  width: min(1100px, calc(100vw - 32px));
}

.campaign-modal-form {
  gap: 10px;
}

.campaign-save-btn {
  width: 100%;
}

.campaign-builder {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.campaign-col {
  display: grid;
  gap: 8px;
  align-content: start;
}

.field-label {
  font-family: var(--display);
  font-size: 0.9rem;
  font-weight: 700;
}

.tag-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-pill {
  position: relative;
}

.tag-pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tag-pill span {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  cursor: pointer;
}

.tag-pill input:checked + span {
  color: #11140d;
  border-color: transparent;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14) inset;
}

.tag-pill[data-color="1"] input:checked + span { background: #c7f34f; }
.tag-pill[data-color="2"] input:checked + span { background: #58d97c; }
.tag-pill[data-color="3"] input:checked + span { background: #5ea2ff; }
.tag-pill[data-color="4"] input:checked + span { background: #ffd166; }
.tag-pill[data-color="5"] input:checked + span { background: #ff9f43; }
.tag-pill[data-color="6"] input:checked + span { background: #ff8fab; }
.tag-pill[data-color="7"] input:checked + span { background: #7bdff2; }
.tag-pill[data-color="8"] input:checked + span { background: #b8f2e6; }
.tag-pill[data-color="9"] input:checked + span { background: #f9c74f; }
.tag-pill[data-color="10"] input:checked + span { background: #90be6d; }

.paths-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.campaign-paths {
  display: grid;
  gap: 8px;
}

.path-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.02);
  display: grid;
  gap: 6px;
}

.path-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.path-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.path-rule-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}

.rule-fields.hidden {
  display: none;
}

.rule-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.source-modal-form {
  gap: 10px;
}

.offer-modal-form,
.landing-modal-form {
  gap: 10px;
}

.source-template-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 8px;
}

.conversion-logs-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(320px, 1.6fr) minmax(150px, 0.8fr) minmax(150px, 0.8fr) max-content;
  gap: 8px;
  margin-bottom: 10px;
}

.conversion-logs-table {
  max-height: 60vh;
}

.monitor-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.monitor-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.monitor-label {
  font-family: var(--display);
  font-size: 1.35rem;
  color: var(--muted);
}

.monitor-track {
  position: relative;
  height: 54px;
  border-radius: 14px;
  overflow: hidden;
  background: #c6cbd4;
}

.monitor-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, #bde47f, #c7f34f);
}

.monitor-text {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #122038;
  font-size: 1rem;
  font-weight: 700;
  padding: 0 10px;
  text-align: center;
}

.monitor-cleanup {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  gap: 10px;
}

.monitor-cleanup-head {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.1rem;
}

.monitor-cleanup-filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) max-content;
  gap: 8px;
}

.monitor-cleanup-stats {
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.92rem;
}

.monitor-recommendation {
  color: var(--muted);
  font-size: 0.95rem;
}

.monitor-recommendation.alert {
  color: #ffd57a;
}

.log-direction {
  display: inline-flex;
  width: 16px;
  justify-content: center;
  margin-right: 6px;
  font-weight: 700;
}

.log-direction.incoming {
  color: #58d97c;
}

.log-direction.outgoing {
  color: #ff7f84;
}

.code-editor {
  min-height: 300px;
  font-family: var(--mono);
  font-size: 11px;
}

.empty-cell {
  padding: 20px 8px;
  color: var(--muted);
}

@media (max-width: 1220px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }
}

@media (max-width: 900px) {
  .filters,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .toolbar {
    flex-direction: column;
    align-items: start;
  }

  .campaign-builder,
  .path-grid,
  .rule-fields,
  .conversion-logs-filters,
  .monitor-cleanup-filters,
  .drilldown-row {
    grid-template-columns: 1fr;
  }

  .monitor-row {
    grid-template-columns: 1fr;
  }
}
