/* ============================================================
   CARELOGR — SIDEBAR LAYOUT & DESIGN SYSTEM
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
    --sidebar-width: 248px;
    --sidebar-collapsed: 0px;
    --topbar-height: 60px;

    --sidebar-bg: #0d2b34;
    --sidebar-hover: rgba(255,255,255,0.07);
    --sidebar-active-bg: rgba(0,151,178,0.18);
    --sidebar-active-border: #0097b2;
    --sidebar-text: #ffffff;
    --sidebar-text-active: #fff;
    --sidebar-section-label: rgba(255,255,255,0.3);

    --topbar-bg: #ffffff;
    --topbar-border: #E2E8F0;

    --page-bg: #F1F5F9;
    --surface: #ffffff;
    --border: #E2E8F0;
    --border-light: #F1F5F9;

    --text-primary: #1E293B;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;

    --blue: #0097b2;
    --blue-dark: #007a91;
    --blue-light: #e0f6fb;

    --green: #10B981;
    --amber: #F59E0B;
    --red: #EF4444;
    --purple: #8B5CF6;
    --teal: #14B8A6;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;

    --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-md: 0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.04);
}

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

html { height: 100%; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--page-bg);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100%;
    margin: 0;
}

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

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.25s ease, transform 0.25s ease;
    scrollbar-width: none;
}

/* ---- Collapsed state ---- */
.sidebar.collapsed { width: 64px; }
.sidebar.collapsed ~ .main-area { margin-left: 64px; }

.sidebar.collapsed .sidebar-link span,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-group-items,
.sidebar.collapsed .nav-arrow,
.sidebar.collapsed .sidebar-user-info,
.sidebar.collapsed .sidebar-logout,
.sidebar.collapsed .sidebar-logo-img,
.sidebar.collapsed .settings-flyout-btn span,
.sidebar.collapsed .settings-flyout-arrow,
.sidebar.collapsed #settingsFlyout { display: none !important; }
.sidebar.collapsed .settings-flyout-btn { justify-content: center; padding: 10px; }
.sidebar.collapsed .settings-flyout-btn-inner { gap: 0; }

/* Keep notification badge visible in collapsed mode — position it over the bell icon */
.sidebar.collapsed .sidebar-link span#notifBadge {
    display: inline-block !important;
    position: absolute;
    top: 5px;
    right: 5px;
    min-width: 16px;
    height: 16px;
    font-size: 9px;
    padding: 0 3px;
    line-height: 16px;
    border-radius: 8px;
    margin: 0;
}

.sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 10px;
}
.sidebar.collapsed .sidebar-brand {
    justify-content: center;
    padding: 16px 0;
}
.sidebar.collapsed .sidebar-brand-mini { display: flex !important; }
.sidebar.collapsed .sidebar-user { justify-content: center; }
.sidebar.collapsed .sidebar-collapse-btn { justify-content: center; padding: 8px; }

/* Mini brand (icon-only state) */
.sidebar-brand-mini {
    display: none;
    width: 34px;
    height: 34px;
    background: rgba(255,255,255,0.15);
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-size: 13px;
    letter-spacing: -0.5px;
}

/* Collapse toggle button */
.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 8px 18px;
    border: none;
    border-top: 1px solid rgba(255,255,255,0.06);
    background: none;
    color: rgba(255,255,255,0.35);
    cursor: pointer;
    width: 100%;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}
.sidebar-collapse-btn:hover { color: rgba(255,255,255,0.8); background: rgba(255,255,255,0.04); }
.sidebar::-webkit-scrollbar { display: none; }

/* Brand / Logo */
.sidebar-brand {
    padding: 31px 18px 29px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
    line-height: 0;
    font-size: 0;
}
.sidebar-logo-img {
    display: block;
    height: 50px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    object-position: left center;
    filter: none;
    opacity: 1;
    margin: 0;
    padding: 0;
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
    scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

/* Section labels */
.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-section-label);
    padding: 14px 10px 6px;
    user-select: none;
}

/* Nav links */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
    width: 100%;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    margin-bottom: 1px;
}
.sidebar-link i {
    width: 18px;
    text-align: center;
    font-size: 14px;
    flex-shrink: 0;
    opacity: 0.8;
}
.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
    text-decoration: none;
}
.sidebar-link:hover i { opacity: 1; }
.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
    border-left: 3px solid var(--sidebar-active-border);
    padding-left: 9px;
}
.sidebar-link.active i { opacity: 1; color: var(--sidebar-active-border); }

/* Sub-items */
.sidebar-link.sub {
    padding-left: 40px;
    font-size: 13px;
    color: rgba(255,255,255,0.5);
}
.sidebar-link.sub:hover { color: #fff; background: var(--sidebar-hover); }
.sidebar-link.sub.active {
    color: var(--sidebar-text-active);
    background: var(--sidebar-active-bg);
    border-left: 3px solid var(--sidebar-active-border);
    padding-left: 37px;
}

/* Nav group */
.nav-group { margin-bottom: 1px; }
.nav-group-btn { width: 100%; }
.nav-group-items { padding-left: 0; }
.nav-arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
    opacity: 0.5;
}

