@font-face {
  font-family: 'Clash Display';
  src: url('fonts/ClashDisplay-Bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'Clash Display';
  src: url('fonts/ClashDisplay-Semibold.ttf') format('truetype');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Satoshi';
  src: url('fonts/Satoshi-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Satoshi';
  src: url('fonts/Satoshi-Medium.ttf') format('truetype');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Satoshi';
  src: url('fonts/Satoshi-Bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #0A0A0A;
  --surface: #131313;
  --surface-raised: #181818;
  --border: #262626;
  --border-soft: #1E1E1E;
  --text-primary: #FFFFFF;
  --text-secondary: #A3A3A3;
  --text-tertiary: #6B6B6B;
  --brand: #FF4326;
  --brand-glow: rgba(255, 67, 38, 0.18);
  --brand-glow-soft: rgba(255, 67, 38, 0.08);
  --success: #34C759;
  --warning: #FF9500;
  --series-2: #2a78d6;
  --series-3: #1baf7a;
  --series-4: #7C4DFF;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --sidebar-w: 232px;
  --font-display: 'Clash Display', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Satoshi', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(ellipse 900px 500px at 15% -10%, var(--brand-glow-soft), transparent 60%),
    radial-gradient(ellipse 700px 500px at 100% 0%, rgba(124, 77, 255, 0.06), transparent 55%);
  background-attachment: fixed;
}

button, input { font-family: inherit; }

/* ---- login ---- */
.login-wrap[hidden] { display: none; }
.login-wrap {
  max-width: 340px;
  margin: 14vh auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0 20px;
}
.login-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--brand);
  text-transform: lowercase;
}
.login-wrap h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 28px;
}
input[type=password] {
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 15px;
  background: var(--surface);
  color: var(--text-primary);
}
input[type=password]:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow-soft);
}
.btn-primary {
  background: var(--brand);
  color: #fff;
  padding: 13px 18px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn-primary:hover { background: #E5331A; }
.btn-primary:active { transform: scale(0.98); }
.error-text { color: #FF6B52; font-size: 13px; margin: 0; }

/* ---- app shell ---- */
.app[hidden] { display: none; }
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #0D0D0D;
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 28px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-top { padding: 0 12px 28px; }
.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  color: var(--text-primary);
}
.brand-mark span { color: var(--brand); }
.brand-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
  letter-spacing: 0.02em;
}
.nav-items { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: #1A1A1A; color: var(--text-primary); }
.nav-item.active { background: var(--brand-glow-soft); color: var(--brand); font-weight: 700; }
.nav-item.logout { color: var(--text-tertiary); margin-top: auto; }
.nav-item.logout:hover { color: var(--text-primary); }

.main {
  flex: 1;
  padding: 36px 44px 64px;
  max-width: 1280px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 32px;
  animation: fadeSlideIn 0.5s ease both;
}
.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 6px;
}
.topbar h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 34px;
  margin: 0;
  letter-spacing: -0.01em;
}
.topbar-meta { font-size: 13px; color: var(--text-tertiary); }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.range-switch {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.range-switch button {
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.range-switch button:hover { color: var(--text-secondary); }
.range-switch button.active { background: var(--brand); color: #fff; }

/* ---- kpi row ---- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 22px 22px 20px;
  position: relative;
  overflow: hidden;
  animation: fadeSlideIn 0.5s ease both;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.kpi-tile:hover {
  border-color: rgba(255, 67, 38, 0.35);
  transform: translateY(-1px);
}
.kpi-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 100% 0%, var(--brand-glow), transparent 60%);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.kpi-tile:hover::before { opacity: 1; }
.kpi-label {
  font-size: 12.5px;
  color: var(--text-tertiary);
  font-weight: 500;
  margin-bottom: 10px;
}
.kpi-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 36px;
  letter-spacing: -0.01em;
  line-height: 1;
}
.kpi-value.accent { color: var(--brand); }

/* ---- grids ---- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 22px 24px 24px;
  animation: fadeSlideIn 0.55s ease both;
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
}
.card-head h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  margin: 0;
}
.card-sub { font-size: 12px; color: var(--text-tertiary); }

.chart-wrap { height: 160px; position: relative; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }

.chart-tooltip {
  position: absolute;
  top: 8px;
  pointer-events: none;
  background: #1C1C1C;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  transform: translateX(-50%);
  z-index: 2;
}
.chart-tooltip .tt-date { color: var(--text-tertiary); margin-bottom: 2px; }
.chart-tooltip .tt-value { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.chart-tooltip[hidden] { display: none; }

.chart-hover-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.15);
  pointer-events: none;
  z-index: 1;
}

/* ---- retention bars ---- */
.retention-bars { display: flex; flex-direction: column; gap: 16px; }
.retention-row { display: flex; align-items: center; gap: 14px; }
.retention-row .r-label { width: 46px; font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.retention-row .r-track {
  flex: 1;
  height: 10px;
  background: #1C1C1C;
  border-radius: 6px;
  overflow: hidden;
}
.retention-row .r-fill {
  height: 100%;
  background: linear-gradient(90deg, #FF4326, #FF8E7B);
  border-radius: 6px;
  width: 0%;
  transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
}
.retention-row .r-value { width: 52px; text-align: right; font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.retention-row .r-meta { font-size: 11px; color: var(--text-tertiary); width: 90px; }

/* ---- funnel ---- */
.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-step { display: flex; flex-direction: column; gap: 6px; }
.funnel-step-head { display: flex; justify-content: space-between; font-size: 13px; }
.funnel-step-head .f-label { color: var(--text-secondary); }
.funnel-step-head .f-count { font-family: var(--font-display); font-weight: 600; color: var(--text-primary); }
.funnel-track { height: 26px; background: #1C1C1C; border-radius: 6px; overflow: hidden; }
.funnel-fill {
  height: 100%;
  background: linear-gradient(90deg, #FF4326, #E5331A);
  width: 0%;
  border-radius: 6px;
  transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
}
.funnel-fill span { font-size: 11px; font-weight: 700; color: #fff; }

/* ---- bar list (feature adoption) ---- */
.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-list-row { display: flex; align-items: center; gap: 12px; }
.bar-list-row .bl-label { width: 110px; font-size: 13px; color: var(--text-secondary); flex-shrink: 0; }
.bar-list-row .bl-track { flex: 1; height: 8px; background: #1C1C1C; border-radius: 5px; overflow: hidden; }
.bar-list-row .bl-fill { height: 100%; background: var(--brand); border-radius: 5px; width: 0%; transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1); }
.bar-list-row .bl-value { width: 40px; text-align: right; font-size: 12.5px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }

/* ---- engagement segments ---- */
.segment-viz { display: flex; flex-direction: column; gap: 14px; }
.segment-bar { display: flex; height: 34px; border-radius: 8px; overflow: hidden; }
.segment-bar div { transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1); }
.seg-power { background: var(--brand); }
.seg-casual { background: #3A3A3A; }
.seg-risk { background: var(--warning); }
.segment-legend { display: flex; gap: 18px; flex-wrap: wrap; }
.segment-legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-secondary); }
.segment-legend-dot { width: 9px; height: 9px; border-radius: 3px; }

/* ---- stat list ---- */
.stat-list { display: flex; flex-direction: column; gap: 14px; }
.stat-row { display: flex; justify-content: space-between; align-items: baseline; }
.stat-row .s-label { font-size: 13px; color: var(--text-secondary); }
.stat-row .s-value { font-family: var(--font-display); font-weight: 600; font-size: 19px; }

/* ---- motion ---- */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.kpi-tile:nth-child(1) { animation-delay: 0.02s; }
.kpi-tile:nth-child(2) { animation-delay: 0.06s; }
.kpi-tile:nth-child(3) { animation-delay: 0.10s; }
.kpi-tile:nth-child(4) { animation-delay: 0.14s; }
.kpi-tile:nth-child(5) { animation-delay: 0.18s; }

.empty-note { font-size: 13px; color: var(--text-tertiary); padding: 8px 0; }

@media (max-width: 760px) {
  :root { --sidebar-w: 64px; }
  .sidebar { padding: 20px 10px; }
  .sidebar-top { padding: 0 2px 20px; }
  .brand-sub, .nav-item .label { display: none; }
  .brand-mark { font-size: 16px; text-align: center; }
  .nav-item { justify-content: center; padding: 11px 4px; }

  .main { padding: 24px 16px 48px; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 6px; }
  .topbar h1 { font-size: 26px; }

  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  .card-head { flex-direction: column; align-items: flex-start; gap: 4px; }
}
