:root {
  --bg: #f4efe6;
  --panel: rgba(255, 252, 248, 0.9);
  --text: #12263a;
  --muted: #4f6475;
  --accent: #ff7a18;
  --accent-two: #007ea7;
  --ok: #157f1f;
  --warn: #bf0603;
  --line: rgba(18, 38, 58, 0.15);
  --shadow: 0 12px 32px rgba(18, 38, 58, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, rgba(255, 122, 24, 0.24), transparent 30%),
    radial-gradient(circle at 90% 0%, rgba(0, 126, 167, 0.22), transparent 28%),
    linear-gradient(140deg, #f4efe6 0%, #eef6fb 48%, #f8f4eb 100%);
  padding: 24px;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  opacity: 0.4;
  border-radius: 999px;
  filter: blur(8px);
  transform: rotate(-9deg);
}

.bg-shape-one {
  width: 280px;
  height: 90px;
  background: #ff9f45;
  right: 12%;
  top: 12%;
}

.bg-shape-two {
  width: 180px;
  height: 60px;
  background: #4ad9d9;
  left: 10%;
  bottom: 9%;
}

.layout {
  max-width: 1260px;
  margin: 0 auto;
  display: grid;
  gap: 18px;
}

.hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px 24px;
  box-shadow: var(--shadow);
  animation: rise 480ms ease-out both;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 12px;
  color: var(--accent-two);
}

.hero-eyebrow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow-version {
  font-variant-numeric: tabular-nums;
}

h1 {
  margin: 4px 0 10px;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.toolbar,
.panel,
.error-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  animation: rise 600ms ease-out both;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  border-color: transparent;
  background: linear-gradient(135deg, #ff7a18, #ffba66);
}

.meta {
  font-size: 11px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 14px;
  min-width: 0;
  flex: 0 1 auto;
  max-width: 320px;
}

.meta p {
  margin: 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta a {
  color: var(--accent-two);
  text-decoration: none;
}

.meta a:hover {
  text-decoration: underline;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status-ok {
  background: rgba(21, 127, 31, 0.16);
  color: #0a5c12;
}

.status-warn {
  background: rgba(191, 6, 3, 0.14);
  color: #8a0302;
}

.status-info {
  background: rgba(0, 126, 167, 0.15);
  color: #045f7c;
}

.refresh-btn {
  margin-left: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.refresh-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #ff7a18, #ffba66);
  color: #fff;
  border-color: transparent;
}

.refresh-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.charts-toggle {
  width: 32px;
  height: 28px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  animation: rise 700ms ease-out both;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 14px;
  min-width: 140px;
  flex: 0 1 auto;
}

.card h3 {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.card h3 .card-sub {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--accent-two);
  margin-left: auto;
}

.card p {
  margin: 4px 0 0;
  font-size: 20px;
  font-family: "IBM Plex Mono", monospace;
}

.charts {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
  align-items: stretch;
}

.charts-section {
  display: grid;
  gap: 10px;
}

.charts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.charts-header h2 {
  margin: 0;
  font-size: 16px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.panel {
  padding: 14px;
  animation: rise 780ms ease-out both;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.chart-shell {
  position: relative;
  width: 100%;
}

.chart-shell-tall canvas {
  max-height: 460px !important;
}

canvas {
  width: 100% !important;
  height: auto !important;
  max-height: 280px;
  display: block;
}

.table-wrap {
  padding-bottom: 0;
}

.table-scroll {
  max-height: 80vh;
  overflow: auto;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  position: sticky;
  top: 0;
  background: #fcefd9;
  z-index: 1;
}

th,
td {
  text-align: left;
  white-space: nowrap;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.35);
}

.error-panel {
  padding: 16px;
}

.app-footer {
  text-align: center;
  padding: 16px 0 4px;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.7;
  letter-spacing: 0.05em;
}

.up {
  color: var(--ok);
}

.down {
  color: var(--warn);
}

.state-cell {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  min-width: 180px;
}

.grid-tower-icon {
  display: inline-block;
  width: 22px;
  height: 22px;
  margin-left: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.legend-grid-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.state-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 9px;
  border: 1px solid transparent;
}

.state-single {
  font-size: 11px;
}

.state-pv-charge,
.state-discharge-grid {
  background: rgba(21, 127, 31, 0.12);
  border-color: rgba(21, 127, 31, 0.3);
  color: #0e6418;
}

.state-grid-charge {
  background: rgba(0, 126, 167, 0.12);
  border-color: rgba(0, 126, 167, 0.28);
  color: #045f7c;
}

.state-frozen {
  background: rgba(79, 100, 117, 0.12);
  border-color: rgba(79, 100, 117, 0.3);
  color: #364a58;
}

.state-export {
  background: rgba(255, 122, 24, 0.12);
  border-color: rgba(255, 122, 24, 0.3);
  color: #8a4a08;
}

.state-discharge,
.state-peak {
  background: rgba(191, 6, 3, 0.1);
  border-color: rgba(191, 6, 3, 0.26);
  color: #8a0302;
}

.state-demand {
  background: rgba(79, 100, 117, 0.12);
  border-color: rgba(79, 100, 117, 0.26);
  color: #364a58;
}

.state-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 10px;
  border-bottom: 1px solid var(--line);
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid transparent;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1080px) {
  .charts {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  body {
    padding: 12px;
  }

  .card {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
  }

  .hero,
  .toolbar,
  .panel {
    border-radius: 14px;
  }

  canvas {
    max-height: 240px;
  }
}