/* Sidebar footer */
.sidebar-footer {
    flex-shrink: 0;
    padding: 12px 10px;
    border-top: 1px solid rgba(255,255,255,0.06);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
}
.sidebar-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(59,130,246,0.25);
    color: #93C5FD;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
    font-size: 12.5px;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: 11px;
    color: var(--sidebar-section-label);
}
.sidebar-logout {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.4);
    transition: all 0.15s;
    flex-shrink: 0;
    text-decoration: none;
}
.sidebar-logout:hover { background: rgba(239,68,68,0.2); color: #FCA5A5; }

/* Mobile overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1039;
}
.sidebar-overlay.visible { display: block; }

/* ============================================================
   MAIN AREA
   ============================================================ */
.main-area {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
    transition: margin-left 0.25s ease;
}

/* ---------- Top Bar ---------- */
.topbar {
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-xs);
    flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.sidebar-toggle {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: none;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    display: none; /* Only shown on mobile */
}
.sidebar-toggle:hover { background: var(--border-light); color: var(--text-primary); }

.topbar-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: none;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}
.topbar-icon-btn:hover { background: var(--border-light); color: var(--text-primary); }

.topbar-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: none;
    color: var(--text-primary);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.topbar-user-btn:hover { background: var(--border-light); }
.topbar-user-btn::after { display: none; }

.topbar-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--blue);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

/* ---------- Flash messages ---------- */
.flash-area {
    padding: 0 1.5rem;
    padding-top: 1rem;
}

/* ---------- Page Content ---------- */
.page-content {
    flex: 1;
    padding: 1.75rem 2rem;
}

