:root {
  --bg: #0b1220;
  --bg-panel: #121c2e;
  --bg-soft: #182338;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8eef6;
  --muted: #8b9bb0;
  --blue: #3b82f6;
  --cyan: #22d3ee;
  --green: #22c55e;
  --yellow: #f0b429;
  --orange: #f97316;
  --red: #ef4444;
  --sidebar: 240px;
  --font-display: "Montserrat", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
}

.dash-body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

h1, h2 {
  font-family: var(--font-display);
  margin: 0;
}

/* Sidebar */
.dash-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #080e1a;
  border-right: 1px solid var(--line);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.dash-brand img {
  width: 100%;
  max-width: 180px;
  height: auto;
  display: block;
}

.dash-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.dash-nav a {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 0.7rem 0.85rem;
  border-radius: 4px;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}

.dash-nav a:hover,
.dash-nav a.is-active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--text);
}

.dash-nav a.is-active {
  border-left: 2px solid var(--yellow);
  padding-left: calc(0.85rem - 2px);
}

.dash-back {
  font-size: 0.85rem;
  color: var(--yellow);
  padding: 0.75rem;
  border-top: 1px solid var(--line);
}

/* Main */
.dash-main {
  padding: 1.25rem 1.5rem 2rem;
  min-width: 0;
}

.dash-top {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 1.25rem;
}

.dash-kicker {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--yellow);
}

.dash-title-block h1 {
  font-size: clamp(1.35rem, 2.4vw, 1.85rem);
  font-weight: 700;
}

.dash-subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.dash-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.dash-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-family: var(--font-display);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.dash-filters select {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.55rem 0.7rem;
  min-width: 140px;
}

.dash-updated {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.55rem 0.7rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* KPIs */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.kpi-card {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.95rem 1rem;
  opacity: 0;
  transform: translateY(12px);
  animation: cardIn 0.55s var(--ease) forwards;
}

.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.1s; }
.kpi-card:nth-child(3) { animation-delay: 0.15s; }
.kpi-card:nth-child(4) { animation-delay: 0.2s; }
.kpi-card:nth-child(5) { animation-delay: 0.25s; }
.kpi-card:nth-child(6) { animation-delay: 0.3s; }

@keyframes cardIn {
  to { opacity: 1; transform: translateY(0); }
}

.kpi-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.1;
}

.kpi-meta {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.kpi-alert {
  border-color: rgba(239, 68, 68, 0.35);
}

.text-ok { color: var(--green); }
.text-danger { color: var(--red); }

/* Panels / charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1rem;
  opacity: 0;
  transform: translateY(16px);
  animation: cardIn 0.6s var(--ease) forwards;
  animation-delay: 0.35s;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
}

.panel-head h2 {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.chart-wrap {
  position: relative;
  height: 220px;
}

.chart-wrap-donut {
  height: 200px;
  max-width: 220px;
  margin: 0 auto;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.donut-center strong {
  font-family: var(--font-display);
  font-size: 1.5rem;
}

.donut-center span {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.legend-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Heat map */
.panel-map .heat-map {
  position: relative;
  height: 220px;
  border-radius: 4px;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 40%, rgba(34, 197, 94, 0.25), transparent 40%),
    radial-gradient(circle at 60% 50%, rgba(249, 115, 22, 0.3), transparent 35%),
    radial-gradient(circle at 40% 70%, rgba(239, 68, 68, 0.28), transparent 30%),
    linear-gradient(145deg, #1a2a3f 0%, #0f1a2a 50%, #162238 100%);
  border: 1px solid var(--line);
}

.heat-spot {
  position: absolute;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  filter: blur(12px);
  opacity: 0;
  animation: heatIn 0.8s var(--ease) forwards;
  animation-delay: calc(0.5s + var(--i) * 0.12s);
}

@keyframes heatIn {
  to { opacity: 0.85; }
}

.heat-a { top: 18%; left: 18%; background: rgba(34, 197, 94, 0.7); }
.heat-b { top: 38%; left: 52%; background: rgba(249, 115, 22, 0.75); width: 90px; height: 90px; }
.heat-c { top: 58%; left: 24%; background: rgba(239, 68, 68, 0.7); }
.heat-d { top: 30%; left: 70%; background: rgba(234, 179, 8, 0.55); width: 50px; height: 50px; }

.heat-label {
  position: absolute;
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(0, 0, 0, 0.35);
  padding: 0.2rem 0.45rem;
  border-radius: 2px;
}

/* Bottom */
.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr;
  gap: 0.85rem;
}

.panel-wide {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--line);
}

th {
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.trend-up { color: var(--red); }
.trend-down { color: var(--green); }

.mini-kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.mini-kpi {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.75rem;
}

.mini-kpi span {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.mini-kpi strong {
  font-family: var(--font-display);
  font-size: 1.15rem;
  display: block;
  margin: 0.25rem 0;
}

.spark {
  display: block;
  width: 100%;
  height: 28px;
}

.btn-ghost-dash {
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--yellow);
  background: transparent;
  border: 1px solid rgba(240, 180, 41, 0.35);
  border-radius: 4px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}

.btn-ghost-dash:hover {
  background: rgba(240, 180, 41, 0.1);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-danger { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.badge-warn { background: rgba(249, 115, 22, 0.2); color: #fdba74; }
.badge-info { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }

.dash-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.dash-footer-logo {
  height: 36px;
  width: auto;
  opacity: 0.85;
}

@media (max-width: 1200px) {
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
  .charts-grid { grid-template-columns: 1fr 1fr; }
  .bottom-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .dash-body {
    grid-template-columns: 1fr;
  }

  .dash-sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .dash-nav {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
  }

  .dash-back {
    border-top: none;
    margin-left: auto;
  }

  .kpi-row,
  .charts-grid,
  .bottom-grid {
    grid-template-columns: 1fr;
  }

  .panel-wide {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kpi-card,
  .panel,
  .heat-spot {
    animation: none;
    opacity: 1;
    transform: none;
  }
}
