:root {
  --bg: #0a0e14;
  --bg-glow: #12233a;
  --surface: #111821;
  --surface-2: #171f2b;
  --sunken: #0c121a;
  --line: #1f2a38;
  --line-strong: #2b394b;
  --text: #e8eef6;
  --muted: #8796ab;
  --faint: #5d6b7f;

  --green: #34d399;
  --green-strong: #22c55e;
  --green-ink: #052e1a;
  --green-soft: rgba(52, 211, 153, 0.12);
  --blue: #60a5fa;
  --blue-soft: rgba(96, 165, 250, 0.12);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.14);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  --focus: 0 0 0 3px rgba(96, 165, 250, 0.45);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-glow: #e3ecf8;
    --surface: #ffffff;
    --surface-2: #f6f8fb;
    --sunken: #eef2f7;
    --line: #e3e8ef;
    --line-strong: #d3dae4;
    --text: #0f1720;
    --muted: #5b6878;
    --faint: #8a96a6;
    --green: #059669;
    --green-strong: #10b981;
    --green-ink: #ffffff;
    --green-soft: rgba(16, 185, 129, 0.1);
    --blue: #2563eb;
    --blue-soft: rgba(37, 99, 235, 0.08);
    --amber: #d97706;
    --amber-soft: rgba(217, 119, 6, 0.1);
    --red: #dc2626;
    --red-soft: rgba(220, 38, 38, 0.08);
    --shadow: 0 1px 2px rgba(15, 23, 32, 0.04), 0 8px 24px -12px rgba(15, 23, 32, 0.12);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1100px 520px at 80% -120px, var(--bg-glow), transparent 70%), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 0;
}
button, input { font: inherit; color: inherit; }
svg { display: block; }
.sprite { position: absolute; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.sm { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.visually-hidden { position: absolute !important; left: 0; top: 0; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; border: 0 !important; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.ic { width: 18px; height: 18px; flex: none; }
.ic.sm { width: 14px; height: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; border: 1px solid var(--line-strong); background: var(--surface-2);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, opacity 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--faint); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible, .icon-btn:focus-visible, .mode:focus-within, .seg-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn.primary {
  background: linear-gradient(180deg, var(--green), var(--green-strong));
  color: var(--green-ink); border-color: transparent;
  box-shadow: 0 6px 18px -8px rgba(34, 197, 94, 0.7);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.danger { color: var(--red); }
.btn.danger:hover:not(:disabled) { border-color: var(--red); background: var(--red-soft); }
.btn.link { background: none; border: none; color: var(--muted); padding: 6px; font-weight: 500; }
.btn.link:hover { color: var(--text); }
.btn.block { width: 100%; }
.btn.lg { padding: 14px 18px; font-size: 15px; border-radius: 14px; }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--text) transparent var(--text) transparent;
  animation: spin 0.7s linear infinite;
}
.btn.primary.busy::after { border-color: var(--green-ink) transparent var(--green-ink) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.sm { width: 30px; height: 30px; border: none; background: transparent; }
.icon-btn.sm svg { width: 15px; height: 15px; }

input[type="password"], input[type="text"], input[type="time"], input[type="number"] {
  background: var(--sunken); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font-size: 15px; transition: border-color 0.15s, box-shadow 0.15s;
  color-scheme: dark light;
}
input:focus { outline: none; border-color: var(--blue); box-shadow: var(--focus); }

/* ---------- Login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px;
  padding: 36px 28px 24px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
  animation: rise 0.35s ease-out;
}
.login-mark {
  width: 64px; height: 64px; margin: 0 auto 4px; border-radius: 20px; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 25%, rgba(52, 211, 153, 0.35), var(--green-soft));
  color: var(--green); border: 1px solid rgba(52, 211, 153, 0.25);
  box-shadow: 0 0 40px -6px rgba(52, 211, 153, 0.45);
}
.login-mark svg { width: 32px; height: 32px; }
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.login-card > p { margin: 0; }
.pw-form { position: relative; display: flex; flex-direction: column; gap: 10px; }
.pw-form input { width: 100%; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.login-err { margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--red-soft); color: var(--red); font-size: 14px; }
.fine { display: flex; gap: 6px; align-items: center; justify-content: center; font-size: 12.5px; margin: 6px 0 0 !important; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- App shell ---------- */
.app { max-width: 1040px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 48px; animation: rise 0.3s ease-out; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 2px 18px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: var(--green-soft); color: var(--green); border: 1px solid rgba(52, 211, 153, 0.22);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 12.5px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.chip {
  font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px;
  padding: 7px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
}

.nudge {
  display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 16px; margin-bottom: 16px;
  border-radius: var(--radius-sm); background: var(--blue-soft); border: 1px solid rgba(96, 165, 250, 0.25);
  font-size: 14px; color: var(--text);
}
.nudge > .ic { color: var(--blue); }
.nudge > div { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.card h3 { margin: 18px 0 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.card h3:first-of-type { margin-top: 6px; }
.card p { margin: 0 0 14px; }
.eyebrow { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); margin-bottom: 2px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid > .card { margin-bottom: 0; }
.grid { margin-bottom: 16px; }

/* ---------- Hero ---------- */
.hero { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 20px 24px; align-items: center; padding: 22px 22px 18px; }
.hero-status { display: flex; align-items: center; gap: 16px; min-width: 0; }
.orb {
  position: relative; width: 60px; height: 60px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--line-strong);
}
.orb svg { width: 26px; height: 26px; position: relative; z-index: 1; }
.orb.idle { color: var(--blue); background: var(--blue-soft); border-color: rgba(96, 165, 250, 0.3); }
.orb.charging { color: var(--green); background: var(--green-soft); border-color: rgba(52, 211, 153, 0.4); }
.orb.charging::before, .orb.charging::after {
  content: ""; position: absolute; inset: -1px; border-radius: 50%; border: 2px solid var(--green);
  animation: ripple 2.2s ease-out infinite; opacity: 0;
}
.orb.charging::after { animation-delay: 1.1s; }
@keyframes ripple { 0% { transform: scale(1); opacity: 0.55; } 100% { transform: scale(1.7); opacity: 0; } }
.status-text { font-size: 26px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.15; }
#status-sub { font-size: 13.5px; }

.hero-rate { min-width: 0; }
.rate { display: flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; }
#rate { font-size: 26px; font-weight: 750; letter-spacing: -0.02em; }
.rate-unit { color: var(--muted); font-size: 14px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 650; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.off { color: var(--green); background: var(--green-soft); border-color: transparent; }
.badge.peak { color: var(--amber); background: var(--amber-soft); border-color: transparent; }
.hero-actions { display: flex; flex-direction: column; gap: 8px; }

.timeline-wrap { grid-column: 1 / -1; padding-top: 4px; }
.timeline { position: relative; height: 14px; border-radius: 999px; background: var(--sunken); overflow: visible; }
.tl-ranges { position: absolute; inset: 0; border-radius: 999px; overflow: hidden; }
.tl-seg { position: absolute; top: 0; bottom: 0; }
.tl-seg.off { background: linear-gradient(180deg, rgba(52, 211, 153, 0.55), rgba(52, 211, 153, 0.35)); }
.tl-seg.peak { background: linear-gradient(180deg, rgba(251, 191, 36, 0.5), rgba(251, 191, 36, 0.3)); }
.tl-window { position: absolute; top: -4px; bottom: -4px; border: 2px dashed var(--blue); border-radius: 8px; pointer-events: none; }
.tl-now { position: absolute; top: -7px; bottom: -7px; width: 2px; margin-left: -1px; background: var(--text); border-radius: 2px; }
.tl-now span {
  position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--text); color: var(--bg); padding: 1px 6px; border-radius: 6px; white-space: nowrap;
}
.tl-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: 6px; font-variant-numeric: tabular-nums; }
.tl-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; margin-top: 8px; align-items: center; }
.tl-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.off { background: rgba(52, 211, 153, 0.6); }
.sw.peak { background: rgba(251, 191, 36, 0.6); }
.sw.win { border: 2px dashed var(--blue); }
.tl-next { margin-left: auto; color: var(--text); font-weight: 550; }

/* ---------- Automation ---------- */
.pill { font-size: 12px; font-weight: 650; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.pill.on { background: var(--green-soft); color: var(--green); border-color: transparent; }
.modes { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 16px; }
.mode {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
}
.mode:hover { border-color: var(--line-strong); }
.mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); transition: 0.15s; }
.mode-ic svg { width: 18px; height: 18px; }
.mode-txt { display: flex; flex-direction: column; min-width: 0; }
.mode-txt b { font-size: 14.5px; font-weight: 650; }
.mode-txt small { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.mode:has(input:checked) { border-color: var(--green); background: var(--green-soft); }
.mode:has(input:checked) .mode-ic { background: var(--green); color: var(--green-ink); }
.fields { display: grid; gap: 12px; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 400; }
.field input[type="time"] { width: 120px; }
.field input[type="number"] { width: 76px; }
.save-row { display: flex; gap: 8px; }

/* ---------- Usage ---------- */
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--sunken); border: 1px solid var(--line); }
.seg-btn { border: none; background: transparent; padding: 4px 10px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 18px; }
.kpi { padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); min-width: 0; }
.kpi-label { font-size: 11.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }
.kpi-num { font-size: 21px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.kpi-num small { font-size: 12px; color: var(--muted); font-weight: 600; margin-left: 2px; }
.kpi-sub { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 20px; }
.col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; gap: 6px; min-width: 0; }
.col-bar {
  position: relative; border-radius: 6px 6px 3px 3px; min-height: 3px;
  background: linear-gradient(180deg, var(--blue), rgba(96, 165, 250, 0.45));
  transition: height 0.45s cubic-bezier(.2, .8, .2, 1), filter 0.15s;
}
.col:last-child .col-bar { background: linear-gradient(180deg, var(--green), rgba(52, 211, 153, 0.45)); }
.col-bar b {
  position: absolute; bottom: calc(100% + 3px); left: 50%; transform: translateX(-50%);
  font-size: 10.5px; font-weight: 650; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.col:hover .col-bar { filter: brightness(1.15); }
.col:hover .col-bar b { color: var(--text); }
.col-label { text-align: center; font-size: 11px; color: var(--faint); }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 18px 0; width: 100%; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--faint); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover td { background: var(--surface-2); }
.tx-date b { font-weight: 600; }
.tx-date span { color: var(--faint); margin-left: 6px; font-size: 12.5px; }
.tag { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 650; padding: 1px 7px; border-radius: 999px; background: var(--green-soft); color: var(--green); }
.price.cheap { color: var(--green); }
.price.pricey { color: var(--amber); }
#tx-more { margin-top: 10px; }