/* ============================================================
   PAGE HEADER COMPONENT
   ============================================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.75rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}
.page-header-left { flex: 1; min-width: 0; }
.page-header-left h1,
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    line-height: 1.3;
}
.page-header-left h1 i,
.page-header h1 i { color: var(--blue); font-size: 1.3rem; }
.page-header-left .page-subtitle,
.page-header .page-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0;
}
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    flex-wrap: wrap;
    padding-top: 0.2rem;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--surface);
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-sm) !important;
}
.card:hover { box-shadow: var(--shadow) !important; }

.card-header:not([style*="background"]) {
    background: #FAFBFC;
    border-bottom: 1px solid var(--border);
}
.card-header {
    padding: 0.875rem 1.25rem !important;
    font-weight: 600;
}
.card-header h5, .card-header h6 {
    margin-bottom: 0;
    font-weight: 600;
}
.card-body { padding: 1.25rem; }

/* ============================================================
   STAT CARDS (Overview)
   ============================================================ */
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: box-shadow 0.2s, transform 0.2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: var(--blue-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon i { font-size: 1.35rem; color: var(--blue); }
.stat-content { flex: 1; min-width: 0; }
.stat-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}
.stat-value {
    font-size: 1.9rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 13px;
    transition: all 0.15s;
}
.btn-primary {
    background: var(--blue) !important;
    border-color: var(--blue) !important;
    color: #fff !important;
}
.btn-primary:hover { background: var(--blue-dark) !important; border-color: var(--blue-dark) !important; }
.btn-success { background: var(--green) !important; border-color: var(--green) !important; color: #fff !important; }
.btn-danger { background: var(--red) !important; border-color: var(--red) !important; color: #fff !important; }
.btn-warning { background: var(--amber) !important; border-color: var(--amber) !important; color: #fff !important; }
.btn-secondary { background: #64748B !important; border-color: #64748B !important; color: #fff !important; }
.btn-outline-primary { color: var(--blue) !important; border-color: var(--blue) !important; }
.btn-outline-primary:hover { background: var(--blue) !important; color: #fff !important; }
.btn-outline-secondary { color: var(--text-secondary) !important; border-color: var(--border) !important; }
.btn-outline-secondary:hover { background: var(--border-light) !important; color: var(--text-primary) !important; }

/* ============================================================
   FORMS
   ============================================================ */
.form-control, .form-select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
    outline: none;
}
.form-label { font-weight: 600; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }

/* ============================================================
   TABLES (generic — matrix table borders are handled separately)
   ============================================================ */
.table-section {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}
.table-section .table { margin-bottom: 0; }
.table-section .table th {
    background: #F8FAFC;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    padding: 12px 14px;
}
.table-section .table td {
    padding: 12px 14px;
    vertical-align: middle;
    font-size: 13.5px;
    border-bottom: 1px solid var(--border-light);
}
.table-section .table tr:last-child td { border-bottom: none; }
.table-section .table tbody tr:hover td { background: #F8FAFC; }

/* ============================================================
   BADGES
   ============================================================ */
.badge { font-size: 11px; font-weight: 600; border-radius: 5px; padding: 3px 8px; }
.bg-primary { background: var(--blue) !important; }
.bg-success { background: var(--green) !important; }
.bg-danger { background: var(--red) !important; }
.bg-warning { background: var(--amber) !important; color: #fff !important; }
.bg-secondary { background: #64748B !important; }
.bg-info { background: var(--teal) !important; }

/* ============================================================
   STATUS FILTER BUTTONS
   ============================================================ */
.status-filters {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.status-filter-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s;
    cursor: pointer;
    white-space: nowrap;
}
.status-filter-btn:hover { border-color: var(--blue); color: var(--blue); }
.status-filter-btn.active {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}

/* ============================================================
   DROPDOWNS
   ============================================================ */
.dropdown-menu {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-size: 13.5px;
    padding: 6px;
}
.dropdown-item {
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    color: var(--text-primary);
    transition: background 0.1s;
}
.dropdown-item:hover { background: var(--border-light); color: var(--text-primary); }
.dropdown-header { font-size: 11px; font-weight: 700; color: var(--text-muted); padding: 6px 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.dropdown-divider { border-color: var(--border); margin: 4px 0; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert { border-radius: var(--radius-sm); border: 1px solid; font-size: 13.5px; }
.alert-info { background: #e0f6fb; border-color: #7ddaed; color: #005a6b; }
.alert-success { background: #F0FDF4; border-color: #BBF7D0; color: #166534; }
.alert-warning { background: #FFFBEB; border-color: #FDE68A; color: #92400E; }
.alert-danger { background: #FEF2F2; border-color: #FECACA; color: #991B1B; }

/* ============================================================
   LINKS
   ============================================================ */
a { color: var(--blue); }
a:hover { color: var(--blue-dark); }

/* ============================================================
   NAVIGATION TABS
   ============================================================ */
.nav-tabs {
    border-bottom: 2px solid var(--border);
    gap: 4px;
}
.nav-tabs .nav-link {
    border: none;
    border-bottom: 3px solid transparent;
    background: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 13.5px;
    padding: 10px 16px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    margin-bottom: -2px;
    transition: all 0.15s;
}
.nav-tabs .nav-link:hover { color: var(--blue); background: var(--blue-light); }
.nav-tabs .nav-link.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination { margin-top: 1rem; gap: 3px; }
.page-link { border-radius: var(--radius-sm) !important; border-color: var(--border) !important; color: var(--text-secondary) !important; font-size: 13px; padding: 6px 12px; }
.page-link:hover { background: var(--border-light) !important; color: var(--text-primary) !important; }
.page-item.active .page-link { background: var(--blue) !important; border-color: var(--blue) !important; color: #fff !important; }

/* ============================================================
   RESPONSIVE SYSTEM
   ============================================================ */

/* --- Fluid typography & proportionate base values --- */
:root {
    --page-padding-x: clamp(1rem, 3vw, 2rem);
    --page-padding-y: clamp(1rem, 2.5vh, 1.75rem);
    --card-padding: clamp(0.875rem, 2vw, 1.25rem);
    --topbar-padding-x: clamp(1rem, 2.5vw, 1.5rem);
}

/* --- Fluid page content padding --- */
.page-content {
    padding: var(--page-padding-y) var(--page-padding-x);
}

/* --- Tables always scroll horizontally rather than breaking layout --- */
.table-responsive-always {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table-section {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- Stat cards: clamp font size so numbers don't overflow --- */
.stat-value {
    font-size: clamp(1.4rem, 3vw, 1.9rem);
}

/* --- Page header title scales with viewport --- */
.page-header-left h1,
.page-header h1 {
    font-size: clamp(1.1rem, 2.5vw, 1.5rem);
}

/* --- Topbar padding uses fluid value --- */
.topbar {
    padding: 0 var(--topbar-padding-x);
}

/* ============================================================
   LARGE — shrink sidebar slightly so content has more room
   ============================================================ */
@media (min-width: 1400px) {
    .page-content { padding: 2rem 2.5rem; }
}

/* ============================================================
   MEDIUM — sidebar still visible but content area is tighter
   ============================================================ */
@media (max-width: 1200px) {
    :root { --sidebar-width: 220px; }

    .sidebar-link { font-size: 13px; padding: 8px 10px; }
    .nav-section-label { font-size: 9.5px; }
    .page-content { padding: 1.5rem 1.25rem; }
}

/* ============================================================
   TABLET — sidebar slides off, hamburger appears
   ============================================================ */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }
    .sidebar.sidebar-open {
        transform: translateX(0);
    }
    .main-area {
        margin-left: 0 !important;
    }
    .sidebar-toggle {
        display: flex !important;
    }

    /* Stat cards: 2-column grid on tablet */
    .row.g-3 > .col-xl-3,
    .row.g-3 > .col-lg-3,
    .row.g-4 > .col-xl-3,
    .row.g-4 > .col-lg-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Nav tabs scroll horizontally instead of wrapping */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 1px;
    }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-tabs .nav-link { white-space: nowrap; }

    /* Page header stacks earlier */
    .page-header {
        flex-direction: column;
        gap: 0.75rem;
    }
    .page-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }
}

/* ============================================================
   MOBILE — full single-column experience
   ============================================================ */
@media (max-width: 576px) {
    :root {
        --topbar-height: 54px;
    }

    .topbar { padding: 0 0.875rem; }

    /* Hide username label in topbar to save space */
    .topbar-user-btn .d-none-mobile { display: none !important; }

    .page-content { padding: 0.875rem; }

    /* All columns become full-width */
    .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Stat card: compact layout */
    .stat-card { padding: 1rem; }
    .stat-icon { width: 42px; height: 42px; border-radius: 10px; }
    .stat-icon i { font-size: 1.1rem; }

    /* Tables: allow horizontal scroll, don't force full width */
    .table-section { border-radius: var(--radius-sm); }

    /* Buttons full-width in page header */
    .page-header-actions { justify-content: stretch; }
    .page-header-actions .btn { flex: 1; justify-content: center; }

    /* Cards */
    .card-body { padding: var(--card-padding); }

    /* Form controls taller for touch */
    .form-control, .form-select {
        min-height: 42px;
        font-size: 14px;
    }

    /* Stack inline form rows */
    .row.g-2 > [class*="col-md"],
    .row.g-3 > [class*="col-md"],
    .row.g-2 > [class*="col-sm"],
    .row.g-3 > [class*="col-sm"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Flash messages closer to content */
    .flash-area { padding: 0.75rem 0.875rem 0; }

    /* Topbar: hide page title text if present */
    .topbar-title { display: none; }

    /* Tabs: smaller font */
    .nav-tabs .nav-link { font-size: 12.5px; padding: 8px 12px; }

    /* Badges slightly smaller */
    .badge { font-size: 10.5px; }
}

/* ============================================================
   OVERRIDE OLD HEADER STYLES (safety — old classes no longer used)
   ============================================================ */
.header-section { display: none !important; }
.main-content {
    padding: 0 !important;
    min-height: unset !important;
}

/* Utility */
.text-muted { color: var(--text-muted) !important; }
.bg-light { background: var(--border-light) !important; }

/* ============================================================
   MATRIX TABLE CELLS — MODERN LOOK
   ============================================================ */
.matrix-table-container {
    border-color: var(--border) !important;
    border-radius: var(--radius) !important;
}
.matrix-table-cell {
    border-right-color: var(--border) !important;
    border-bottom-color: var(--border) !important;
    font-size: 13.5px;
    color: var(--text-primary);
    justify-content: center;
    text-align: center;
}
.matrix-table-cell.header-cell {
    background: #F0F6FF !important;
    color: var(--blue) !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.07em !important;
    border-color: #D4E5FF !important;
    min-height: 42px !important;
}

/* Card section headers — keep them compact and unobtrusive */
.card-header .card-title,
.card-header h5,
.card-header h4 {
    font-size: 13px !important;
    font-weight: 600 !important;
    letter-spacing: 0.01em;
    margin-bottom: 0;
}
.card-header .card-title i,
.card-header h5 i,
.card-header h4 i {
    font-size: 12px !important;
    opacity: 0.75;
}
.matrix-table-cell:not(.header-cell):hover {
    background: #F8FAFC;
}

/* ============================================================
   TABLE ACTIONS
   ============================================================ */
.table-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.btn-action { border-radius: 6px !important; }

/* ============================================================
   SEARCH BOX
   ============================================================ */
.search-box .form-control {
    border-right: none;
}
.search-box .input-group-text {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-muted);
}

/* ============================================================
   PROFILE PAGES (staff_profile / customer_profile)
   ============================================================ */
.profile-header {
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
    color: white;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.profile-avatar-large {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    border: 3px solid rgba(255,255,255,0.4);
}
.profile-nav .nav-tabs { border-bottom: 2px solid var(--border); }
.profile-nav .nav-tabs .nav-link.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
    font-weight: 600;
}

/* Section headings inside profile/detail cards */
h5 .fa-user, h5 .fa-heart, h5 .fa-pills, h5 .fa-file, h5 .fa-clipboard,
h5 .fa-shield, h5 .fa-star, h5 .fa-home, h5 .fa-phone {
    color: var(--blue) !important;
}

/* ============================================================
   OVERVIEW / COMPLIANCE CARDS
   ============================================================ */
.compliance-score-circle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: conic-gradient(var(--green) 0%, var(--green) calc(var(--score, 0) * 1%), #E2E8F0 calc(var(--score, 0) * 1%));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

/* ============================================================
   EMAR SPECIFIC
   ============================================================ */
.customer-compact-card {
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-sm) !important;
    transition: box-shadow 0.2s;
}
.customer-compact-card:hover {
    box-shadow: var(--shadow-md) !important;
}
.customer-compact-card .card-header {
    border-radius: var(--radius) var(--radius) 0 0 !important;
}

/* ============================================================
   RECRUITMENT PAGE
   ============================================================ */
.recruitment-card {
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-sm) !important;
    transition: all 0.2s;
}
.recruitment-card:hover {
    box-shadow: var(--shadow-md) !important;
    transform: translateY(-1px);
}

/* ============================================================
   DOCUMENT LIBRARY
   ============================================================ */
.folder-card {
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-sm) !important;
    transition: all 0.2s;
    cursor: pointer;
}
.folder-card:hover {
    border-color: var(--blue) !important;
    box-shadow: var(--shadow-md) !important;
    transform: translateY(-1px);
}

/* ============================================================
   TRAINING MANAGEMENT
   ============================================================ */
.training-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

/* ============================================================
   SUPERVISION
   ============================================================ */
.supervision-card {
    border-left: 4px solid var(--blue) !important;
    border-radius: var(--radius) !important;
}

/* ============================================================
   SETTINGS PAGE
   ============================================================ */
.settings-section {
    padding: 1.5rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
}
.settings-section h5 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.75rem;
    margin-bottom: 1.25rem;
}

/* ============================================================
   BREADCRUMB / PAGE SUBTITLE STRIPS
   ============================================================ */
.section-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 1.5rem 0 1rem;
}
.section-divider h6 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    white-space: nowrap;
    margin: 0;
}
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    opacity: 0.4;
    display: block;
}
.empty-state p { margin: 0; font-size: 14px; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-content {
    border: none !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-md) !important;
}
.modal-header {
    border-bottom: 1px solid var(--border);
    padding: 1.125rem 1.5rem;
}
.modal-footer {
    border-top: 1px solid var(--border);
    padding: 1rem 1.5rem;
}
.modal-title { font-weight: 700; font-size: 1.05rem; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0F172A 0%, #1E3A5F 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    background: white;
    border-radius: 16px;
    padding: 2.5rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 420px;
}
.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}
.login-logo img {
    height: 48px;
    object-fit: contain;
}
.login-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}
.login-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

/* ============================================================
   INLINE FORM ROWS (add-customer, add-staff etc.)
   ============================================================ */
.form-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}
.form-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

/* ============================================================
   ENSURE BOOTSTRAP COLORS USE NEW PALETTE
   ============================================================ */
.text-primary { color: var(--blue) !important; }
.border-primary { border-color: var(--blue) !important; }
.bg-primary { background: var(--blue) !important; }

/* Dashboard gradient badges */
.dashboard-badge { background: var(--blue) !important; color: white !important; }

/* Input group text */
.input-group-text {
    border-color: var(--border);
    background: #FAFBFC;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Focus rings */
*:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

/* Scrollbar (WebKit) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

/* ============================================================
   CUSTOMER PROFILE PAGE
   ============================================================ */

/* Banner */
.cust-banner {
    background: linear-gradient(135deg, #475569 0%, #64748B 100%);
    border-radius: var(--radius-lg);
    padding: 1.75rem 2rem;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.cust-banner::before {
    content: '';
    position: absolute;
    top: -60px; right: -60px;
    width: 200px; height: 200px;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
    pointer-events: none;
}
.cust-banner::after {
    content: '';
    position: absolute;
    bottom: -40px; left: 30%;
    width: 120px; height: 120px;
    border-radius: 50%;
    background: rgba(255,255,255,0.04);
    pointer-events: none;
}

/* Avatar in banner */
.cust-banner-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: 3px solid rgba(255,255,255,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 800;
    color: white;
    backdrop-filter: blur(4px);
    flex-shrink: 0;
    transition: border-color 0.2s;
}
.cust-banner-avatar:hover { border-color: rgba(255,255,255,0.8); }
.cust-banner-photo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(255,255,255,0.5);
    flex-shrink: 0;
}

/* Banner text */
.cust-banner-name {
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    line-height: 1.2;
}
.cust-banner-preferred {
    font-size: 14px;
    color: rgba(255,255,255,0.6);
    font-style: italic;
}
.cust-banner-meta {
    font-size: 12.5px;
    color: rgba(255,255,255,0.65);
}
.cust-banner-meta i { opacity: 0.7; }

/* Status pills */
.cust-status-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
}
.cust-status-pill.active { background: rgba(16,185,129,0.2); color: #34D399; border: 1px solid rgba(52,211,153,0.3); }
.cust-status-pill.high-risk { background: rgba(239,68,68,0.2); color: #FCA5A5; border: 1px solid rgba(252,165,165,0.3); }
.cust-status-pill.warning { background: rgba(245,158,11,0.2); color: #FCD34D; border: 1px solid rgba(252,211,77,0.3); }
.cust-status-pill.secondary { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.7); border: 1px solid rgba(255,255,255,0.2); }

/* ---- In-page profile sidebar nav ---- */
.cust-side-nav {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 8px;
    overflow-y: auto;
    max-height: calc(100vh - 140px);
}
.cust-side-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #0097b2;
    padding: 8px 10px 4px;
    user-select: none;
}
.cust-side-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.12s, color 0.12s;
    margin-bottom: 1px;
    cursor: pointer;
}
.cust-side-link:hover {
    background: var(--border-light);
    color: var(--text-primary);
    text-decoration: none;
}
.cust-side-link.active {
    background: var(--blue-light);
    color: var(--blue);
    font-weight: 600;
}
.cust-side-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}

/* ============================================================
   SIDEBAR — COLORED ICONS (flat dark bg)
   ============================================================ */

/* ============================================================
   FIX: Clip white square corners inside gradient card headers
   The card handles all corner rounding via overflow:hidden.
   Card-headers must NOT have their own border-radius — their
   own curves create transparent cutouts that reveal the white
   card background behind them (the visible white corners).
   ============================================================ */
.card.rounded-4,
.card.rounded-3,
.card:has(.card-header[class*="rounded"]) {
    overflow: hidden;
}

/* Strip border-radius from all card-headers inside rounded
   cards — the parent card's overflow:hidden does the clipping */
.card.rounded-4 .card-header,
.card.rounded-3 .card-header,
.card:has(.card-header[class*="rounded"]) .card-header {
    border-radius: 0 !important;
}

.emar-page-header {
    overflow: hidden;
}

/* ============================================================
   SETTINGS FLYOUT — bottom-of-sidebar popup panel
   ============================================================ */
.settings-flyout {
    flex-shrink: 0;
    padding: 0 10px 6px;
    position: relative;
}

.settings-flyout-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: none;
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.75);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.18s, color 0.18s;
    border: 1px solid rgba(255,255,255,0.07);
}
.settings-flyout-btn:hover,
.settings-flyout-btn[aria-expanded="true"] {
    background: rgba(255,255,255,0.10);
    color: #fff;
}
.settings-flyout-btn-inner {
    display: flex;
    align-items: center;
    gap: 10px;
}
.settings-flyout-cog {
    color: #94A3B8;
    font-size: 14px;
    transition: transform 0.3s;
}
.settings-flyout-btn[aria-expanded="true"] .settings-flyout-cog {
    transform: rotate(60deg);
    color: #0097b2;
}
.settings-flyout-arrow {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
    transition: transform 0.25s;
}
.settings-flyout-btn[aria-expanded="true"] .settings-flyout-arrow {
    transform: rotate(180deg);
    color: rgba(255,255,255,0.7);
}

/* The panel itself */
.settings-flyout-panel {
    background: #0a2030;
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 12px;
    padding: 10px 8px 8px;
    margin-bottom: 6px;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.35);
    max-height: 55vh;
    overflow-y: auto;
}
.settings-flyout-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.35);
    padding: 0 8px 8px;
}
.settings-flyout-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px;
    border-radius: 8px;
    text-decoration: none;
    color: rgba(255,255,255,0.8);
    transition: background 0.15s, color 0.15s;
    margin-bottom: 2px;
}
.settings-flyout-item:hover {
    background: rgba(255,255,255,0.07);
    color: #fff;
    text-decoration: none;
}
.settings-flyout-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}
.settings-flyout-item-title {
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.2;
}
.settings-flyout-item-sub {
    font-size: 10.5px;
    color: rgba(255,255,255,0.4);
    margin-top: 1px;
}


