/* ============================================================
   SMART ENERGY METER — PREMIUM DASHBOARD STYLES
   FILE: style.css
   Design: Dark glassmorphism · Syne font · Electric palette
============================================================ */

/* ─── VARIABLES ─────────────────────────────────────────── */
:root {
  --bg-base:      #080c14;
  --bg-surface:   #0d1320;
  --bg-card:      rgba(255,255,255,0.04);
  --bg-card-h:    rgba(255,255,255,0.07);
  --border:       rgba(255,255,255,0.07);
  --border-glow:  rgba(99,211,255,0.25);

  --accent:       #63d3ff;
  --accent-dim:   rgba(99,211,255,0.15);
  --accent-2:     #7c6fff;
  --accent-3:     #3dffc8;
  --accent-warn:  #ffbe45;
  --accent-err:   #ff5e6c;
  --accent-ok:    #3dffc8;

  --text-primary: #eef2ff;
  --text-secondary: rgba(238,242,255,0.5);
  --text-muted:   rgba(238,242,255,0.28);

  --sidebar-w:    240px;
  --radius:       16px;
  --radius-sm:    10px;
  --shadow:       0 4px 32px rgba(0,0,0,0.45);

  --font-main:    'Syne', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;
}

/* ─── RESET ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-main);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
select { font-family: inherit; }
canvas { display: block; }
.hidden { display: none !important; }

/* ─── BACKGROUND GLOW MESH ──────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, rgba(99,211,255,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 50% 35% at 80% 80%, rgba(124,111,255,0.07) 0%, transparent 55%),
    radial-gradient(ellipse 40% 30% at 50% 50%, rgba(61,255,200,0.04) 0%, transparent 50%);
  z-index: 0;
}

/* ─── LOADING SCREEN ────────────────────────────────────── */
#loader {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-base);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  transition: opacity .6s ease, transform .6s ease;
}
#loader.fade-out { opacity: 0; transform: scale(1.03); pointer-events: none; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.loader-ring {
  position: relative; width: 110px; height: 110px;
}
.loader-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track {
  fill: none; stroke: rgba(255,255,255,0.07); stroke-width: 6;
}
.ring-progress {
  fill: none; stroke: var(--accent); stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 326; stroke-dashoffset: 326;
  animation: ringFill 2s cubic-bezier(.4,0,.2,1) forwards;
  filter: drop-shadow(0 0 8px var(--accent));
}
@keyframes ringFill {
  to { stroke-dashoffset: 0; }
}
.loader-bolt {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
}
.loader-bolt svg { width: 36px; height: 36px; color: var(--accent); filter: drop-shadow(0 0 12px var(--accent)); animation: boltPulse 1.6s ease-in-out infinite; }
@keyframes boltPulse { 0%,100%{opacity:.7;transform:scale(1)} 50%{opacity:1;transform:scale(1.12)} }
.loader-label { font-size: .8rem; letter-spacing: .15em; text-transform: uppercase; color: var(--text-secondary); }
.loader-dots { display: flex; gap: 6px; }
.loader-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: dotBounce 1.2s ease-in-out infinite;
}
.loader-dots span:nth-child(2) { animation-delay: .2s; background: var(--accent-2); }
.loader-dots span:nth-child(3) { animation-delay: .4s; background: var(--accent-3); }
@keyframes dotBounce { 0%,100%{transform:translateY(0);opacity:.4} 50%{transform:translateY(-8px);opacity:1} }

/* ─── APP LAYOUT ────────────────────────────────────────── */
#app {
  display: flex; min-height: 100vh; position: relative; z-index: 1;
  animation: appReveal .7s ease both;
}
@keyframes appReveal { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }

/* ─── SIDEBAR ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: rgba(13,19,32,0.85);
  backdrop-filter: blur(20px) saturate(1.3);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 24px 0;
  position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 100;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.sidebar-logo {
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px 28px;
  border-bottom: 1px solid var(--border);
}
.logo-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 20px rgba(99,211,255,0.35);
}
.logo-icon svg { width: 20px; height: 20px; color: #fff; }
.logo-name { display: block; font-weight: 700; font-size: .95rem; letter-spacing: .02em; }
.logo-sub  { display: block; font-size: .68rem; color: var(--text-muted); letter-spacing: .06em; text-transform: uppercase; margin-top: 1px; }

.sidebar-nav { flex: 1; padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: .88rem; font-weight: 500;
  transition: all .2s;
  position: relative; overflow: hidden;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { color: var(--text-primary); background: var(--bg-card-h); }
.nav-item.active {
  color: var(--accent); background: var(--accent-dim);
}
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 3px; border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.sidebar-status {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  font-size: .75rem; color: var(--text-muted); font-family: var(--font-mono);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
  transition: background .4s;
  flex-shrink: 0;
}
.status-dot.online  { background: var(--accent-3); box-shadow: 0 0 8px var(--accent-3); animation: pulse .8s infinite alternate; }
.status-dot.offline { background: var(--accent-err); }
@keyframes pulse { from{opacity:.6} to{opacity:1} }

/* ─── MAIN ──────────────────────────────────────────────── */
.main {
  flex: 1; margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  min-height: 100vh;
}

/* ─── TOPBAR ────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px;
  background: rgba(13,19,32,0.7);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.menu-toggle { display: none; color: var(--text-primary); padding: 6px; }
.menu-toggle svg { width: 22px; height: 22px; }
.topbar-title { flex: 1; }
.topbar-title h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em; }
.topbar-title p  { font-size: .75rem; color: var(--text-muted); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.device-selector-wrap { display: flex; align-items: center; gap: 8px; }
.device-selector-wrap label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; }
.device-select {
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 8px;
  padding: 7px 12px; font-size: .82rem; cursor: pointer;
  outline: none; transition: border .2s;
}
.device-select:focus { border-color: var(--accent); }

.timestamp-badge {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px;
  font-size: .75rem; font-family: var(--font-mono); color: var(--text-secondary);
}
.timestamp-badge svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ─── VIEWS ─────────────────────────────────────────────── */
.view { display: none; padding: 24px 28px; animation: fadeIn .35s ease; }
.view.active { display: block; }
@keyframes fadeIn { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:none} }

