/* ─── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --bg: #f5f5f3;
    --surface: #ffffff;
    --border: rgba(0,0,0,0.10);
    --border-strong: rgba(0,0,0,0.20);
    --text: #1a1a18;
    --text-muted: #6b6b67;
    --accent: #1d9e75;
    --accent-light: #e1f5ee;
    --amber: #ba7517;
    --amber-light: #faeeda;
    --red: #a32d2d;
    --red-light: #fcebeb;
    --blue: #185fa5;
    --blue-light: #e6f1fb;
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-w: 220px;
    font-size: 15px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

/* ─── Layout ────────────────────────────────────────────────────── */
body { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--surface);
    border-right: 0.5px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 20px 16px;
    font-weight: 600;
    font-size: 16px;
    border-bottom: 0.5px solid var(--border);
}
.brand-icon { font-size: 20px; }

.nav-list { list-style: none; padding: 8px 0; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    border-radius: 0;
    transition: background 0.1s, color 0.1s;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { color: var(--accent); background: var(--accent-light); font-weight: 500; }
.nav-icon { font-size: 15px; width: 20px; text-align: center; }
.sidebar-section-label {
    padding: 16px 16px 4px;
    font-size: 11px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 500;
}

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 28px 12px;
    border-bottom: 0.5px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 50;
}
.page-title { font-size: 18px; font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

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

/* ─── Cards ─────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 500; }

/* ─── Metric tiles ──────────────────────────────────────────────── */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.metric-tile {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 14px 16px;
}
.metric-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.metric-value { font-size: 22px; font-weight: 500; }
.metric-unit { font-size: 13px; color: var(--text-muted); margin-left: 3px; }
.metric-tile.green .metric-value { color: var(--accent); }
.metric-tile.amber .metric-value { color: var(--amber); }
.metric-tile.red   .metric-value { color: var(--red); }
.metric-tile.blue  .metric-value { color: var(--blue); }

/* ─── Energy-lost hero ──────────────────────────────────────────── */
.dashboard-summary {
    display: grid;
    grid-template-columns: minmax(280px, 1.4fr) 2fr;
    gap: 16px;
    margin-bottom: 20px;
}
@media (max-width: 900px) {
    .dashboard-summary { grid-template-columns: 1fr; }
}

.energy-wasted-card {
    position: relative;
    background: linear-gradient(135deg, var(--surface) 0%, var(--red-light) 100%);
    border: 0.5px solid rgba(163, 45, 45, 0.20);
    border-radius: var(--radius-lg);
    padding: 24px 28px;
    overflow: hidden;
    transition: box-shadow 0.6s ease, transform 0.3s ease, border-color 0.4s ease;
}
.energy-wasted-card.losing {
    background: linear-gradient(135deg, var(--red-light) 0%, #fbd7d7 100%);
    border-color: rgba(163, 45, 45, 0.45);
    box-shadow: 0 0 0 0 rgba(163, 45, 45, 0.0);
    animation: lossGlow 2.2s ease-in-out infinite;
}
.energy-wasted-card.safe {
    background: linear-gradient(135deg, var(--surface) 0%, var(--accent-light) 100%);
    border-color: rgba(29, 158, 117, 0.30);
}

@keyframes lossGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(163, 45, 45, 0.0); }
    50%      { box-shadow: 0 0 36px 8px rgba(163, 45, 45, 0.25); }
}

.tenant-tz {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg);
    border: 0.5px solid var(--border);
    padding: 3px 9px;
    border-radius: 99px;
    margin-left: 10px;
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
    user-select: none;
}

.loss-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--red);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 3px 8px;
    border-radius: 99px;
    margin-left: auto;
    animation: badgePulse 1.6s ease-in-out infinite;
}
@keyframes badgePulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.65; }
}

.energy-wasted-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.energy-wasted-icon {
    font-size: 32px;
    line-height: 1;
    transform-origin: center;
    display: inline-block;
}
.energy-wasted-card.losing .energy-wasted-icon {
    animation: iconBob 1.6s ease-in-out infinite;
}
@keyframes iconBob {
    0%, 100% { transform: translateY(0) rotate(0); }
    25%      { transform: translateY(-4px) rotate(-8deg); }
    75%      { transform: translateY(-4px) rotate(8deg); }
}
.energy-wasted-label {
    font-size: 13px;
    font-weight: 500;
    letter-spacing: .04em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.energy-wasted-value {
    font-size: 56px;
    font-weight: 600;
    line-height: 1;
    color: var(--red);
    margin: 4px 0 14px;
    font-variant-numeric: tabular-nums;
    transition: color 0.4s ease, opacity 0.25s ease;
}
.energy-wasted-card.safe .energy-wasted-value { color: var(--accent); }
.energy-wasted-value.flash { animation: numFlash 0.7s ease-out; }

/* Three-column hero (Live / Month / Year) */
.energy-wasted-cols {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 6px 0 14px;
}
@media (max-width: 720px) {
    .energy-wasted-cols { grid-template-columns: 1fr; gap: 14px; }
}
.wasted-col {
    border-left: 0.5px solid var(--border);
    padding: 2px 0 2px 14px;
    min-width: 0;
}
.wasted-col:first-child { border-left: 0; padding-left: 0; }
.wasted-col-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}
.wasted-col-val {
    font-size: 32px;
    font-weight: 600;
    line-height: 1;
    color: var(--red);
    font-variant-numeric: tabular-nums;
    transition: opacity 0.25s ease;
}
.energy-wasted-card.safe .wasted-col-val { color: var(--accent); }
.wasted-col-val.flash { animation: numFlash 0.7s ease-out; }