/* ============================
   GLOBAL TABLE RESTYLE
   Remove Bootstrap table borders, apply clean themed look
   ============================ */
.table {
    --bs-table-border-color: transparent;
    --bs-table-striped-bg: transparent;
    border-color: transparent;
}
.table > :not(caption) > * > * {
    border-bottom-width: 0 !important;
    border-top-width: 0 !important;
    border-width: 0 !important;
}
.table > thead > tr > th,
.table > thead > tr > td {
    border: none !important;
    background: #f8fafc;
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-top: 12px;
    padding-bottom: 12px;
}
.table > tbody > tr > td,
.table > tbody > tr > th {
    border: none !important;
    vertical-align: middle;
    padding-top: 13px;
    padding-bottom: 13px;
    color: #334155;
    font-size: 0.875rem;
}
.table > tbody > tr {
    border-bottom: 1px solid #f1f5f9 !important;
}
.table > tbody > tr:last-child {
    border-bottom: none !important;
}
.table-hover > tbody > tr:hover > * {
    background-color: #f8fafc;
}
.table-bordered,
.table-bordered > :not(caption) > * > * {
    border: none !important;
}

/* ============================================================
   MOBILE IMPROVEMENTS — max-width: 767px
   All rules here are mobile-ONLY. Desktop (≥768px) unchanged.
   ============================================================ */

