/* ══════════════════════════════════════
   DESIGN TOKENS
══════════════════════════════════════ */
:root {
  /* Colors — pure black, zero blue tint */
  --bg-base:       #080808;
  --bg-surface:    #101010;
  --bg-card:       #141414;
  --bg-card-hover: #1c1c1c;
  --border:        rgba(255,255,255,0.08);
  --border-accent: rgba(255,160,30,0.4);

  --accent:        #FFA01E;
  --accent-dim:    rgba(255,160,30,0.12);
  --accent-glow:   rgba(255,160,30,0.3);

  --green:         #22D3A5;
  --green-dim:     rgba(34,211,165,0.12);
  --red:           #FF4F6C;
  --red-dim:       rgba(255,79,108,0.12);
  --blue:          #3EA6FF;
  --blue-dim:      rgba(62,166,255,0.12);
  --purple:        #A78BFA;
  --purple-dim:    rgba(167,139,250,0.12);

  --text-primary:  #EEEEEE;
  --text-secondary:#888888;
  --text-muted:    #444444;

  /* Radius — sharp, minimal rounding */
  --radius-sm:  4px;
  --radius-md:  6px;
  --radius-lg:  8px;
  --radius-xl:  10px;

  /* Shadow */
  --shadow-card: 0 2px 16px rgba(0,0,0,0.6), 0 1px 0 rgba(255,255,255,0.03) inset;
  --shadow-glow: 0 0 32px rgba(255,160,30,0.15);

  /* Transitions */
  --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --fast: 0.18s var(--ease);
  --med:  0.3s var(--ease);
}

/* ══════════════════════════════════════
   RESET & BASE
══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Top accent line */
body::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 5%, var(--accent) 40%, var(--green) 60%, transparent 95%);
  z-index: 100;
}

/* ══════════════════════════════════════
   HEADER
══════════════════════════════════════ */
.header {
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: rgba(8,8,8,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-text {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #FFD060, #FFA01E);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.device-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Status dot */
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.dot--online  { background: var(--green); }
.dot--offline { background: var(--red); }
.dot--pulsing {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(34,211,165,0.6);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(34,211,165,0.5); }
  70%  { box-shadow: 0 0 0 6px rgba(34,211,165,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,211,165,0); }
}

.refresh-label { font-size: 0.7rem; color: var(--text-muted); }
.refresh-time  { font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; }

.btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--fast), color var(--fast), border-color var(--fast);
}
.btn-icon:hover { background: var(--accent-dim); border-color: var(--border-accent); color: var(--accent); }
.btn-icon.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════
   MAIN & SECTIONS
══════════════════════════════════════ */
.main {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px 56px;
  display: flex;
  flex-direction: column;
  gap: 36px;
}

.section { display: flex; flex-direction: column; gap: 12px; }

.section-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ══════════════════════════════════════
   CARD
══════════════════════════════════════ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: border-color var(--med);
}
.card:hover { border-color: rgba(255,255,255,0.14); }

/* ══════════════════════════════════════
   POWER FLOW CARD
══════════════════════════════════════ */
.flow-card {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "pv  center right"
    "pv  bat    right";
  gap: 0;
  padding: 28px;
  min-height: 280px;
  align-items: center;
  position: relative;
  overflow: hidden;
}

/* Subtle center glow */
.flow-card::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(255,160,30,0.06) 0%, transparent 70%);
  pointer-events: none;
}

.flow-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px;
}

