*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #141210;
  --sidebar: #0F0E0C;
  --card: #1C1917;
  --tile: rgba(245,239,230,0.05);
  --border: rgba(245,239,230,0.08);
  --text: #F5EFE6;
  --text-secondary: #B7B0A4;
  --muted: #8A8478;
  --dim: #6E695F;
  --orange: #E04E24;
  --orange-hover: #C84420;
  --orange-soft-text: #E8907A;
  --orange-alert-text: #F0C9BC;
  --good: #79B08F;
  --bad: #C2694F;
  --warn: #C99A4B;
  --cream-btn-text: #FFF6E8;
  --font-display: 'Poppins', -apple-system, sans-serif;
  --font-body: 'Nunito Sans', -apple-system, sans-serif;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

table, .metric-tile .value, .page-title, .card-header h2, h1, h2, h3 {
  font-variant-numeric: tabular-nums;
}
.page-title, .card-header h2 {
  font-family: var(--font-display);
  font-weight: 600;
}
.metric-tile .value, .big-numeral {
  font-family: var(--font-display);
}
.page-title { font-size: 22px; letter-spacing: -0.02em; color: var(--text); }
.card-header h2 { font-size: 15px; }

header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15,14,12,0.92);
  border-bottom: 1px solid rgba(245,239,230,0.07);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  backdrop-filter: blur(10px);
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #fff;
}

#meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #8A8478;
}

#refresh {
  background: #E04E24;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: background 0.15s;
}
#refresh:hover { background: var(--orange-hover); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: #1c1917;
  border: 1px solid rgba(245,239,230,0.07);
  border-radius: 14px;
  padding: 20px 24px;
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 16px;
}

.card-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.card-header .week-range {
  font-size: 12px;
  color: #8A8478;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

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

@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr; }
  header { flex-wrap: wrap; }
}

.metric-tile {
  background: #201e1a;
  border: 1px solid rgba(245,239,230,0.05);
  border-radius: 10px;
  padding: 14px 16px;
  transition: border-color 0.2s;
}

.metric-tile:hover {
  border-color: rgba(224,78,36,0.3);
}

.metric-tile .label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #8A8478;
  margin-bottom: 6px;
}

.metric-tile .value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #F5EFE6;
  line-height: 1.2;
}