/* ── 1. Profile banner (staff & customer) ─────────────────── */
@media (max-width: 767px) {
    .cust-banner {
        padding: 1.1rem 1.1rem;
    }
    .cust-banner > .d-flex {
        flex-direction: column;
        gap: 0.75rem !important;
        align-items: flex-start !important;
    }
    .cust-banner-avatar,
    .cust-banner-photo {
        width: 56px !important;
        height: 56px !important;
        font-size: 1.3rem !important;
    }
    .cust-banner-name {
        font-size: 1.15rem !important;
    }
    /* Action button row wraps below info */
    .cust-banner .d-flex.gap-2.flex-shrink-0 {
        width: 100%;
        flex-wrap: wrap;
    }
    .cust-banner .d-flex.gap-2.flex-shrink-0 .btn {
        flex: 1;
        min-width: 0;
        text-align: center;
        justify-content: center;
    }
    .cust-banner-meta {
        font-size: 12px;
    }
}

/* ── 2. Profile sidebar → horizontal scrolling pill nav ───── */
@media (max-width: 767px) {
    /* The sidebar column goes full width and sits above content */
    #sidebar-nav.col-lg-3,
    #sidebar-nav.col-md-4 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        padding-right: 0;
        padding-left: 0;
    }

    .cust-side-nav {
        background: #fff;
        border-radius: 10px;
        border: 1px solid var(--border);
        padding: 6px 8px;
        overflow-x: auto;
        overflow-y: hidden;
        max-height: none !important;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        position: static !important;
        margin-bottom: 1rem;
    }
    .cust-side-nav::-webkit-scrollbar { display: none; }

    /* Hide the section label in horizontal mode */
    .cust-side-section-label { display: none; }

    .cust-side-link {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 6px 12px;
        border-radius: 20px;
        margin-bottom: 0;
        font-size: 12.5px;
        gap: 6px;
    }
    .cust-side-link.active {
        background: #0097b2;
        color: #fff !important;
    }
    .cust-side-icon {
        width: 22px;
        height: 22px;
        font-size: 10px;
    }

    /* Profile main content goes full width below the nav */
    .col-lg-9.col-md-8,
    .col-md-8.col-lg-9 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        padding-left: 0;
        padding-right: 0;
    }
}

