:root {
  /* Modern Dark Palette (Deep Blues & Purples) */
  --bg: #06060c;
  --surface: rgba(15, 15, 24, 0.7);
  --surface2: rgba(22, 22, 33, 0.85);
  --surface3: rgba(30, 30, 44, 0.95);
  --border: rgba(255, 255, 255, 0.06);
  --border2: rgba(255, 255, 255, 0.12);
  --text: #f1f1f6;
  --muted: #9494b0;
  --faint: #47475c;
  
  /* Accent Indigo / Violet Glows */
  --accent: #6366f1;
  --accent2: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.16);
  
  /* Unified Status Colors */
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.08);
  --green-border: rgba(16, 185, 129, 0.25);
  
  --red: #f43f5e;
  --red-bg: rgba(244, 63, 94, 0.08);
  --red-border: rgba(244, 63, 94, 0.25);
  
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.08);
  --amber-border: rgba(245, 158, 11, 0.25);
  
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.08);
  
  /* Typography */
  --font: 'Plus Jakarta Sans', sans-serif;
  --font-heading: 'Syne', sans-serif;
  --mono: 'DM Mono', monospace;
  
  /* Premium Shadows & Transitions */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 24px rgba(99, 102, 241, 0.15);
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

[data-theme="light"] {
  /* Sleek Light Palette */
  --bg: #f8fafc;
  --surface: rgba(255, 255, 255, 0.75);
  --surface2: rgba(241, 245, 249, 0.85);
  --surface3: rgba(226, 232, 240, 0.95);
  --border: rgba(0, 0, 0, 0.05);
  --border2: rgba(0, 0, 0, 0.09);
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  
  --accent: #4f46e5;
  --accent2: #6366f1;
  --accent-glow: rgba(79, 70, 229, 0.08);
  
  --green: #059669;
  --green-bg: rgba(5, 150, 105, 0.06);
  --green-border: rgba(5, 150, 105, 0.2);
  
  --red: #dc2626;
  --red-bg: rgba(220, 38, 38, 0.06);
  --red-border: rgba(220, 38, 38, 0.2);
  
  --amber: #d97706;
  --amber-bg: rgba(217, 119, 6, 0.06);
  --amber-border: rgba(217, 119, 6, 0.2);
  
  --blue: #2563eb;
  --blue-bg: rgba(37, 99, 235, 0.06);
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(149, 157, 165, 0.1);
  --shadow-lg: 0 16px 32px rgba(149, 157, 165, 0.15);
  --shadow-glow: 0 0 24px rgba(79, 70, 229, 0.08);
}

[data-theme="light"] .topbar {
  background: rgba(248, 250, 252, 0.7);
}

/* ---- BACKGROUND GLOWS ---- */
.bg-glow-1, .bg-glow-2 {
  position: fixed;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  filter: blur(120px);
  opacity: 0.12;
  transition: opacity 0.5s ease;
}
[data-theme="light"] .bg-glow-1, [data-theme="light"] .bg-glow-2 {
  opacity: 0.04;
  filter: blur(140px);
}
.bg-glow-1 {
  top: -120px;
  right: -80px;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
}
.bg-glow-2 {
  bottom: -150px;
  left: 5%;
  background: radial-gradient(circle, var(--blue) 0%, transparent 70%);
}

