/* ===== Deye Solar Dashboard — premium theme ===== */
:root {
  --bg: #0b1220;
  --bg2: #0e1626;
  --surface: #131d31;
  --surface2: #18243c;
  --border: #233149;
  --text: #e7edf7;
  --muted: #8da2c0;
  --accent: #4f8cff;
  --solar: #ffb020;
  --batt: #25c685;
  --grid: #ff5d5d;
  --load: #8b7dff;
  --save: #36c2a8;
  --temp: #ff8a5b;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 18px;
}
[data-theme="light"] {
  --bg: #eef2f8;
  --bg2: #e7edf6;
  --surface: #ffffff;
  --surface2: #f4f7fc;
  --border: #dfe6f1;
  --text: #16233b;
  --muted: #5d6f8c;
  --shadow: 0 10px 30px rgba(20,40,80,.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(79,140,255,.10), transparent 60%), var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 18px 24px; max-width: 1280px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  font-size: 24px; background: linear-gradient(135deg, var(--solar), #ff7a59); color: #1b1300;
  box-shadow: 0 6px 18px rgba(255,176,32,.35);
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-size: 13px; font-weight: 600;
}
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status-pill.online .dot { background: var(--batt); box-shadow: 0 0 0 4px rgba(37,198,133,.18); }
.status-pill.offline .dot { background: var(--grid); box-shadow: 0 0 0 4px rgba(255,93,93,.18); }
.status-pill.error .dot { background: var(--solar); }
.updated { font-size: 12.5px; color: var(--muted); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 16px; transition: .15s;
}
.icon-btn:hover { background: var(--surface2); transform: translateY(-1px); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 8px 24px 40px; }

/* stale banner */
.stale-banner {
  background: linear-gradient(90deg, #4a3a00, #5c4a00); color: #ffe49a; text-align: center;
  padding: 10px; font-size: 13.5px; font-weight: 600; border-bottom: 1px solid #7a6200;
}
.hidden { display: none !important; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; position: relative; overflow: hidden;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { font-size: 14px; font-weight: 700; margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

/* kpi */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 16px 0;
}
.kpi { display: flex; align-items: center; gap: 14px; padding: 16px; }
.kpi-ico {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; font-size: 20px; flex: none;
  background: var(--surface2);
}
.kpi-ico.solar { color: var(--solar); box-shadow: inset 0 0 0 1px rgba(255,176,32,.3); }
.kpi-ico.load { color: var(--load); }
.kpi-ico.batt { color: var(--batt); }
.kpi-ico.grid { color: var(--grid); }
.kpi-ico.gen { color: var(--accent); }
.kpi-ico.save { color: var(--save); font-weight: 800; }
.kpi-ico.temp { color: var(--temp); }
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.kpi-val { font-size: 22px; font-weight: 750; letter-spacing: .3px; }
.kpi-val small { font-size: 13px; color: var(--muted); font-weight: 600; }

/* layout grids */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }

/* flow */
.flow-card .flow-wrap { width: 100%; }
.flow-wrap svg { width: 100%; height: auto; display: block; }
.flow-node rect { rx: 14; }
.flow-line { stroke-width: 3.5; fill: none; opacity: .35; }
.flow-line.active { opacity: 1; stroke-dasharray: 7 9; animation: dash 1s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -32; } }
.flow-label { font-size: 12px; fill: var(--muted); }
.flow-val { font-size: 14px; font-weight: 700; fill: var(--text); }

/* soc ring */
.soc-card .soc-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.soc-ring { width: 200px; height: 200px; }
.soc-track { fill: none; stroke: var(--surface2); stroke-width: 16; }
.soc-fill { fill: none; stroke: var(--batt); stroke-width: 16; stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: 100px 100px; transition: stroke-dashoffset .8s ease, stroke .4s; }
.soc-pct { fill: var(--text); font-size: 40px; font-weight: 800; text-anchor: middle; }
.soc-sub { fill: var(--muted); font-size: 13px; text-anchor: middle; text-transform: capitalize; }
.soc-meta { display: flex; gap: 28px; }
.soc-meta div { display: flex; flex-direction: column; align-items: center; }
.soc-meta span { font-size: 11.5px; color: var(--muted); }
.soc-meta b { font-size: 16px; margin-top: 3px; }

/* charts */
.chart-box { height: 240px; position: relative; }

/* table */
.table-wrap { overflow-x: auto; max-height: 320px; overflow-y: auto; }
.rt { width: 100%; border-collapse: collapse; font-size: 13px; }
.rt th { text-align: start; color: var(--muted); font-weight: 600; padding: 8px 10px; position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--border); }
.rt td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.rt tr:last-child td { border-bottom: none; }

/* health */
.health { list-style: none; margin: 0; padding: 0; }
.health li { display: flex; justify-content: space-between; padding: 11px 2px; border-bottom: 1px dashed var(--border); font-size: 13.5px; }
.health li:last-child { border-bottom: none; }
.health span { color: var(--muted); }
.health b { font-weight: 650; }

/* footer */
.foot { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; margin-top: 26px; }

/* skeleton */
.skeleton { color: transparent !important; border-radius: 7px;
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 37%, var(--surface2) 63%);
  background-size: 400% 100%; animation: sk 1.4s ease infinite; min-width: 70px; min-height: 1em; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* card polish */
.card { transition: transform .15s ease, box-shadow .15s ease; }
.card:hover { transform: translateY(-2px); box-shadow: 0 16px 40px rgba(0,0,0,.42); }
[data-theme="light"] .card:hover { box-shadow: 0 16px 40px rgba(20,40,80,.16); }
.kpi { transition: transform .15s ease; }
.kpi:hover { transform: translateY(-2px); }
.card-head h2 { position: relative; padding-inline-start: 12px; }
.card-head h2::before { content: ""; position: absolute; inset-inline-start: 0; top: 50%; transform: translateY(-50%); width: 4px; height: 14px; border-radius: 3px; background: linear-gradient(var(--accent), var(--solar)); }

/* weather card */
.wx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.wx { background: var(--surface2); border: 1px solid var(--border); border-radius: 14px; padding: 16px; text-align: center; }
.wx-when { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.wx-icon { font-size: 42px; line-height: 1; margin: 8px 0 4px; }
.wx-desc { font-size: 14px; font-weight: 650; }
.wx-temp { font-size: 14px; color: var(--muted); margin-top: 2px; }
.wx-exp { margin-top: 12px; font-size: 11.5px; color: var(--muted); }
.wx-exp b { display: block; font-size: 19px; color: var(--solar); margin-top: 3px; font-weight: 750; }

/* savings card */
.savings-card { display: flex; flex-direction: column; }
.save-hero { display: flex; align-items: baseline; gap: 5px; margin: 4px 0 16px; }
.save-cur { font-size: 28px; color: var(--save); font-weight: 700; }
.save-big { font-size: 48px; font-weight: 800; color: var(--save); line-height: 1; letter-spacing: .5px; }
.save-break { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.save-break div { background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 8px; text-align: center; }
.save-break span { font-size: 10.5px; color: var(--muted); display: block; }
.save-break b { font-size: 14.5px; margin-top: 5px; display: block; }
.save-note { margin-top: auto; padding-top: 14px; font-size: 12px; color: var(--muted); line-height: 1.55; }

/* responsive */
@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .topbar { padding: 14px; }
  .wrap { padding: 6px 14px 30px; }
  .kpi-val { font-size: 19px; }
}

/* RTL */
[dir="rtl"] .kpi { flex-direction: row-reverse; }
[dir="rtl"] .topbar-right { flex-direction: row-reverse; }
