:root {
    --sidebar-w: 240px;
    --topbar-h: 60px;
    --bg: #0f1117;
    --sidebar-bg: #13151c;
    --sidebar-border: #1e2130;
    --surface: #1a1d27;
    --surface-2: #21253a;
    --border: #252840;
    --accent: #3b7fff;
    --accent-light: #5a9aff;
    --accent-glow: rgba(59, 127, 255, 0.15);
    --green: #22c55e;
    --yellow: #f59e0b;
    --red: #ef4444;
    --orange: #f97316;
    --text: #e2e8f0;
    --text-muted: #64748b;
    --text-dim: #94a3b8;
    --font: 'Inter', system-ui, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

/* ── App Layout ── */
.app-wrapper { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform 0.25s ease;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--sidebar-border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 18px;
    flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: 15px; color: var(--text); }
.brand-sub { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 12px 8px 4px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 400;
    transition: all 0.15s;
    margin-bottom: 1px;
}
.nav-item i { font-size: 16px; width: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--accent-glow); color: var(--accent-light); font-weight: 500; }
.nav-item.active i { color: var(--accent); }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--sidebar-border);
}
.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.user-avatar {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; color: #fff;
    flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-muted); }
.logout-btn { color: var(--text-muted); text-decoration: none; font-size: 16px; }
.logout-btn:hover { color: var(--red); }

/* ── Main Area ── */
.main-area {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.25s ease;
}

/* ── Topbar ── */
.topbar {
    height: var(--topbar-h);
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}
.sidebar-toggle:hover { color: var(--text); }
.topbar-breadcrumb { flex: 1; font-size: 13px; color: var(--text-dim); }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.status-indicator { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 2px rgba(34,197,94,0.25); }
.topbar-time { font-family: var(--mono); font-size: 12px; color: var(--text-muted); }

/* ── Flash messages ── */
.flash-container { padding: 0 24px; padding-top: 12px; }
.message { border-radius: var(--radius-sm); font-size: 13.5px; }

/* ── Page Content ── */
.page-content { padding: 24px; flex: 1; }

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: none;
    color: var(--text);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-body { padding: 20px; }

/* ── Stat Cards ── */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: border-color 0.2s;
}
.stat-card:hover { border-color: var(--accent); }
.stat-icon {
    width: 46px; height: 46px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.stat-icon.blue { background: var(--accent-glow); color: var(--accent); }
.stat-icon.green { background: rgba(34,197,94,0.12); color: var(--green); }
.stat-icon.yellow { background: rgba(245,158,11,0.12); color: var(--yellow); }
.stat-icon.red { background: rgba(239,68,68,0.12); color: var(--red); }
.stat-icon.orange { background: rgba(249,115,22,0.12); color: var(--orange); }
.stat-icon.purple { background: rgba(99,102,241,0.12); color: #818cf8; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.1; color: var(--text); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 3px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.4px; }

/* ── Tables ── */
.table {
    color: var(--text);
    border-color: var(--border);
    margin-bottom: 0;
}
.table thead th {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 16px;
    white-space: nowrap;
}
.table tbody td {
    padding: 13px 16px;
    border-color: var(--border);
    vertical-align: middle;
    font-size: 13.5px;
}
.table tbody tr:hover td { background: var(--surface-2); }
.table-responsive { border-radius: var(--radius); overflow: hidden; }

/* ── Badges ── */
.badge { font-size: 11px; font-weight: 500; padding: 4px 8px; border-radius: 5px; }

/* ── Barcode display ── */
.barcode-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
    color: var(--accent-light);
    background: var(--accent-glow);
    border: 1px solid rgba(59,127,255,0.2);
    padding: 3px 10px;
    border-radius: 5px;
}
.barcode-chip i { font-size: 12px; }

/* ── Buttons ── */
.btn { font-size: 13px; font-weight: 500; border-radius: var(--radius-sm); padding: 7px 16px; border: 1px solid transparent; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); border-color: var(--accent-light); color: #fff; }
.btn-outline-secondary { border-color: var(--border); color: var(--text-dim); background: transparent; }
.btn-outline-secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); }

