/* ── Portal Base ──────────────────────────────────────────────────────────── */

:root {
    --bg-base:       #0b1527;
    --bg-card:       #0f1e35;
    --bg-card-hover: #132240;
    --bg-input:      #0d1929;
    --border:        rgba(255,255,255,0.10);
    --border-focus:  rgba(59,130,246,0.6);
    --text-primary:  #ffffff;
    --text-muted:    #b8c9da;
    --text-sub:      #dde6f0;
    --accent:        #3b82f6;
    --accent-hover:  #2563eb;
    --green:         #4ade80;
    --amber:         #fbbf24;
    --red:           #ef4444;
    --sidebar-w:     260px;
    --topbar-h:      64px;
    --radius:        12px;
    --radius-sm:     8px;
}

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

html, body {
    height: 100%;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    background: var(--bg-base);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.portal-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: #060f1e;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform .25s ease;
    overflow-y: auto;
}

.portal-main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin .25s ease;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.brand-icon { flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-size: 15px; font-weight: 700; color: #fff; letter-spacing: -.3px; }
.brand-sub  { font-size: 10px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid var(--border);
}

.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px; color: #fff;
    flex-shrink: 0;
}

.user-name  { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.user-email { font-size: 11px; color: #b8c9da; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-nav { list-style: none; padding: 12px 12px; flex: 1; }

.nav-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .8px;
    text-transform: uppercase;
    color: #7a90a8;
    padding: 12px 8px 6px;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-sub);
    font-weight: 500;
    transition: all .15s;
    position: relative;
}

.sidebar-nav li a i { font-size: 16px; }

.sidebar-nav li a:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

.sidebar-nav li a.active {
    background: rgba(59,130,246,0.12);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-nav li a.active::before {
    content: '';
    position: absolute;
    left: 0; top: 6px; bottom: 6px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
}

.sidebar-nav li a.disabled-link { opacity: .45; pointer-events: none; cursor: default; }

.badge-soon {
    margin-left: auto;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    background: rgba(251,191,36,.15);
    color: var(--amber);
    padding: 2px 6px;
    border-radius: 4px;
}

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.2);
    border-radius: var(--radius-sm);
    color: #f87171;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
}

