/* Design tokens — light theme is default, dark is opt-in via [data-theme="dark"].
   Two-color system: teal (primary / brand) + orange (secondary / accent). */
:root {
  --page: #f2f7f6;
  --surface-1: #ffffff;
  --surface-2: #eff6f4;
  --surface-3: #e6efec;
  --text-primary: #142420;
  --text-secondary: #5c6d68;
  --text-muted: #8b9a95;
  --gridline: #e6ece9;
  --baseline: #d3dedb;
  --border: rgba(20, 36, 32, 0.09);
  --shadow-card: 0 1px 2px rgba(20, 36, 32, 0.04), 0 8px 20px -8px rgba(20, 36, 32, 0.10);

  --teal-accent: #1baf7a;   /* graphical marks: lines, rings, icons */
  --teal-solid: #0c8267;    /* text-safe: buttons, active states */
  --teal-tint: #e3f7f1;     /* soft fills / hover / active bg */
  --orange-accent: #eb6834;
  --orange-tint: #fdece3;

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;

  --radius-card: 18px;
  --radius-pill: 999px;
  --radius-sm: 10px;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --page: #101614;
  --surface-1: #1a2320;
  --surface-2: #202b27;
  --surface-3: #29352f;
  --text-primary: #f3f7f5;
  --text-secondary: #aebbb5;
  --text-muted: #78877f;
  --gridline: #2b3733;
  --baseline: #3a4842;
  --border: rgba(255, 255, 255, 0.08);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 20px -8px rgba(0, 0, 0, 0.4);

  --teal-accent: #2bd696;
  --teal-solid: #22b98a;
  --teal-tint: #16302a;
  --orange-accent: #ef7d4c;
  --orange-tint: #3a2419;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  transition: background 0.2s ease, color 0.2s ease;
}

button, select, input { font-family: inherit; font-size: inherit; }
a { color: inherit; }

/* ---------- App shell: sidebar + main ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
  font-weight: 700;
  font-size: 15px;
}

.brand .mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--teal-solid), var(--orange-accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.navlabel {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 14px 12px 6px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
  width: 100%;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab .ico { width: 18px; text-align: center; flex-shrink: 0; }
.tab .soon {
  margin-left: auto;
  font-size: 9.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 1px 6px;
}

.tab:hover { background: var(--surface-2); color: var(--text-primary); }

.tab.active {
  background: var(--teal-tint);
  color: var(--teal-solid);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  padding: 10px;
  font-size: 11px;
  color: var(--text-muted);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  padding: 7px 12px;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}
.theme-toggle:hover { color: var(--text-primary); }

.content { flex: 1; min-width: 0; }

/* ---------- Filter bar ---------- */

.filterbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--page);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(6px);
}

