:root {
  --bg: #09090b;
  --surface: #121214;
  --surface-2: #18181b;
  --surface-3: #1f1f23;
  --text: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --accent: #f59e0b;
  --accent-soft: rgba(245, 158, 11, 0.14);
  --positive: #4ade80;
  --negative: #f87171;
  --bar: rgba(161, 161, 170, 0.35);
  --bar-active: rgba(244, 244, 245, 0.55);
  --grid: rgba(255, 255, 255, 0.04);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-viewport {
  min-height: 100dvh;
}

.app-shell {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
}

@media (min-width: 768px) {
  .app-shell {
    max-width: 560px;
    padding-top: calc(24px + var(--safe-top));
  }
}

@media (min-width: 1024px) {
  .app-shell {
    max-width: 640px;
  }
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-text {
  min-width: 0;
}

.brand-name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-tag {
  margin: 1px 0 0;
  font-size: 0.72rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.filter-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border: none;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s var(--ease-out), transform 0.15s var(--ease-out);
}

.filter-trigger:active {
  transform: scale(0.97);
  background: var(--surface-3);
}

.page-intro {
  margin-bottom: 18px;
}

.page-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.page-subtitle {
  margin: 6px 0 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.segmented {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 3px;
  margin-bottom: 14px;
  border-radius: 12px;
  background: var(--surface);
}

.segmented-indicator {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  border-radius: 9px;
  background: var(--surface-3);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  transition: transform 0.32s var(--ease-out);
  pointer-events: none;
}

.segmented--three {
  grid-template-columns: 1fr 1fr 1fr;
}

.segmented--three .segment {
  font-size: 0.72rem;
  padding: 11px 4px;
}

.segmented--three .segmented-indicator {
  width: calc(33.333% - 2px);
}

.segmented-indicator.at-sites {
  transform: translateX(100%);
}

.segmented-indicator.at-fte {
  transform: translateX(200%);
}

.kpi-grid--triple {
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.kpi-grid--triple .kpi-value {
  font-size: clamp(1.05rem, 4.5vw, 1.35rem);
}

.kpi-value--hours {
  font-size: clamp(1.05rem, 4.5vw, 1.35rem) !important;
}

.filter-sales-hidden {
  display: none !important;
}

.histogram--fte {
  height: 220px;
}

.sales-map-wrap {
  margin-bottom: 18px;
  border-radius: var(--radius-lg);
  position: relative;
  overflow: visible;
  background: var(--surface);
}

.sales-map-head {
  padding: 14px 16px 10px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface);
}

.sales-map-title {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sales-map-site {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.site-map {
  height: 200px;
  width: 100%;
  background: #e8e8e8;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  overflow: hidden;
  isolation: isolate;
}

.site-map.leaflet-container {
  font-family: var(--font);
}

.site-map .leaflet-control-attribution {
  display: none;
}

.site-map-float-tip {
  position: absolute;
  z-index: 30;
  left: 0;
  top: 0;
  transform: translate(-50%, calc(-100% - 10px));
  width: max-content;
  max-width: min(300px, calc(100vw - 40px));
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.35);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  color: #e2e8f0;
  font: 500 10px/1.4 var(--font);
  pointer-events: auto;
  white-space: normal;
  overflow-wrap: anywhere;
}

.site-map-float-tip::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  background: rgba(15, 23, 42, 0.96);
  border-right: 1px solid rgba(148, 163, 184, 0.35);
  border-bottom: 1px solid rgba(148, 163, 184, 0.35);
  transform: rotate(45deg);
}

.site-map-float-tip[hidden] {
  display: none !important;
}

.map-marker-wrap {
  background: transparent;
  border: none;
}

.map-pulse {
  display: block;
  width: 16px;
  height: 16px;
  margin: 4px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.65);
  animation: mapPulse 1.6s ease-out infinite;
}

.map-dot-other {
  display: block;
  width: 10px;
  height: 10px;
  margin: 4px;
  border-radius: 50%;
  background: #475569;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35);
}

.site-map-tooltip {
  display: none !important;
}

.site-tip-title {
  font-weight: 700;
  font-size: 10px;
  margin-bottom: 2px;
  color: #f8fafc;
  line-height: 1.25;
}

.site-tip-row {
  margin-top: 3px;
  line-height: 1.35;
}

.site-tip-muted {
  color: #94a3b8;
  font-size: 9px;
}

.site-tip-label {
  color: #64748b;
  font-weight: 600;
}

.site-tip-desc {
  margin-top: 6px;
  color: #cbd5e1;
  font-size: 9px;
  line-height: 1.35;
}

@keyframes mapPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.65);
  }
  70% {
    box-shadow: 0 0 0 14px rgba(245, 158, 11, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .map-pulse {
    animation: none;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.35);
  }
}