/* ---- CUSTOM SCROLLBARS ---- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 20px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--faint);
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* ---- RESET & GENERAL ---- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 80% 50% at 50% -20%, var(--accent-glow), transparent);
  pointer-events: none;
  z-index: 0;
}

/* ---- LAYOUT ---- */
.app {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}
.sidebar {
  width: 240px;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.main {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}
.topbar {
  height: 56px;
  background: rgba(7, 7, 13, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.content {
  padding: 28px;
  max-width: 1300px;
  width: 100%;
  margin: 0 auto;
}

/* ---- SIDEBAR ---- */
.logo {
  padding: 16px 20px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}
.logo-text {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.3px;
  line-height: 1.2;
}
.logo-sub {
  font-size: 10px;
  color: #f59e0b;
  font-family: var(--mono);
  letter-spacing: 0.5px;
  font-weight: 600;
}
.nav {
  padding: 16px 12px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}
.nav::-webkit-scrollbar {
  width: 3px;
}
.nav::-webkit-scrollbar-track {
  background: transparent;
}
.nav::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.12);
  border-radius: 3px;
}
.nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,.25);
}
.nav-section {
  font-size: 9px;
  font-family: var(--mono);
  letter-spacing: 1.8px;
  color: var(--muted);
  opacity: 0.5;
  padding: 12px 10px 4px;
  text-transform: uppercase;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  transition: var(--transition);
  margin-bottom: 1px;
  border: 1px solid transparent;
  position: relative;
}
.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text);
}
.nav-item.active {
  background: rgba(245, 158, 11, 0.13);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.18);
  font-weight: 600;
}
.nav-item.active::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
}
.nav-item .icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  opacity: 0.85;
}
.nav-item.active .icon {
  opacity: 1;
}
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.2);
}
.user-info {
  flex: 1;
  overflow: hidden;
}
.user-name {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--mono);
}

/* ---- TOPBAR ---- */
.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}
.page-title {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 800;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert-bell {
  position: relative;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.alert-bell:hover {
  background: var(--surface2);
  color: var(--text);
  transform: scale(1.05);
}
.alert-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  background: var(--red);
  border-radius: 20px;
  border: 2px solid var(--bg);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  font-family: var(--mono);
  color: #fff;
  padding: 0 4px;
  line-height: 1;
  animation: pulse 2s infinite;
}
.alert-badge.show {
  display: flex;
}

/* ---- BUTTONS ---- */
.btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active {
  transform: scale(0.96);
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.22);
}
.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
}
.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-ghost:hover {
  border-color: var(--border2);
  background: var(--surface3);
  color: var(--text);
  transform: translateY(-1px);
}
.btn-danger {
  background: linear-gradient(135deg, var(--red), #fda4af);
  color: #fff;
  box-shadow: 0 4px 14px rgba(244, 63, 94, 0.22);
}
.btn-danger:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}
.btn-success {
  background: linear-gradient(135deg, var(--green), #6ee7b7);
  color: #fff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.22);
}
.btn-success:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}
.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
}
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