.metric-tile .value.positive { color: #79B08F; }
.metric-tile .value.negative { color: #C2694F; }

#historical h2 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  border: 1px solid rgba(245,239,230,0.07);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

thead {
  background: #181714;
}

thead th {
  text-align: right;
  padding: 10px 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8A8478;
  white-space: nowrap;
  border-bottom: 1px solid rgba(245,239,230,0.06);
}

thead th:first-child { text-align: left; }

tbody tr { border-bottom: 1px solid rgba(245,239,230,0.04); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover td { filter: brightness(1.25); outline: none; }

tbody td {
  padding: 9px 12px;
  text-align: right;
  white-space: nowrap;
  background: #1c1917;
  color: #B7B0A4;
}

tbody td:first-child { text-align: left; font-weight: 500; color: #F5EFE6; }

thead th:first-child,
tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  box-shadow: 2px 0 8px -2px rgba(0,0,0,0.5);
}
thead th:first-child { background: #181714; }
tbody td:first-child { background: #1c1917; }
tbody tr.current-week td:first-child { background: #281c18; }
tbody tr.last-week td:first-child { background: #201e1a; }

tbody tr.current-week td { background: rgba(224,78,36,0.06); color: #8A8478; }
tbody tr.last-week td { background: #201e1a; }
tbody tr.current-week td:first-child::after {
  content: 'NOW'; margin-left: 8px; font-size: 9px; font-weight: 800;
  color: var(--orange-soft-text); letter-spacing: 0.05em;
}

.net-positive { color: #79B08F; font-weight: 600; }
.net-negative { color: #C2694F; font-weight: 600; }

.dash { color: #403d39; }

#error {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: 8px;
  padding: 14px 18px;
  color: #C2694F;
  font-size: 13px;
  margin-top: 16px;
}

.no-data {
  padding: 32px;
  text-align: center;
  color: #8A8478;
}

/* ---- App shell: sidebar + content ---- */
.app-shell { display: flex; align-items: flex-start; min-height: 100vh; }

.top-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
  width: 226px;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
  padding: 18px 14px 16px;
  border-right: 1px solid rgba(245,239,230,0.07);
  background: #0f0e0c;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 18px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
}

.side-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #6E695F;
  margin: 16px 10px 6px;
}
.side-group-label:first-of-type { margin-top: 6px; }

.top-nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: #B7B0A4;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.top-nav-btn.active {
  color: var(--cream-btn-text);
  background: rgba(224,78,36,0.13);
  font-weight: 700;
}

.top-nav-btn:hover:not(.active) { color: #F5EFE6; background: rgba(245,239,230,0.04); }

.top-nav-btn .side-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  background: #E04E24;
  color: #f9f5ef;
  white-space: nowrap;
}
.top-nav-btn .side-badge-muted {
  margin-left: auto;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 7px;
  border-radius: 20px;
  background: #34190f;
  color: #e8907a;
  white-space: nowrap;
}
.top-nav-btn .side-dot {
  margin-left: auto;
  width: 7px; height: 7px; border-radius: 50%;
  background: #C2694F; flex-shrink: 0;
}

.top-nav-sub-group {
  display: none;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 4px 14px;
}
.top-nav-btn.active[data-top="adspy"] + .top-nav-sub-group { display: flex; }
.top-nav-btn.active[data-top="reels"] + .top-nav-sub-group { display: flex; }

.top-nav-sub {
  display: flex;
  align-items: center;
  padding: 6px 10px 6px 18px;
  border: none;
  border-radius: 8px;
  background: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: #8A8478;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.top-nav-sub.active { color: var(--cream-btn-text); background: rgba(224,78,36,0.13); font-weight: 700; }
.top-nav-sub:hover:not(.active) { color: #F5EFE6; background: rgba(245,239,230,0.04); }

.side-footer {
  margin-top: auto;
  padding: 14px 10px 4px;
  border-top: 1px solid rgba(245,239,230,0.07);
  font-size: 11px;
  color: #6E695F;
}
.side-footer button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #8A8478;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}
.side-footer button:hover { color: #F5EFE6; }

main { flex: 1; min-width: 0; }

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .top-nav {
    position: static; width: 100%; height: auto; flex-direction: row;
    flex-wrap: wrap; border-right: none; border-bottom: 1px solid rgba(245,239,230,0.07);
  }
  .side-group-label { display: none; }
  .side-footer { display: none; }
  .side-brand { padding: 4px 10px; width: 100%; }
}

.sub-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  background: var(--card);
  border-radius: 20px;
  padding: 4px;
  width: fit-content;
}

.sub-tab-btn {
  padding: 6px 18px;
  border: none;
  border-radius: 20px;
  background: transparent;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  color: var(--muted);
  transition: all 0.15s;
}

.sub-tab-btn.active {
  background: var(--text);
  color: var(--bg);
}

.sub-tab-btn:hover:not(.active) { color: var(--text); }

/* ---- Global alert strip (Today home + reused for bot-signal / next-check banners) ---- */
.alert-strip {
  display: flex; align-items: center; gap: 12px;
  background: rgba(224,78,36,0.1); border: 1px solid rgba(224,78,36,0.35);
  border-radius: 10px; padding: 11px 16px; margin-bottom: 18px;
  font-size: 13px; color: var(--orange-alert-text);
}
.alert-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); flex-shrink: 0; }
.alert-btn {
  background: var(--orange); color: var(--cream-btn-text); text-decoration: none;
  padding: 6px 16px; border-radius: 20px; font-weight: 700; font-size: 12px; white-space: nowrap;
}
.alert-btn:hover { background: var(--orange-hover); }

.top-panel { display: none; }
.top-panel.active { display: block !important; }
.sub-panel { display: none; }
.sub-panel.active { display: block; }

/* ---- Loading spinner ---- */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 72px 0;
  gap: 14px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(224,78,36,0.2);
  border-top-color: #E04E24;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state span { color: #8A8478; font-size: 13px; }

/* ---- Settings overlay ---- */
#settings-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  overflow-y: auto;
}
#settings-overlay.visible { display: block; }
#settings-header {
  position: sticky;
  top: 0;
  background: rgba(20,18,16,0.95);
  border-bottom: 1px solid rgba(245,239,230,0.07);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  backdrop-filter: blur(10px);
  z-index: 10;
}
#settings-header h2 { font-family: var(--font-display); font-size: 16px; font-weight: 600; color: var(--text); }
#settings-close {
  margin-left: auto;
  background: rgba(245,239,230,0.07);
  border: none;
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  color: #F5EFE6;
  cursor: pointer;
  font-family: inherit;
}
#settings-close:hover { background: rgba(245,239,230,0.13); }
#gear-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #8A8478;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
#gear-btn:hover { color: #F5EFE6; }

/* ---- Lightbox ---- */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 500;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
#lightbox.open { display: flex; }
#lightbox-content {
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
}
#lightbox-close {
  position: fixed;
  top: 18px;
  right: 22px;
  background: rgba(245,239,230,0.1);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  padding: 4px 10px;
  cursor: pointer;
}
#lightbox-close:hover { background: rgba(245,239,230,0.2); }
.creative-thumb { cursor: zoom-in; }
