﻿:root {
  --dm-bg: #0f172a;
  --dm-card: #1e293b;
  --dm-surface: #0f172a;
  --dm-surface-soft: rgba(15, 23, 42, 0.65);
  --dm-border: #334155;
  --dm-border-soft: rgba(51, 65, 85, 0.7);
  --dm-gridline: #1e293b;
  --dm-flow-bg: #334155;
  --dm-text: #f8fafc;
  --dm-text-secondary: #cbd5e1;
  --dm-muted: #94a3b8;
  --dm-tooltip-bg: rgba(15, 23, 42, 0.96);
  --dm-pv: #f59e0b;
  --dm-load: #8b5cf6;
  --dm-feed: #38bdf8;
  --dm-export: #10b981;
  --dm-bat-chg: #22c55e;
  --dm-bat-dis: #f43f5e;
  --dm-grid: #3b82f6;
}

:root.dm-theme-light {
  --dm-bg: #f1f5f9;
  --dm-card: #ffffff;
  --dm-surface: #f8fafc;
  --dm-surface-soft: #f8fafc;
  --dm-border: #cbd5e1;
  --dm-border-soft: #e2e8f0;
  --dm-gridline: #e2e8f0;
  --dm-flow-bg: #cbd5e1;
  --dm-text: #0f172a;
  --dm-text-secondary: #334155;
  --dm-muted: #475569;
  --dm-tooltip-bg: rgba(255, 255, 255, 0.98);
  --dm-pv: #d97706;
  --dm-load: #7c3aed;
  --dm-feed: #0284c7;
  --dm-export: #059669;
  --dm-bat-chg: #16a34a;
  --dm-bat-dis: #e11d48;
  --dm-grid: #2563eb;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--dm-bg);
  color: var(--dm-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  padding: env(safe-area-inset-top) 14px calc(24px + env(safe-area-inset-bottom)) 14px;
  transition: background 0.2s ease, color 0.2s ease;
}

.dm-app { max-width: 1120px; margin: 14px auto 0; display: flex; flex-direction: column; gap: 16px; }

.dm-header {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--dm-card); padding: 12px 16px; border-radius: 16px; border: 1px solid var(--dm-border);
}

.dm-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dm-brand-text { display: flex; flex-direction: column; min-width: 0; }
.dm-brand-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-brand-text span { font-size: 11px; color: var(--dm-muted); }

.dm-dot { width: 11px; height: 11px; border-radius: 50%; background: #64748b; flex-shrink: 0; }
.dm-dot.live { background: var(--dm-export); box-shadow: 0 0 10px var(--dm-export); }

.dm-header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.dm-icon-btn, .dm-pill-btn {
  background: var(--dm-surface); color: var(--dm-text); border: 1px solid var(--dm-border);
  border-radius: 10px; height: 34px; cursor: pointer; font-weight: 700;
}
.dm-icon-btn { width: 34px; font-size: 15px; display: grid; place-items: center; }
.dm-pill-btn { padding: 0 10px; font-size: 12px; }

/* 3-Tier Warning Banner */
.dm-alert {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 14px; border: 1px solid; font-size: 13px;
}
.dm-alert-main { display: flex; flex-direction: column; gap: 2px; }
.dm-alert.simple { background: rgba(245, 158, 11, 0.14); border-color: #f59e0b; color: var(--dm-text); }
.dm-alert.medium { background: rgba(249, 115, 22, 0.2); border-color: #f97316; color: var(--dm-text); }
.dm-alert.severe {
  background: rgba(239, 68, 68, 0.24); border-color: #ef4444; color: var(--dm-text);
  animation: dmPulseAlert 1.2s infinite;
}
@keyframes dmPulseAlert {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.dm-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; }
.dm-span-all { grid-column: 1 / -1; }
@media (max-width: 860px) { .dm-grid { grid-template-columns: 1fr; } }

.dm-card {
  background: var(--dm-card); border: 1px solid var(--dm-border); border-radius: 20px;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}

.dm-card-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.dm-card-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dm-muted); font-weight: 700; }
.dm-title-bright { color: var(--dm-text); font-size: 13px; text-transform: none; letter-spacing: 0; }
.dm-badge { font-size: 12px; font-weight: 700; color: var(--dm-export); }

.dm-flow-wrapper { width: 100%; aspect-ratio: 600 / 320; max-height: 310px; }
.dm-flow-svg { width: 100%; height: 100%; overflow: visible; }
.dm-bg-line { fill: none; stroke: var(--dm-flow-bg); stroke-width: 3; stroke-linecap: round; }
.dm-active-line { fill: none; stroke-linecap: round; stroke-dasharray: 10 14; opacity: 0; transition: stroke-width 0.3s ease, opacity 0.3s ease; }

@keyframes dmFlowFwd { from { stroke-dashoffset: 24; } to { stroke-dashoffset: 0; } }
@keyframes dmFlowRev { from { stroke-dashoffset: 0; } to { stroke-dashoffset: 24; } }
.dm-anim-fwd { animation: dmFlowFwd var(--dm-speed, 1s) linear infinite; }
.dm-anim-rev { animation: dmFlowRev var(--dm-speed, 1s) linear infinite; }

.dm-node-circle { fill: var(--dm-surface); stroke-width: 3; }
.dm-node-label { fill: var(--dm-muted); font-size: 11px; font-weight: 700; text-anchor: middle; }
.dm-node-val { fill: var(--dm-text); font-size: 16px; font-weight: 700; text-anchor: middle; }
.dm-node-sub { fill: var(--dm-muted); font-size: 11px; font-weight: 700; text-anchor: middle; }

.dm-stack { display: flex; flex-direction: column; gap: 16px; }
.dm-bat-body { display: flex; align-items: center; gap: 14px; }
.dm-ring-wrap { position: relative; width: 84px; height: 84px; flex-shrink: 0; }
.dm-ring-wrap svg { transform: rotate(-90deg); width: 84px; height: 84px; }
.dm-ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.dm-ring-text strong { font-size: 18px; color: var(--dm-export); }
.dm-ring-text span { font-size: 10px; color: var(--dm-muted); }

.dm-metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; width: 100%; }
.dm-mini-stat { background: var(--dm-surface-soft); padding: 9px 10px; border-radius: 12px; border: 1px solid var(--dm-border-soft); }
.dm-mini-stat span { display: block; font-size: 10px; color: var(--dm-muted); margin-bottom: 3px; }
.dm-mini-stat strong { font-size: 14px; font-weight: 700; color: var(--dm-text); }

