/* ============================================================
   ColdChain Platform — Custom Styles
   Bootstrap 5 augmentation (no Node.js dependencies)
   ============================================================ */

/* ---------- Layout ---------- */
:root {
    --navbar-h: 60px;
    --sidebar-w: 250px;

    /* ----- Design tokens (added 2026-05) ----- */
    /* Brand palette — cold-chain blue/teal */
    --cc-brand: #0d6efd;
    --cc-brand-600: #0b5ed7;
    --cc-teal: #0d9488;
    --cc-ink: #1f2a37;          /* primary text */
    --cc-muted: #6b7280;        /* secondary text */
    --cc-surface: #ffffff;
    --cc-bg: #f4f6f9;
    --cc-border: rgba(17, 24, 39, 0.08);

    /* Semantic status colors (single source of truth) */
    --cc-ok: #198754;
    --cc-warn: #f59e0b;
    --cc-critical: #dc3545;
    --cc-oos: #6c757d;
    --cc-info: #0dcaf0;

    /* Elevation & shape */
    --cc-radius: 0.65rem;
    --cc-radius-lg: 0.9rem;
    --cc-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    --cc-shadow: 0 4px 12px rgba(16, 24, 40, 0.08);
    --cc-shadow-lg: 0 12px 28px rgba(16, 24, 40, 0.12);
    --cc-transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--cc-bg);
    color: var(--cc-ink);
    padding-top: var(--navbar-h);
}

#main-content {
    min-height: calc(100vh - var(--navbar-h) - 60px); /* navbar + footer */
    margin-left: var(--sidebar-w);
    transition: margin-left 0.3s ease;
}

@media (max-width: 991.98px) {
    #main-content {
        margin-left: 0;
    }
}

/* ---------- Navbar ---------- */
.navbar {
    height: var(--navbar-h);
    z-index: 1050;
}

.navbar .container-fluid {
    flex-wrap: nowrap;
}

.navbar-brand {
    font-size: 1.1rem;
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    top: var(--navbar-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    padding-top: 0.5rem;
    overflow-y: auto;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar .nav-link {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    border-radius: 0;
    transition: background-color 0.15s ease;
}

.sidebar .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.sidebar .nav-link.active {
    background-color: rgba(255, 255, 255, 0.15);
    font-weight: 600;
}

.sidebar .nav-header {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

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

/* ---------- Cards ---------- */
.card {
    border: none;
    border-radius: 0.5rem;
}

.card-header {
    background-color: #fff;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    padding: 0.75rem 1rem;
}

/* ---------- Tables ---------- */
.table th {
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6c757d;
}

.table td {
    vertical-align: middle;
}

/* ---------- KPI Cards ---------- */
.border-start.border-4 {
    border-left-width: 4px !important;
}

/* ---------- Badges ---------- */
.badge {
    font-weight: 500;
    font-size: 0.78rem;
    padding: 0.35em 0.65em;
}

/* ---------- Status colors ---------- */
.status-ok { color: #198754; }
.status-alert { color: #ffc107; }
.status-critical { color: #dc3545; }
.status-oos { color: #6c757d; }

/* ---------- Auth pages ---------- */
.min-vh-100 .card {
    border-radius: 0.75rem;
}

/* ---------- Footer ---------- */
.footer {
    margin-left: var(--sidebar-w);
    transition: margin-left 0.3s ease;
}

@media (max-width: 991.98px) {
    .footer {
        margin-left: 0;
    }
}

/* ---------- Notifications ---------- */
.notification-unread {
    background-color: #e8f4fd;
    border-left: 3px solid #0d6efd;
}

.notification-badge {
    font-size: 0.65rem;
}

/* ---------- Map ---------- */
#map, #fullmap {
    border-radius: 0 0 0.5rem 0.5rem;
}

/* ---------- Print ---------- */
@media print {
    .sidebar, .navbar, .footer, .btn, .breadcrumb {
        display: none !important;
    }
    #main-content {
        margin-left: 0 !important;
    }
    body {
        padding-top: 0;
    }
}

/* ---------- RTL Support ---------- */
[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
}

[dir="rtl"] #main-content {
    margin-left: 0;
    margin-right: var(--sidebar-w);
}

[dir="rtl"] .footer {
    margin-left: 0;
    margin-right: var(--sidebar-w);
}

@media (max-width: 991.98px) {
    [dir="rtl"] #main-content,
    [dir="rtl"] .footer {
        margin-right: 0;
    }
    [dir="rtl"] .sidebar {
        transform: translateX(100%);
    }
    [dir="rtl"] .sidebar.show {
        transform: translateX(0);
    }
}

/* ---------- Scrollbar ---------- */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* ---------- Transitions ---------- */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Form improvements ---------- */
.form-control:focus,
.form-select:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.15rem rgba(13, 110, 253, 0.15);
}

/* ---------- Misc ---------- */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cursor-pointer {
    cursor: pointer;
}

/* ============================================================
   Design-system components (added 2026-05)
   Reusable across dashboard, energy, reports, etc.
   ============================================================ */

/* ---------- Page header ---------- */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.page-header__title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--cc-ink);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.page-header__subtitle {
    color: var(--cc-muted);
    font-size: 0.9rem;
    margin-top: 0.15rem;
}
.section-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--cc-muted);
    margin-bottom: 0.75rem;
}