/* ---------- Activity / rows ---------- */
.log { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.log li { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.log li:last-child { border-bottom: none; }
.log-ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; margin-top: 1px; }
.log-ic svg { width: 12px; height: 12px; }
.log-ic.ok { background: var(--green-soft); color: var(--green); }
.log-ic.bad { background: var(--red-soft); color: var(--red); }
.log-msg { min-width: 0; }
.log-msg b { font-weight: 600; }
.log-msg small { display: block; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.log time { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.rows { list-style: none; margin: 0 0 12px; padding: 0; }
.rows li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.rows li:last-child { border-bottom: none; }
.rows .row-ic { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); flex: none; }
.rows .row-ic svg { width: 16px; height: 16px; }
.rows .row-main { flex: 1; min-width: 0; }
.rows .row-main b { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .row-main small { color: var(--muted); font-size: 12.5px; }
.rows .here { color: var(--green); font-weight: 650; }
.rows .empty-row { color: var(--muted); font-size: 13.5px; }

.foot { text-align: center; font-size: 12.5px; margin-top: 4px; }

/* ---------- Dialog & toasts ---------- */
.dialog {
  border: 1px solid var(--line); border-radius: 20px; padding: 22px; width: min(400px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.6);
}
.dialog::backdrop { background: rgba(5, 8, 12, 0.55); backdrop-filter: blur(4px); }
.dialog h3 { margin: 0 0 6px; font-size: 18px; }
.dialog p { margin: 0 0 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog[open] { animation: rise 0.2s ease-out; }

.toasts { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 550;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.5); animation: rise 0.2s ease-out;
}
.toast svg { width: 16px; height: 16px; flex: none; }
.toast.ok svg { color: var(--green-strong); }
.toast.bad { background: var(--red); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); transition: 0.25s; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr auto; }
  .hero-actions { grid-column: 1 / -1; flex-direction: row; }
  .hero-actions .btn { flex: 1; }
  .hero-rate { text-align: right; }
  .rate { justify-content: flex-end; }
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .hero { padding: 18px 16px 16px; gap: 16px; }
  .orb { width: 50px; height: 50px; }
  .status-text, #rate { font-size: 22px; }
  .kpi { padding: 10px; }
  .kpi-num { font-size: 17px; }
  .brand-sub, .tl-next { display: none; }
  .nudge { flex-wrap: wrap; }
  .nudge > div { flex-basis: calc(100% - 40px); }
  .nudge > .btn { margin-left: 30px; }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
