/* ============================================================
   DocBag.ai (Qinect MED) — Main Stylesheet
   Brand: Teal #0F9590 (doctor's bag) | Dark navy #0E1A2C (wordmark)
   View tints: Doctor=Teal | Intake Specialist=Plum | Patient=Amber
   Mobile-first: hamburger sidebar < 900px; bottom-safe touch targets
============================================================ */

:root {
    /* Brand */
    --color-dark:        #0E1A2C;
    --color-dark-light:  #162739;
    --color-dark-hover:  #1c2f44;
    --color-teal:        #0F9590;
    --color-teal-dark:   #0c7a76;
    --color-teal-light:  #1eaaa3;
    --color-teal-fade:   rgba(15, 149, 144, 0.12);
    --color-plum:        #8B5CF6;
    --color-plum-dark:   #6e44d0;
    --color-plum-fade:   rgba(139, 92, 246, 0.12);
    --color-amber:       #F59E0B;
    --color-amber-dark:  #c87f06;
    --color-amber-fade:  rgba(245, 158, 11, 0.14);
    --color-slate:       #475569;
    --color-slate-dark:  #334155;
    --color-slate-fade:  rgba(71, 85, 105, 0.12);
    --color-white:       #ffffff;
    --color-bg:          #f3f6f8;
    --color-surface:     #ffffff;
    --color-border:      #e2e7eb;
    --color-border-light:#eef2f5;
    --color-text:        #0E1A2C;
    --color-text-muted:  #5d6c7a;
    --color-text-light:  #94a3b1;
    --color-success:     #22c55e;
    --color-warning:     #f59e0b;
    --color-danger:      #ef4444;
    --color-info:        #3b82f6;

    /* Active view tint — overridden by body.view-* below */
    --color-primary:      var(--color-teal);
    --color-primary-dark: var(--color-teal-dark);
    --color-primary-fade: var(--color-teal-fade);
    --view-name:          'Doctor';

    --sidebar-width:     260px;
    --header-height:     60px;
    --border-radius:     10px;
    --border-radius-sm:  6px;
    --border-radius-lg:  16px;
    --shadow-sm: 0 1px 3px rgba(14,26,44,0.06), 0 1px 2px rgba(14,26,44,0.04);
    --shadow-md: 0 4px 12px rgba(14,26,44,0.08), 0 2px 6px rgba(14,26,44,0.05);
    --shadow-lg: 0 10px 30px rgba(14,26,44,0.12), 0 4px 10px rgba(14,26,44,0.06);
    --transition: 0.2s ease;
}

/* === View tinting (per active interface) === */
/* Admin view also tints the page background so it's instantly
   distinguishable from the clinical views even when no widgets
   are on screen. Cooler / slightly darker neutral. */
body.view-admin {
    --color-primary:      var(--color-slate);
    --color-primary-dark: var(--color-slate-dark);
    --color-primary-fade: var(--color-slate-fade);
    --color-bg:           #e7ecf2;
    --view-name:          'Admin';
}
body.view-doctor {
    --color-primary:      var(--color-teal);
    --color-primary-dark: var(--color-teal-dark);
    --color-primary-fade: var(--color-teal-fade);
    --view-name:          'Doctor';
}
body.view-nurse {
    --color-primary:      var(--color-plum);
    --color-primary-dark: var(--color-plum-dark);
    --color-primary-fade: var(--color-plum-fade);
    --view-name:          'Intake Specialist';
}
body.view-patient {
    --color-primary:      var(--color-amber);
    --color-primary-dark: var(--color-amber-dark);
    --color-primary-fade: var(--color-amber-fade);
    --view-name:          'Patient';
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}
a { color: var(--color-primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--color-primary-dark); }
img { max-width: 100%; display: block; }
button { font-family: inherit; }

/* === Layout === */
.layout-wrapper { display: flex; min-height: 100vh; min-height: 100dvh; }

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--color-dark);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 200;
    transition: transform var(--transition);
    overflow: hidden;
}

.sidebar-header {
    padding: 18px 16px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--color-white);
}

.sidebar-logo img {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: var(--color-white);
    border-radius: 8px;
    padding: 2px;
}

.sidebar-logo-text {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--color-white);
}
.sidebar-logo-text .accent { color: var(--color-teal-light); }