.logout-btn:hover { background: rgba(239,68,68,0.15); color: #ef4444; }

/* ── Top Bar ─────────────────────────────────────────────────────────────── */

.portal-topbar {
    height: var(--topbar-h);
    background: #060f1e;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
}

.topbar-toggle:hover { background: rgba(255,255,255,0.05); }

.topbar-breadcrumb { font-size: 16px; font-weight: 600; color: var(--text-primary); flex: 1; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.topbar-user {
    display: flex;
    align-items: center;
    font-size: 13px;
    color: var(--text-sub);
}

/* ── Content ─────────────────────────────────────────────────────────────── */

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

.portal-footer {
    text-align: center;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12px;
}

/* ── Page Header ─────────────────────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title    { font-size: 22px; font-weight: 700; color: #fff; margin: 0; }
.page-subtitle { font-size: 13px; color: #b8c9da; margin: 4px 0 0; }

/* ── Cards ───────────────────────────────────────────────────────────────── */

.portal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color .15s;
}

.portal-card:hover { border-color: rgba(255,255,255,0.12); }

.card-header-custom {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 600;
    color: #f1f5f9;
    display: flex;
    align-items: center;
}

.card-body-custom { padding: 20px; }

.btn-card-link {
    font-size: 12px;
    color: var(--accent);
    font-weight: 500;
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-card-link:hover { color: var(--accent-hover); }

/* ── Stat Cards ──────────────────────────────────────────────────────────── */

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all .15s;
    height: 100%;
    min-height: 100px;
}

.stat-card:hover { border-color: rgba(255,255,255,0.15); transform: translateY(-1px); }

.stat-icon {
    width: 48px; height: 48px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.stat-body  { flex: 1; min-width: 0; }
.stat-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: #b8c9da; margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 700; color: #fff; line-height: 1; }
.stat-unit  { font-size: 14px; font-weight: 400; color: #b8c9da; }
.stat-sub   { font-size: 12px; color: #dde6f0; margin-top: 6px; }

/* ── Info List ───────────────────────────────────────────────────────────── */

.info-list { display: flex; flex-direction: column; gap: 14px; }

.info-row  {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.info-row:last-child { border-bottom: none; padding-bottom: 0; }

.info-key  { font-size: 12px; color: #b8c9da; font-weight: 600; }
.info-val  { font-size: 13px; color: #ffffff; font-weight: 500; max-width: 60%; text-align: right; }

/* ── Progress ────────────────────────────────────────────────────────────── */

.portal-progress {
    background: rgba(255,255,255,0.06);
    border-radius: 100px;
    overflow: hidden;
}

.device-mini-bar {
    height: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: 100px;
    overflow: hidden;
    margin-top: 8px;
}

.device-mini-fill { height: 100%; border-radius: 100px; transition: width .4s; }

/* ── Device Rows (dashboard) ─────────────────────────────────────────────── */

.device-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.device-row:last-child { border-bottom: none; }

.device-icon {
    width: 36px; height: 36px;
    background: rgba(59,130,246,0.1);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: var(--accent);
    font-size: 16px;
    flex-shrink: 0;
}

.device-name { font-size: 13px; font-weight: 600; color: #ffffff; }
.device-meta { font-size: 11px; color: #b8c9da; margin-top: 2px; }
.device-info { flex: 1; min-width: 0; }

.device-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 100px;
    flex-shrink: 0;
}

.device-badge.online  { background: rgba(74,222,128,.12); color: var(--green); }
.device-badge.offline { background: rgba(100,116,139,.12); color: var(--text-muted); }

/* ── Device Cards (devices page) ─────────────────────────────────────────── */

.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all .15s;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.device-card:hover { border-color: rgba(255,255,255,0.12); transform: translateY(-2px); }
.device-card-active { border-color: rgba(74,222,128,.25); }

.device-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
}

.device-card-icon {
    width: 44px; height: 44px;
    background: rgba(59,130,246,0.1);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    color: var(--accent);
}

.device-card-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
}

.status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
}

.status-online  .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-offline .status-dot { background: var(--text-muted); }
.status-online  { color: var(--green); }
.status-offline { color: var(--text-muted); }

.device-card-body { padding: 16px 20px; flex: 1; }
.device-card-name { font-size: 15px; font-weight: 700; color: #fff; margin-bottom: 2px; }
.device-card-type { font-size: 12px; color: var(--text-muted); text-transform: capitalize; margin-bottom: 12px; }

.device-detail-grid { display: flex; flex-direction: column; gap: 8px; }

.device-detail {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-sub);
}

.device-detail i { font-size: 13px; color: var(--text-muted); width: 16px; }

.device-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,.15);
}

.device-count-badge {
    background: rgba(59,130,246,.12);
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 100px;
    border: 1px solid rgba(59,130,246,.2);
}

.portal-btn-add-device {
    display: inline-flex;
    align-items: center;
    background: linear-gradient(135deg, #16a34a, #15803d);
    border: 1px solid rgba(74,222,128,.3);
    border-radius: 100px;
    color: #fff !important;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 18px;
    transition: all .2s;
    text-decoration: none;
    white-space: nowrap;
    box-shadow: 0 2px 12px rgba(22,163,74,.25);
}

.portal-btn-add-device:hover {
    background: linear-gradient(135deg, #15803d, #166534);
    box-shadow: 0 4px 16px rgba(22,163,74,.35);
    transform: translateY(-1px);
    color: #fff !important;
}

.portal-btn-add-device.btn-sm {
    font-size: 12px;
    padding: 5px 14px;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */

.badge-status {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 100px;
}

.badge-peak {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    background: rgba(251,191,36,.15);
    color: var(--amber);
    padding: 2px 6px;
    border-radius: 4px;
    vertical-align: middle;
}

/* ── Mini stats ──────────────────────────────────────────────────────────── */

.mini-stat-val { font-size: 20px; font-weight: 700; color: #fff; }
.mini-stat-lbl { font-size: 10px; color: #b8c9da; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; margin-top: 2px; }

/* ── Table ───────────────────────────────────────────────────────────────── */

.portal-table {
    color: var(--text-primary);
    border-color: var(--border);
    font-size: 13px;
}

.portal-table thead th {
    background: rgba(0,0,0,.25);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-color: var(--border);
    padding: 12px 16px;
}

.portal-table tbody td {
    border-color: var(--border);
    padding: 12px 16px;
    vertical-align: middle;
}

.portal-table tbody tr:hover td { background: rgba(255,255,255,0.02); }

.peak-row td { background: rgba(251,191,36,0.04); }

.table-total td {
    background: rgba(59,130,246,0.05);
    border-top: 2px solid rgba(59,130,246,.2);
    font-weight: 600;
}

/* ── Chart Legend ────────────────────────────────────────────────────────── */

.chart-legend { display: flex; flex-direction: column; gap: 6px; }

.legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-sub);
}

.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.portal-btn-primary {
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    padding: 11px 20px;
    transition: all .15s;
}

.portal-btn-primary:hover { background: var(--accent-hover); color: #fff; transform: translateY(-1px); }
.portal-btn-primary:active { transform: none; }

.portal-btn-outline {
    background: transparent;
    border: 1px solid rgba(59,130,246,.4);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-weight: 500;
    font-size: 13px;
    padding: 8px 16px;
    transition: all .15s;
}

.portal-btn-outline:hover { background: rgba(59,130,246,.08); color: var(--accent); }

.portal-btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-sub);
    font-weight: 500;
    font-size: 13px;
    padding: 8px 16px;
    transition: all .15s;
}

.portal-btn-ghost:hover { background: rgba(255,255,255,.04); color: var(--text-primary); }

/* ── Modal ───────────────────────────────────────────────────────────────── */

.portal-modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
}

/* ── Form Inputs ─────────────────────────────────────────────────────────── */

.portal-input {
    background: var(--bg-input) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    color: var(--text-primary) !important;
    padding: 11px 16px 11px 42px !important;
    font-size: 14px;
    transition: all .15s;
    width: 100%;
}

.portal-input:focus {
    border-color: var(--border-focus) !important;
    box-shadow: 0 0 0 3px rgba(59,130,246,.12) !important;
    outline: none;
}

/* Override browser autofill white/yellow background */
.portal-input:-webkit-autofill,
.portal-input:-webkit-autofill:hover,
.portal-input:-webkit-autofill:focus,
.portal-input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 9999px #0d1929 inset !important;
    box-shadow: 0 0 0 9999px #0d1929 inset !important;
    -webkit-text-fill-color: #f1f5f9 !important;
    caret-color: #f1f5f9;
    border: 1px solid rgba(255,255,255,0.10) !important;
}

.portal-input:-webkit-autofill:focus {
    border-color: rgba(59,130,246,0.6) !important;
}

/* Placeholder — muted disabled-style text */
.portal-input::placeholder { color: #5a7080 !important; opacity: 1; }

.input-icon-group { position: relative; }

.input-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 15px;
    pointer-events: none;
    z-index: 1;
}

.input-icon-right {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    padding: 2px;
    z-index: 1;
}

/* ── Login Page ──────────────────────────────────────────────────────────── */

.login-body {
    background: var(--bg-base);
    min-height: 100vh;
    display: flex;
}

.login-page {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.login-brand {
    flex: 0 0 420px;
    background: linear-gradient(160deg, #050d1a 0%, #0b1e38 60%, #0d2348 100%);
    border-right: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    position: relative;
    overflow: hidden;
}

.login-brand::before {
    content: '';
    position: absolute;
    top: -60px; right: -60px;
    width: 320px; height: 320px;
    background: radial-gradient(circle, rgba(59,130,246,.15) 0%, transparent 70%);
}

.login-brand::after {
    content: '';
    position: absolute;
    bottom: -80px; left: -40px;
    width: 280px; height: 280px;
    background: radial-gradient(circle, rgba(124,58,237,.1) 0%, transparent 70%);
}

.login-brand-inner { position: relative; z-index: 1; }

.login-logo {
    width: 72px; height: 72px;
    background: rgba(59,130,246,.12);
    border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 20px;
    border: 1px solid rgba(59,130,246,.2);
}

.login-brand-name    { font-size: 28px; font-weight: 800; color: #fff; letter-spacing: -.5px; }
.login-brand-tagline { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.login-features { display: flex; flex-direction: column; gap: 16px; }

.login-feature {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-sub);
    font-size: 14px;
}

.login-feature i {
    width: 32px; height: 32px;
    background: rgba(59,130,246,.1);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
    color: var(--accent);
    flex-shrink: 0;
}

.login-form-panel {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    background: var(--bg-base);
}

.login-form-inner { width: 100%; max-width: 400px; }

.login-title    { font-size: 26px; font-weight: 800; color: #fff; margin-bottom: 6px; }
.login-subtitle { font-size: 14px; color: var(--text-muted); margin-bottom: 28px; }

.form-label { font-size: 12px; font-weight: 600; color: var(--text-sub); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; display: block; }

.login-footer-text { font-size: 13px; color: var(--text-muted); text-align: center; }

/* ── Empty state ─────────────────────────────────────────────────────────── */

.empty-state-small { display: flex; flex-direction: column; align-items: center; padding: 20px 0; }

/* ── Sidebar overlay (mobile) ────────────────────────────────────────────── */

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 999;
    backdrop-filter: blur(2px);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 991.98px) {
    .portal-sidebar {
        transform: translateX(-100%);
    }

    .portal-sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open { display: block; }

    .portal-main { margin-left: 0; }

    .topbar-toggle { display: flex; }
}

@media (max-width: 767.98px) {
    .portal-content { padding: 20px 16px; }

    .login-brand { display: none; }

    .login-form-panel { padding: 32px 20px; }

    .page-header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 575.98px) {
    .stat-value { font-size: 22px; }
}