/* ─── METRIC CARDS ──────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(12px);
  transition: border-color .25s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.4,0,.2,1), box-shadow .25s ease;
  position: relative; overflow: hidden;
}
.metric-card::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  opacity: 0; transition: opacity .3s ease;
  background: linear-gradient(135deg, rgba(99,211,255,0.06) 0%, transparent 70%);
}
.metric-card:hover { border-color: var(--border-glow); transform: translateY(-3px); box-shadow: 0 12px 48px rgba(99,211,255,0.1); }
.metric-card:hover::before { opacity: 1; }

.card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-icon {
  width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.card-icon svg { width: 18px; height: 18px; }
.voltage-icon  { background: rgba(99,211,255,0.12); color: var(--accent); }
.current-icon  { background: rgba(124,111,255,0.12); color: var(--accent-2); }
.power-icon    { background: rgba(255,94,108,0.12); color: var(--accent-err); }
.apparent-icon { background: rgba(255,190,69,0.12); color: var(--accent-warn); }
.pf-icon       { background: rgba(61,255,200,0.12); color: var(--accent-3); }
.energy-icon   { background: rgba(99,211,255,0.15); color: var(--accent); }
.card-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; }
.card-value {
  font-size: 2.2rem; font-weight: 600; letter-spacing: -.02em;
  display: flex; align-items: baseline; gap: 6px;
  margin-bottom: 12px; line-height: 1;
}
.card-value small { font-size: .75rem; font-weight: 500; color: var(--text-muted); margin-bottom: 3px; letter-spacing: .04em; }
.card-sparkline { margin: 0 -4px 10px; }
.card-footer { font-size: .72rem; color: var(--text-muted); font-family: var(--font-mono); }
.card-status { transition: color .4s; }

.energy-card { grid-column: span 2; }
.energy-value { font-size: 2.4rem; font-weight: 600; }
.energy-bar-wrap {
  height: 6px; background: rgba(255,255,255,0.05); border-radius: 10px;
  overflow: hidden; margin: 6px 0 12px; position: relative;
}
.energy-bar {
  height: 100%; border-radius: 10px; width: 0%;
  background: linear-gradient(90deg, #63d3ff 0%, #3dffc8 100%);
  transition: width 1.2s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 0 12px rgba(99,211,255,0.4), inset 0 0 6px rgba(255,255,255,0.2);
}
.card-badge {
  display: inline-block; background: linear-gradient(135deg, rgba(61,255,200,0.15), rgba(61,255,200,0.08));
  color: var(--accent-3); border-radius: 20px;
  padding: 4px 12px; font-size: .68rem; letter-spacing: .06em; font-weight: 500;
  border: 1px solid rgba(61,255,200,0.25);
}
.live-badge {
  display: inline-block; background: linear-gradient(135deg, rgba(255,94,108,0.2), rgba(255,94,108,0.1));
  color: var(--accent-err); border-radius: 20px;
  padding: 3px 10px; font-size: .68rem; font-weight: 600; letter-spacing: .1em;
  border: 1px solid rgba(255,94,108,0.3);
  vertical-align: middle; margin-left: 6px;
  animation: livePulse 1.5s infinite;
}
@keyframes livePulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.65;transform:scale(1.02)} }

/* ─── CHARTS ─────────────────────────────────────────────── */
.section-header { margin-bottom: 18px; }
.section-header h2 { font-size: 1.05rem; font-weight: 700; display: flex; align-items: center; letter-spacing: -.01em; }
.section-header p  { font-size: .78rem; color: var(--text-muted); margin-top: 4px; letter-spacing: .03em; }
.chart-section {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  backdrop-filter: blur(12px); margin-bottom: 16px;
  transition: border-color .25s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.chart-section:hover { border-color: var(--border-glow); }
.chart-wrap { position: relative; height: 280px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ─── TENANTS ────────────────────────────────────────────── */
.tenants-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.tenant-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  backdrop-filter: blur(12px);
  transition: border-color .25s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.4,0,.2,1), box-shadow .25s ease;
  position: relative;
}
.tenant-card:hover { border-color: var(--border-glow); transform: translateY(-3px); box-shadow: 0 12px 48px rgba(99,211,255,0.1); }
.tenant-name { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; letter-spacing: -.01em; }
.tenant-id   { font-size: .72rem; color: var(--text-muted); font-family: var(--font-mono); margin-bottom: 16px; letter-spacing: .04em; }
.tenant-stat { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.tenant-stat:last-child { border-bottom: none; }
.tenant-stat-label { font-size: .76rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 500; }
.tenant-stat-value { font-size: .9rem; font-weight: 600; font-family: var(--font-mono); }
.devices-badge { display: inline-flex; align-items: center; gap: 6px; }
.dev-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-3); box-shadow: 0 0 8px var(--accent-3); }

/* ─── BILLING ────────────────────────────────────────────── */
.billing-controls {
  display: flex; align-items: flex-end; gap: 12px; margin-top: 20px; padding: 20px;
  background: rgba(99,211,255,0.04); border: 1px solid var(--border-glow);
  border-radius: var(--radius); backdrop-filter: blur(8px);
}
.billing-controls label {
  font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--accent); display: block; margin-bottom: 6px;
}
.billing-controls input {
  flex: 1; max-width: 180px;
  padding: 10px 14px; font-size: .9rem; font-family: var(--font-mono);
  background: var(--bg-surface); border: 1px solid var(--accent-dim); border-radius: 8px;
  color: var(--text-primary); transition: all .2s ease;
}
.billing-controls input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 16px rgba(99,211,255,0.2); }
.billing-controls .btn {
  padding: 10px 24px; font-size: .9rem; font-weight: 600; letter-spacing: .03em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg-base); border-radius: 8px;
  transition: all .2s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 4px 16px rgba(99,211,255,0.2);
  text-transform: uppercase;
}
.billing-controls .btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(99,211,255,0.35); }
.billing-controls .btn:active { transform: translateY(0); }
.billing-controls .btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.billing-controls .hint {
  font-size: .7rem; color: var(--text-muted); display: block; margin-top: 4px; text-transform: uppercase; letter-spacing: .03em;
}
.billing-container { display: flex; flex-direction: column; gap: 16px; }
.billing-table-wrap {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.billing-table-title { padding: 20px 24px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: .95rem; letter-spacing: -.01em; }
table.billing-table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.billing-table th {
  padding: 14px 24px; text-align: left;
  font-size: .73rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border); font-weight: 600;
}
.billing-table td {
  padding: 16px 24px; font-size: .85rem; border-bottom: 1px solid rgba(255,255,255,0.04);
  font-family: var(--font-mono);
}
.billing-table tr:last-child td { border-bottom: none; }
.billing-table tr:hover td { background: rgba(255,255,255,0.02); transition: background .15s ease; }
.bill-amount { color: var(--accent-warn); font-weight: 700; letter-spacing: -.01em; }
.bill-kwh    { color: var(--accent-3); font-weight: 600; }
.month-chip {
  display: inline-block; background: var(--accent-dim); color: var(--accent);
  border-radius: 8px; padding: 4px 10px; font-size: .73rem; font-weight: 600;
  border: 1px solid rgba(99,211,255,0.2);
}