/* ---- FORMS ---- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-label {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}
input, select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
  width: 100%;
}
input:hover, select:hover, textarea:hover {
  border-color: var(--border2);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  background: var(--surface3);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
input[type="time"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.7;
  border-radius: 3px;
  padding: 1px;
}
[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator,
:not([data-theme="light"]) input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.6) sepia(1) saturate(4) hue-rotate(220deg) brightness(1.4);
  opacity: 1;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%239494b0' d='M5 7L0 2h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.input-row {
  display: flex;
  gap: 8px;
}
.input-row input {
  flex: 1;
}

/* ---- CARDS ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}
.card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--border2);
}
.card-title {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 16px;
  letter-spacing: -0.2px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.metric-card:hover {
  transform: translateY(-3px);
  border-color: var(--border2);
  box-shadow: var(--shadow-md);
  background: var(--surface3);
}
.metric-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(to bottom, var(--accent), var(--accent2));
  opacity: 0;
  transition: var(--transition);
}
.metric-card:hover::after {
  opacity: 1;
}
.m-label {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  font-weight: 500;
}
.m-value {
  font-family: var(--font);
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.3px;
  white-space: nowrap;
}
.m-sub {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--mono);
  margin-top: 5px;
}

/* ---- ADSET CARDS ---- */
.adset-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  margin-bottom: 12px;
  transition: var(--transition);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.adset-card:hover {
  transform: translateY(-2px);
  border-color: var(--border2);
  box-shadow: var(--shadow-md);
}
.adset-card.good {
  border-color: var(--green-border);
  background: linear-gradient(135deg, var(--surface), var(--green-bg));
}
.adset-card.good:hover {
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.08);
}
.adset-card.bad {
  border-color: var(--red-border);
  background: linear-gradient(135deg, var(--surface), var(--red-bg));
}
.adset-card.bad:hover {
  box-shadow: 0 8px 24px rgba(244, 63, 94, 0.08);
}
.adset-card.warn {
  border-color: var(--amber-border);
  background: linear-gradient(135deg, var(--surface), var(--amber-bg));
}
.adset-card.warn:hover {
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.08);
}
.adset-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.adset-name {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
  flex: 1;
  line-height: 1.4;
}
.badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.badge {
  font-size: 9px;
  font-family: var(--mono);
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}
.b-green {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}
.b-red {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
}
.b-amber {
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid var(--amber-border);
}
.b-blue {
  background: var(--blue-bg);
  color: var(--blue);
  border: 1px solid rgba(59, 130, 246, 0.2);
}
.b-gray {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border: 1px solid var(--border);
}
[data-theme="light"] .b-gray {
  background: rgba(0, 0, 0, 0.04);
}
.adset-metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 14px 0;
  background: var(--surface2);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.am {
  text-align: center;
}
.am-v {
  font-size: 14px;
  font-weight: 700;
}
.am-l {
  font-size: 9px;
  color: var(--muted);
  font-family: var(--mono);
  margin-top: 3px;
  text-transform: uppercase;
}
.adset-tip {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--accent-glow);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}
.adset-tip strong {
  color: var(--text);
}

/* ---- TABS ---- */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 5px;
}
.tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  transition: var(--transition);
  border: 1px solid transparent;
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.tab:hover:not(.active) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}
[data-theme="light"] .tab:hover:not(.active) {
  background: rgba(0, 0, 0, 0.02);
}

/* ---- PERIOD BAR ---- */
.period-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.period-btn {
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: var(--transition);
  font-weight: 600;
}
.period-btn.active, .period-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

/* ---- TABLE ---- */
.tbl-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}
th {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  padding: 12px 16px;
  text-align: left;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  transition: var(--transition);
}
tr:last-child td {
  border-bottom: none;
}
tr:hover td {
  background: var(--surface2);
}

/* ---- CHART ---- */
.chart-wrap {
  position: relative;
  height: 240px;
  margin-bottom: 8px;
}