.preset-group {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.preset-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.preset-btn:hover { color: var(--text-primary); }
.preset-btn.active { background: var(--teal-solid); color: #fff; }

.date-input {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

select.filter-select {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  min-width: 128px;
  cursor: pointer;
}

.mode-toggle {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-left: auto;
  gap: 2px;
}
.mode-btn { border: none; background: transparent; color: var(--text-secondary); padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.mode-btn.active { background: var(--surface-1); color: var(--teal-solid); font-weight: 600; box-shadow: var(--shadow-card); }

.reset-btn {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.reset-btn:hover { color: var(--text-primary); }

/* ---------- Layout ---------- */

.main { padding: 22px 28px 60px; max-width: 1680px; margin: 0 auto; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 18px;
  animation: fadeUp 0.35s ease both;
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.kpi-card { cursor: pointer; transition: transform 0.15s ease, box-shadow 0.15s ease; position: relative; overflow: hidden; }
.kpi-card:hover { transform: translateY(-3px); box-shadow: 0 4px 8px rgba(20,36,32,0.06), 0 14px 26px -10px rgba(20,36,32,0.16); }
.kpi-card .label { color: var(--text-secondary); font-size: 12px; display: flex; align-items: center; gap: 4px; }
.kpi-card .value { font-size: 27px; font-weight: 700; margin-top: 6px; font-variant-numeric: proportional-nums; }
.kpi-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi-card .spark { position: absolute; right: 14px; top: 16px; width: 74px; height: 28px; }

.grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; margin-bottom: 16px; align-items: stretch; }
.grid-2b { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }

.panel-title { font-size: 14.5px; font-weight: 700; }
.panel-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; margin-bottom: 10px; }

.chart-box { width: 100%; height: 260px; }

/* Funnel */
.funnel-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; cursor: pointer; border-radius: var(--radius-sm); }
.funnel-row:hover { background: var(--surface-2); }
.funnel-label { width: 118px; flex-shrink: 0; font-size: 12.5px; color: var(--text-secondary); }
.funnel-track { flex: 1; background: var(--surface-3); border-radius: var(--radius-sm); height: 30px; position: relative; overflow: hidden; }
.funnel-fill { height: 100%; border-radius: var(--radius-sm); transition: width 0.6s cubic-bezier(.2,.8,.2,1); }
.funnel-value { width: 54px; text-align: right; font-weight: 700; flex-shrink: 0; }
.funnel-conv { font-size: 11px; color: var(--text-muted); margin-left: 130px; margin-top: -3px; margin-bottom: 2px; }

/* Conversion rings */
.rings-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; text-align: center; }
.ring-box { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px; cursor: pointer; border-radius: var(--radius-sm); }
.ring-box:hover { background: var(--surface-2); }
.ring-svg { width: 92px; height: 92px; }
.ring-name { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.ring-sub { font-size: 10.5px; color: var(--text-muted); }

/* Table */
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th {
  text-align: right; color: var(--text-muted); font-weight: 600; padding: 8px 10px;
  border-bottom: 1px solid var(--gridline); white-space: nowrap; position: sticky; top: 0; background: var(--surface-1);
}
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--gridline); white-space: nowrap; font-variant-numeric: tabular-nums; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--surface-2); }
.data-table .src-row { font-weight: 700; }
.data-table .camp-row td:first-child { padding-left: 26px; color: var(--text-secondary); font-weight: 400; }
.data-table .caret { display: inline-block; width: 10px; transition: transform 0.15s ease; color: var(--text-muted); }
.data-table .caret.open { transform: rotate(90deg); }
.pos { color: var(--good); font-weight: 600; }
.neg { color: var(--critical); font-weight: 600; }
.muted { color: var(--text-muted); }

.table-scroll { overflow-x: auto; max-height: 480px; overflow-y: auto; }

/* Bar-scale cell (revenue magnitude, data-bar style) */
.bar-cell { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.bar-cell .bar-track { flex: 1; max-width: 90px; height: 7px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.bar-cell .bar-fill { height: 100%; border-radius: var(--radius-pill); background: linear-gradient(90deg, var(--teal-accent), var(--teal-solid)); }
.bar-cell .bar-val { min-width: 78px; text-align: right; }

/* Geo map */
.map-box { width: 100%; height: 460px; }
.map-legend { display: flex; align-items: center; gap: 10px; font-size: 11.5px; color: var(--text-muted); padding: 6px 4px 0; flex-wrap: wrap; }
.map-legend .ramp { display: flex; height: 10px; border-radius: var(--radius-pill); overflow: hidden; width: 130px; }
.map-legend .ramp span { flex: 1; }
.map-legend .size-note { display: flex; align-items: center; gap: 4px; margin-left: auto; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 20, 18, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; z-index: 100; overflow-y: auto;
  animation: fadeIn 0.15s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); width: 100%; max-width: 1180px; animation: fadeUp 0.2s ease both; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--gridline); }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-header .count { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.modal-close { border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px; }
.modal-body { padding: 8px 20px 20px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill); font-size: 11px; background: var(--surface-3); color: var(--text-secondary); }
.crm-link { border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary); padding: 3px 8px; border-radius: 6px; font-size: 11px; text-decoration: none; cursor: default; }

.empty-note { color: var(--text-muted); font-size: 12px; padding: 20px; text-align: center; }

.ph-badge { font-size: 10px; color: var(--text-muted); background: var(--surface-2); border-radius: var(--radius-pill); padding: 1px 7px; margin-left: 6px; }

::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 980px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; }
  .brand { padding: 6px 10px; }
  .grid-2, .grid-2b { grid-template-columns: 1fr; }
}