.segment {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 11px 8px;
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.25s var(--ease-out);
}

.segment.active {
  color: var(--text);
}

.filter-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 16px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.filter-chip span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-chip--category {
  background: var(--accent-soft);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.28);
}

.filter-chip--site {
  background: var(--surface-3);
  color: var(--text);
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.filter-chip--date {
  background: transparent;
  color: var(--text-secondary);
  font-weight: 500;
  padding-left: 2px;
  padding-right: 2px;
}

.loading-bar {
  height: 2px;
  margin: -8px 0 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.1s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.report-panel {
  animation: panelIn 0.38s var(--ease-out);
}

.report-panel[hidden] {
  display: none !important;
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .report-panel,
  .segmented-indicator,
  .filter-sheet,
  .filter-backdrop,
  .loading-bar {
    animation: none !important;
    transition: none !important;
  }
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}

.kpi-card {
  padding: 16px 16px 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
}

.kpi-card--primary {
  background: linear-gradient(160deg, rgba(245, 158, 11, 0.07), transparent 55%), var(--surface);
}

.kpi-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.kpi-value {
  margin: 0;
  font-size: clamp(1.45rem, 6vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums lining-nums;
  line-height: 1.05;
}

.kpi-delta {
  margin: 0 0 18px;
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.kpi-delta.positive {
  color: var(--positive);
}

.kpi-delta.negative {
  color: var(--negative);
}

.kpi-delta.neutral {
  color: var(--text-secondary);
}

.insight-banner {
  margin-bottom: 22px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--surface);
}

.insight-metric {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.insight-copy {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.chart-block {
  margin-bottom: 8px;
}

.chart-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.chart-subtitle {
  margin: 0 0 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.histogram {
  position: relative;
  height: 248px;
  padding: 8px 4px 4px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  touch-action: none;
}

@media (min-width: 768px) {
  .histogram {
    height: 280px;
  }
}

.histogram canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.marker-tag {
  position: absolute;
  transform: translate(-50%, -100%);
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--accent);
  color: #18181b;
  font-size: 0.62rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  transition: left 0.35s var(--ease-out), top 0.35s var(--ease-out);
  max-width: min(168px, 46vw);
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 148px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(24, 24, 27, 0.96);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transition: opacity 0.18s var(--ease-out);
}

.chart-tooltip--rich {
  padding: 14px 14px 12px;
  border-radius: var(--radius-md);
  pointer-events: auto;
}

.chart-tooltip--rich .tip-kicker {
  margin: 0;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.chart-tooltip--rich .tip-range {
  margin: 6px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.chart-tooltip--rich .tip-summary {
  margin: 4px 0 0;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.chart-tooltip--rich .tip-divider {
  height: 1px;
  margin: 12px 0 10px;
  background: rgba(255, 255, 255, 0.08);
}

.chart-tooltip--rich .tip-heading {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
}

.chart-tooltip--rich .tip-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chart-tooltip--rich .tip-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chart-tooltip--rich .tip-list li:last-child {
  border-bottom: none;
}

.chart-tooltip--rich .tip-list li span:last-child {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart-tooltip--rich .tip-list li span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-tooltip--rich .tip-list--scroll {
  max-height: 168px;
  overflow-y: auto;
  padding-right: 4px;
}

.chart-tooltip--rich .tip-foot {
  margin: 10px 0 0;
  font-size: 0.65rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.chart-tooltip p {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.chart-tooltip p + p {
  margin-top: 4px;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.78rem;
  color: var(--text);
  font-weight: 600;
}

.chart-footnote {
  margin: 12px 2px 0;
  font-size: 0.78rem;
  color: var(--text-tertiary);
  font-weight: 500;
  line-height: 1.45;
}

.filter-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.62);
  opacity: 0;
  transition: opacity 0.28s var(--ease-out);
}

.filter-backdrop.visible {
  opacity: 1;
}

.filter-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  max-width: 520px;
  margin: 0 auto;
  padding: 8px 22px calc(22px + var(--safe-bottom));
  background: var(--surface-2);
  border-radius: 22px 22px 0 0;
  transform: translateY(105%);
  transition: transform 0.36s var(--ease-out);
}

.filter-sheet.open {
  transform: translateY(0);
}

.sheet-grabber {
  width: 36px;
  height: 4px;
  margin: 4px auto 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sheet-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-secondary);
  cursor: pointer;
}

.sheet-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sheet-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-field span,
.sheet-metric legend {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.sheet-field select,
.sheet-field input[type="date"] {
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  appearance: none;
}

.sheet-metric {
  border: none;
  margin: 0;
  padding: 0;
}

.metric-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.metric-option {
  cursor: pointer;
}

.metric-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.metric-option span {
  display: block;
  text-align: center;
  padding: 13px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.2s, color 0.2s;
}

.metric-option input:checked + span {
  background: var(--accent-soft);
  color: var(--accent);
}

.sheet-submit {
  margin-top: 6px;
  padding: 16px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #18181b;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s var(--ease-out), filter 0.2s;
}

.sheet-submit:active {
  transform: scale(0.98);
  filter: brightness(0.95);
}

.bin-detail-backdrop {
  position: fixed;
  inset: 0;
  z-index: 85;
  background: rgba(0, 0, 0, 0.62);
  opacity: 0;
  transition: opacity 0.28s var(--ease-out);
}

.bin-detail-backdrop.visible {
  opacity: 1;
}

.bin-detail-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 95;
  max-width: 520px;
  margin: 0 auto;
  max-height: min(72vh, 520px);
  padding: 8px 22px calc(22px + var(--safe-bottom));
  background: var(--surface-2);
  border-radius: 22px 22px 0 0;
  transform: translateY(105%);
  transition: transform 0.36s var(--ease-out);
  display: flex;
  flex-direction: column;
}

.bin-detail-sheet.open {
  transform: translateY(0);
}

.bin-detail-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding-bottom: 8px;
}

.bin-detail-body .tip-range {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.bin-detail-body .tip-summary {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.bin-detail-body .tip-divider {
  height: 1px;
  margin: 16px 0 12px;
  background: rgba(255, 255, 255, 0.08);
}

.bin-detail-body .tip-heading {
  margin: 0 0 10px;
  font-size: 0.88rem;
  font-weight: 700;
}

.bin-detail-body .tip-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.bin-detail-body .tip-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.bin-detail-body .tip-list li:last-child {
  border-bottom: none;
}

.bin-detail-body .tip-list li span:first-child {
  flex: 1;
  min-width: 0;
  padding-right: 8px;
}

.bin-detail-body .tip-list li span:last-child {
  flex-shrink: 0;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart-tooltip--compact {
  padding: 8px 10px;
  min-width: 0;
  max-width: min(200px, 58vw);
  pointer-events: none;
}

.chart-tooltip--compact .tip-range {
  margin: 2px 0 0;
  font-size: 0.82rem;
  font-weight: 700;
}

.chart-tooltip--compact .tip-summary {
  margin: 2px 0 0;
  font-size: 0.68rem;
}

.chart-tooltip--compact .tip-hint {
  margin: 4px 0 0;
  font-size: 0.6rem;
  color: var(--text-tertiary);
}
