:root, [data-theme="light"] {
  --bg: #f1f5f9;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e2e8f0;
  --card: #ffffff;
  --card-border: #e2e8f0;
  --hover: #f8fafc;
  --line: #e2e8f0;

  --ink: #0f172a;
  --ink-secondary: #334155;
  --muted: #64748b;
  --subtle: #94a3b8;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --accent-ink: #ffffff;
  --accent-cyan: #0284c7;

  --ok: #16a34a;
  --ok-bg: #ecfdf5;
  --ok-border: #bbf7d0;

  --alert: #dc2626;
  --alert-bg: #fef2f2;
  --alert-border: #fecaca;

  --code-bg: #f8fafc;
  --code-border: #e2e8f0;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --input-focus: #2563eb;

  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --r: 16px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", monospace;
}

[data-theme="dark"] {
  --bg: #121212;
  --sidebar-bg: #1a1a1a;
  --sidebar-border: #2c2c2e;
  --card: #1e1e1e;
  --card-border: #2c2c2e;
  --hover: #252525;
  --line: #2c2c2e;

  --ink: #ffffff;
  --ink-secondary: #e2e8f0;
  --muted: #98989d;
  --subtle: #636366;

  --accent: #00e5ff;
  --accent-hover: #33ebff;
  --accent-light: rgba(0, 229, 255, 0.12);
  --accent-ink: #001318;
  --accent-cyan: #00e5ff;

  --ok: #32d74b;
  --ok-bg: rgba(50, 215, 75, 0.12);
  --ok-border: rgba(50, 215, 75, 0.3);

  --alert: #ff453a;
  --alert-bg: #3a1c1c;
  --alert-border: rgba(255, 69, 58, 0.4);

  --code-bg: #161616;
  --code-border: #2c2c2e;
  --input-bg: #161616;
  --input-border: #2c2c2e;
  --input-focus: #00e5ff;

  --shadow-sm: none;
  --shadow-md: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
::selection { background: var(--accent-light); color: var(--accent); }
a { color: var(--accent); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--accent-hover); text-decoration: none; }

/* Layout Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
}
.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--sidebar-border);
}
.brand-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.02em;
}
.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, #00e5ff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 900;
  font-size: 18px;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}
.brand-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding-left: 42px;
}
.system-status {
  margin-top: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ok);
}
.system-status .pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 2px rgba(22, 163, 74, .2);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.nav-category {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--subtle);
  padding: 12px 12px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  transition: all .15s ease;
}
.nav-link svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .8;
}
.nav-link:hover {
  background: var(--hover);
  color: var(--ink);
}
.nav-link.on {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}
.nav-link.on svg {
  stroke: var(--accent);
  opacity: 1;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--hover);
  border-radius: 12px;
  border: 1px solid var(--line);
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}
.user-meta {
  flex: 1;
  min-width: 0;
}
.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 11px;
  color: var(--muted);
}
.logout-btn {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color .15s;
}
.logout-btn:hover { color: var(--alert); }

/* Main Content Panel */
.main-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Top Header Bar */
.top-header {
  height: 70px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-title-box h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
  letter-spacing: -.02em;
}
.header-title-box p {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0 0;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--hover);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  transition: all .15s;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.content-body {
  padding: 32px;
  flex: 1;
}

/* Typography */
h1 { font-size: 24px; font-weight: 700; margin: 0 0 16px; letter-spacing: -.02em; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 14px; letter-spacing: -.01em; color: var(--ink); }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.head h1 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono, code, pre, textarea.mono { font-family: var(--mono); }
code { background: var(--code-bg); border: 1px solid var(--code-border); padding: 2px 6px; border-radius: 6px; font-size: 12.5px; }
pre { background: var(--code-bg); border: 1px solid var(--code-border); padding: 14px 16px; border-radius: 12px; overflow-x: auto; font-size: 13px; margin: 8px 0 16px; }
pre code { background: none; border: none; padding: 0; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

/* Grid System */
.grid { display: grid; gap: 20px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g-main { grid-template-columns: 2fr 1fr; align-items: start; }
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g-main { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .top-header { padding: 0 16px; }
  .content-body { padding: 16px; }
  .sidebar { display: none; }
}

/* KPI Stat Cards (Matching WattVision desktop-light.png) */
.kpi-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}
.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.kpi-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.kpi-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-light);
  color: var(--accent);
}
.kpi-badge.ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.kpi-value-box {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.kpi-value {
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -.03em;
}
.kpi-card.highlight .kpi-value {
  color: var(--accent);
}
.kpi-unit {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.kpi-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* Area Chart Styling */
.chart-container {
  margin: 16px 0 8px;
  padding: 16px 0 0;
  position: relative;
}
.chart-svg {
  width: 100%;
  height: 130px;
  overflow: visible;
}
.chart-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--subtle);
  font-family: var(--mono);
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

/* Asset / Merchant Progress Breakdown (Like WattVision Consumption by Asset) */
.asset-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.asset-item:last-child { border-bottom: none; }
.asset-header {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}
.asset-name {
  font-weight: 600;
  color: var(--ink);
}
.asset-val {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
}
.asset-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--hover);
  border-radius: 999px;
  overflow: hidden;
}
.asset-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, #00e5ff 100%);
}