/* ── 3. Tables — horizontal scroll + compact cells ─────────── */
@media (max-width: 767px) {
    /* Wrap any table that isn't already in a table-responsive */
    .table-section .table,
    .card .table,
    .card-body .table {
        font-size: 0.8rem;
    }
    /* Reduce cell padding so rows fit better on narrow screens */
    .table > thead > tr > th,
    .table > tbody > tr > td,
    .table > tbody > tr > th {
        padding: 9px 8px !important;
    }
    /* Always allow horizontal overflow on table wrappers */
    .table-responsive,
    .table-section {
        -webkit-overflow-scrolling: touch;
    }
    /* Hide less important columns on mobile where templates add d-none d-md-table-cell */
    .d-none-mobile-cell { display: none !important; }
}

/* ── 4. Modals — near full-width on mobile ─────────────────── */
@media (max-width: 767px) {
    .modal-dialog {
        margin: 0.5rem auto;
        max-width: calc(100vw - 1rem) !important;
        width: calc(100vw - 1rem) !important;
    }
    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        max-width: calc(100vw - 1rem) !important;
        width: calc(100vw - 1rem) !important;
    }
    .modal-content {
        border-radius: 16px;
    }
    .modal-body {
        padding: 1rem;
    }
    .modal-header {
        padding: 0.875rem 1rem;
    }
    .modal-footer {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .modal-footer .btn {
        flex: 1;
        min-width: 0;
        justify-content: center;
    }
}