/* ---- FUNIL VISUAL ---- */
.funnel-wrap {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.05), rgba(99, 102, 241, 0.05));
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.funnel-title {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 20px;
  text-align: center;
}
.funnel-layout {
  display: flex;
  gap: 28px;
  align-items: center;
}
.funnel-3d {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
}
.funnel-step {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}
.funnel-bowl {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  transition: var(--transition);
  cursor: default;
  height: 60px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.funnel-bowl:hover {
  transform: translateY(-2px) scaleX(1.01);
  filter: brightness(1.06);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}
.funnel-bowl-label {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  opacity: 0.8;
  margin-bottom: 2px;
}
.funnel-bowl-value {
  font-size: 16px;
  font-weight: 900;
  line-height: 1.1;
}
.funnel-bowl-sub {
  font-size: 9px;
  opacity: 0.8;
  margin-top: 2px;
}
.funnel-taxa {
  position: absolute;
  bottom: -12px;
  z-index: 3;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.funnel-side {
  width: 160px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.fside-item {
  background: var(--surface2);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  border-left: 4px solid var(--accent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.fside-item.green {
  border-left-color: var(--green);
}
.fside-item.amber {
  border-left-color: var(--amber);
}
.fside-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.fside-value {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}

@media(max-width:768px){
  .funnel-layout{flex-direction:column; gap:16px;}
  .funnel-wrap{padding:18px 16px;}
  .funnel-3d{gap:8px;}
  .funnel-step{margin-bottom:8px;}
  .funnel-bowl{
    width:95% !important;
    border-radius:var(--radius-md);
    height:auto;
    min-height:58px;
    padding:10px 16px;
  }
  .funnel-bowl-value{font-size:14px;}
  .funnel-bowl-label{font-size:8px;}
  .funnel-taxa{display:none;}
  .funnel-side{width:100%;display:grid;grid-template-columns:1fr 1fr;gap:8px;}
}

/* ---- AI HISTORY EXPAND ---- */
.hist-expand { display: none; }
.hist-expand.open { display: block; }

/* ---- OPTIMIZER ACTION CARDS ---- */
.camp-opt-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 14px 16px;
  transition: opacity .2s;
}
.camp-opt-card:has(button:disabled) { opacity: .5; pointer-events: none; }

/* ---- AI PANEL & TEXT ---- */
.ai-panel {
  background: linear-gradient(135deg, var(--surface), rgba(99, 102, 241, 0.08));
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-md);
}
.ai-panel h3 {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 800;
  color: var(--accent2);
  margin-bottom: 14px;
}
.ai-text {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.8;
}
.ai-text strong {
  color: var(--text);
  font-weight: 700;
}
.ai-text h1, .ai-text h2 {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  margin: 24px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.ai-text h3 {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent2);
  margin: 18px 0 8px;
}
.ai-text ul, .ai-text ol {
  margin: 10px 0 16px 20px;
  padding-left: 0;
}
.ai-text li {
  margin-bottom: 6px;
}
.ai-text li::marker {
  color: var(--accent);
}
.ai-text p {
  margin-bottom: 14px;
}
.ai-text blockquote {
  margin: 16px 0;
  padding: 12px 18px;
  background: var(--surface2);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text);
}

/* ---- LOGIN ---- */
#login-page {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 999;
  overflow-y: auto;
}
#login-page::before {
  content: '';
  position: absolute;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  filter: blur(100px);
  opacity: 0.2;
  top: 15%;
  left: 20%;
  pointer-events: none;
}
#login-page::after {
  content: '';
  position: absolute;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, var(--blue) 0%, transparent 70%);
  filter: blur(100px);
  opacity: 0.2;
  bottom: 15%;
  right: 20%;
  pointer-events: none;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: var(--radius-lg);
  padding: 44px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 10;
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo .icon {
  font-size: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  background: var(--accent-glow);
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 1px solid rgba(99, 102, 241, 0.2);
}
.login-logo h1 {
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.login-logo p {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  margin-top: 4px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-err {
  font-size: 12px;
  color: var(--red);
  font-family: var(--mono);
  min-height: 18px;
  text-align: center;
}

/* ---- MODAL ---- */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
  padding: 16px;
}
.modal-bg.open {
  display: flex;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: var(--radius-lg);
  padding: 30px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalScale 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
}
@keyframes modalScale {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
.modal-title {
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 22px;
}
.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

/* ---- MISC & UTILS ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.section-title {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 800;
}
.section-sub {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}
.loading {
  text-align: center;
  padding: 40px;
  font-size: 13px;
  font-family: var(--mono);
  color: var(--muted);
}
.spin {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 10px;
  vertical-align: middle;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.8);
  }
}
.empty {
  text-align: center;
  padding: 48px;
  color: var(--muted);
  font-size: 13px;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.row .form-group {
  flex: 1;
}
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}
.tag {
  display: inline-block;
  font-size: 10px;
  font-family: var(--mono);
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--surface3);
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 600;
}
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border2);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 9999;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  box-shadow: var(--shadow-lg);
}
.toast.show {
  transform: translateY(0);
  opacity: 1;
}
.toast.ok {
  border-color: var(--green-border);
  color: var(--green);
}
.toast.err {
  border-color: var(--red-border);
  color: var(--red);
}
[data-page] {
  display: none;
}
[data-page].active {
  display: block;
}

/* ============================================================
   MOBILE RESPONSIVE + PWA
   ============================================================ */

/* Hambúrguer */
.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
}
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: 0.2s;
}
.hamburger.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.hamburger.open span:nth-child(2) {
  opacity: 0;
}
.hamburger.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Overlay sidebar mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 49;
  backdrop-filter: blur(3px);
}
.sidebar-overlay.show {
  display: block;
}