/* Loss percentage chip — small red pill shown next to each number */
.loss-percent {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 99px;
    background: rgba(163, 45, 45, 0.10);
    color: var(--red);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .02em;
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
    transition: background 0.4s ease, color 0.4s ease;
}
.energy-wasted-card.safe .loss-percent {
    background: rgba(29, 158, 117, 0.10);
    color: var(--accent);
}
.wasted-col-unit {
    font-size: 13px;
    color: var(--text-muted);
    margin-left: 4px;
    font-weight: 400;
}
.wasted-col-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    line-height: 1.5;
}
.wasted-col-sub strong { color: var(--text); font-weight: 500; }
@keyframes numFlash {
    0%   { transform: scale(1.06); opacity: 0.6; }
    100% { transform: scale(1);    opacity: 1;   }
}
.energy-wasted-unit { font-size: 22px; color: var(--text-muted); margin-left: 6px; font-weight: 400; }

.energy-wasted-formula {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    line-height: 1.4;
}
.energy-wasted-formula .op { opacity: 0.5; margin: 0 2px; }

/* ─── Data points card ──────────────────────────────────────────── */
.data-points-card {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
}
.data-points-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-weight: 500;
}
.data-points-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 16px;
}
@media (min-width: 1200px) {
    .data-points-grid { grid-template-columns: repeat(3, 1fr); }
}
.data-point {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 0.5px dashed var(--border);
}
.data-point:nth-last-child(-n+2) { border-bottom: 0; } /* last row clean */
.dp-icon { font-size: 18px; line-height: 1; flex: 0 0 24px; text-align: center; }
.dp-body { flex: 1; min-width: 0; }
.dp-label { font-size: 11px; color: var(--text-muted); margin-bottom: 1px; }
.dp-value { font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.dp-value .dp-unit { font-size: 11px; color: var(--text-muted); margin-left: 3px; font-weight: 400; }
.dp-value.flash { animation: numFlash 0.7s ease-out; }

/* ─── Energy chart ──────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 180px; }
canvas { width: 100% !important; }

/* ─── Appliance grid ────────────────────────────────────────────── */
.appliance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.appliance-card {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.appliance-card.running { border-color: var(--accent); background: var(--accent-light); }
.appliance-card.charging { border-color: var(--blue); background: var(--blue-light); }
.appliance-card.error { border-color: var(--red); background: var(--red-light); }
.appliance-name { font-weight: 500; font-size: 14px; }
.appliance-type { font-size: 12px; color: var(--text-muted); }
.appliance-status { font-size: 12px; }
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}
.badge-green { background: var(--accent-light); color: var(--accent); }
.badge-amber { background: var(--amber-light); color: var(--amber); }
.badge-red   { background: var(--red-light);   color: var(--red); }
.badge-blue  { background: var(--blue-light);  color: var(--blue); }
.badge-gray  { background: var(--bg);          color: var(--text-muted); }

/* ─── Tables ────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 500; color: var(--text-muted); border-bottom: 0.5px solid var(--border); background: var(--bg); }
td { padding: 10px 12px; border-bottom: 0.5px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* ─── Forms ─────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.single { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 500; color: var(--text-muted); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], select, textarea {
    padding: 9px 11px;
    border: 0.5px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    width: 100%;
    transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(29,158,117,0.12);
}
input[type=range] { width: 100%; accent-color: var(--accent); }
.form-hint { font-size: 12px; color: var(--text-muted); }
.form-actions { display: flex; gap: 10px; padding-top: 8px; }

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px;
    border: 0.5px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #0f6e56; }
.btn-danger  { background: var(--red-light); color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: #f7c1c1; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-icon { padding: 6px 8px; }

/* ─── Alerts ────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 14px; margin-bottom: 16px; }
.alert-success { background: var(--accent-light); color: var(--accent); border: 0.5px solid var(--accent); }
.alert-error   { background: var(--red-light); color: var(--red); border: 0.5px solid var(--red); }
.alert-warning { background: var(--amber-light); color: var(--amber); border: 0.5px solid var(--amber); }

/* ─── Mode selector ─────────────────────────────────────────────── */
.mode-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.mode-pill {
    padding: 6px 14px;
    border: 0.5px solid var(--border-strong);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    background: var(--surface);
    transition: all 0.12s;
}
.mode-pill.selected { background: var(--accent); color: #fff; border-color: var(--accent); }
.mode-pill input[type=radio] { display: none; }

/* ─── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
}
.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 400px; max-width: 95vw;
    border: 0.5px solid var(--border);
    overflow: hidden;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 0.5px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 500; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px; }
.modal-body a { display: block; padding: 10px 12px; border-radius: var(--radius); text-decoration: none; color: var(--text); font-size: 14px; }
.modal-body a:hover { background: var(--bg); }

/* ─── Toggle switch ─────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle {
    position: relative; width: 36px; height: 20px;
    display: inline-block;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--border-strong);
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
}
.toggle-slider::after {
    content: ''; position: absolute;
    width: 14px; height: 14px; border-radius: 50%;
    background: #fff; top: 3px; left: 3px;
    transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::after { transform: translateX(16px); }

/* ─── Section divider ───────────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title { font-size: 15px; font-weight: 500; }

/* ─── Connection mode selector ──────────────────────────────────── */
.mode-card {
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.12s;
}
.mode-card.selected { border-color: var(--accent); background: var(--accent-light); }
.mode-card-title { font-size: 14px; font-weight: 500; }
.mode-card-desc { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* ─── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
    :root { --sidebar-w: 0px; }
    .sidebar { transform: translateX(-220px); transition: transform 0.2s; }
    .sidebar.open { transform: translateX(0); width: 220px; }
    .main-content { margin-left: 0; }
    .form-grid { grid-template-columns: 1fr; }
}