.flow-node--pv  { grid-area: pv; }
.flow-right-col {
  grid-area: right;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.flow-battery { grid-area: bat; }

.flow-icon {
  width: 56px; height: 56px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--fast);
}
.flow-node--pv   .flow-icon { background: rgba(255,208,96,0.1);  color: #FFD060; }
.flow-node--grid .flow-icon { background: var(--blue-dim);        color: var(--blue); }
.flow-node--load .flow-icon { background: var(--purple-dim);      color: var(--purple); }
.flow-node--bat  .flow-icon { background: var(--green-dim);       color: var(--green); }

.flow-node:hover .flow-icon { transform: scale(1.06); }

.flow-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.flow-value {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ── Center / Inverter ── */
.flow-center {
  grid-area: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 8px;
  position: relative;
}

.flow-inverter {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: #1a1a1a;
  border: 2px solid var(--border-accent);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  box-shadow: 0 0 16px rgba(255,160,30,0.18);
}
.flow-inverter__label {
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.flow-inverter__icon { font-size: 1.4rem; }

/* ── Arrows ── */
.flow-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.2;
  transition: opacity var(--med);
}
.flow-arrow.active { opacity: 1; }

.flow-arrow--right { flex-direction: row; }
.flow-arrow--left  { flex-direction: row-reverse; }
.flow-arrow--down  { flex-direction: column; }

.flow-arrow__line {
  width: 48px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  position: relative;
  overflow: hidden;
}
.flow-arrow--down .flow-arrow__line {
  width: 2px; height: 36px;
  background: linear-gradient(180deg, transparent, var(--green), transparent);
}

.flow-arrow__dot {
  position: absolute;
  top: 50%; left: -8px;
  transform: translateY(-50%);
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}
.flow-arrow--down .flow-arrow__dot {
  left: 50%; top: -8px;
  transform: translateX(-50%);
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.flow-arrow--right.active .flow-arrow__dot { animation: flow-right 1s linear infinite; }
.flow-arrow--left.active  .flow-arrow__dot { animation: flow-right 1s linear infinite reverse; }
.flow-arrow--down.active  .flow-arrow__dot { animation: flow-down 1.2s linear infinite; }

@keyframes flow-right {
  from { left: -8px; } to { left: calc(100% + 8px); }
}
@keyframes flow-down {
  from { top: -8px; } to { top: calc(100% + 8px); }
}

.flow-arrow--grid-sell .flow-arrow__line { background: linear-gradient(90deg, transparent, var(--green), transparent); }
.flow-arrow--grid-sell .flow-arrow__dot  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.flow-arrow--grid-buy  .flow-arrow__line { background: linear-gradient(90deg, transparent, var(--red), transparent); }
.flow-arrow--grid-buy  .flow-arrow__dot  { background: var(--red);  box-shadow: 0 0 6px var(--red); }

/* ══════════════════════════════════════
   KPI GRID
══════════════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.kpi-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  cursor: default;
  transition: border-color var(--fast), box-shadow var(--fast);
}
.kpi-card:hover { box-shadow: var(--shadow-card), var(--shadow-glow); }

.kpi-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.kpi-icon--pv   { background: rgba(255,208,96,0.1);  color: #FFD060; }
.kpi-icon--bat  { background: var(--green-dim);       color: var(--green); }
.kpi-icon--feed { background: var(--blue-dim);        color: var(--blue); }
.kpi-icon--grid { background: var(--red-dim);         color: var(--red); }
.kpi-icon--load { background: var(--purple-dim);      color: var(--purple); }
.kpi-icon--self { background: var(--accent-dim);      color: var(--accent); }

.kpi-body { min-width: 0; }

.kpi-value {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.kpi-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 2px;
}

/* SOC bar */
.soc-bar-wrap {
  margin-top: 7px;
  height: 3px;
  background: rgba(255,255,255,0.07);
  border-radius: 0;
  overflow: hidden;
}
.soc-bar {
  height: 100%;
  border-radius: 0;
  background: linear-gradient(90deg, var(--green), #7AFFCF);
  transition: width 0.8s var(--ease);
  width: 0%;
}

/* ══════════════════════════════════════
   CHARTS
══════════════════════════════════════ */
.charts-section { flex-direction: row; flex-wrap: wrap; gap: 12px; }

.chart-card {
  flex: 1 1 420px;
  padding: 20px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chart-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.chart-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
}

.chart-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}

.chart-wrap {
  position: relative;
  height: 200px;
}
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ══════════════════════════════════════
   DEVICE CARD
══════════════════════════════════════ */
.device-card { padding: 24px; }

.device-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px 28px;
}

.device-field { display: flex; flex-direction: column; gap: 3px; }

.device-field__label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.device-field__val {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}
.device-field__val.mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.82rem; }

/* ══════════════════════════════════════
   ALERT
══════════════════════════════════════ */
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 500;
}
.alert--error {
  background: rgba(255,79,108,0.1);
  border: 1px solid rgba(255,79,108,0.25);
  color: #FF8090;
}

/* ══════════════════════════════════════
   LOADING OVERLAY
══════════════════════════════════════ */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  transition: opacity 0.4s var(--ease);
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }

.loading-spinner {
  width: 44px; height: 44px;
  border: 2px solid rgba(255,160,30,0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.loading-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ══════════════════════════════════════
   FOOTER
══════════════════════════════════════ */
.footer {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  max-width: 1320px;
  margin: 0 auto;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ══════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════ */
@media (max-width: 900px) {
  .flow-card {
    grid-template-columns: 1fr;
    grid-template-areas:
      "pv"
      "center"
      "right"
      "bat";
    padding: 18px;
    min-height: auto;
  }
  .flow-right-col { flex-direction: row; justify-content: center; }
  .flow-battery   { display: flex; justify-content: center; }
  .flow-center    { flex-direction: row; padding: 8px 0; }
  .flow-arrow--right { width: 40px; }
  .flow-arrow--left  { width: 40px; }
  .flow-arrow--down  { height: 30px; }
  .charts-section { flex-direction: column; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .main      { padding: 16px 14px 40px; }
  .header    { padding: 0 14px; }
  .header-left { gap: 10px; }
  .kpi-grid  { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 1.2rem; }
  .logo-text { display: none; }
  .refresh-label { display: none; }
  .flow-value { font-size: 1.1rem; }
}

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