@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

:root {
  --bg-dark: #0a0e1a;
  --bg-card: #111827;
  --border-card: #1e293b;
  --blue: #006DEF;
  --purple: #8958FE;
  --cyan: #55D2F0;
  --off-white: #F3FAFF;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --dim-text: #94a3b8;
  --mid-text: #cbd5e1;
}

/* Light mode overrides */
body.light {
  --bg-dark: #f1f5f9;
  --bg-card: #ffffff;
  --border-card: #e2e8f0;
  --off-white: #0f172a;
  --dim-text: #64748b;
  --mid-text: #334155;
}
body.light .info-icon::after {
  background: #ffffff;
  border-color: #e2e8f0;
  color: #334155;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
body.light .metric-change.up { color: #16a34a; }
body.light .metric-change.down { color: #dc2626; }
body.light .period-btn.active {
  background: rgba(0,109,239,0.08);
}
body.light .funnel-pct-main { color: #006DEF; }

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

body {
  min-height: 100vh;
  background: var(--bg-dark);
  color: var(--off-white);
  font-family: 'Poppins', -apple-system, sans-serif;
  display: flex;
  transition: background 0.3s, color 0.3s;
}

/* Login Screen */
.login-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  z-index: 10000;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.login-brand .blue { color: var(--blue); }
.login-subtitle {
  font-size: 13px;
  color: var(--dim-text);
  margin-bottom: 32px;
}
.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card input {
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-card);
  background: var(--bg-dark);
  color: var(--off-white);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--blue); }
.login-card input::placeholder { color: var(--dim-text); }
.login-btn {
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--blue);
  color: white;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.2s;
  margin-top: 4px;
}
.login-btn:hover { opacity: 0.9; }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.login-error {
  color: var(--red);
  font-size: 12px;
  min-height: 18px;
}
.login-hint {
  font-size: 11px;
  color: var(--dim-text);
  margin-top: 16px;
}

/* Light mode login */
body.light .login-card input {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #0f172a;
}

/* Sidebar */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: #080b14;
  border-right: 1px solid var(--border-card);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.25s ease;
}
.sidebar.collapsed {
  width: 56px;
}
.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .sidebar-item-text,
.sidebar.collapsed .sidebar-btn-text {
  display: none;
}
.sidebar.collapsed .sidebar-brand {
  padding: 0 0 16px;
  text-align: center;
}
.sidebar.collapsed .sidebar-nav { padding: 0 4px; }
.sidebar.collapsed .sidebar-item {
  justify-content: center;
  padding: 10px 8px;
}
.sidebar.collapsed .sidebar-item .icon { width: auto; margin: 0; }
.sidebar.collapsed .sidebar-footer { padding: 8px 4px 0; }
.sidebar.collapsed .sidebar-btn {
  justify-content: center;
  padding: 8px;
  font-size: 14px;
}
body.light .sidebar { background: #f8fafc; border-color: #e2e8f0; }

/* Sidebar toggle button */
.sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--dim-text);
  cursor: pointer;
  padding: 8px 16px;
  font-size: 16px;
  text-align: right;
  transition: color 0.15s;
  font-family: inherit;
}
.sidebar-toggle:hover { color: var(--mid-text); }
.sidebar.collapsed .sidebar-toggle {
  text-align: center;
  padding: 8px;
}

.sidebar-brand {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border-card);
  margin-bottom: 12px;
}
.sidebar-brand .blue { color: var(--blue); }
.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--dim-text);
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.sidebar-item:hover { background: rgba(255,255,255,0.05); color: var(--mid-text); }
body.light .sidebar-item:hover { background: rgba(0,0,0,0.04); }
.sidebar-item.active {
  background: rgba(0,109,239,0.12);
  color: var(--blue);
  font-weight: 600;
}
.sidebar-item .icon {
  font-size: 16px;
  width: 22px;
  text-align: center;
}
.sidebar-footer {
  padding: 12px 8px 0;
  border-top: 1px solid var(--border-card);
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 11px;
  color: var(--dim-text);
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: all 0.15s;
}
.sidebar-btn:hover { background: rgba(255,255,255,0.05); color: var(--mid-text); }

/* Main Content */
.main-content {
  flex: 1;
  padding: 24px;
  min-width: 0;
  overflow-x: hidden;
}

