/* =========================================================
   ColdChain IoT — Professional UI (Admin + Portal)
   Fully responsive — mobile first
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --sidebar-width: 268px;
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --primary-soft: rgba(14, 165, 233, 0.12);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #0f172a;
    --muted: #64748b;
    --bg: #f1f5f9;
    --card: #ffffff;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.1);
    --topbar-h: 60px;
}

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

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--dark);
    overflow-x: hidden;
    margin: 0;
    min-height: 100vh;
    line-height: 1.5;
}

img, svg, video { max-width: 100%; height: auto; }

a { color: var(--primary-dark); }
a:hover { color: var(--primary); }

/* ---------- Layout shell ---------- */
#wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

#page-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* ---------- Admin sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    max-height: 100vh;
    position: sticky;
    top: 0;
    flex-shrink: 0;
    z-index: 1040;
    background: linear-gradient(180deg, #0b1220 0%, #0f172a 55%, #0b1628 100%) !important;
    border-right: 1px solid rgba(148, 163, 184, 0.12);
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.28s ease, margin 0.28s ease;
    -webkit-overflow-scrolling: touch;
}

.sidebar-header {
    position: sticky;
    top: 0;
    z-index: 2;
    background: inherit;
    backdrop-filter: blur(8px);
}

.sidebar .nav-link {
    border-radius: 10px;
    margin: 2px 6px;
    padding: 0.65rem 0.9rem;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s, transform 0.15s;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.sidebar .nav-link i {
    font-size: 1.05rem;
    width: 1.4rem;
    text-align: center;
    opacity: 0.9;
}

.sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff !important;
}

.sidebar .nav-link.active {
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.32), rgba(14, 165, 233, 0.08));
    color: #e0f2fe !important;
    font-weight: 600;
    box-shadow: inset 3px 0 0 #38bdf8;
}


/* Desktop hide/show */
.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}
body.sidebar-collapsed #page-content {
    /* content expands when sidebar hidden */
}

/* Elegant scrollbar — thin, low contrast (or effectively minimal) */
.sidebar {
    scrollbar-width: thin;              /* Firefox */
    scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}
.sidebar::-webkit-scrollbar {
    width: 4px;
}
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.35);
    border-radius: 99px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.55);
}
/* Optional: almost invisible until hover */
.sidebar:not(:hover)::-webkit-scrollbar-thumb {
    background: transparent;
}


/* Mobile overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 1035;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ---------- Topbar ---------- */
.navbar.bg-white,
.portal-topbar {
    min-height: var(--topbar-h);
    background: rgba(255, 255, 255, 0.92) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 1020;
    border-bottom: 1px solid rgba(226, 232, 240, 0.95) !important;
}

main.p-4,
main.portal-main {
    padding: 1.25rem 1.25rem 2rem;
    flex: 1;
    width: 100%;
    max-width: 100%;
}

/* ---------- Cards & stats ---------- */
.stat-card,
.portal-stat,
.table-card,
.portal-panel,
.monitor-card {
    border: none;
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
}

.stat-card {
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.stat-card .stat-icon,
.portal-stat .icon-wrap {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-card .stat-value,
.portal-stat .val {
    font-size: 1.7rem;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: -0.03em;
}

.stat-card .stat-label,
.portal-stat .lbl {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.table-card {
    overflow: hidden;
}
.table-card .card-header,
.portal-panel .panel-head {
    background: #fff;
    border-bottom: 1px solid #f1f5f9;
    padding: 1rem 1.15rem;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    margin-bottom: 0;
    min-width: 520px;
}
.table th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 700;
    white-space: nowrap;
    border-bottom-width: 1px;
}
.table td {
    vertical-align: middle;
    font-size: 0.9rem;
}

/* ---------- Status ---------- */
.status-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
    background: #94a3b8;
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.25);
}
.status-dot.online { background: var(--success); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25); }
.status-dot.warning { background: var(--warning); box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25); }
.status-dot.unknown { background: #94a3b8; }

.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: #fff;
    background: linear-gradient(135deg, #ef4444, #f97316);
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    animation: livePulse 1.6s ease infinite;
}
.live-indicator::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #fff;
}
@keyframes livePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.75; }
}
.live-indicator.pulse-once { animation: none; filter: brightness(1.2); }

