:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --bg-2: #11151d;
  --bg-3: #1a2030;
  --border: #232a3a;
  --text: #d9e0ee;
  --text-dim: #8a93a8;
  --accent: #4aa3ff;
  --brand: #f97316;
  --ok: #3ecf8e;
  --warn: #f5c542;
  --err: #f26d6d;
  --charging: #3ecf8e;
  --preparing: #f5c542;
  --available: #6e7791;
  --suspended: #f5a742;
  --faulted: #f26d6d;
  --unavailable: #3d4356;
}
* { box-sizing: border-box; }
html, body, #root { margin: 0; padding: 0; height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, select {
  font-family: inherit; font-size: 0.9rem;
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: #0b0e14; border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--err); border-color: var(--err); }
label { display: block; font-size: 0.8rem; color: var(--text-dim); margin: 8px 0 4px; }
input[type="checkbox"] { transform: scale(1.1); }
h1, h2, h3 { margin: 0; }
a { color: var(--accent); }

.app { display: grid; grid-template-rows: auto 1fr; height: 100%; }
.topbar { display: flex; align-items: center; gap: 24px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--bg-2); }
.topbar h1 { font-size: 1.05rem; letter-spacing: 0.02em; }
.topbar h1 .brand-erg { color: var(--brand); }
.topbar .totals { display: flex; gap: 24px; font-size: 0.9rem; color: var(--text-dim); }
.topbar .totals b { color: var(--text); font-size: 1.05rem; margin-right: 6px; }
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 10px; }

/* columns are set inline (charger area | resizer | log panel) so the log can be dragged/collapsed */
.main { display: grid; grid-template-columns: 1fr 5px 320px; overflow: hidden; }
.chargers { padding: 16px; overflow: auto; }
.sidebar { border-left: 1px solid var(--border); background: var(--bg-2); display: flex; flex-direction: column; overflow: hidden; }

.resizer { cursor: col-resize; background: var(--border); transition: background 0.12s; }
.resizer:hover { background: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing .resizer { background: var(--accent); }

.sidebar.collapsed .head { padding: 10px 0; justify-content: center; }
.sidebar .head button.collapse { padding: 2px 7px; font-size: 0.8rem; line-height: 1; color: var(--text-dim); }
.sidebar .rail-label { flex: 1; display: flex; justify-content: center; padding-top: 12px; writing-mode: vertical-rl; letter-spacing: 0.14em; font-size: 0.7rem; color: var(--text-dim); user-select: none; }
.sidebar .logs { overflow: auto; padding: 8px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.75rem; line-height: 1.5; }
.sidebar .logs .row { display: grid; grid-template-columns: 60px 40px 90px 1fr; gap: 6px; padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,0.03); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .logs .row.in { color: #a2c4ff; }
.sidebar .logs .row.out { color: #b1e6c4; }
.sidebar .logs .row.sys { color: var(--text-dim); }
.sidebar .logs .row .detail { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; }
.sidebar .head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 14px; }

.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card .head { display: flex; align-items: center; gap: 10px; }
.card .head h2 { font-size: 1rem; }
.card .head .id { font-family: ui-monospace, monospace; color: var(--text-dim); font-size: 0.8rem; }
.card .head .spacer { flex: 1; }
.card .head button { padding: 4px 8px; font-size: 0.75rem; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--available); }
.dot.connected { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.connecting { background: var(--warn); }
.dot.disconnected { background: var(--faulted); }

.stat { display: flex; gap: 4px; align-items: baseline; }
.stat b { font-size: 1.1rem; }
.stat .u { color: var(--text-dim); font-size: 0.8rem; }
.stat-row { display: flex; justify-content: space-between; gap: 16px; font-size: 0.85rem; color: var(--text-dim); }

.pill { padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; background: var(--unavailable); color: var(--text); }
.pill.Available { background: var(--available); }
.pill.Preparing { background: var(--preparing); color: #2a1f00; }
.pill.Charging { background: var(--charging); color: #062d19; }
.pill.SuspendedEV, .pill.SuspendedEVSE { background: var(--suspended); color: #241100; }
.pill.Finishing { background: var(--preparing); color: #2a1f00; }
.pill.Reserved { background: var(--accent); color: #0b0e14; }
.pill.Unavailable { background: var(--unavailable); color: var(--text-dim); }
.pill.Faulted { background: var(--faulted); }

.connector { background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.connector .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.connector .metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; font-size: 0.78rem; color: var(--text-dim); }
.connector .metrics b { color: var(--text); font-size: 0.95rem; display: block; }
.connector .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.connector .actions button { padding: 4px 8px; font-size: 0.75rem; }

.bar { height: 6px; background: var(--bg-3); border-radius: 4px; overflow: hidden; margin-top: 2px; }
.bar .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--charging)); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 10; }
.modal { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: min(440px, 90vw); max-height: 90vh; overflow: auto; }
.modal h3 { margin-bottom: 10px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal .full { grid-column: span 2; }
.modal input, .modal select { width: 100%; }

.error-toast { position: fixed; bottom: 20px; right: 20px; background: var(--faulted); color: white; padding: 10px 14px; border-radius: 8px; z-index: 20; box-shadow: 0 4px 12px rgba(0,0,0,0.4); }

.center-msg { display: grid; place-items: center; height: 100%; text-align: center; padding: 40px; }
.center-msg .box { max-width: 480px; }
.center-msg h1 { margin-bottom: 10px; }
.center-msg p { color: var(--text-dim); line-height: 1.6; }
.center-msg pre { background: var(--bg-2); border: 1px solid var(--border); padding: 12px; border-radius: 8px; text-align: left; font-size: 0.85rem; overflow: auto; }

.load-panel { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.load-head { display: flex; align-items: center; gap: 12px; }
.load-head .title { font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.load-head .spacer { flex: 1; }
.load-head .now { font-size: 0.85rem; color: var(--text-dim); }
.load-head .now b { color: var(--text); font-size: 1rem; }
.load-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 0.78rem; color: var(--text-dim); }
.load-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.load-plot { position: relative; margin-top: 8px; }
.load-plot svg { display: block; width: 100%; height: 220px; }
.load-plot .grid-line { stroke: var(--border); stroke-width: 1; }
.load-plot .axis-line { stroke: #333c52; stroke-width: 1; }
.load-plot .band-gap { fill: none; stroke: var(--bg-2); stroke-width: 2; }
.load-plot .tick { fill: var(--text-dim); font-size: 10px; }
.load-plot .crosshair { stroke: var(--text-dim); stroke-width: 1; }
.load-empty { height: 220px; display: grid; place-items: center; color: var(--text-dim); font-size: 0.85rem; }
.load-tooltip { position: absolute; top: 10px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.78rem; pointer-events: none; min-width: 150px; box-shadow: 0 4px 12px rgba(0,0,0,0.4); z-index: 5; }
.load-tooltip .t { color: var(--text-dim); margin-bottom: 4px; }
.load-tooltip > div:not(.t) { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.load-tooltip i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.load-tooltip span { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.load-tooltip b { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }
.load-tooltip .total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }

.profile-chart { background: var(--bg-3); border-radius: 8px; padding: 8px; }
.profile-chart svg { display: block; width: 100%; height: 120px; }
.profile-chart .axis text { fill: var(--text-dim); font-size: 10px; }
.profile-chart .line { stroke: var(--accent); stroke-width: 2; fill: none; }
.profile-chart .area { fill: rgba(74, 163, 255, 0.15); }