@media (max-width: 768px) {
  body { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-height: auto;
    height: auto;
    position: relative;
    flex-direction: row;
    padding: 12px;
    overflow-x: auto;
  }
  .sidebar-brand { display: none; }
  .sidebar-nav { flex-direction: row; gap: 4px; padding: 0; }
  .sidebar-footer { flex-direction: row; border-top: none; margin-top: 0; border-left: 1px solid var(--border-card); padding: 0 0 0 8px; }
  .main-content { padding: 16px; }
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.header-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.header-sub {
  font-size: 11px;
  color: var(--dim-text);
  margin-top: 2px;
}
.header-actions { display: flex; gap: 8px; }
.header-btn {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 11px;
  cursor: pointer;
  border: 1px solid;
  background: transparent;
  font-family: inherit;
}
.header-btn.blue {
  color: var(--blue);
  border-color: rgba(0,109,239,0.25);
  background: rgba(0,109,239,0.08);
}
.header-btn.purple {
  color: var(--purple);
  border-color: rgba(137,88,254,0.25);
  background: rgba(137,88,254,0.08);
}
.header-btn.theme {
  color: var(--amber);
  border-color: rgba(245,158,11,0.25);
  background: rgba(245,158,11,0.08);
  font-size: 14px;
}

/* Period Filter Bar */
.period-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  padding: 8px 0;
  overflow-x: auto;
  align-items: center;
  flex-wrap: wrap;
}
.period-btn {
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 500;
  color: var(--dim-text);
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.2s;
}
.period-btn:hover { border-color: #334155; color: var(--mid-text); }
.period-btn.active {
  color: var(--blue);
  border-color: var(--blue);
  background: rgba(0,109,239,0.1);
}
.period-range {
  font-size: 10px;
  color: var(--dim-text);
  margin-left: 12px;
  padding: 4px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-card);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab-btn {
  padding: 10px 18px;
  font-size: 12px;
  font-weight: 400;
  color: var(--dim-text);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.2s;
}
.tab-btn.active {
  font-weight: 600;
  color: var(--blue);
  border-bottom-color: var(--blue);
}
.tab-btn:hover:not(.active) { color: var(--mid-text); }

/* Grid */
.grid { display: grid; gap: 12px; margin-bottom: 16px; align-items: stretch; }
.grid > div { display: flex; }
.grid > div > * { flex: 1; }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-1 { grid-template-columns: 1fr; }

@media (max-width: 900px) {
  .grid-5 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .grid-5, .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  body { padding: 16px; }
}

/* Metric Card */
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  min-height: 130px;
  transition: border-color 0.2s;
}
.metric-card .metric-change {
  margin-top: auto;
  padding-top: 4px;
}
.metric-card:hover { border-color: #334155; }
.metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.table-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.table-card-header .table-card-title { margin-bottom: 0; }
.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

/* Info icon tooltip */
.info-icon {
  font-size: 14px;
  color: var(--dim-text);
  cursor: help;
  opacity: 0.5;
  transition: opacity 0.2s;
  position: relative;
  flex-shrink: 0;
}
.info-icon:hover { opacity: 1; color: var(--cyan); }
.info-icon::after {
  content: attr(data-tip);
  position: absolute;
  top: 100%;
  margin-top: 6px;
  right: 0;
  width: 260px;
  padding: 10px 14px;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--mid-text);
  z-index: 9999;
  white-space: normal;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
}
.info-icon.tip-left::after { right: 0; left: auto; }
.info-icon.tip-right::after { left: 0; right: auto; }
.info-icon:hover::after {
  opacity: 1;
  visibility: visible;
}
.info-icon:hover { z-index: 9999; }
.metric-card.small { padding: 14px 16px; }
.metric-label {
  font-size: 11px;
  color: var(--dim-text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}
.metric-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.metric-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--off-white);
  line-height: 1.1;
}
.metric-card.small .metric-value { font-size: 22px; }
.metric-subtitle {
  font-size: 10px;
  color: var(--dim-text);
  margin-top: 2px;
}
.metric-change {
  font-size: 11px;
  margin-top: 2px;
}
.metric-change.up { color: var(--green); }
.metric-change.down { color: var(--red); }
.metric-change.neutral { color: var(--dim-text); }

/* Table Card */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 20px 24px;
  overflow: auto;
}
.table-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--off-white);
  margin-bottom: 14px;
}
.table-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.table-card th {
  text-align: left;
  padding: 6px 8px;
  color: var(--dim-text);
  font-weight: 500;
  border-bottom: 1px solid var(--border-card);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.table-card th:not(:first-child) { text-align: right; }
.table-card td {
  padding: 8px;
  color: var(--mid-text);
}
.table-card td:first-child { font-weight: 500; }
.table-card td:not(:first-child) { text-align: right; }
.table-card tr + tr { border-top: 1px solid rgba(30,41,59,0.3); }

/* Chart Card */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 20px 24px;
}
.chart-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--off-white);
  margin-bottom: 14px;
}

/* Bar Chart */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 180px;
  padding-top: 20px;
}
.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}
.bar-value {
  font-size: 10px;
  color: var(--dim-text);
  margin-bottom: 4px;
}
.bar-fill {
  width: 100%;
  max-width: 40px;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height 0.6s ease;
}
.bar-label {
  font-size: 9px;
  color: var(--dim-text);
  margin-top: 4px;
  white-space: nowrap;
}

/* Donut Chart */
.donut-container {
  display: flex;
  align-items: center;
  gap: 32px;
}
.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--mid-text);
}
.donut-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Funnel Chart — Tapered Shape */
.funnel-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 0;
}
.funnel-labels {
  display: flex;
  flex-direction: column;
  width: 140px;
  flex-shrink: 0;
  padding-right: 16px;
}
.funnel-label-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.funnel-label-row span {
  font-size: 12px;
  color: var(--dim-text);
  font-weight: 500;
  text-align: right;
}
.funnel-svg-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
}
.funnel-svg-wrap svg {
  max-width: 100%;
  height: auto;
}
.funnel-pcts {
  display: flex;
  flex-direction: column;
  width: 120px;
  flex-shrink: 0;
  padding-left: 16px;
}
.funnel-pct-row {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.funnel-pct-main {
  font-size: 14px;
  font-weight: 700;
  color: var(--cyan);
}
.funnel-pct-drop {
  font-size: 10px;
  color: var(--dim-text);
}
@media (max-width: 700px) {
  .funnel-labels { width: 100px; }
  .funnel-pcts { width: 80px; }
}

/* Section Title */
.section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--dim-text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 8px 0 4px;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--dim-text);
  font-size: 13px;
}
.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-card);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Footer */
.footer {
  margin-top: 32px;
  padding: 16px 0;
  border-top: 1px solid var(--border-card);
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--dim-text);
}

/* Tab content */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Spacing for direct children of tab content area */
#tab-content > div,
#tab-content > .chart-card,
#tab-content > .table-card {
  margin-bottom: 16px;
}
#tab-content > .section-title {
  margin-bottom: 8px;
  margin-top: 16px;
}