/* ---------- Monitor / device tiles ---------- */
.monitor-card {
    padding: 1.15rem 1.2rem;
    border-left: 4px solid var(--success);
    height: 100%;
    transition: transform 0.18s, box-shadow 0.18s;
}
.monitor-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.monitor-card.critical { border-left-color: var(--danger); }
.monitor-card.warning { border-left-color: var(--warning); }
.monitor-card.normal { border-left-color: var(--success); }

.temp-value, .t-val {
    font-size: clamp(1.6rem, 4vw, 2rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--dark);
}
.hum-value, .h-val {
    font-size: 0.9rem;
    color: var(--muted);
    font-weight: 500;
}

.device-tile {
    display: block;
    background: #fff;
    border-radius: var(--radius);
    padding: 1.15rem 1.2rem;
    text-decoration: none;
    color: inherit;
    border: 1px solid #e8eef5;
    border-left: 4px solid #10b981;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
    transition: transform 0.18s, box-shadow 0.18s;
    height: 100%;
}
.device-tile:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    color: inherit;
}
.device-tile.offline { border-left-color: var(--danger); opacity: 0.92; }

/* ---------- Forms & buttons ---------- */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: #e2e8f0;
    font-size: 0.92rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.btn {
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.875rem;
}
.btn-primary {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    border: none;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.25);
}
.btn-primary:hover {
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
}
.btn-pill, .rounded-pill { border-radius: 999px !important; }

.badge { font-weight: 600; }

/* ---------- Page titles ---------- */
.page-title, h4.fw-bold {
    font-weight: 800 !important;
    letter-spacing: -0.02em;
}
.page-sub, .text-muted.small {
    color: var(--muted) !important;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--muted);
}
.empty-state i {
    font-size: 2.5rem;
    opacity: 0.4;
    display: block;
    margin-bottom: 0.75rem;
}

/* Live data flash */
.data-flash {
    animation: dataFlash 0.6s ease;
}
@keyframes dataFlash {
    0% { background-color: rgba(14, 165, 233, 0.3); }
    100% { background-color: transparent; }
}

/* ---------- Auth ---------- */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: radial-gradient(ellipse at top, #e0f2fe 0%, #f1f5f9 45%, #e2e8f0 100%);
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    padding: 2rem 1.75rem;
}

/* ---------- Portal extras ---------- */
.portal-stat:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

/* ---------- Responsive: tablets ---------- */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-105%);
        margin-left: 0 !important;
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.25);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .sidebar.collapsed {
        transform: translateX(-105%);
    }

    main.p-4,
    main.portal-main {
        padding: 1rem 0.9rem 1.75rem;
    }

    .stat-card .stat-value,
    .portal-stat .val {
        font-size: 1.4rem;
    }

    .table {
        min-width: 480px;
        font-size: 0.85rem;
    }
}

/* ---------- Responsive: phones ---------- */
@media (max-width: 575.98px) {
    :root {
        --radius: 14px;
        --topbar-h: 56px;
    }

    main.p-4,
    main.portal-main {
        padding: 0.85rem 0.75rem 1.5rem;
    }

    .stat-card .stat-icon,
    .portal-stat .icon-wrap {
        width: 40px;
        height: 40px;
        font-size: 1.05rem;
        border-radius: 12px;
    }

    .stat-card .stat-value,
    .portal-stat .val {
        font-size: 1.25rem;
    }

    .temp-value, .t-val {
        font-size: 1.5rem;
    }

    .btn-group {
        flex-wrap: wrap;
        width: 100%;
    }
    .btn-group .btn {
        flex: 1 1 auto;
    }

    .card-body.row.g-2 > [class*="col-"] {
        width: 100%;
        max-width: 100%;
    }

    .navbar .dropdown-toggle {
        max-width: 140px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    h3.page-title, h4.fw-bold {
        font-size: 1.25rem;
    }

    .table {
        min-width: 420px;
        font-size: 0.8rem;
    }
    .table th, .table td {
        padding: 0.5rem 0.55rem;
    }
}

/* Safe area (notched phones) */
@supports (padding: max(0px)) {
    main.p-4,
    main.portal-main {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    }
}

/* Print */
@media print {
    .sidebar, .navbar, .portal-topbar, .sidebar-overlay, .live-indicator { display: none !important; }
    #page-content { width: 100% !important; }
    main { padding: 0 !important; }
}