/* ── Forms ── */
.form-label { font-size: 13px; font-weight: 500; color: var(--text-dim); margin-bottom: 6px; }
.form-control, .form-select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    padding: 8px 12px;
}
.form-control:focus, .form-select:focus {
    background: var(--surface-2);
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-control::placeholder { color: var(--text-muted); }
.form-select option { background: var(--surface-2); }
.form-text { font-size: 12px; color: var(--text-muted); }
.invalid-feedback { font-size: 12px; }

/* ── Detail Cards ── */
.detail-row { display: flex; padding: 10px 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-label { width: 160px; flex-shrink: 0; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); padding-top: 2px; }
.detail-value { flex: 1; font-size: 13.5px; color: var(--text); }

/* ── Alert indicators ── */
.alert-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.alert-dot.red { background: var(--red); }
.alert-dot.yellow { background: var(--yellow); }
.alert-dot.green { background: var(--green); }

/* ── Status badges ── */
.badge-active { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-inactive { background: rgba(100,116,139,0.2); color: var(--text-muted); }
.badge-suspended { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-faulty { background: rgba(249,115,22,0.15); color: var(--orange); }
.badge-pending { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge-confirmed { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-failed { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-sent { background: rgba(59,127,255,0.15); color: var(--accent); }
.badge-acked { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-timeout { background: rgba(249,115,22,0.15); color: var(--orange); }
.badge-applied { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-open { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-closed { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-online { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-offline { background: rgba(100,116,139,0.2); color: var(--text-muted); }

/* ── Meter alert bar ── */
.meter-alerts { display: flex; gap: 6px; flex-wrap: wrap; }
.alert-badge {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 7px;
    border-radius: 4px;
}
.alert-badge.low-battery { background: rgba(245,158,11,0.15); color: var(--yellow); }
.alert-badge.tamper { background: rgba(239,68,68,0.15); color: var(--red); }
.alert-badge.leak { background: rgba(249,115,22,0.15); color: var(--orange); }
.alert-badge.fault { background: rgba(239,68,68,0.2); color: var(--red); }

/* ── JSON display ── */
.json-display {
    background: #0d0f18;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: var(--mono);
    font-size: 12px;
    color: #94d1f3;
    overflow-x: auto;
    white-space: pre;
    max-height: 300px;
    overflow-y: auto;
}

/* ── Reconciliation ── */
.recon-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
}
.recon-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.variance-bar {
    height: 6px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}
.variance-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}
.variance-ok .variance-fill { background: var(--green); }
.variance-warning .variance-fill { background: var(--yellow); }
.variance-critical .variance-fill { background: var(--red); }

/* ── Signal strength ── */
.signal-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.signal-bar { width: 3px; border-radius: 1px; background: var(--border); }
.signal-bar.active { background: var(--green); }
.signal-bar:nth-child(1) { height: 4px; }
.signal-bar:nth-child(2) { height: 7px; }
.signal-bar:nth-child(3) { height: 10px; }
.signal-bar:nth-child(4) { height: 14px; }

/* ── Pagination ── */
.pagination { gap: 4px; }
.page-link { background: var(--surface); border-color: var(--border); color: var(--text-dim); border-radius: var(--radius-sm) !important; font-size: 13px; padding: 6px 12px; }
.page-link:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.page-item.active .page-link { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-item.disabled .page-link { background: var(--surface); color: var(--text-muted); }

/* ── Login ── */
.login-body { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-bg {
    position: fixed; inset: 0;
    background: radial-gradient(ellipse at 30% 20%, rgba(59,127,255,0.08) 0%, transparent 60%),
                radial-gradient(ellipse at 80% 80%, rgba(99,102,241,0.06) 0%, transparent 50%);
}
.login-content { position: relative; z-index: 1; width: 100%; max-width: 400px; padding: 24px; }
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 40px;
    box-shadow: var(--shadow);
}
.login-logo {
    width: 52px; height: 52px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; color: #fff;
    margin: 0 auto 20px;
}
.login-title { text-align: center; font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-sub { text-align: center; font-size: 13px; color: var(--text-muted); margin-bottom: 28px; }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state i { font-size: 40px; display: block; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ── Balance display ── */
.balance-display {
    font-family: var(--mono);
    font-size: 24px;
    font-weight: 700;
    color: var(--green);
}
.balance-display.low { color: var(--red); }
.balance-display.medium { color: var(--yellow); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
    .sidebar.show { transform: translateX(0); }
    .main-area { margin-left: 0; }
    .page-content { padding: 16px; }
    .stat-value { font-size: 22px; }
}