.dm-balance-row { display: flex; justify-content: space-between; align-items: baseline; }
.dm-sub-label { font-size: 11px; color: var(--dm-muted); }
.dm-big-num { font-size: 22px; font-weight: 700; }
.dm-bar-track { width: 100%; height: 9px; background: var(--dm-surface); border: 1px solid var(--dm-border-soft); border-radius: 999px; overflow: hidden; display: flex; }
.dm-bar-fill { height: 100%; transition: width 0.3s ease; }

.dm-zoom-controls { display: inline-flex; align-items: center; gap: 3px; background: var(--dm-surface); border: 1px solid var(--dm-border); border-radius: 10px; padding: 2px; }
.dm-zoom-btn { background: transparent; color: var(--dm-text); border: none; border-radius: 7px; padding: 4px 8px; font-size: 12px; font-weight: 700; cursor: pointer; }
.dm-zoom-badge { font-size: 11px; font-weight: 700; color: var(--dm-muted); padding: 0 4px; }

.dm-chart-box { background: var(--dm-surface); border: 1px solid var(--dm-border); border-radius: 16px; padding: 12px; position: relative; user-select: none; }
.dm-chart-legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.dm-legend-item {
  display: inline-flex; align-items: center; background: var(--dm-card); color: var(--dm-text-secondary);
  border: 1px solid var(--dm-border); border-radius: 999px; padding: 4px 9px; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.dm-legend-item.dm-series-off { opacity: 0.38; text-decoration: line-through; background: transparent; }
.dm-legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

.dm-svg-wrap { display: block; width: 100%; height: 220px; min-height: 220px; touch-action: pan-y; }
.dm-tooltip {
  position: absolute; pointer-events: none; background: var(--dm-tooltip-bg); border: 1px solid var(--dm-border);
  border-radius: 10px; padding: 8px 12px; font-size: 12px; color: var(--dm-text); box-shadow: 0 8px 20px rgba(0,0,0,0.3);
  display: none; z-index: 10; white-space: nowrap;
}

.dm-modal { position: fixed; inset: 0; background: rgba(2, 6, 23, 0.8); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.dm-hidden { display: none !important; }
.dm-modal-card { width: 100%; max-width: 400px; background: var(--dm-card); border: 1px solid var(--dm-border); border-radius: 20px; padding: 20px; }
.dm-form { display: flex; flex-direction: column; gap: 12px; }
.dm-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--dm-muted); font-weight: 600; }
.dm-form input, .dm-form select { background: var(--dm-surface); border: 1px solid var(--dm-border); border-radius: 10px; padding: 10px 12px; color: var(--dm-text); font-size: 14px; }
.dm-login-msg { font-size: 12px; color: var(--dm-pv); min-height: 16px; }
.dm-form-actions { display: flex; gap: 10px; margin-top: 4px; }
.dm-btn-primary { flex: 1; background: var(--dm-export); color: #ffffff; border: none; border-radius: 12px; padding: 11px; font-weight: 700; font-size: 14px; cursor: pointer; }
.dm-btn-secondary { background: var(--dm-surface); color: var(--dm-text-secondary); border: 1px solid var(--dm-border); border-radius: 12px; padding: 11px 14px; font-weight: 600; font-size: 14px; cursor: pointer; }

/* Load Warnings & Daily Peak Stats Drawer */
.dm-drawer { position: fixed; inset: 0; background: rgba(2, 6, 23, 0.72); display: flex; justify-content: flex-end; z-index: 110; }
.dm-drawer-panel {
  width: 100%; max-width: 420px; height: 100%; background: var(--dm-card); border-left: 1px solid var(--dm-border);
  padding: 18px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto;
}
.dm-warn-summary { display: flex; gap: 8px; flex-wrap: wrap; }
.dm-level-pill {
  font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--dm-border);
}
.dm-level-pill.simple { background: rgba(245, 158, 11, 0.14); border-color: #f59e0b; color: #f59e0b; }
.dm-level-pill.medium { background: rgba(249, 115, 22, 0.18); border-color: #f97316; color: #f97316; }
.dm-level-pill.severe { background: rgba(239, 68, 68, 0.2); border-color: #ef4444; color: #ef4444; }
.dm-warn-list { display: flex; flex-direction: column; gap: 8px; }
.dm-warn-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--dm-surface-soft); border: 1px solid var(--dm-border-soft); border-radius: 12px; padding: 10px 12px;
}
.dm-warn-time { font-size: 12px; color: var(--dm-text-secondary); }
.dm-warn-watts { font-size: 14px; font-weight: 700; color: var(--dm-text); }
.dm-warn-empty { font-size: 13px; color: var(--dm-muted); padding: 14px 0; text-align: center; }
