:root {
  --chart-bar: #3b82f6;
  --chart-bar-soft: rgba(59, 130, 246, 0.45);
  --chart-line: #8e8e93;
  --chart-grid: #2c2c2e;
  --spark-line: #c7c7cc;
  --spark-fill: rgba(255, 255, 255, 0.06);
  --plan-paid: #3b82f6;
  --plan-trial: #93c5fd;
  --plan-free: #8e8e93;
  --plan-unknown: #3a3a3c;
}

:root.light {
  --chart-bar: #2563eb;
  --chart-bar-soft: rgba(37, 99, 235, 0.4);
  --chart-line: #8e8e93;
  --chart-grid: #ececf0;
  --spark-line: #8e8e93;
  --spark-fill: rgba(0, 0, 0, 0.04);
  --plan-paid: #2563eb;
  --plan-trial: #93c5fd;
  --plan-free: #aeaeb2;
  --plan-unknown: #e5e5ea;
}

.dashboard-shell > section + section,
.dashboard-shell > section + footer {
  margin-top: 12px;
}

/* Shared card anatomy */

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 0;
}

.card-head h2 {
  font-size: 12px;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  margin-top: auto;
  padding: 0 20px;
  border-top: 1px solid var(--border-soft);
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.filter-summary {
  color: var(--muted);
  font-size: 12px;
}

.filter-button.is-active {
  background: var(--accent-soft);
  color: var(--link);
}

.filter-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.filter-badge[hidden] {
  display: none;
}

/* Stat cards */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  min-height: 128px;
  display: flex;
  flex-direction: column;
  padding: 18px 20px 16px;
}

.stat-main {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-top: auto;
}