/* Bottom nav mobile */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
}
.bn-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 700;
  transition: var(--transition);
  min-width: 50px;
}
.bn-item.active {
  color: var(--accent2);
  background: var(--accent-glow);
}
.bn-item .bn-icon {
  font-size: 18px;
  line-height: 1;
}

/* Instalar PWA banner */
#pwa-banner {
  display: none;
  position: fixed;
  bottom: 80px;
  left: 12px;
  right: 12px;
  z-index: 60;
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-lg);
}
.pwa-banner-inner {
  display: flex;
  align-items: center;
  gap: 12px;
}
.pwa-banner-icon {
  font-size: 28px;
  flex-shrink: 0;
}
.pwa-banner-text {
  flex: 1;
}
.pwa-banner-title {
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}
.pwa-banner-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.pwa-banner-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

@media (max-width: 768px) {
  /* Layout principal */
  .sidebar {
    position: fixed;
    top: 0;
    left: -260px;
    height: 100vh;
    z-index: 50;
    width: 260px;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    padding-bottom: 80px;
  }
  .sidebar.open {
    left: 0;
  }
  .main {
    margin-left: 0;
  }
  .topbar {
    padding: 0 16px;
  }
  .hamburger {
    display: flex;
  }
  .content {
    padding: 16px 16px 90px;
  }

  /* Bottom nav */
  .bottom-nav {
    display: flex;
  }

  /* Esconde nav lateral no mobile (usa bottom nav) */
  .nav, .sidebar-footer {
    display: none;
  }
  .logo {
    padding: 20px 16px;
  }

  /* Grids */
  .grid-2, .ata-grid {
    grid-template-columns: 1fr;
  }
  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .metric-card {
    padding: 14px 16px;
  }
  .m-value {
    font-size: 18px;
  }
  .adset-metrics {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Selects globais ficam na mesma linha mesmo em telas menores */
  #global-selects {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
  }
  #global-selects .form-group {
    flex: 1;
    min-width: 0;
  }

  /* Topbar */
  .page-title {
    font-size: 14px;
  }
  .topbar-right .btn {
    font-size: 11px;
    padding: 6px 10px;
  }

  /* Cards */
  .card {
    padding: 16px 18px;
  }
  .tabs {
    flex-wrap: wrap;
  }
  .tab {
    flex: 1;
    min-width: 80px;
    font-size: 11px;
    padding: 8px 6px;
  }

  /* Modais fullscreen/bottom-sheet no mobile */
  .modal-bg {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 85vh;
    padding: 24px 20px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  .modal-title {
    font-size: 16px;
  }

  /* Toast */
  .toast {
    left: 16px;
    right: 16px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    transform: translateY(120px);
  }
  .toast.show {
    transform: translateY(0);
  }

  /* Tabelas responsivas */
  .tbl-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table {
    min-width: 600px;
  }

  /* Score bar + meta CPR empilham no mobile */
  #score-bar {
    min-width: unset !important;
    width: 100%;
  }
  #dash-content > div:nth-child(2) {
    flex-direction: column;
  }
  #score-bar .sbars {
    grid-template-columns: 1fr 1fr;
  }

  /* Charts */
  .chart-wrap {
    height: 220px;
  }

  /* Login */
  .login-box {
    margin: 0 16px;
    padding: 32px 24px;
  }
  .login-logo .icon {
    font-size: 34px;
    width: 60px;
    height: 60px;
  }
  .login-logo h1 {
    font-size: 20px;
  }

  /* Periodo personalizado */
  #custom-date-bar {
    flex-direction: column;
    align-items: stretch;
  }
  #custom-date-bar > div {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .metric-grid {
    grid-template-columns: 1fr;
  }
  .adset-metrics {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Safe area para iPhone X+ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
}

