/* ─── Reset & Base ──────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --content-bg: #f5f6fa;
  --card-bg: #ffffff;

  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;

  --border: #e5e7eb;
  --border-light: #f3f4f6;

  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);

  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);

  /* aliases used by login.html */
  --bg-card: var(--card-bg);
  --bg-secondary: #f3f4f6;
  --border-glass: var(--border);
  --shadow-glass: var(--shadow-card);
}

html { font-size: 14px; }

body {
  font-family: var(--font);
  background: var(--content-bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ─── App shell & Sidebar ───────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 1.1rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.4rem 1rem;
  border-bottom: 1px solid var(--border-light);
}
.brand-logo { height: 32px; width: auto; display: block; }
.brand-name { font-size: 1.1rem; font-weight: 800; letter-spacing: -0.01em; }

.sidebar-label {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  padding: 0 0.55rem;
  margin-bottom: 0.45rem;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 0.2rem; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.55rem;
  font-family: var(--font);
  font-size: 0.86rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-secondary); color: var(--text-primary); }
.nav-item.active {
  background: #eef0ff;
  color: var(--accent);
  font-weight: 600;
}
.nav-item.nav-disabled {
  color: var(--text-muted);
  cursor: default;
}
.nav-item.nav-disabled:hover { background: transparent; color: var(--text-muted); }

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

/* ─── Topbar ────────────────────────────────────────────────────────── */
.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar-title { display: flex; align-items: center; gap: 0.75rem; }
.topbar-title h1 { font-size: 1.25rem; font-weight: 700; line-height: 1.3; }
.subtitle { color: var(--text-secondary); font-size: 0.82rem; }
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.fetched-at { color: var(--text-muted); font-size: 0.78rem; display: block; }

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn:hover { background: var(--accent-light); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-secondary); color: var(--text-primary); }

/* ─── Layout ────────────────────────────────────────────────────────── */
.content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.error-banner {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
}

.disclaimer-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(99, 102, 241, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.18);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}
.disclaimer-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
  line-height: 1;
}

/* ─── KPI Cards ─────────────────────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
}
.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
  text-align: center;
}
.kpi-label {
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}
.kpi-value {
  color: var(--accent);
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1.2;
}
.kpi-sub { color: var(--text-muted); font-size: 0.78rem; margin-top: 0.4rem; }
.kpi-sub .row { display: block; }

/* ─── Revenue by product type (bar list) ────────────────────────────── */
.bar-list { padding: 0.35rem 0; }
.bar-list .loading { padding: 1.25rem 1.5rem; }
.pt-row {
  display: grid;
  grid-template-columns: 220px 1fr 150px 56px;
  grid-template-areas:
    "name bar total share"
    "meta meta .     .";
  column-gap: 1.1rem;
  row-gap: 0.2rem;
  align-items: center;
  padding: 0.6rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.pt-row:last-child { border-bottom: none; }
.pt-row:hover { background: #fafbff; }
.pt-row.active {
  background: rgba(99, 102, 241, 0.06);
  box-shadow: inset 3px 0 0 var(--accent);
}
.pt-name {
  grid-area: name;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pt-bar {
  grid-area: bar;
  height: 8px;
  background: var(--border-light);
  border-radius: 999px;
  overflow: hidden;
}
.pt-bar span {
  display: block;
  height: 100%;
  min-width: 4px;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.35s ease;
}
.pt-total {
  grid-area: total;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pt-share {
  grid-area: share;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pt-meta {
  grid-area: meta;
  color: var(--text-muted);
  font-size: 0.74rem;
}
.section-note {
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.5;
  margin: 0;
  padding: 0.8rem 1.5rem 1rem;
  border-top: 1px solid var(--border-light);
}
@media (max-width: 700px) {
  .pt-row {
    grid-template-columns: 1fr max-content;
    grid-template-areas:
      "name total"
      "bar  share"
      "meta meta";
  }
}

/* ─── Card & Table ──────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
}
.card-header h2 { font-size: 1rem; font-weight: 700; }
.card-filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.year-pills { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.year-pill {
  background: var(--card-bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.year-pill:hover { border-color: var(--accent); color: var(--accent); }
.year-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.product-filter { position: relative; }
.product-filter-btn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-family: var(--font);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.product-filter-btn:hover { border-color: var(--accent); }
.product-filter-btn:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.product-filter-btn .caret { font-size: 0.65rem; color: var(--text-secondary); }
.product-filter-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 260px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 0.4rem;
}
.pf-actions {
  display: flex;
  gap: 0.75rem;
  padding: 0.2rem 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 0.3rem;
}
.pf-actions button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.pf-actions button:hover { text-decoration: underline; }
.pf-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  font-size: 0.83rem;
  cursor: pointer;
  user-select: none;
}
.pf-option:hover { background: #fafbff; }
.pf-option input { accent-color: var(--accent); cursor: pointer; }
.pf-option span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card-header select {
  background: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-family: var(--font);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: auto;
}
.card-header select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.card-header input[type="search"] {
  background: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-family: var(--font);
  font-size: 0.82rem;
  width: 280px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.card-header input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: #fafafa;
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 1.25rem;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th.sorted-asc::after { content: ' ↑'; color: var(--accent); }
thead th.sorted-desc::after { content: ' ↓'; color: var(--accent); }
tbody td {
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.85rem;
}
td.num, td:has(.badge), td:last-child { white-space: nowrap; }
tbody tr:hover { background: #fafbff; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }
td .deal-link { color: var(--accent); text-decoration: none; font-weight: 500; }
td .deal-link:hover { text-decoration: underline; }
td .company-link { color: var(--accent); text-decoration: none; font-weight: 500; }
td .company-link:hover { text-decoration: underline; }
.muted { color: var(--text-muted); }
.loading { text-align: center; color: var(--text-muted); padding: 2rem !important; }

/* ─── Grouped rows (company → products) ─────────────────────────────── */
.group-row { cursor: pointer; user-select: none; }
.group-row td { font-weight: 500; }
.group-row .chevron {
  display: inline-block;
  width: 1.3rem;
  color: var(--text-muted);
  transition: transform var(--transition);
}
.group-row.expanded .chevron { transform: rotate(90deg); color: var(--accent); }
.group-row.expanded td { background: #fafbff; border-bottom: none; }
.count-pill {
  display: inline-block;
  min-width: 1.8rem;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  background: #eef0ff;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
}
.detail-row > td {
  padding: 0 1.25rem 1rem 2.55rem;
  background: #fafbff;
}
.sub-table {
  width: 100%;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  background: var(--card-bg);
}
.sub-table thead th {
  font-size: 0.66rem;
  padding: 0.5rem 1rem;
  cursor: default;
}
.sub-table tbody td {
  padding: 0.5rem 1rem;
  font-size: 0.82rem;
}
.sub-table tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
}
.badge-new { background: #eef0ff; color: var(--accent); }
.badge-growth { background: #ecfdf5; color: var(--success); }
.badge-notset { background: var(--bg-secondary); color: var(--text-muted); }

@media (max-width: 768px) {
  .content { padding: 1rem; }
  .topbar { padding: 0.85rem 1rem; }
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 1rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-brand { padding: 0; border-bottom: none; }
  .brand-name, .sidebar-label, .sidebar-section:last-child { display: none; }
  .sidebar-nav { flex-direction: row; }
}