/* ── 5. Page headers — stack title + actions vertically ───── */
@media (max-width: 767px) {
    .page-header {
        gap: 0.625rem !important;
    }
    .page-header h1,
    .page-header h2,
    .page-header .page-title {
        font-size: 1.15rem !important;
    }
    .page-header-actions {
        justify-content: flex-start;
        gap: 0.4rem;
    }
    .page-header-actions .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.75rem;
    }
    /* Overview-style page header */
    .ov-page-header {
        flex-direction: column;
        gap: 0.5rem;
        margin-bottom: 1rem;
    }
    .ov-page-title { font-size: 1.15rem !important; }
}

/* ── 6. Cards — better spacing + no horizontal overflow ───── */
@media (max-width: 767px) {
    .card-body {
        padding: 0.875rem !important;
    }
    .card-header {
        padding: 0.75rem 0.875rem !important;
    }
    /* Cards that use d-flex for split layouts */
    .card-body > .d-flex:not(.flex-column) {
        flex-wrap: wrap;
    }
}

/* ── 7. Buttons & touch targets ───────────────────────────── */
@media (max-width: 767px) {
    .btn:not(.btn-sm):not(.btn-xs) {
        min-height: 40px;
    }
    .btn-sm {
        min-height: 34px;
        font-size: 0.78rem;
    }
}

/* ── 8. Forms — comfortable inputs & labels for touch ──────── */
@media (max-width: 767px) {
    /* Form labels */
    .form-label { font-size: 0.82rem; font-weight: 600; }
    /* Selects and inputs: comfortable height; 16px prevents iOS auto-zoom */
    .form-control, .form-select { font-size: 16px !important; }
    /* Give inputs a touch-friendly height */
    .form-control:not(textarea),
    .form-select {
        min-height: 42px;
    }
}

/* ── 9. Overview / stat cards ─────────────────────────────── */
@media (max-width: 767px) {
    .ov-stat {
        padding: 1rem 1.1rem;
        gap: 0.75rem;
        border-radius: 14px;
    }
    .ov-stat-icon {
        width: 42px;
        height: 42px;
        font-size: 1.1rem;
        border-radius: 10px;
    }
    .ov-stat-val { font-size: 1.6rem; }
    /* Section cards in overview */
    .ov-card { border-radius: 14px; }
    .ov-card-header { padding: 0.875rem 1rem 0.75rem; }
    .ov-row-item { padding: 0.625rem 1rem; }
}