/* ---------- Stat card (KPI) ---------- */
.stat-card {
    position: relative;
    background: var(--cc-surface);
    border: 1px solid var(--cc-border);
    border-radius: var(--cc-radius);
    box-shadow: var(--cc-shadow-sm);
    padding: 1.1rem 1.25rem;
    height: 100%;
    overflow: hidden;
    transition: transform var(--cc-transition), box-shadow var(--cc-transition);
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--cc-shadow);
}
.stat-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--_accent, var(--cc-brand));
}
.stat-card--ok       { --_accent: var(--cc-ok); }
.stat-card--warn     { --_accent: var(--cc-warn); }
.stat-card--critical { --_accent: var(--cc-critical); }
.stat-card--oos      { --_accent: var(--cc-oos); }
.stat-card--info     { --_accent: var(--cc-info); }
.stat-card--brand    { --_accent: var(--cc-brand); }
.stat-card--teal     { --_accent: var(--cc-teal); }

.stat-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}
.stat-card__label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--cc-muted);
}
.stat-card__value {
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--cc-ink);
    margin-top: 0.15rem;
}
.stat-card__value small { font-size: 0.95rem; font-weight: 600; color: var(--cc-muted); }
.stat-card__icon {
    font-size: 1.6rem;
    line-height: 1;
    color: var(--_accent, var(--cc-brand));
    opacity: 0.85;
    background: color-mix(in srgb, var(--_accent, var(--cc-brand)) 12%, transparent);
    width: 2.6rem; height: 2.6rem;
    display: flex; align-items: center; justify-content: center;
    border-radius: 0.6rem;
    flex-shrink: 0;
}
.stat-card__foot {
    margin-top: 0.55rem;
    font-size: 0.78rem;
    color: var(--cc-muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.trend-up   { color: var(--cc-ok); font-weight: 600; }
.trend-down { color: var(--cc-critical); font-weight: 600; }

/* ---------- Elevated panel ---------- */
.panel {
    background: var(--cc-surface);
    border: 1px solid var(--cc-border);
    border-radius: var(--cc-radius);
    box-shadow: var(--cc-shadow-sm);
}
.panel__head {
    padding: 0.85rem 1.15rem;
    border-bottom: 1px solid var(--cc-border);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.panel__body { padding: 1.15rem; }

/* ---------- Status dot ---------- */
.status-dot {
    display: inline-block;
    width: 0.6rem; height: 0.6rem;
    border-radius: 50%;
    margin-right: 0.35rem;
    vertical-align: middle;
}
.status-dot--ok       { background: var(--cc-ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cc-ok) 20%, transparent); }
.status-dot--warn     { background: var(--cc-warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cc-warn) 20%, transparent); }
.status-dot--critical { background: var(--cc-critical); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cc-critical) 20%, transparent); }
.status-dot--oos      { background: var(--cc-oos); }