/* Flash Messages */
.flash {
  padding: 14px 16px;
  border-radius: 12px;
  margin-bottom: 20px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.flash.err {
  background: var(--alert-bg);
  color: var(--alert);
  border: 1px solid var(--alert-border);
  border-left: 4px solid var(--alert);
}
.flash.ok {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid var(--ok-border);
  border-left: 4px solid var(--ok);
}

/* Form Controls */
label { display: block; font-weight: 600; margin: 0 0 6px; font-size: 13.5px; color: var(--ink-secondary); }
.field { margin-bottom: 16px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  transition: all .15s ease;
}
input::placeholder, textarea::placeholder { color: var(--subtle); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
[data-theme="dark"] input:focus, [data-theme="dark"] select:focus, [data-theme="dark"] textarea:focus {
  box-shadow: 0 0 0 3px rgba(0, 229, 255, .25);
}
select option { background: var(--card); color: var(--ink); }
textarea { min-height: 110px; resize: vertical; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 5px; }

/* Radio buttons group */
.radios {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--input-border);
  background: var(--card);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
}
.radio-pill:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}
.radio-pill input { accent-color: var(--accent); margin: 0; }

/* Buttons */
.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 10px;
  padding: 10px 18px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}
.btn:hover {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}
.btn.sec {
  background: var(--hover);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn.sec:hover {
  background: var(--line);
  color: var(--ink);
}
.btn.danger {
  background: var(--alert-bg);
  color: var(--alert);
  border: 1px solid var(--alert-border);
  box-shadow: none;
}
.btn.danger:hover {
  background: var(--alert);
  color: #fff;
}
.btn.sm {
  padding: 6px 12px;
  font-size: 12.5px;
  border-radius: 8px;
}
button.link {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 6px 10px;
}
button.link:hover { color: var(--ink); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; margin: 0; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--hover); }
th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 700;
  background: var(--hover);
}
th:first-child { border-top-left-radius: 10px; }
th:last-child { border-top-right-radius: 10px; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.num { font-family: var(--mono); font-size: 13px; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; padding: 0; }
.table-wrap table { margin: 0; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--hover);
  color: var(--muted);
  border: 1px solid var(--line);
}
.badge.api {
  background: var(--accent-light);
  color: var(--accent);
  border-color: rgba(37, 99, 235, 0.2);
}
.badge.dashboard {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok-border);
}
.badge.off, .badge.admin {
  background: var(--alert-bg);
  color: var(--alert);
  border-color: var(--alert-border);
}
.empty { text-align: center; color: var(--muted); padding: 36px 0; }

/* QR and Secret Card */
.qr {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  max-width: 300px;
  margin: 0 auto 16px;
  box-shadow: var(--shadow-sm);
}
.qr svg { display: block; width: 100%; height: auto; }
.payload { word-break: break-all; }
.secret {
  background: var(--ok-bg);
  border: 1px dashed var(--ok);
  border-left: 4px solid var(--ok);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}
.secret code { font-size: 14px; word-break: break-all; background: transparent; border: none; font-weight: 700; color: var(--ok); }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 20px; }

/* Standalone Login Screen */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r);
  padding: 32px;
  box-shadow: var(--shadow-md);
}
.login-header {
  text-align: center;
  margin-bottom: 24px;
}
.login-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, #00e5ff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 26px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, .35);
}
.login-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--ink);
}
.login-desc {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

.scan-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }

/* Quick-create modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 16px 16px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r);
  padding: 22px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}
