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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: #1a1a2e;
  color: white;
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 0.75rem; }
header h1 { font-size: 1.25rem; font-weight: 600; }
.header-actions { display: flex; gap: 1rem; align-items: center; }
.btn-icon {
  background: none; border: none; color: white; font-size: 1.25rem;
  cursor: pointer; padding: 4px 8px; border-radius: 4px;
}
.btn-icon:hover { background: rgba(255,255,255,0.1); }
.btn-logout {
  color: rgba(255,255,255,0.7); text-decoration: none; font-size: 0.85rem;
  padding: 0.4rem 0.8rem; border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
}
.btn-logout:hover { background: rgba(255,255,255,0.1); color: white; }
.demo-badge {
  font-size: 0.75rem; color: rgba(255,255,255,0.5);
  padding: 0.25rem 0.6rem; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
}

/* ── Layout ── */
.app-layout {
  display: flex;
  min-height: calc(100vh - 52px);
}

/* ── Sidebar ── */
.sidebar {
  width: 220px;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  padding: 1rem 0;
  flex-shrink: 0;
  overflow-y: auto;
  transition: margin-left 0.2s;
}
.sidebar.collapsed { margin-left: -220px; }
.sidebar-section { padding: 0 0.75rem; margin-bottom: 0.5rem; }
.sidebar-bottom { border-top: 1px solid #e8e8e8; padding-top: 0.75rem; margin-top: 0.5rem; }
.sidebar-label {
  font-size: 0.68rem; color: #888; text-transform: uppercase;
  letter-spacing: 0.5px; padding: 0.5rem 0.75rem;
}
.sidebar-item {
  padding: 0.6rem 0.75rem; border-radius: 6px; cursor: pointer;
  font-size: 0.875rem; color: #444; display: flex;
  align-items: center; justify-content: space-between;
  border-left: 3px solid transparent; margin-bottom: 2px;
}
.sidebar-item:hover { background: #f5f5f8; }
.sidebar-item.active {
  background: #f0f0f5; font-weight: 600; color: #1a1a2e;
  border-left-color: #1a1a2e;
}
.sidebar-item .status-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.status-dot.live { background: #4caf50; }
.status-dot.stale { background: #ff9800; }
.status-dot.error { background: #f44336; }
.badge {
  font-size: 0.65rem; padding: 1px 6px; border-radius: 8px;
  font-weight: 600; background: #ff9800; color: #fff;
}

/* ── Main Content ── */
.main-content { flex: 1; padding: 1.5rem; overflow-y: auto; }

.view { display: none; }
.view.active { display: block; }

/* ── Portfolio Summary Bar ── */
.summary-bar {
  background: #f8f9fa; border-radius: 8px; padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem; border: 1px solid #e0e0e0;
  display: flex; gap: 2.5rem; flex-wrap: wrap;
}
.summary-stat .stat-value {
  font-size: 1.75rem; font-weight: 700; color: #1a1a2e;
}
.summary-stat .stat-label { font-size: 0.75rem; color: #888; margin-top: 2px; }

/* ── Brand Cards Grid ── */
.brand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
.brand-card {
  background: #fff; border-radius: 8px; padding: 1.25rem;
  border: 1px solid #e0e0e0; cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.brand-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  border-color: #1a1a2e;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.75rem;
}
.card-brand-name { font-size: 1rem; font-weight: 600; }
.sync-badge {
  font-size: 0.68rem; padding: 2px 8px; border-radius: 4px; font-weight: 600;
}
.sync-badge.live { background: #e8f5e9; color: #2e7d32; }
.sync-badge.stale { background: #fff3e0; color: #e65100; }
.sync-badge.ok { background: #e3f2fd; color: #1565c0; }
.sync-badge.error { background: #ffebee; color: #c62828; }
.card-revenue {
  font-size: 1.5rem; font-weight: 700; color: #1a1a2e;
}
.card-delta { font-size: 0.8rem; font-weight: 500; margin-left: 0.5rem; }
.card-delta.up { color: #2e7d32; }
.card-delta.down { color: #c62828; }
.card-sublabel { font-size: 0.75rem; color: #888; margin-bottom: 0.75rem; }
.card-metrics { display: flex; gap: 1rem; font-size: 0.8rem; margin-bottom: 0.75rem; }
.card-metrics span { color: #666; }
.card-metrics strong { color: #333; }
.card-alert {
  padding: 0.4rem 0.6rem; background: #fff3e0; border-radius: 4px;
  font-size: 0.75rem; color: #e65100; margin-top: 0.5rem;
}

/* ── Mini Bar Chart ── */
.mini-bar-chart { display: flex; align-items: flex-end; gap: 3px; height: 56px; }
.mini-bar-wrapper { display: flex; flex-direction: column; align-items: center; flex: 1; }
.mini-bar {
  width: 100%; max-width: 28px; border-radius: 3px 3px 0 0;
  background: #b0bec5; min-height: 0;
}
.mini-bar.current { background: #1a1a2e; }
.mini-bar.empty { background: #e0e0e0; opacity: 0.3; height: 4px !important; }
.mini-bar-label { font-size: 0.56rem; color: #888; margin-top: 2px; }

/* ── Detail View ── */
.btn-back {
  background: none; border: none; color: #1a1a2e; cursor: pointer;
  font-size: 0.875rem; margin-bottom: 1rem; padding: 0; font-weight: 500;
}
.btn-back:hover { text-decoration: underline; }
.detail-header {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 1.25rem; flex-wrap: wrap;
}
.detail-icon { font-size: 2rem; }
.detail-name { font-size: 1.35rem; font-weight: 700; color: #1a1a2e; }
.detail-sub { font-size: 0.8rem; color: #888; }
.detail-sync { margin-left: auto; }

/* ── KPI Tiles ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem; margin-bottom: 1.25rem;
}
.kpi-tile {
  background: #f8f9fa; border-radius: 8px; padding: 0.875rem 1rem;
  border: 1px solid #e8e8e8;
}
.kpi-label {
  font-size: 0.65rem; color: #888; text-transform: uppercase;
  letter-spacing: 0.3px; margin-bottom: 4px;
}
.kpi-value { font-size: 1.25rem; font-weight: 700; color: #1a1a2e; }
.kpi-sub { font-size: 0.7rem; margin-top: 2px; }
.kpi-sub.up { color: #2e7d32; }
.kpi-sub.down { color: #c62828; }

/* ── Gauge Cards ── */
.gauge-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1rem; margin-bottom: 1.25rem;
}
.gauge-card {
  background: #fff; border-radius: 8px; padding: 1.25rem;
  border: 1px solid #e0e0e0;
}
.gauge-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.75rem;
}
.gauge-title { font-size: 0.875rem; font-weight: 600; }
.target-badge {
  font-size: 0.68rem; padding: 2px 8px; border-radius: 4px; font-weight: 600;
}
.target-badge.ok { background: #e8f5e9; color: #2e7d32; }
.target-badge.warn { background: #fff3e0; color: #e65100; }
.gauge-value { font-size: 2rem; font-weight: 700; }
.gauge-value.ok { color: #1a1a2e; }
.gauge-value.warn { color: #e65100; }
.gauge-target { font-size: 0.8rem; color: #888; margin-left: 0.5rem; }
.gauge-bar {
  margin-top: 0.75rem; height: 8px; background: #e0e0e0;
  border-radius: 4px; overflow: hidden;
}
.gauge-fill { height: 100%; border-radius: 4px; }
.gauge-fill.ok { background: #4caf50; }
.gauge-fill.warn { background: #ff9800; }

/* ── Detail Chart ── */
.detail-chart {
  background: #fff; border-radius: 8px; padding: 1.25rem;
  border: 1px solid #e0e0e0; margin-bottom: 1.25rem;
}
.chart-title { font-size: 0.875rem; font-weight: 600; margin-bottom: 1rem; }
.chart-bars { display: flex; align-items: flex-end; gap: 0.5rem; height: 140px; }
.chart-bar-wrapper { flex: 1; display: flex; flex-direction: column; align-items: center; }
.chart-bar-value { font-size: 0.6rem; color: #666; margin-bottom: 4px; }
.chart-bar {
  width: 100%; max-width: 48px; border-radius: 4px 4px 0 0;
  background: #1a1a2e;
}
.chart-bar.empty { background: #e0e0e0; opacity: 0.15; }
.chart-bar-label { font-size: 0.7rem; color: #888; margin-top: 4px; }

/* ── Detail Alerts ── */
.detail-alerts {
  background: #fff; border-radius: 8px; padding: 1.25rem;
  border: 1px solid #e0e0e0;
}
.alerts-title { font-size: 0.875rem; font-weight: 600; margin-bottom: 0.75rem; }
.alert-item {
  padding: 0.6rem 0.875rem; border-radius: 6px; margin-bottom: 0.5rem;
  font-size: 0.8rem;
}
.alert-item.warning { background: #fff3e0; color: #e65100; }
.alert-item.info { background: #e3f2fd; color: #1565c0; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 52px;
        bottom: 0;
        z-index: 90;
        width: 220px;
        transform: translateX(-220px);
        transition: transform 0.2s;
        box-shadow: none;
        visibility: hidden;
      }
      .sidebar.open {
        visibility: visible;
        transform: translateX(0);
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
      }
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 80;
  }
  .sidebar-overlay.visible {
    display: block;
  }
  .brand-grid { grid-template-columns: 1fr; }
  .gauge-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-bar { gap: 1.5rem; }
  header h1 { font-size: 1.1rem; }
}

/* ── Login Page ── */
.login-page {
  display: flex; align-items: center; justify-content: center;
  background: #1a1a2e; min-height: 100vh;
}
.login-container {
  background: white; padding: 2rem; border-radius: 8px;
  text-align: center; width: 100%; max-width: 360px;
}
.login-container h1 { margin-bottom: 0.5rem; color: #1a1a2e; font-size: 1.5rem; }
.login-container .login-sub { color: #888; font-size: 0.85rem; margin-bottom: 1.5rem; }
.login-container input {
  width: 100%; padding: 0.75rem; border: 1px solid #ddd;
  border-radius: 4px; margin-bottom: 1rem; font-size: 1rem;
}
.login-container button {
  width: 100%; padding: 0.75rem; background: #1a1a2e; color: white;
  border: none; border-radius: 4px; font-size: 1rem; cursor: pointer;
}
.login-container button:hover { background: #2a2a4e; }
.login-container .error { color: #e74c3c; margin-bottom: 1rem; font-size: 0.85rem; }