/* === View pill (shown in sidebar header for switchable users) === */
.view-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--color-primary-fade);
    color: var(--color-primary);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 10px;
}
.view-pill::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-primary);
}

/* === View switcher (segmented, in sidebar) === */
/* 4 segments must fit on one line at 260px sidebar width.
   Available cell ~58px. Labels: Admin/Doctor/Intake Specialist/Patient. */
.view-switcher {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 2px;
    margin: 12px 10px 6px;
    background: rgba(255,255,255,0.06);
    padding: 2px;
    border-radius: 10px;
}
.view-switcher-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 6px 2px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.7);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.15;
    border-radius: 7px;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    /* Allow longer labels (e.g. "Intake Specialist") to wrap rather than
       truncate; the grid keeps all four tabs the same height. */
    white-space: normal;
    overflow-wrap: anywhere;
    min-width: 0;
}
.view-switcher-btn:hover { color: var(--color-white); background: rgba(255,255,255,0.06); }
.view-switcher-btn.active {
    background: var(--color-primary);
    color: var(--color-white);
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

/* === Sidebar navigation === */
.sidebar-section-label {
    padding: 18px 16px 6px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.35);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px 0 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 0.925rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
    overflow: hidden;
}
.nav-item:hover {
    color: var(--color-white);
    background: rgba(255,255,255,0.06);
    border-left-color: rgba(255,255,255,0.2);
}
.nav-item.active {
    color: var(--color-white);
    background: var(--color-primary-fade);
    border-left-color: var(--color-primary);
}
.nav-item.nav-soon { opacity: 0.5; cursor: default; }

.nav-icon {
    width: 20px; height: 20px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.nav-icon svg { width: 18px; height: 18px; }
.nav-label { flex: 1; }

.nav-badge-soon {
    font-size: 0.62rem;
    font-weight: 700;
    background: rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.55);
    padding: 2px 7px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* === Sidebar footer === */
.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 12px 16px;
    flex-shrink: 0;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-user-avatar { flex-shrink: 0; }
.sidebar-user-info {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.sidebar-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-white);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.55);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-logout-btn {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    color: rgba(255,255,255,0.5);
    border-radius: var(--border-radius-sm);
    transition: all var(--transition);
    flex-shrink: 0;
    text-decoration: none;
}
.sidebar-logout-btn:hover { color: var(--color-white); background: rgba(255,255,255,0.1); }
.sidebar-logout-btn svg { width: 18px; height: 18px; }

/* === Mobile sidebar overlay === */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(14,26,44,0.55);
    z-index: 190;
    backdrop-filter: blur(2px);
}

/* === Main wrapper === */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    transition: margin-left var(--transition);
}

/* === Top header === */
.top-header {
    height: var(--header-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    border-top: 3px solid var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}
.top-header-left {
    display: flex; align-items: center; gap: 14px;
    min-width: 0;
}
.page-heading {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-header-right {
    display: flex; align-items: center; gap: 12px;
    flex-shrink: 0;
}

/* Hamburger */
.hamburger-btn {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--border-radius-sm);
    transition: background var(--transition);
    flex-shrink: 0;
}
.hamburger-btn:hover { background: var(--color-bg); }
.hamburger-btn span {
    display: block;
    width: 22px; height: 2px;
    background: var(--color-text);
    border-radius: 2px;
    transition: all var(--transition);
}

/* User menu */
.header-user-menu { position: relative; }
.header-user-btn {
    display: flex; align-items: center; gap: 8px;
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 50px;
    padding: 4px 12px 4px 4px;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--color-text);
}
.header-user-btn:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-fade);
}
.header-user-name {
    font-size: 0.875rem;
    font-weight: 500;
}
.header-user-chevron {
    width: 14px; height: 14px;
    transition: transform var(--transition);
}
.header-user-dropdown {
    position: absolute;
    top: calc(100% + 8px); right: 0;
    min-width: 230px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    display: none;
    overflow: hidden;
    z-index: 300;
}
.header-user-dropdown.open {
    display: block;
    animation: dropdownIn 0.15s ease;
}
@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.dropdown-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border);
    display: flex; flex-direction: column; gap: 2px;
}
.dropdown-header strong { font-size: 0.875rem; color: var(--color-text); }
.dropdown-header span   { font-size: 0.8rem;   color: var(--color-text-muted); }
.dropdown-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px;
    font-size: 0.875rem;
    color: var(--color-text);
    text-decoration: none;
    transition: background var(--transition);
}
.dropdown-item:hover { background: var(--color-bg); color: var(--color-text); }
.dropdown-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.dropdown-item-danger { color: var(--color-danger); }
.dropdown-item-danger:hover { background: rgba(239,68,68,0.06); color: var(--color-danger); }