/* ── 10. Care plan review — compact nav + sections ─────────── */
@media (max-width: 767px) {
    /* The left sticky nav in CPR (inside col-lg-3) — same fix as profile */
    .cpr-nav {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 4px;
        padding: 6px;
        position: static !important;
        max-height: none !important;
        margin-bottom: 0.75rem;
    }
    .cpr-nav::-webkit-scrollbar { display: none; }
    .cpr-nav-item {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 5px 12px;
        border-radius: 20px;
        font-size: 12px;
    }
    /* Section headers in CPR */
    .cpr-section-header {
        padding: 0.75rem 1rem !important;
    }
    .cpr-section-body {
        padding: 0.875rem 1rem !important;
    }
    /* Care plan review section numbers */
    .sec-num {
        width: 22px !important;
        height: 22px !important;
        font-size: 10px !important;
    }
}

/* ── 11. Staff profile tabs (below the banner) ─────────────── */
@media (max-width: 767px) {
    /* Nav tabs used in staff profile, customer profile etc */
    .nav-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0;
        border-bottom: 2px solid #E2E8F0;
    }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-tabs .nav-link {
        white-space: nowrap;
        font-size: 12.5px !important;
        padding: 8px 14px !important;
        flex-shrink: 0;
    }
}

/* ── 12. Inline d-flex items with min-width constraints ───── */
@media (max-width: 575px) {
    /* Items that declare a min-width for alignment — relax on very small screens */
    [style*="min-width:120px"],
    [style*="min-width: 120px"],
    [style*="min-width:160px"],
    [style*="min-width: 160px"] {
        min-width: 0 !important;
    }
}

/* ── 13. EMAR / medication tables — better on mobile ───────── */
@media (max-width: 767px) {
    .emar-page-header {
        padding: 1rem !important;
    }
    /* eMar matrix: ensure it scrolls */
    .matrix-table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}

/* ── 14. Content area general — reduce spacing on small screens */
@media (max-width: 767px) {
    .page-content {
        padding: 0.875rem 0.75rem !important;
    }
    /* Flash messages align with the reduced padding */
    .flash-area {
        padding: 0.5rem 0.75rem 0 !important;
    }
    /* Row gutter reduction on very small screens */
    .row.g-4 { --bs-gutter-x: 0.75rem; --bs-gutter-y: 0.75rem; }
    .row.g-3 { --bs-gutter-x: 0.625rem; --bs-gutter-y: 0.625rem; }
}

/* ── 15. Topbar on mobile — cleaner ─────────────────────────── */
@media (max-width: 767px) {
    .topbar {
        padding: 0 0.75rem !important;
    }
    /* Dropdown menus — constrain to viewport */
    .dropdown-menu {
        max-width: calc(100vw - 1.5rem);
    }
}

/* ── 16. Table-responsive guard — wrap any naked table ──────── */
@media (max-width: 767px) {
    /* If a table is NOT inside a .table-responsive, make its parent scroll */
    .card-body:has(.table):not(:has(.table-responsive)) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================================
   MOBILE LIST CARDS — customers.html / workforce.html
   ============================================================ */
.mobile-list-card {
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 12px;
    padding: 0.875rem 1rem;
    margin-bottom: 0.625rem;
    transition: box-shadow 0.15s;
}
.mobile-list-card:last-child { margin-bottom: 0; }
.mobile-list-card:active { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }

.mobile-list-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0097b2 0%, #005f73 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: 0.03em;
}

/* ============================================================
   SIDEBAR NAV MOBILE OVERRIDE — stronger specificity
   Make the profile sidebar a horizontal pill bar on mobile
   ============================================================ */
@media (max-width: 767px) {
    #sidebar-nav {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        width: 100% !important;
        padding-right: calc(var(--bs-gutter-x) * 0.5);
        padding-left: calc(var(--bs-gutter-x) * 0.5);
    }
    #sidebar-nav .cust-side-nav {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        max-height: none !important;
        position: static !important;
        padding: 6px 6px !important;
        gap: 4px !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin-bottom: 1rem !important;
    }
    #sidebar-nav .cust-side-nav::-webkit-scrollbar { display: none; }
    #sidebar-nav .cust-side-section-label { display: none !important; }
    #sidebar-nav .cust-side-link {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        padding: 6px 14px !important;
        border-radius: 20px !important;
        margin-bottom: 0 !important;
        font-size: 12.5px !important;
        gap: 6px !important;
    }
    #sidebar-nav .cust-side-link.active {
        background: #0097b2 !important;
        color: #fff !important;
    }
    #sidebar-nav .cust-side-link.active .cust-side-icon {
        background: rgba(255,255,255,0.2) !important;
        color: #fff !important;
    }
    #sidebar-nav .cust-side-icon {
        width: 20px !important;
        height: 20px !important;
        font-size: 9px !important;
    }
}