/* ─── SKELETONS ──────────────────────────────────────────── */
.skeleton-card {
  border-radius: var(--radius); height: 180px;
  background: linear-gradient(90deg, var(--bg-card) 25%, rgba(255,255,255,0.06) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
.skeleton-card.tall { height: 300px; }
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ─── VALUE ANIMATIONS ───────────────────────────────────── */
.value-flash { animation: valueFlash .4s ease; }
@keyframes valueFlash {
  0%  { opacity:.3; transform: scale(.95); }
  60% { opacity:1;  transform: scale(1.04); }
  100%{ opacity:1;  transform: scale(1); }
}

/* ─── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 1200px) {
  .cards-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .energy-card { grid-column: span 2; }
}

@media (max-width: 900px) {
  .analytics-grid { grid-template-columns: 1fr; }
  .energy-card { grid-column: span 1; }
  .cards-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .tenants-grid { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 240px; }
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); z-index: 200; }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 40px rgba(0,0,0,.6); }
  .main { margin-left: 0; }
  .menu-toggle { display: flex; }
  .view { padding: 16px 12px; }
  .topbar { padding: 12px 14px; gap: 10px; flex-wrap: wrap; }
  .topbar-title { flex: 1; min-width: 200px; }
  .topbar-title h1 { font-size: 1rem; }
  .topbar-right { width: 100%; flex-wrap: wrap; gap: 8px; }
  .device-selector-wrap { flex: 1; min-width: 150px; }
  .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card-value { font-size: 1.8rem; }
  .card-icon { width: 30px; height: 30px; }
  .card-icon svg { width: 16px; height: 16px; }
  .tenants-grid { grid-template-columns: 1fr; }
  .billing-table { font-size: .8rem; }
  .billing-table th, .billing-table td { padding: 12px 14px; }
}

@media (max-width: 480px) {
  .cards-grid { grid-template-columns: 1fr; gap: 10px; }
  .energy-card { grid-column: span 1; }
  .card-value { font-size: 1.6rem; }
  .card-label { font-size: .7rem; }
  .topbar { flex-direction: column; gap: 8px; }
  .topbar-title { width: 100%; }
  .topbar-right { flex-direction: column; gap: 8px; align-items: stretch; }
  .device-selector-wrap { width: 100%; }
  .device-select { width: 100%; }
  .billing-controls { flex-direction: column; align-items: stretch; }
  .billing-controls input { width: 100%; max-width: none; }
  .billing-controls .btn { width: 100%; }
  .billing-table { font-size: .76rem; }
  .billing-table th, .billing-table td { padding: 10px 12px; }
  .tenant-stat { flex-direction: column; align-items: flex-start; gap: 4px; }
  .tenant-stat-label, .tenant-stat-value { width: 100%; }
  .chart-wrap { height: 220px; }
}

@media (max-width: 360px) {
  .topbar { padding: 10px 12px; }
  .topbar-title h1 { font-size: 1rem; }
  .device-selector-wrap label { font-size: .68rem; }
  .device-select { font-size: .82rem; padding: 10px 12px; }
  .billing-controls { padding: 16px; gap: 10px; }
  .billing-controls .hint { font-size: .68rem; }
  .tenant-card { padding: 18px; }
  .metric-card { padding: 16px; }
  .card-value { font-size: 1.5rem; }
}