/* === Content === */
.content { flex: 1; padding: 0; }
.content-inner {
    padding: 26px 26px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* === Welcome banner (dashboard) === */
.welcome-banner {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: var(--color-white);
    padding: 26px 28px;
    border-radius: var(--border-radius-lg);
    margin-bottom: 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}
.welcome-banner::after {
    content: '';
    position: absolute;
    right: -40px; top: -40px;
    width: 200px; height: 200px;
    background: radial-gradient(circle at center, rgba(255,255,255,0.15) 0%, transparent 70%);
    pointer-events: none;
}
.welcome-text h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.01em;
}
.welcome-text p {
    font-size: 0.95rem;
    opacity: 0.9;
    margin: 0;
}
.welcome-badge {
    background: rgba(255,255,255,0.18);
    color: var(--color-white);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 6px 12px;
    border-radius: 20px;
    backdrop-filter: blur(4px);
    flex-shrink: 0;
    z-index: 1;
}

/* === Cards === */
.card {
    background: var(--color-surface);
    border-radius: var(--border-radius);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.card-title { font-size: 1rem; font-weight: 600; color: var(--color-text); }
.card-body { padding: 20px; }
.card-body-flush { padding: 0; }
.card-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
}

/* === Stats grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.stat-card {
    background: var(--color-surface);
    border-radius: var(--border-radius);
    border: 1px solid var(--color-border);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), transform var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-icon {
    width: 44px; height: 44px;
    border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon-primary { background: var(--color-primary-fade); color: var(--color-primary); }
.stat-icon-teal    { background: var(--color-teal-fade);    color: var(--color-teal); }
.stat-icon-plum    { background: var(--color-plum-fade);    color: var(--color-plum); }
.stat-icon-amber   { background: var(--color-amber-fade);   color: var(--color-amber-dark); }
.stat-icon-success { background: rgba(34,197,94,0.12);      color: var(--color-success); }
.stat-icon-info    { background: rgba(59,130,246,0.12);     color: var(--color-info); }
.stat-info { min-width: 0; flex: 1; }
.stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1;
    margin-bottom: 4px;
}
.stat-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 18px;
    border-radius: var(--border-radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
    min-height: 40px;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary {
    background: var(--color-primary);
    color: var(--color-white);
    border-color: var(--color-primary);
}
.btn-primary:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
    color: var(--color-white);
}
.btn-secondary {
    background: transparent;
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover {
    background: var(--color-bg);
    border-color: var(--color-text-muted);
}
.btn-danger {
    background: var(--color-danger);
    color: var(--color-white);
    border-color: var(--color-danger);
}
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; min-height: 32px; }
.btn-sm svg { width: 14px; height: 14px; }

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 6px;
}
.form-label .required { color: var(--color-danger); margin-left: 3px; }
.form-control {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    font-size: 0.95rem;
    color: var(--color-text);
    background: var(--color-white);
    transition: border-color var(--transition), box-shadow var(--transition);
    line-height: 1.5;
    appearance: none;
    -webkit-appearance: none;
}
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-fade);
}
.form-control::placeholder { color: var(--color-text-light); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.form-hint { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 5px; }

/* === Badges === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.74rem;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.4;
}
.badge-ultra        { background: rgba(14,26,44,0.85);     color: #fff; }
.badge-clinic-super { background: rgba(15,149,144,0.14);   color: var(--color-teal-dark); }
.badge-doctor       { background: rgba(15,149,144,0.14);   color: var(--color-teal-dark); }
.badge-nurse        { background: rgba(139,92,246,0.14);   color: var(--color-plum-dark); }
.badge-patient      { background: rgba(245,158,11,0.16);   color: var(--color-amber-dark); }
.badge-active       { background: rgba(34,197,94,0.12);    color: #15803d; }
.badge-inactive     { background: rgba(156,163,175,0.15);  color: #6b7280; }
.badge-suspended    { background: rgba(239,68,68,0.12);    color: var(--color-danger); }
.badge-default      { background: var(--color-bg);         color: var(--color-text-muted); }

/* Clinical condition severity */
.badge-severity-mild     { background: rgba(34,197,94,0.12);  color: #15803d; }
.badge-severity-moderate { background: rgba(245,158,11,0.14); color: #b45309; }
.badge-severity-severe   { background: rgba(239,68,68,0.12);  color: #b91c1c; }

/* Device connection indicator (vitals form) — small status pill
   with a filled dot. When real device detection lands, swap the
   class on a per-field basis. */
.device-status {
    font-size: 0.7rem;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}
.device-not-connected { color: #2563eb; }   /* blue — manual entry */
.device-connected     { color: #16a34a; }   /* green — auto from device */

/* === Alerts === */
.alert {
    padding: 12px 16px;
    border-radius: var(--border-radius-sm);
    margin-bottom: 18px;
    font-size: 0.9rem;
}
.alert-success { background: rgba(34,197,94,0.1);  color: #15803d; border: 1px solid rgba(34,197,94,0.25); }
.alert-error   { background: rgba(239,68,68,0.1);  color: #b91c1c; border: 1px solid rgba(239,68,68,0.25); }
.alert-warning { background: rgba(245,158,11,0.1); color: #b45309; border: 1px solid rgba(245,158,11,0.25); }
.alert-info    { background: rgba(59,130,246,0.1); color: #1d4ed8; border: 1px solid rgba(59,130,246,0.25); }

/* === Avatar + Clinic logo === */
.avatar-img,
.clinic-logo-img { border-radius: 50%; object-fit: cover; }
.avatar-initials,
.clinic-logo-initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-white);
    font-weight: 600;
    flex-shrink: 0;
}

/* === Image uploader widget === */
.img-uploader {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.img-uploader .img-preview {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.img-uploader .img-preview img { width: 100%; height: 100%; object-fit: cover; }
.img-uploader .img-preview .initials-fallback {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--color-text-muted);
    letter-spacing: 0.02em;
}
.img-uploader .img-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}
.img-uploader .img-actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.img-uploader .img-status {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    min-height: 1.2em;
}

/* === Empty state === */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 40px 20px;
}
.empty-state svg {
    width: 48px; height: 48px;
    color: var(--color-border);
    margin-bottom: 14px;
}
.empty-state-title  { font-size: 1rem;   font-weight: 600; color: var(--color-text-muted); margin-bottom: 6px; }
.empty-state-text   { font-size: 0.875rem; color: var(--color-text-light); margin-bottom: 16px; }

/* === Tables === */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th {
    text-align: left;
    padding: 11px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
    background: var(--color-bg);
}
.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border-light);
    color: var(--color-text);
    vertical-align: middle;
}
.table tbody tr:hover { background: var(--color-bg); }
.table tbody tr:last-child td { border-bottom: none; }

/* === Key/value detail grids (responsive) ===
   Two-column label/value list; .detail-grid-2 doubles up to four
   columns on wider screens. Collapses to a single column on phones. */
.detail-grid {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 8px 18px;
    align-items: center;
}
.detail-grid-2 { grid-template-columns: 150px 1fr 150px 1fr; }
/* Long unbroken values (UUIDs, codes) wrap instead of overflowing a card */
.detail-value code,
.table td code { overflow-wrap: anywhere; }

/* === Field grids (form inputs side by side, mobile-first) ===
   Stacks on phones; lays out on wider screens. */
.field-grid { display: grid; gap: 14px; }
@media (min-width: 560px) {
    .field-grid-3        { grid-template-columns: 140px 1fr 1fr; }
    .field-grid-title-2  { grid-template-columns: 140px 1fr; }
}

/* === Utilities === */
.text-muted { color: var(--color-text-muted); }
.text-small { font-size: 0.825rem; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

/* ============================================================
   Responsive — Tablet & Mobile
============================================================ */

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); width: var(--sidebar-width); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-overlay.open { display: block; }
    .main-wrapper { margin-left: 0; }
    .hamburger-btn { display: flex; }
    .content-inner { padding: 18px 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .top-header { padding: 0 16px; }
    .welcome-banner { flex-direction: column; align-items: flex-start; padding: 22px 20px; }
    .welcome-text h2 { font-size: 1.25rem; }
    .welcome-text p  { font-size: 0.875rem; }
}

@media (max-width: 600px) {
    .content-inner { padding: 14px 12px; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .stat-card  { padding: 14px 14px; }
    .stat-value { font-size: 1.35rem; }
    .stat-label { font-size: 0.72rem; }
    .stat-icon  { width: 36px; height: 36px; }
    .stat-icon svg { width: 18px; height: 18px; }
    .card-header { padding: 14px 16px; }
    .card-body   { padding: 16px; }
    .header-user-name { display: none; }
    .page-heading     { font-size: 0.95rem; }
    .top-header       { padding: 0 12px; }
}

@media (max-width: 400px) {
    .stats-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   Responsive — phone tables + detail grids (vertical screens)
   Tables become stacked, labelled cards so nothing needs sideways
   scrolling. Opt a dense numeric table out with .table-flat.
============================================================ */
@media (max-width: 640px) {
    /* --- Stack table rows into cards --- */
    .table:not(.table-flat) thead {
        position: absolute;
        width: 1px; height: 1px;
        padding: 0; margin: -1px;
        overflow: hidden; clip: rect(0, 0, 0, 0);
        white-space: nowrap; border: 0;
    }
    .table:not(.table-flat),
    .table:not(.table-flat) tbody,
    .table:not(.table-flat) tr,
    .table:not(.table-flat) td { display: block; width: 100%; }

    .table:not(.table-flat) tr {
        border: 1px solid var(--color-border);
        border-radius: var(--border-radius-sm);
        margin-bottom: 12px;
        background: var(--color-white);
        overflow: hidden;
    }
    .table:not(.table-flat) tbody tr:last-child { margin-bottom: 0; }
    .table:not(.table-flat) tbody tr:hover { background: var(--color-white); }

    .table:not(.table-flat) td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 14px;
        padding: 9px 14px;
        text-align: right;
        border-bottom: 1px solid var(--color-border-light);
        white-space: normal;
    }
    .table:not(.table-flat) tr td:last-child { border-bottom: none; }

    /* Label from the cell's data-label attribute */
    .table:not(.table-flat) td::before {
        content: attr(data-label);
        font-size: 0.72rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--color-text-muted);
        text-align: left;
        flex: 0 0 auto;
        white-space: nowrap;
    }

    /* Primary cell (avatar + name) — full-width banner, no label */
    .table:not(.table-flat) td.cell-primary {
        justify-content: flex-start;
        text-align: left;
        background: var(--color-bg);
        border-bottom: 1px solid var(--color-border);
    }
    .table:not(.table-flat) td.cell-primary::before { content: none; }

    /* Actions cell (e.g. Edit) — button spans the card width */
    .table:not(.table-flat) td.cell-actions::before { content: none; }
    .table:not(.table-flat) td.cell-actions { padding: 12px 14px; }
    .table:not(.table-flat) td.cell-actions .btn { width: 100%; }

    /* A dense numeric table that keeps its grid still scrolls sideways */
    .table-flat { white-space: nowrap; }

    /* --- Detail grids collapse to one column --- */
    .detail-grid,
    .detail-grid-2 { grid-template-columns: 1fr; gap: 0; }
    .detail-grid .detail-label {
        margin-top: 12px;
        font-size: 0.78rem;
        color: var(--color-text-muted);
    }
    .detail-grid .detail-label:first-child { margin-top: 0; }
    .detail-grid .detail-value { padding-bottom: 8px; }
}

/* Four-column detail grids drop to two columns on small tablets */
@media (min-width: 641px) and (max-width: 760px) {
    .detail-grid-2 { grid-template-columns: 140px 1fr; }
}

/* === Safe-area for iOS (notch / home indicator) === */
@supports (padding: env(safe-area-inset-bottom)) {
    .sidebar-footer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
    .content-inner  { padding-bottom: calc(26px + env(safe-area-inset-bottom)); }
}