/* ============================================================ WhatsApp Tabs */
.wa-tab-btn {
  padding: 9px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .2s, border-color .2s;
  font-family: var(--font);
  white-space: nowrap;
}
.wa-tab-btn:hover { color: var(--text); }
.wa-tab-btn.active { color: var(--accent2); border-bottom-color: var(--accent); }

/* ============================================================ Google Ads */
.google-account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  width: 190px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  position: relative;
}
.google-account-card:hover { border-color: #4285F4; }
.google-account-card.active {
  border-color: #4285F4;
  background: rgba(66,133,244,0.08);
}
.gac-header { display:flex; align-items:center; gap:6px; margin-bottom:4px; }
.gac-name   { font-size:13px; font-weight:600; color:var(--text); flex:1; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.gac-id     { font-size:11px; color:var(--text-muted); margin-bottom:6px; font-family:var(--font-mono,monospace); }
.gac-footer { display:flex; align-items:center; justify-content:space-between; }
.gac-currency { font-size:11px; color:var(--text-muted); background:var(--bg); padding:2px 7px; border-radius:20px; border:1px solid var(--border); }
.gac-remove   { border:none; background:none; color:var(--text-muted); cursor:pointer; font-size:13px; padding:2px 5px; border-radius:4px; line-height:1; }
.gac-remove:hover { color:var(--red); background:rgba(239,68,68,0.1); }
.badge-test { font-size:9px; font-weight:700; background:rgba(251,188,4,0.18); color:#FBBC04; border:1px solid rgba(251,188,4,0.35); border-radius:4px; padding:1px 5px; text-transform:uppercase; letter-spacing:.5px; }
.google-empty-accounts { display:flex; flex-direction:column; align-items:flex-start; gap:10px; padding:4px 0; }
.channel-badge { display:inline-block; font-size:10px; font-weight:600; padding:2px 7px; border-radius:20px; border:1px solid; }
.channel-search      { color:#4285F4; border-color:rgba(66,133,244,.35); background:rgba(66,133,244,.08); }
.channel-display     { color:#34A853; border-color:rgba(52,168,83,.35); background:rgba(52,168,83,.08); }
.channel-video       { color:#EA4335; border-color:rgba(234,67,53,.35); background:rgba(234,67,53,.08); }
.channel-shopping    { color:#FBBC04; border-color:rgba(251,188,4,.35); background:rgba(251,188,4,.08); }
.channel-performance_max, .channel-pmax { color:#ab47bc; border-color:rgba(171,71,188,.35); background:rgba(171,71,188,.08); }
.channel-smart       { color:#888; border-color:rgba(136,136,136,.35); background:rgba(136,136,136,.08); }

/* ---- PRINT / PDF EXPORT ---- */
@media print {
  body { background: #fff !important; color: #111 !important; font-size: 12px !important; }
  .sidebar, .top-bar, .nav-tabs, #dash-load-bar, .modal-bg,
  button:not(.print-keep), .btn, #balance-bar .btn,
  #dash-loading, #dash-empty { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
  .card { background: #fff !important; border: 1px solid #ddd !important; box-shadow: none !important; break-inside: avoid; }
  .metric-grid { grid-template-columns: repeat(4, 1fr) !important; }
  .kpi-card { background: #f8f8f8 !important; border: 1px solid #ddd !important; }
  .kpi-value { color: #111 !important; }
  .kpi-label { color: #555 !important; }
  canvas { max-height: 180px !important; }
  #dash-content { display: block !important; }
  #print-header { display: block !important; }
}
#print-header {
  display: none;
  padding: 12px 0 18px;
  border-bottom: 2px solid #333;
  margin-bottom: 18px;
}
.hidden { display: none !important; }
