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

:root {
  --blue: #378ADD;
  --teal: #1D9E75;
  --purple: #534AB7;
  --purple-light: rgba(83,74,183,0.10);
  --blue-light: rgba(55,138,221,0.12);
  --teal-light: rgba(29,158,117,0.10);
  --gray-100: #f5f5f4;
  --gray-200: #e8e8e6;
  --gray-400: #a0a09a;
  --gray-600: #5f5e5a;
  --gray-900: #1a1a18;
  --text: #1a1a18;
  --text-muted: #6b6b66;
  --text-hint: #a0a09a;
  --border: rgba(0,0,0,0.10);
  --border-md: rgba(0,0,0,0.16);
  --bg: #ffffff;
  --bg-secondary: #f7f7f5;
  --radius: 8px;
  --radius-lg: 12px;
  --up: #1D9E75;
  --down: #D85A30;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-secondary);
  line-height: 1.5;
}

/* Login wall */
#login-wall {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
}
.login-box {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  text-align: center;
  width: 320px;
}
.login-logo {
  width: 48px; height: 48px;
  background: var(--purple);
  color: white;
  font-weight: 600;
  font-size: 16px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1rem;
}
.login-box h1 { font-size: 18px; font-weight: 500; margin-bottom: 6px; }
.login-box p { color: var(--text-muted); font-size: 13px; margin-bottom: 1.5rem; }
.login-box button {
  width: 100%; padding: 10px;
  background: var(--purple); color: white;
  border: none; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; cursor: pointer;
}
.login-box button:hover { opacity: 0.88; }

/* Header */
header {
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  padding: 0 1.5rem;
  height: 52px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px;
  background: var(--purple); color: white;
  font-weight: 600; font-size: 11px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-size: 14px; font-weight: 500; }
.header-right { display: flex; align-items: center; gap: 14px; }
.sync-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); }
.sign-out-btn {
  font-size: 12px; color: var(--text-muted);
  background: none; border: 0.5px solid var(--border-md);
  border-radius: var(--radius); padding: 4px 10px; cursor: pointer;
}
.sign-out-btn:hover { color: var(--text); }

/* Platform toggle */
.platform-toggle {
  display: flex;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius);
  overflow: hidden;
}
.platform-toggle button {
  padding: 5px 14px; font-size: 13px;
  background: transparent; border: none;
  cursor: pointer; color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
}
.platform-toggle button.active {
  background: var(--gray-100);
  color: var(--text); font-weight: 500;
}

/* Upload bar */
.upload-bar {
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  padding: 8px 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--text-muted);
}
.status-pill { display: flex; align-items: center; gap: 7px; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot.green { background: var(--teal); }
.upload-right { display: flex; align-items: center; gap: 16px; }
.upload-label {
  display: flex; align-items: center; gap: 5px;
  color: var(--blue); font-weight: 500; cursor: pointer;
}
.upload-label:hover { opacity: 0.8; }
.last-sync { color: var(--text-hint); }

/* Tab nav */
.tab-nav {
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  padding: 0 1.5rem;
  display: flex; gap: 0;
}
.tab-nav button {
  padding: 10px 16px; font-size: 13px;
  background: transparent; border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer; color: var(--text-muted);
  margin-bottom: -0.5px;
  transition: color 0.12s;
}
.tab-nav button.active {
  color: var(--text); font-weight: 500;
  border-bottom: 2px solid var(--text);
}

/* Main content */
main { padding: 1.25rem 1.5rem; max-width: 1200px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Controls */
.controls {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-bottom: 1rem; align-items: flex-end;
}
.ctrl-group { display: flex; flex-direction: column; gap: 3px; }
.ctrl-group label {
  font-size: 10px; color: var(--text-hint); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.ctrl-group select {
  font-size: 13px; padding: 6px 10px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  cursor: pointer; min-width: 150px;
}

/* Summary cards */
.summary-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin-bottom: 1.1rem;
}
.metric-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.metric-card.skeleton {
  height: 72px;
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }
.mlabel { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.mvalue { font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; }
.mchange { font-size: 11px; margin-top: 3px; }
.mchange.up { color: var(--up); }
.mchange.down { color: var(--down); }
.mchange.neutral { color: var(--text-hint); }

/* Chart */
.chart-header {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 6px; flex-wrap: wrap; gap: 6px;
}
.chart-period { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.viewby { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.viewby select {
  font-size: 12px; padding: 3px 8px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg); color: var(--text);
}
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 14px;
  margin-bottom: 8px; font-size: 12px; color: var(--text-muted);
}
.chart-legend span { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.chart-wrap {
  position: relative; width: 100%; height: 260px;
  background: var(--bg); border: 0.5px solid var(--border);
  border-radius: var(--radius); padding: 12px;
}

/* Section headers */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.75rem; flex-wrap: wrap; gap: 8px;
}
.section-header h2 { font-size: 14px; font-weight: 500; }

/* Mini toggles */
.mini-toggle {
  display: flex;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius); overflow: hidden;
}
.mini-toggle button {
  padding: 4px 10px; font-size: 12px;
  background: transparent; border: none;
  cursor: pointer; color: var(--text-muted);
}
.mini-toggle button.active {
  background: var(--gray-100);
  color: var(--text); font-weight: 500;
}

/* Tables */
.table-wrap {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; padding: 9px 12px;
  font-size: 10px; font-weight: 500;
  color: var(--text-hint);
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap; user-select: none;
  background: var(--bg-secondary);
}
.data-table th.sortable { cursor: pointer; }
.data-table th.sortable:hover { color: var(--text-muted); }
.data-table th.sorted { color: var(--text); }
.data-table td {
  padding: 9px 12px;
  border-bottom: 0.5px solid var(--border);
  color: var(--text);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-secondary); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sort-arrow { font-size: 11px; margin-left: 2px; }
.loading-cell { color: var(--text-hint); text-align: center; padding: 2rem !important; font-size: 13px; }
.source-badge {
  display: inline-block; font-size: 10px;
  padding: 2px 7px; border-radius: 10px; font-weight: 500;
}
.badge-tpt { background: #E1F5EE; color: #0F6E56; }
.badge-shopify { background: #E6F1FB; color: #185FA5; }

/* Bubble chart for search */
.bubble-wrap {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  gap: 12px; padding: 1rem 0;
}
.bubble {
  border-radius: 50%; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-weight: 500; color: white; text-align: center; padding: 8px;
  flex-shrink: 0;
}
.bubble .bkw { font-size: 11px; line-height: 1.3; }
.bubble .bct { font-size: 13px; font-weight: 600; }

@media (max-width: 600px) {
  main { padding: 1rem; }
  header { padding: 0 1rem; }
  .upload-bar { padding: 8px 1rem; flex-direction: column; align-items: flex-start; gap: 6px; }
  .tab-nav { padding: 0 1rem; }
  .controls { gap: 8px; }
  .ctrl-group select { min-width: 130px; }
}

.badge-both { background: #F0EEFF; color: #534AB7; }