.metric-value {
  display: block;
  width: fit-content;
  min-width: 2ch;
  color: var(--text);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.metric-value.is-ticking {
  animation: metric-tick 420ms ease;
}

@keyframes metric-tick {
  from { opacity: 0.4; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.kpi-spark {
  flex: 1;
  min-width: 0;
  height: 32px;
  overflow: visible;
}

.spark-line {
  fill: none;
  stroke: var(--spark-line);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.spark-fill {
  fill: var(--spark-fill);
  stroke: none;
}

.spark-dot {
  fill: none;
  stroke: var(--spark-line);
  stroke-width: 6;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.metric-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 16px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.metric-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-weight: 600;
}

.metric-change i {
  font-size: 10px;
}

.metric-change.positive {
  color: var(--ok);
}

.metric-change.negative {
  color: var(--danger);
}

.stat-grid.compact .stat-card {
  min-height: 0;
  gap: 10px;
  padding: 16px 20px;
}

.stat-grid.compact .metric-value {
  font-size: 22px;
}

/* Trend chart */

.chart-card {
  padding-bottom: 14px;
}

.axis-note {
  margin: 12px 20px 0;
  color: var(--muted);
  font-size: 12px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 8px 20px 0;
  color: var(--muted);
  font-size: 13px;
}

.chart-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chart-bar);
}

.legend-line {
  width: 22px;
  height: 3px;
  border-radius: 2px;
  background: var(--chart-line);
}

.legend-dash {
  width: 22px;
  height: 0;
  border-top: 2px dashed var(--chart-line);
}

.trend-chart {
  position: relative;
  height: 240px;
  margin: 12px 16px 0 8px;
}

.trend-chart svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart-grid line {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.chart-axis text {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-bar {
  fill: var(--chart-bar);
  transform-box: fill-box;
  transform-origin: center bottom;
}

.chart-bar.today {
  fill: var(--chart-bar-soft);
}

.trend-chart.is-animating .chart-bar {
  animation: bar-rise 620ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes bar-rise {
  from { transform: scaleY(0); }
}

.chart-line {
  fill: none;
  stroke: var(--chart-line);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-baseline {
  stroke: var(--chart-line);
  stroke-width: 1.25;
  stroke-dasharray: 5 5;
  opacity: 0.8;
}

.chart-cursor {
  stroke: var(--text);
  stroke-width: 1;
  opacity: 0.85;
}

.chart-marker {
  fill: var(--panel);
  stroke: var(--text);
  stroke-width: 2.5;
}

.chart-hit {
  fill: transparent;
  outline: 0;
  cursor: crosshair;
}

.chart-tooltip[hidden] {
  display: none;
}

.chart-tooltip {
  position: absolute;
  z-index: 4;
  min-width: 180px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: var(--tooltip-bg);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

:root.light .chart-tooltip {
  border-color: var(--border);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.12);
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.chart-tooltip span {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  white-space: nowrap;
}

.chart-tooltip b {
  margin-left: auto;
  padding-left: 24px;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tooltip-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.tooltip-dot.bar { background: var(--chart-bar); }
.tooltip-dot.line { background: var(--chart-line); }
.tooltip-dot.new { background: var(--muted-2); }

/* Audience, segments, habits */

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.list-card {
  display: flex;
  flex-direction: column;
  min-height: 380px;
}

.list-body {
  flex: 1;
  padding: 4px 20px 6px;
}

.meter-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 20px;
}

.meter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.meter-head .insight-value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.meter small {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 5px;
  margin: 8px 0 5px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel-2);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

.pair-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: auto 0 0;
  border-top: 1px solid var(--border-soft);
}

.pair-stats > div {
  padding: 14px 20px;
}

.pair-stats > div + div {
  border-left: 1px solid var(--border-soft);
}

.pair-stats dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pair-stats dd {
  width: fit-content;
  min-width: 2ch;
  margin: 6px 0 0;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tabs {
  display: flex;
  margin: 14px 20px 0;
}

.tabs button {
  flex: 1;
  padding: 0 8px;
}

.plan-stack {
  display: flex;
  gap: 3px;
  height: 8px;
  margin: 14px 0 4px;
  overflow: hidden;
  border-radius: 999px;
}

.plan-stack[hidden] {
  display: none;
}

.plan-segment {
  min-width: 3px;
  height: 100%;
}

.plan-swatch {
  width: 8px;
  height: 8px;
  display: inline-block;
  flex: 0 0 auto;
  border-radius: 50%;
}

.paid { --plan-color: var(--plan-paid); }
.trial { --plan-color: var(--plan-trial); }
.free { --plan-color: var(--plan-free); }
.unknown { --plan-color: var(--plan-unknown); }

.plan-segment,
.plan-swatch {
  background: var(--plan-color, var(--plan-unknown));
}

.share-list[hidden],
.rank-list[hidden] {
  display: none;
}

.share-row,
.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  column-gap: 14px;
  row-gap: 6px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-soft);
}

.share-row:last-child,
.rank-row:last-child {
  border-bottom: 0;
}

.share-name,
.rank-name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.rank-index {
  width: 18px;
  flex: 0 0 auto;
  color: var(--muted-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.share-count,
.rank-count {
  min-width: 3ch;
  font-size: 14px;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.share-pct,
.rank-sub {
  min-width: 56px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.share-track {
  grid-column: 1 / -1;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel-2);
}

.share-track span {
  display: block;
  width: var(--share-width, 0);
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  animation: track-fill 600ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.share-track.tinted span {
  background: var(--plan-color);
}

@keyframes track-fill {
  from { width: 0; }
}

/* Signups table */

.table-card {
  display: flex;
  flex-direction: column;
}

.table-scroll {
  margin-top: 14px;
  overflow-x: auto;
}

.table-scroll .data-table th {
  border-top: 1px solid var(--border-soft);
}

.data-table[hidden] {
  display: none;
}

.data-table tbody tr {
  cursor: pointer;
}

.row-action-col {
  width: 32px;
}

.row-action {
  color: var(--muted-2);
  font-size: 11px;
}

tbody tr:hover .row-action {
  color: var(--text);
}

.table-muted {
  color: var(--muted);
}

.table-number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar.lg {
  width: 48px;
  height: 48px;
  font-size: 16px;
}

.user-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.user-copy strong {
  max-width: 260px;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
}

.user-copy span {
  max-width: 260px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.status-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--plan-color, var(--muted-2));
}

.status-chip.paid,
.status-chip.trial,
.status-chip.complete {
  color: var(--text);
}

.status-chip.complete::before {
  background: var(--ok);
}

.status-chip.pending::before {
  background: var(--warn);
}

.pager-buttons {
  display: flex;
  gap: 8px;
}

.empty-state.compact {
  min-height: 140px;
}

.dashboard-footnote {
  color: var(--muted-2);
  font-size: 12px;
}

/* Drawer */

.drawer-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: min(480px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow-float);
  outline: 0;
  animation: slide-in 240ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes slide-in {
  from { transform: translateX(32px); opacity: 0; }
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 20px 18px 24px;
  border-bottom: 1px solid var(--border-soft);
}

.drawer-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.drawer-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 24px 28px;
}

.drawer-search {
  position: sticky;
  top: -22px;
  z-index: 1;
  margin: -22px -24px 6px;
  padding: 16px 24px 14px;
  background: var(--panel);
}

.drawer-search input,
.filter-field input:not([type="checkbox"]),
.filter-field select {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  outline: 0;
}

.drawer-search input:focus,
.filter-field input:not([type="checkbox"]):focus,
.filter-field select:focus {
  border-color: var(--link);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 22%, transparent);
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.profile-head .user-copy strong {
  font-size: 17px;
}

.profile-head .user-copy span {
  max-width: 340px;
  font-family: var(--mono);
  font-size: 12px;
}

.section-label {
  margin: 26px 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-list {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  margin: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--panel-2);
}

.detail-list dt,
.detail-list dd {
  margin: 0;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 14px;
}

:root:not(.light) .detail-list dt,
:root:not(.light) .detail-list dd {
  border-bottom-color: #353538;
}

.detail-list dt:nth-last-child(2),
.detail-list dd:last-child {
  border-bottom: 0;
}

.detail-list dt {
  color: var(--muted);
}

.detail-list dd {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.mini-stats > div {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--panel-2);
}

.mini-stats span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mini-stats strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.activity-strip {
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  gap: 5px;
}

.activity-cell {
  aspect-ratio: 1;
  border-radius: 5px;
  background: var(--panel-2);
}

.activity-cell[data-level="1"] { background: color-mix(in srgb, var(--chart-bar) 35%, var(--panel-2)); }
.activity-cell[data-level="2"] { background: color-mix(in srgb, var(--chart-bar) 65%, var(--panel-2)); }
.activity-cell[data-level="3"] { background: var(--chart-bar); }

.activity-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--muted-2);
  font-size: 11px;
}

/* Filter modal */

.filter-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 18px 16px 24px;
}

.filter-modal-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.filter-modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.filter-modal-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 6px 24px 8px;
}

.filter-modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 18px 24px;
  border-top: 1px solid var(--border-soft);
}

.filter-modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-match {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-field > span,
.filter-legend {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.filter-check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 14px;
  cursor: pointer;
}

.filter-check input,
.filter-check-list input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.filter-chip:has(input:checked) {
  background: var(--accent-soft);
  color: var(--link);
}

.filter-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.filter-check-list {
  max-height: 176px;
  overflow: auto;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}

.filter-check-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  font-size: 14px;
  cursor: pointer;
}

@media (max-width: 1180px) {
  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-grid > :first-child {
    grid-column: 1 / -1;
    min-height: 0;
  }
}

@media (max-width: 960px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .list-card {
    min-height: 0;
  }
}

@media (max-width: 560px) {
  .stat-grid {
    gap: 10px;
  }

  .stat-card {
    min-height: 150px;
    padding: 18px 16px;
  }

  .stat-main {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .kpi-spark {
    flex: 0 0 32px;
    height: 32px;
  }

  .metric-value {
    font-size: 28px;
  }

  .stat-grid.compact .metric-value {
    font-size: 22px;
  }

  .card-head {
    flex-wrap: wrap;
    padding: 18px 16px 0;
  }

  .axis-note,
  .chart-legend {
    margin-left: 16px;
    margin-right: 16px;
  }

  .trend-chart {
    height: 280px;
    margin: 14px 8px 0 4px;
  }

  .list-body,
  .meter-list,
  .card-foot {
    padding-left: 16px;
    padding-right: 16px;
  }

  .tabs {
    margin: 16px 16px 0;
  }

  .filter-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .detail-list {
    grid-template-columns: 110px minmax(0, 1fr);
  }
}

.chart-axis text.is-today {
  fill: var(--text);
  font-weight: 600;
}

.chart-focus[hidden] {
  display: none;
}