/* ---------- Soft badges ---------- */
.badge-soft { font-weight: 600; border-radius: 0.5rem; padding: 0.3em 0.6em; }
.badge-soft-ok       { background: color-mix(in srgb, var(--cc-ok) 14%, transparent); color: #11633f; }
.badge-soft-warn     { background: color-mix(in srgb, var(--cc-warn) 18%, transparent); color: #92600a; }
.badge-soft-critical { background: color-mix(in srgb, var(--cc-critical) 14%, transparent); color: #a11722; }
.badge-soft-brand    { background: color-mix(in srgb, var(--cc-brand) 12%, transparent); color: var(--cc-brand-600); }
.badge-soft-oos      { background: color-mix(in srgb, var(--cc-oos) 15%, transparent); color: #495057; }

/* ---------- Insight / callout ---------- */
.insight {
    border-radius: var(--cc-radius);
    border: 1px solid var(--cc-border);
    border-left: 4px solid var(--_accent, var(--cc-brand));
    background: color-mix(in srgb, var(--_accent, var(--cc-brand)) 5%, var(--cc-surface));
    padding: 0.9rem 1.1rem;
}
.insight--warn     { --_accent: var(--cc-warn); }
.insight--critical { --_accent: var(--cc-critical); }
.insight--ok       { --_accent: var(--cc-ok); }

/* ---------- Mini progress meter ---------- */
.meter {
    height: 8px;
    border-radius: 6px;
    background: color-mix(in srgb, var(--cc-ink) 8%, transparent);
    overflow: hidden;
}
.meter__fill {
    height: 100%;
    border-radius: 6px;
    background: var(--_accent, var(--cc-brand));
    transition: width var(--cc-transition);
}

/* ---------- Table polish ---------- */
.table-clean tbody tr { transition: background-color var(--cc-transition); }
.table-clean tbody tr:hover { background-color: color-mix(in srgb, var(--cc-brand) 5%, transparent); }

/* RTL: accent bar on the right */
[dir="rtl"] .stat-card::before { inset: 0 0 0 auto; }
[dir="rtl"] .insight { border-left: 1px solid var(--cc-border); border-right: 4px solid var(--_accent, var(--cc-brand)); }
[dir="rtl"] .status-dot { margin-right: 0; margin-left: 0.35rem; }

/* ============================================================
   Dark mode (Bootstrap 5.3 `data-bs-theme="dark"`).
   Opt-in via the navbar toggle; persisted in localStorage.
   Default stays light → no change for existing users.
   Bootstrap handles standard components; here we re-map the
   custom design-system tokens + a few hard-coded light values.
   ============================================================ */
[data-bs-theme="dark"] {
    --cc-ink: #e6e9ee;
    --cc-muted: #9aa4b2;
    --cc-surface: #1e2733;
    --cc-bg: #0f1722;
    --cc-border: rgba(255, 255, 255, 0.10);
    --cc-shadow-sm: 0 1px 2px rgba(0,0,0,.35), 0 1px 3px rgba(0,0,0,.40);
    --cc-shadow: 0 4px 12px rgba(0,0,0,.45);
    --cc-shadow-lg: 0 12px 28px rgba(0,0,0,.55);
}
[data-bs-theme="dark"] .card-header { background-color: var(--cc-surface); border-bottom-color: var(--cc-border); }
[data-bs-theme="dark"] .table th { color: var(--cc-muted); }
[data-bs-theme="dark"] .notification-unread { background-color: rgba(13,110,253,.14); border-left-color: #3d8bfd; }
[data-bs-theme="dark"] .badge-soft-ok       { color:#6ee7b7; }
[data-bs-theme="dark"] .badge-soft-warn     { color:#fcd34d; }
[data-bs-theme="dark"] .badge-soft-critical { color:#fca5a5; }
[data-bs-theme="dark"] .badge-soft-brand    { color:#8ab4ff; }
[data-bs-theme="dark"] .badge-soft-oos      { color:#cbd5e1; }
