/* ==============================================================================
   TIFA MIS — Design System & Light Theme
   Maternal Health & Pediatric TB Integration
   ============================================================================== */

/* ---------- Design Tokens ---------- */
:root {
    /* Canvas */
    --bg-canvas: #f5f7fa;
    --bg-card: #ffffff;
    --bg-subtle: #f0f3f7;
    --bg-hover: #e8ecf2;
    --bg-active: #dfe4ec;

    /* Primary — Teal (healthcare) */
    --primary-50: #f0fdfa;
    --primary-100: #ccfbf1;
    --primary-200: #99f6e4;
    --primary-300: #5eead4;
    --primary-400: #2dd4bf;
    --primary-500: #14b8a6;
    --primary-600: #0d9488;
    --primary-700: #0f766e;
    --primary-800: #115e59;
    --primary-900: #134e4a;

    /* Accent — Blue */
    --accent-50: #eff6ff;
    --accent-100: #dbeafe;
    --accent-500: #3b82f6;
    --accent-600: #2563eb;
    --accent-700: #1d4ed8;

    /* Semantic */
    --success-50: #f0fdf4;
    --success-100: #dcfce7;
    --success-500: #22c55e;
    --success-600: #16a34a;
    --success-700: #15803d;

    --warning-50: #fffbeb;
    --warning-100: #fef3c7;
    --warning-500: #f59e0b;
    --warning-600: #d97706;

    --danger-50: #fef2f2;
    --danger-100: #fee2e2;
    --danger-500: #ef4444;
    --danger-600: #dc2626;

    --info-50: #f0f9ff;
    --info-500: #0ea5e9;
    --info-600: #0284c7;

    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-disabled: #cbd5e1;
    --text-inverse: #ffffff;

    /* Borders */
    --border-light: #e2e8f0;
    --border-medium: #cbd5e1;
    --border-strong: #94a3b8;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -4px rgba(0, 0, 0, 0.03);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

    /* Typography */
    --font-sans: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-display: 'Outfit', var(--font-sans);
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Spacing */
    --space-0: 0;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
    --duration-fast: 150ms;
    --duration-normal: 200ms;
    --duration-slow: 300ms;

    /* Layout */
    --sidebar-width: 200px;
    --sidebar-collapsed: 60px;
    --topbar-height: 56px;
    --bottombar-height: 60px;
}

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

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

body {
    font-family: var(--font-sans);
    background: var(--bg-canvas);
    color: var(--text-secondary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

img {
    max-width: 100%;
    display: block;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
    cursor: pointer;
}

input,
select,
textarea {
    font-family: inherit;
}

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

.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transform: translateZ(0);
    will-change: transform;
    transition: transform var(--duration-slow) var(--ease-out);
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-topbar,
.mobile-topbar,
.sidebar-close-btn {
    display: none !important;
}

.mobile-sidebar-btn {
    display: none;
}

.app-content {
    flex: 1;
    padding: 10px 20px 8px 20px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* ---------- Sidebar ---------- */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-light);
    min-height: var(--topbar-height);
}

.sidebar-brand img {
    height: 24px;
    object-fit: contain;
}

.sidebar-brand-text {
    flex: 1;
    min-width: 0;
}

.sidebar-brand-text h2 {
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary-700);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-brand-text p {
    font-size: 0.62rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.sidebar-nav {
    flex: 1;
    padding: 4px 5px;
    overflow-y: auto;
}

.sidebar-section-label {
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 4px 6px 2px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 6px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 500;
    transition: background-color var(--duration-fast) ease, color var(--duration-fast) ease, border-color var(--duration-fast) ease;
    margin-bottom: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1.5px solid transparent;
}

.sidebar-link:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

.sidebar-link.active {
    background: var(--primary-50);
    color: var(--primary-700);
    font-weight: 600;
    border: 1.5px solid var(--primary-500, #0d9488);
}

.sidebar-link .nav-icon {
    flex-shrink: 0;
    width: 18px;
    text-align: center;
    font-size: 0.95rem;
}

.nav-icon-bubble {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 5px;
    margin-right: 5px;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.nav-icon-bubble svg {
    width: 14px;
    height: 14px;
}

.nav-icon-bubble.tint-teal {
    background: rgba(13, 148, 136, 0.12);
    color: #0d9488;
}

.nav-icon-bubble.tint-blue {
    background: rgba(37, 99, 235, 0.12);
    color: #2563eb;
}

.nav-icon-bubble.tint-amber {
    background: rgba(245, 158, 11, 0.14);
    color: #d97706;
}

.nav-icon-bubble.tint-purple {
    background: rgba(147, 51, 234, 0.12);
    color: #9333ea;
}

.nav-icon-bubble.tint-indigo {
    background: rgba(79, 70, 229, 0.12);
    color: #4f46e5;
}

.nav-icon-bubble.tint-emerald {
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
}

.nav-icon-bubble.tint-rose {
    background: rgba(225, 29, 72, 0.12);
    color: #e11d48;
}

.sidebar-link .nav-badge {
    margin-left: auto;
    font-size: 0.65rem;
    font-weight: 700;
    background: var(--primary-100);
    color: var(--primary-700);
    padding: 1px 6px;
    border-radius: var(--radius-full);
}

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

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: var(--radius-md);
    transition: background var(--duration-fast);
}

.sidebar-user:hover {
    background: var(--bg-subtle);
}

.sidebar-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--primary-100);
    color: var(--primary-700);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.sidebar-user-role {
    font-size: 0.68rem;
    color: var(--text-muted);
    line-height: 1.2;
    text-transform: capitalize;
}

.sidebar-logout-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid transparent;
    color: var(--danger-600);
    cursor: pointer;
    transition: all var(--duration-fast);
    padding: 0;
    flex-shrink: 0;
    margin-left: auto;
}

.sidebar-logout-btn:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #b91c1c;
    transform: scale(1.08);
}

.sidebar-logout-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

/* ---------- Topbar ---------- */
.topbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.topbar-breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.82rem;
    color: var(--text-muted);
}

.topbar-breadcrumb .current {
    color: var(--text-primary);
    font-weight: 600;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    transition: all var(--duration-fast);
}

.topbar-btn:hover {
    background: var(--bg-subtle);
    border-color: var(--border-medium);
}

.topbar-status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: var(--radius-full);
}

.topbar-status.online {
    background: var(--success-50);
    color: var(--success-600);
    border: 1px solid var(--success-100);
}

.topbar-status.offline {
    background: var(--warning-50);
    color: var(--warning-600);
    border: 1px solid var(--warning-100);
}

.topbar-status .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.sidebar-toggle {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    background: var(--bg-card);
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
}

/* ---------- Page Header ---------- */
.page-header {
    position: sticky;
    top: 0;
    z-index: 35;
    background: var(--bg-canvas);
    padding-top: 4px;
    padding-bottom: 4px;
    margin-top: -4px;
    margin-bottom: 6px;
}

.page-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    line-height: 1.2;
    margin: 0;
}

.page-subtitle {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--duration-normal);
}

.card:hover {
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-light);
}

.card-title {
    font-family: var(--font-display);
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.card-body {
    padding: var(--space-5);
}

.card-footer {
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border-light);
    background: var(--bg-subtle);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ---------- KPI Cards ---------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    box-shadow: var(--shadow-xs);
    transform: translateZ(0);
    will-change: transform, box-shadow;
    transition: transform var(--duration-normal) ease, box-shadow var(--duration-normal) ease;
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.kpi-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-1);
}

.kpi-value {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
}

.kpi-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: var(--space-1);
}

.kpi-card.accent-teal {
    border-top: 3px solid var(--primary-500);
}

.kpi-card.accent-blue {
    border-top: 3px solid var(--accent-500);
}

.kpi-card.accent-green {
    border-top: 3px solid var(--success-500);
}

.kpi-card.accent-amber {
    border-top: 3px solid var(--warning-500);
}

.kpi-card.accent-purple {
    border-top: 3px solid #8b5cf6;
}

.kpi-card.accent-rose {
    border-top: 3px solid #e11d48;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transform: translateZ(0);
    will-change: transform, background-color, box-shadow;
    transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease, color var(--duration-fast) ease, box-shadow var(--duration-fast) ease, transform var(--duration-fast) ease;
    white-space: nowrap;
    line-height: 1.4;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-600);
    color: var(--text-inverse);
    border-color: var(--primary-600);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-700);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-secondary);
    border-color: var(--border-medium);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger-50);
    color: var(--danger-600);
    border-color: var(--danger-100);
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-100);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
    background: var(--bg-subtle);
}

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: 0.75rem;
}

.btn-xs {
    padding: 2px 6px;
    font-size: 0.7rem;
    line-height: 1.2;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: var(--space-3) var(--space-6);
    font-size: 0.9rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
}

.btn-round-add {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
    color: #ffffff !important;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 800;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.38);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    flex-shrink: 0;
    text-decoration: none;
    line-height: 1;
}

.btn-round-add:hover {
    background: linear-gradient(135deg, #0f766e 0%, #115e59 100%);
    color: #ffffff !important;
    transform: scale(1.08) translateY(-1px);
    box-shadow: 0 6px 18px rgba(13, 148, 136, 0.52);
}

.btn-round-add:active {
    transform: scale(0.95);
}

.btn-round-add svg {
    width: 20px;
    height: 20px;
    stroke: #ffffff;
    stroke-width: 2.8;
}

.btn-round-export {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-radius: 50% !important;
    background: #ffffff;
    color: var(--text-secondary, #475569) !important;
    border: 1px solid var(--border-medium, #cbd5e1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    flex-shrink: 0;
    text-decoration: none;
    line-height: 1;
}

.btn-round-export:hover {
    background: #f1f5f9;
    color: var(--primary-700, #0f766e) !important;
    border-color: var(--primary-500, #14b8a6);
    transform: scale(1.08) translateY(-1px);
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.2);
}

.btn-round-export:active {
    transform: scale(0.95);
}

.btn-round-export svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2.2;
}

.btn-round-search {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-radius: 50% !important;
    background: #ffffff;
    color: var(--text-secondary, #475569) !important;
    border: 1px solid var(--border-medium, #cbd5e1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    flex-shrink: 0;
    text-decoration: none;
    line-height: 1;
}

.btn-round-search:hover,
.btn-round-search.active {
    background: #f1f5f9;
    color: var(--primary-700, #0f766e) !important;
    border-color: var(--primary-500, #14b8a6);
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.2);
}

.btn-round-search:active {
    transform: scale(0.95);
}

.btn-round-search svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2.2;
}

.btn-round-reset {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: #ffffff !important;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.35);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    flex-shrink: 0;
    text-decoration: none;
    line-height: 1;
}

.btn-round-reset:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: #ffffff !important;
    transform: scale(1.1) translateY(-1px);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.5);
}

.btn-round-reset:active {
    transform: scale(0.95);
}

.btn-round-reset svg {
    width: 16px;
    height: 16px;
    stroke: #ffffff;
    stroke-width: 2.2;
}

.btn-round-refresh {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff !important;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.38);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    flex-shrink: 0;
    text-decoration: none;
    line-height: 1;
}

.btn-round-refresh:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    color: #ffffff !important;
    transform: scale(1.08) translateY(-1px);
    box-shadow: 0 5px 16px rgba(16, 185, 129, 0.5);
}

.btn-round-refresh:active {
    transform: scale(0.95);
}

.btn-round-refresh svg {
    width: 18px;
    height: 18px;
    stroke: #ffffff;
    stroke-width: 2.2;
}

/* Expandable search bar that collapses out of view by default */
.expandable-search-bar {
    display: none;
    margin-bottom: 12px;
    animation: expandSearch 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.expandable-search-bar.is-open {
    display: flex;
    align-items: center;
    gap: 8px;
}

@keyframes expandSearch {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.expandable-search-bar .search-input-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.expandable-search-bar .search-input-wrapper input {
    width: 100%;
    height: 38px;
    padding: 0 36px 0 36px;
    border-radius: 20px;
    border: 1px solid var(--border-medium, #cbd5e1);
    background: #ffffff;
    font-size: 0.88rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    outline: none;
    transition: all 0.2s;
}

.expandable-search-bar .search-input-wrapper input:focus {
    border-color: var(--primary-600, #0d9488);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.expandable-search-bar .search-input-wrapper .search-icon-inside {
    position: absolute;
    left: 12px;
    color: var(--text-muted, #94a3b8);
    pointer-events: none;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
}

.expandable-search-bar .search-input-wrapper .search-clear-btn {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.expandable-search-bar .search-close-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-medium, #cbd5e1);
    background: #ffffff;
    color: var(--text-secondary, #64748b);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.expandable-search-bar .search-close-btn:hover {
    background: #f8fafc;
    color: var(--danger-600, #dc2626);
    border-color: var(--danger-300, #fca5a5);
}

/* ---------- Forms ---------- */
.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
}

.form-label .required {
    color: var(--danger-500);
    margin-left: 2px;
}

.form-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: var(--space-1);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.85rem;
    line-height: 1.5;
    outline: none;
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.12);
}

.form-input:disabled,
.form-select:disabled {
    background: var(--bg-subtle);
    color: var(--text-muted);
    cursor: not-allowed;
}

.form-input.error,
.form-select.error {
    border-color: var(--danger-500);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-textarea {
    min-height: 80px;
    resize: vertical;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    cursor: pointer;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
}

.form-checkbox-group,
.form-radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.form-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-full);
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--duration-fast);
    user-select: none;
}

.form-chip:hover {
    border-color: var(--border-medium);
    background: var(--bg-subtle);
}

.form-chip.selected {
    background: var(--primary-50);
    border-color: var(--primary-400);
    color: var(--primary-700);
    font-weight: 600;
}

.form-chip input[type="checkbox"],
.form-chip input[type="radio"] {
    display: none;
}

/* Conditional field animation */
.form-conditional {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height var(--duration-slow) var(--ease-out),
        opacity var(--duration-normal) var(--ease-in-out),
        margin var(--duration-normal);
    margin-top: 0;
}

.form-conditional.visible {
    max-height: 1000px;
    opacity: 1;
    margin-top: var(--space-4);
}

/* ---------- Tables ---------- */
.table-container,
.data-table-container {
    overflow: auto;
    height: calc(100vh - 180px);
    height: calc(100dvh - 180px);
    max-height: calc(100vh - 180px);
    max-height: calc(100dvh - 180px);
    min-height: 80vh;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    width: 100%;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: var(--border-medium) transparent;
}

.table-container::-webkit-scrollbar,
.data-table-container::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.table-container::-webkit-scrollbar-track,
.data-table-container::-webkit-scrollbar-track {
    background: transparent;
}

.table-container::-webkit-scrollbar-thumb,
.data-table-container::-webkit-scrollbar-thumb {
    background-color: var(--border-medium);
    border-radius: var(--radius-full);
}

.card>.table-container,
.card>.data-table-container,
.card-body>.table-container,
.card-body>.data-table-container {
    border: none;
    border-radius: 0;
    height: calc(100vh - 185px);
    height: calc(100dvh - 185px);
    max-height: calc(100vh - 185px);
    max-height: calc(100dvh - 185px);
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.82rem;
}

.data-table.table-fixed {
    table-layout: fixed;
    width: 100%;
}

.data-table thead,
.data-table thead tr {
    position: sticky;
    top: 0;
    z-index: 25;
    background: #ffffff !important;
    background-color: #ffffff !important;
}

.data-table th,
.data-table thead th,
table.data-table thead th,
.training-table thead th,
.hrp-table thead th,
.plan-table thead th,
.qr-table thead th,
.dat-table thead th,
.assessment-table thead th,
#usersTable thead th {
    background: #ffffff !important;
    background-color: #ffffff !important;
    background-image: none !important;
    color: #0f172a !important;
    font-weight: 800 !important;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    text-align: left;
    padding: 6px 10px !important;
    border-top: 2px solid #facc15 !important;
    border-bottom: 2px solid #059669 !important;
    white-space: nowrap;
    position: sticky !important;
    top: 0 !important;
    z-index: 25 !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04) !important;
}

.data-table td {
    padding: 6px 10px !important;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    vertical-align: middle;
    background: var(--bg-card);
    transition: background-color 0.15s ease;
}

.data-table tbody tr:hover td,
.data-table tbody tr:hover,
table.data-table tbody tr:hover td,
.training-table tbody tr:hover td,
.hrp-table tbody tr:hover td,
.plan-table tbody tr:hover td,
.qr-table tbody tr:hover td,
.dat-table tbody tr:hover td,
.assessment-table tbody tr:hover td,
#usersTable tbody tr:hover td {
    background: #f0fdfa !important;
    background-color: #f0fdfa !important;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Compact Table Variant (for fit-to-screen laptop views) */
.data-table.table-compact th {
    padding: 5px 8px !important;
    font-size: 0.68rem;
    letter-spacing: 0.2px;
    white-space: normal;
    word-break: break-word;
    line-height: 1.25;
    background: #ffffff !important;
    background-color: #ffffff !important;
    background-image: none !important;
    border-top: 2px solid #facc15 !important;
    border-bottom: 2px solid #059669 !important;
    color: #0f172a !important;
    font-weight: 800 !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 25 !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04) !important;
}

.data-table.table-compact td {
    padding: 5px 8px !important;
    font-size: 0.76rem;
    line-height: 1.35;
    word-break: break-word;
}

.data-table.table-compact .badge {
    padding: 1px 5px;
    font-size: 0.66rem;
    font-weight: 600;
}

/* Specific HRP Table Layout Elements */
.hrp-mother-name {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.82rem;
    line-height: 1.2;
}

.hrp-mother-age {
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.74rem;
}

.hrp-subtext {
    font-size: 0.70rem;
    color: var(--text-muted);
    line-height: 1.3;
    margin-top: 2px;
}

.hrp-facility-name {
    color: var(--text-secondary);
}

.hrp-rch-badge {
    display: inline-block;
    font-size: 0.64rem;
    font-family: var(--font-mono);
    color: var(--primary-700);
    background: var(--primary-50);
    border: 1px solid var(--primary-200);
    padding: 0 5px;
    border-radius: var(--radius-sm);
    margin-top: 3px;
    font-weight: 600;
}

.hrp-block-name {
    font-weight: 600;
    font-size: 0.80rem;
    color: var(--text-primary);
}

.hrp-weeks {
    font-size: 0.82rem;
    color: var(--text-primary);
}

.hrp-risk-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    align-items: center;
}

.hrp-hb-tag {
    font-size: 0.68rem;
    color: var(--danger-700);
    margin-top: 3px;
    font-weight: 600;
}

.hrp-tb-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    white-space: normal;
    text-align: left;
    line-height: 1.25;
}

.hrp-tb-symptoms {
    font-size: 0.67rem;
    color: var(--danger-700);
    margin-top: 2px;
    line-height: 1.2;
    font-weight: 500;
}

.hrp-contact-subtext {
    font-size: 0.68rem;
    line-height: 1.25;
    margin-top: 3px;
    color: var(--text-secondary);
}

.hrp-action-btn {
    padding: 5px 9px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    border-radius: var(--radius-md);
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-xs);
}

/* ---------- Badges / Pills ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
}

.badge-success {
    background: var(--success-50);
    color: var(--success-700);
}

.badge-warning {
    background: var(--warning-50);
    color: var(--warning-600);
}

.badge-danger {
    background: var(--danger-50);
    color: var(--danger-600);
}

.badge-info {
    background: var(--info-50);
    color: var(--info-600);
}

.badge-neutral {
    background: var(--bg-subtle);
    color: var(--text-muted);
}

.badge-primary {
    background: var(--primary-50);
    color: var(--primary-700);
}

.badge-purple {
    background: #faf5ff;
    color: #7c3aed;
    border: 1px solid #ede9fe;
}

.badge-teal {
    background: #f0fdfa;
    color: #0f766e;
    border: 1px solid #ccfbf1;
}

.badge-blue {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #dbeafe;
}

/* ---------- Filter Toolbar ---------- */
.filter-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.filter-search {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.filter-search input {
    width: 100%;
    padding: var(--space-2) var(--space-3) var(--space-2) 32px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    outline: none;
    transition: border-color var(--duration-fast);
}

.filter-search input:focus {
    border-color: var(--primary-500);
}

.filter-search::before {
    content: '🔍';
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.82rem;
}

.filter-select {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 0.78rem;
    background: var(--bg-card);
    outline: none;
    min-width: 140px;
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: var(--space-4);
}

.modal-overlay.active {
    display: flex;
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: modalSlideUp var(--duration-slow) var(--ease-out);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5);
    border-bottom: 1px solid var(--border-light);
}

.modal-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--bg-subtle);
    color: var(--text-muted);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--duration-fast);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-5);
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-light);
}

/* ---------- Toast Notifications ---------- */
.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    display: flex;
    flex-direction: column-reverse;
    gap: var(--space-2);
    z-index: 600;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
    animation: toastIn var(--duration-slow) var(--ease-out);
    pointer-events: all;
    max-width: 380px;
}

.toast.success {
    border-left: 4px solid var(--success-500);
}

.toast.error {
    border-left: 4px solid var(--danger-500);
}

.toast.warning {
    border-left: 4px solid var(--warning-500);
}

.toast.info {
    border-left: 4px solid var(--info-500);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast-exit {
    animation: toastOut var(--duration-normal) var(--ease-in-out) forwards;
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(40px);
    }
}

/* ---------- Skeleton Loading ---------- */
.skeleton {
    background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--bg-hover) 50%, var(--bg-subtle) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.skeleton-text {
    height: 14px;
    margin-bottom: var(--space-2);
}

.skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: var(--space-3);
}

.skeleton-card {
    height: 120px;
}

/* ---------- Empty State ---------- */
.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-4);
    opacity: 0.5;
}

.empty-state-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-state-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 400px;
    margin: 0 auto var(--space-5);
}

/* ---------- Login Screen ---------- */
.login-screen {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-canvas) 0%, #e8f5f3 50%, var(--primary-50) 100%);
    padding: var(--space-4);
}

.login-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    width: 100%;
    max-width: 380px;
    padding: 32px 24px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(15, 23, 42, 0.04);
    text-align: center;
}

.login-logo-group {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.login-logo-group img {
    height: 42px;
    object-fit: contain;
}

.login-title {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--primary-700);
    margin-bottom: var(--space-1);
}

.login-subtitle {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: var(--space-6);
}

.login-form .form-group {
    text-align: left;
}

.login-error {
    display: none;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    background: var(--danger-50);
    color: var(--danger-600);
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: var(--space-4);
    border: 1px solid var(--danger-100);
}

.login-error.visible {
    display: block;
}

.login-error.login-error-locked {
    background: #fff1f2;
    color: #be123c;
    border: 1px solid #fecdd3;
    box-shadow: 0 2px 8px rgba(225, 29, 72, 0.08);
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 8px;
    font-size: 0.76rem;
    color: var(--text-muted);
}

.pagination-buttons {
    display: flex;
    gap: var(--space-1);
}

.pagination-btn {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all var(--duration-fast);
}

.pagination-btn:hover:not(:disabled) {
    background: var(--bg-subtle);
}

.pagination-btn.active {
    background: var(--primary-600);
    color: var(--text-inverse);
    border-color: var(--primary-600);
}

/* ---------- Charts Container ---------- */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

/* ---------- PWA Install Banner ---------- */
.pwa-install-banner {
    position: fixed;
    bottom: var(--space-4);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-5);
    box-shadow: var(--shadow-lg);
    display: none;
    align-items: center;
    gap: var(--space-4);
    z-index: 400;
    max-width: 420px;
}

.pwa-install-banner.visible {
    display: flex;
}

/* ---------- Mobile Bottom Nav ---------- */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottombar-height);
    background: var(--bg-card);
    border-top: 1px solid var(--border-light);
    padding: 0 var(--space-2);
    z-index: 100;
}

.mobile-nav-items {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 100%;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-1);
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--text-muted);
    border: none;
    background: none;
    cursor: pointer;
    transition: color var(--duration-fast);
    min-width: 48px;
}

.mobile-nav-item.active {
    color: var(--primary-700);
}

.mobile-nav-item .nav-icon {
    font-size: 1.2rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {

    /*
     * Phones do NOT get a smaller root font. Every rem-based size in the design
     * system scales off this value, so shrinking it here pushed labels, badges
     * and table text down to 8–10px on the very screens least able to read it.
     * Keep 15px and pull the smallest utilities back up explicitly below.
     */
    html {
        font-size: 15px;
    }

    /* --- iOS Auto-Zoom Prevention (All form controls >= 16px) --- */
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="month"],
    input[type="search"],
    select,
    textarea,
    .form-input,
    .form-select,
    .form-textarea,
    .filter-select,
    .filter-search input {
        font-size: 16px !important;
        line-height: 1.35 !important;
    }

    /* --- Readability floor: nothing below ~10.5px on a phone --- */
    .badge {
        font-size: 0.72rem !important;
        padding: 3px 8px !important;
    }

    .kpi-label {
        font-size: 0.72rem !important;
    }

    .kpi-meta {
        font-size: 0.7rem !important;
        line-height: 1.3 !important;
    }

    .page-subtitle {
        font-size: 0.8rem !important;
    }

    .mobile-topbar-title {
        font-size: 0.84rem !important;
    }

    .mobile-topbar-brand {
        font-size: 0.9rem !important;
    }

    .sidebar-section-label {
        font-size: 0.72rem !important;
    }

    .sidebar-brand-text p {
        font-size: 0.72rem !important;
    }

    .sidebar-user-name {
        font-size: 0.82rem !important;
    }

    .sidebar-user-role {
        font-size: 0.72rem !important;
    }

    .mobile-nav-item {
        font-size: 0.68rem !important;
    }

    .data-table th {
        font-size: 0.74rem !important;
    }

    .data-table.table-compact th {
        font-size: 0.74rem !important;
    }

    .data-table.table-compact td {
        font-size: 0.82rem !important;
    }

    .data-table.table-compact .badge {
        font-size: 0.74rem !important;
    }

    /*
     * Cell contents are sprinkled with inline font-size:0.65–0.78rem in the
     * tool modules. Inline styles can only be beaten by !important, so impose a
     * legibility floor here instead of rewriting 100+ markup strings (which
     * would also loosen desktop density). `1em` = the parent's size, so this
     * reads as "never smaller than 0.76rem", and role classes below re-assert
     * the emphasised rows so the hierarchy survives.
     */
    .data-table td,
    .data-table td * {
        font-size: max(0.76rem, 1em) !important;
    }

    .data-table td strong,
    .data-table td b,
    .data-table td .hrp-mother-name,
    .data-table td .hrp-block-name {
        font-size: max(0.88rem, 1em) !important;
    }

    .hrp-mother-name {
        font-size: 0.86rem !important;
    }

    .hrp-mother-age,
    .hrp-subtext,
    .hrp-tb-symptoms,
    .hrp-hb-tag,
    .hrp-contact-subtext,
    .hrp-rch-badge {
        font-size: 0.7rem !important;
        line-height: 1.35 !important;
    }

    .hrp-block-name,
    .hrp-weeks {
        font-size: 0.82rem !important;
    }

    /* --- Touch targets: 38px minimum hit area (thumb-friendly) --- */
    .btn {
        min-height: 38px !important;
    }

    .btn-xs {
        min-height: 36px !important;
        padding: 6px 10px !important;
        font-size: 0.78rem !important;
        border-radius: var(--radius-md) !important;
    }

    .btn-sm {
        min-height: 36px !important;
        padding: 6px 12px !important;
    }

    .btn-icon {
        width: 40px !important;
        height: 40px !important;
    }

    .modal-close,
    .sidebar-close-btn,
    .mobile-sync-dot-btn {
        min-width: 38px !important;
        min-height: 38px !important;
    }

    .sidebar-link {
        min-height: 36px;
    }

    .sidebar-logout-btn {
        width: 38px !important;
        height: 38px !important;
    }

    .sidebar-logout-btn svg {
        width: 18px;
        height: 18px;
    }

    .training-pill {
        min-height: 40px !important;
    }

    .pagination-btn {
        min-height: 38px !important;
        min-width: 38px !important;
    }

    /* Badges double as status toggles in the Planning/Training tables */
    button.badge,
    a.badge,
    .badge[onclick] {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-height: 36px !important;
        padding: 7px 14px !important;
        font-size: 0.76rem !important;
    }

    /* --- Mobile Topbar (Google Stitch Design) --- */
    .mobile-topbar {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: calc(54px + env(safe-area-inset-top, 0px));
        padding-top: env(safe-area-inset-top, 0px);
        background: rgba(255, 255, 255, 0.94) !important;
        backdrop-filter: blur(14px) !important;
        -webkit-backdrop-filter: blur(14px) !important;
        border-bottom: 1px solid #e2e8f0 !important;
        padding: 0 12px;
        z-index: 140;
        box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
    }

    .mobile-sidebar-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        background: #f1f5f9;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        color: #0f172a;
        cursor: pointer;
        flex-shrink: 0;
        padding: 0;
        transition: all 0.15s ease;
    }

    .mobile-sidebar-btn:active {
        background: #e2e8f0;
        transform: scale(0.95);
    }

    .mobile-topbar-center {
        display: flex;
        align-items: center;
        gap: 8px;
        min-width: 0;
        flex: 1;
        padding: 0 8px;
    }

    .mobile-topbar-brand {
        font-family: var(--font-display);
        font-weight: 800;
        font-size: 0.92rem;
        color: #0f172a;
        letter-spacing: -0.02em;
        flex-shrink: 0;
    }

    .mobile-topbar-pill {
        background: #f1f5f9;
        border: 1px solid #e2e8f0;
        color: #334155;
        font-size: 0.76rem;
        font-weight: 600;
        padding: 2px 10px;
        border-radius: 16px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 150px;
        display: inline-block;
    }

    .mobile-topbar-right {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
    }

    .mobile-sync-dot-btn {
        background: none;
        border: none;
        padding: 2px;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
    }

    .mobile-status-chip {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        padding: 3px 8px;
        border-radius: 20px;
        font-size: 0.7rem;
        font-weight: 700;
        background: #f1f5f9;
        color: #475569;
        border: 1px solid #e2e8f0;
    }

    .mobile-status-chip.online {
        background: #ecfdf5;
        color: #065f46;
        border-color: #a7f3d0;
    }

    .mobile-status-chip.offline {
        background: #fef2f2;
        color: #991b1b;
        border-color: #fecaca;
    }

    .pulse-dot {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: #10b981;
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
        animation: pulseLive 2s infinite;
    }

    .mobile-status-chip.offline .pulse-dot {
        background: #ef4444;
        animation: none;
    }

    @keyframes pulseLive {
        0% {
            transform: scale(0.95);
            box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
        }

        70% {
            transform: scale(1);
            box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
        }

        100% {
            transform: scale(0.95);
            box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
        }
    }

    .mobile-topbar-avatar {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: linear-gradient(135deg, #0d9488 0%, #047857 100%);
        color: #ffffff;
        font-size: 0.75rem;
        font-weight: 700;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        border: 2px solid #ffffff;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    }

    /* --- Sidebar Drawer & Backdrop (Google Stitch Slide-Over) --- */
    .sidebar-close-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        border-radius: 8px;
        border: 1px solid #e2e8f0;
        background: #f8fafc;
        color: #475569;
        cursor: pointer;
        margin-left: auto;
        transition: all 0.15s ease;
    }

    .sidebar-close-btn:hover {
        background: #e2e8f0;
        color: #0f172a;
    }

    .app-sidebar {
        width: min(260px, 78vw);
        max-width: 280px;
        transform: translateX(-100%);
        z-index: 200;
        box-shadow: none;
        background: #ffffff;
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .app-sidebar.open {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(15, 23, 42, 0.25);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 180;
        display: none;
    }

    .sidebar-backdrop.visible {
        display: block;
    }

    .app-main {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .app-content {
        padding: 12px 10px !important;
        padding-top: calc(54px + env(safe-area-inset-top, 0px) + 12px) !important;
        padding-bottom: calc(58px + env(safe-area-inset-bottom, 12px) + 24px) !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden;
    }

    /* Keep the drawer clear of the notch and home indicator */
    .app-sidebar {
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Login card breathing room on narrow phones */
    .login-card {
        padding: 24px 18px !important;
    }

    .login-logo-group img {
        max-height: 46px;
    }

    .login-title {
        font-size: 1.35rem;
    }

    /* --- Mobile Bottom Nav Bar (Stitch Elevated Glassmorphism) --- */
    .mobile-nav {
        display: block !important;
        height: calc(58px + env(safe-area-inset-bottom, 0)) !important;
        padding-bottom: env(safe-area-inset-bottom, 0) !important;
        background: rgba(255, 255, 255, 0.96) !important;
        backdrop-filter: blur(16px) !important;
        -webkit-backdrop-filter: blur(16px) !important;
        border-top: 1px solid #e2e8f0 !important;
        box-shadow: 0 -3px 16px rgba(15, 23, 42, 0.06) !important;
        z-index: 130 !important;
    }

    .mobile-nav-items {
        height: 58px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-around !important;
        padding: 0 4px !important;
    }

    .mobile-nav-item {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 2px !important;
        flex: 1 !important;
        min-width: 0 !important;
        padding: 5px 6px !important;
        border-radius: 12px !important;
        color: #64748b !important;
        font-size: 0.64rem !important;
        font-weight: 600 !important;
        background: none !important;
        border: none !important;
        cursor: pointer !important;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .mobile-nav-item.active {
        color: #0d9488 !important;
        background: rgba(13, 148, 136, 0.1) !important;
        font-weight: 700 !important;
    }

    .mobile-nav-item .nav-icon {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .mobile-nav-item .nav-icon svg {
        width: 20px !important;
        height: 20px !important;
        transition: transform 0.2s ease !important;
    }

    .mobile-nav-item.active .nav-icon svg {
        transform: scale(1.08) !important;
        stroke: #0d9488 !important;
    }

    .mobile-nav-item .nav-text {
        letter-spacing: -0.01em;
    }

    /* --- Page Headers & Action Buttons --- */
    .page-header {
        position: static !important;
        margin-top: 0 !important;
        margin-bottom: 12px !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
    }

    .page-title {
        font-size: 1.22rem !important;
        line-height: 1.25 !important;
        word-break: break-word;
    }

    .page-subtitle {
        font-size: 0.76rem !important;
        line-height: 1.35 !important;
        color: var(--text-muted);
    }

    .page-header>div:last-child {
        width: 100% !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        align-items: center !important;
    }

    .page-header>div:last-child .btn,
    .page-header>div:last-child a.btn {
        flex: 1 1 auto;
        min-height: 38px;
        justify-content: center;
        text-align: center;
    }

    .btn-round-add {
        flex-shrink: 0;
        width: 38px !important;
        height: 38px !important;
    }

    /* --- Filter Bars --- */
    .filter-bar {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
        padding: 10px 12px !important;
        margin-bottom: 12px !important;
        border-radius: var(--radius-md) !important;
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
    }

    .filter-bar>* {
        width: 100% !important;
        min-width: 0 !important;
    }

    .filter-search {
        width: 100% !important;
        min-width: 0 !important;
    }

    .filter-search input {
        width: 100% !important;
        height: 40px !important;
        border-radius: 10px !important;
        border: 1px solid #cbd5e1 !important;
        padding-left: 32px !important;
    }

    .filter-select {
        width: 100% !important;
        min-width: 0 !important;
        height: 40px !important;
        border-radius: 10px !important;
        border: 1px solid #cbd5e1 !important;
        background-color: #f8fafc !important;
    }

    .filter-bar div[style*="display:flex"],
    .filter-bar div[style*="display: flex"] {
        flex-wrap: wrap !important;
        width: 100% !important;
        min-width: 0 !important;
        gap: 6px !important;
    }

    /* --- Data Tables (Prevention of Squishing & Overlap on Mobile) --- */
    .table-container,
    .data-table-container,
    .card>.table-container,
    .card>.data-table-container,
    .card-body>.table-container,
    .card-body>.data-table-container {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior-x: contain !important;
        border-radius: 12px !important;
        margin-bottom: 8px !important;
        scrollbar-width: thin !important;
        height: calc(100dvh - 225px) !important;
        max-height: calc(100dvh - 225px) !important;
        overflow-y: auto !important;
        min-height: 280px !important;
        overscroll-behavior: contain !important;
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
    }

    /* Eliminate all column squishing: table-layout auto with readable min-width */
    .data-table,
    .data-table.table-fixed,
    .plan-table,
    .qr-table,
    #usersTable,
    #facilitiesTable {
        table-layout: auto !important;
        min-width: 820px !important;
        font-size: 0.78rem !important;
        border-collapse: separate !important;
    }

    #usersTable {
        min-width: 900px !important;
    }

    /* Disable percentage colgroups that break on mobile */
    .plan-table colgroup,
    .qr-table colgroup {
        display: none !important;
    }

    .data-table th,
    .data-table td {
        padding: 6px 8px !important;
        white-space: nowrap !important;
    }

    /* Allow readable wrapped columns for names and activities */
    .data-table td:nth-child(2),
    .data-table td:nth-child(3),
    .data-table td.cell-wrap {
        white-space: normal !important;
        min-width: 140px !important;
    }

    /* --- Google Stitch Mobile Clinical Cards --- */
    .stitch-card,
    .mobile-record-card {
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 12px !important;
        padding: 14px 16px !important;
        margin-bottom: 12px !important;
        box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03) !important;
        position: relative !important;
        overflow: hidden !important;
    }

    .stitch-card::before,
    .mobile-record-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: 4px;
        background: #0d9488;
    }

    .stitch-card.accent-teal::before {
        background: #0d9488;
    }

    .stitch-card.accent-amber::before {
        background: #f59e0b;
    }

    .stitch-card.accent-rose::before {
        background: #e11d48;
    }

    .stitch-card.accent-blue::before {
        background: #2563eb;
    }

    .stitch-card.accent-purple::before {
        background: #8b5cf6;
    }

    .stitch-card.accent-emerald::before {
        background: #10b981;
    }

    /* --- Training MIS & QR Referral Pill Tabs (Smooth Horizontal Swipe) --- */
    .training-pill-tabs {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 6px !important;
        padding-bottom: 6px !important;
        margin-bottom: 10px !important;
        scrollbar-width: none !important;
    }

    .training-pill-tabs::-webkit-scrollbar {
        display: none !important;
    }

    .training-pill {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        padding: 3px 9px !important;
        font-size: 0.70rem !important;
    }

    /* --- Forms, Rows & Chips --- */
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .form-group {
        margin-bottom: 10px !important;
    }

    .form-label {
        font-size: 0.82rem !important;
        margin-bottom: 4px !important;
    }

    .form-chip {
        padding: 7px 12px !important;
        min-height: 36px !important;
        font-size: 0.8rem !important;
    }

    .form-radio-group,
    .form-checkbox-group {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    #ancFacilityDropdownList {
        max-height: 200px !important;
        width: 100% !important;
    }

    /* Form Save/Reset action bar on mobile */
    div[style*="justify-content:flex-end;margin-bottom:40px"],
    div[style*="justify-content: flex-end; margin-bottom: 40px"],
    div[style*="justify-content:flex-end;gap:12px;padding:16px 24px"],
    div[style*="justify-content: flex-end; gap: 12px; padding: 16px 24px"] {
        flex-direction: column !important;
        gap: 8px !important;
        margin-bottom: 24px !important;
        padding: 12px !important;
    }

    div[style*="justify-content:flex-end;margin-bottom:40px"] .btn,
    div[style*="justify-content: flex-end; margin-bottom: 40px"] .btn,
    div[style*="justify-content:flex-end;gap:12px;padding:16px 24px"] .btn,
    div[style*="justify-content: flex-end; gap: 12px; padding: 16px 24px"] .btn {
        width: 100% !important;
        min-height: 42px !important;
        justify-content: center !important;
    }

    /* --- Modals & Bottom Sheets --- */
    .modal-overlay {
        padding: 0 !important;
        align-items: flex-end !important;
    }

    .modal-card {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 90vh !important;
        max-height: 90dvh !important;
        border-radius: 20px 20px 0 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        animation: mobileSheetSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }

    @keyframes mobileSheetSlideUp {
        from {
            transform: translateY(100%);
        }

        to {
            transform: translateY(0);
        }
    }

    .modal-header {
        padding: 12px 16px !important;
        flex-shrink: 0 !important;
        border-bottom: 1px solid var(--border-light) !important;
    }

    .modal-body {
        padding: 14px 16px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex: 1 !important;
        max-height: calc(90dvh - 120px) !important;
    }

    .modal-footer {
        padding: 12px 16px !important;
        flex-shrink: 0 !important;
        border-top: 1px solid var(--border-light) !important;
        display: flex !important;
        gap: 8px !important;
        flex-wrap: wrap !important;
        background: var(--bg-card) !important;
    }

    .modal-footer .btn,
    .modal-footer button {
        flex: 1 1 120px !important;
        min-height: 40px !important;
        justify-content: center !important;
    }

    /* Modal detail grids: 2-column to 1-column on mobile */
    .modal-body div[style*="grid-template-columns:1fr 1fr"],
    .modal-body div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 6px !important;
    }

    /* --- Pagination --- */
    .pagination {
        flex-direction: column !important;
        gap: 8px !important;
        align-items: center !important;
        padding: 10px !important;
    }

    .pagination-buttons {
        gap: 4px !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
    }

    .pagination-btn {
        padding: 5px 10px !important;
        min-width: 34px !important;
        height: 34px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* --- Cards & Dashboard --- */
    .card {
        border-radius: var(--radius-md) !important;
        margin-bottom: 12px !important;
    }

    .card-header {
        padding: 10px 14px !important;
    }

    .card-title {
        font-size: 0.92rem !important;
    }

    .card-body {
        padding: 12px 14px !important;
    }

    .charts-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Quick Action buttons on dashboard */
    .card-body div[style*="display:flex;flex-wrap:wrap;gap:12px"],
    .card-body div[style*="display: flex; flex-wrap: wrap; gap: 12px"] {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    .card-body div[style*="display:flex;flex-wrap:wrap;gap:12px"] a.btn,
    .card-body div[style*="display: flex; flex-wrap: wrap; gap: 12px"] a.btn {
        width: 100% !important;
        justify-content: center !important;
        text-align: center !important;
        min-height: 40px !important;
        padding: 8px 10px !important;
        font-size: 0.78rem !important;
    }

    /* Toast Notification placement */
    .toast-container {
        bottom: calc(var(--bottombar-height) + env(safe-area-inset-bottom, 12px) + 12px) !important;
        right: 12px !important;
        left: 12px !important;
    }

    .toast {
        max-width: 100% !important;
    }

    /* District Posters Grid & Assessment Bento Grids */
    #districtPostersGrid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    div[style*="minmax(280px, 1fr)"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* --- Stitch Clinical Mobile Cards System --- */
    .clinical-card-list {
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 2px 0;
        width: 100%;
    }

    .clinical-card {
        background: var(--bg-surface, #ffffff);
        border: 1px solid var(--border-light, #e2e8f0);
        border-radius: 14px;
        padding: 14px;
        box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
        position: relative;
        border-left: 4px solid var(--primary-500, #0d9488);
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }

    .clinical-card.card-pending {
        border-left-color: var(--warning-500, #f59e0b) !important;
        background: #fffdfa !important;
    }

    .clinical-card.card-highrisk {
        border-left-color: var(--danger-500, #e11d48) !important;
        background: #fffafa !important;
    }

    .clinical-card.card-linked {
        border-left-color: var(--success-500, #10b981) !important;
    }

    .clinical-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 10px;
        padding-bottom: 8px;
        border-bottom: 1px solid var(--border-subtle, #f1f5f9);
        gap: 6px;
    }

    .clinical-card-id {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-wrap: wrap;
    }

    .badge-token {
        background: #f0fdfa;
        color: #0f766e;
        border: 1px solid #ccfbf1;
        font-family: var(--font-mono, monospace);
        font-weight: 800;
        font-size: 0.76rem;
        padding: 3px 8px;
        border-radius: 6px;
        cursor: pointer;
    }

    .clinical-card-date {
        font-size: 0.72rem;
        color: var(--text-muted, #64748b);
        font-weight: 500;
    }

    .clinical-card-patient {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 10px;
        gap: 8px;
    }

    .patient-main .patient-name {
        font-size: 0.96rem;
        font-weight: 800;
        color: var(--text-primary, #0f172a);
        line-height: 1.3;
    }

    .patient-main .patient-age {
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--text-muted, #64748b);
    }

    .patient-main .patient-rch {
        font-size: 0.72rem;
        color: var(--primary-700, #0f766e);
        font-weight: 700;
        font-family: var(--font-mono, monospace);
        margin-top: 2px;
    }

    .patient-phone-btn {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        background: #f0fdf4;
        border: 1px solid #bbf7d0;
        color: #166534;
        padding: 5px 10px;
        border-radius: 20px;
        font-size: 0.75rem;
        font-weight: 700;
        text-decoration: none;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .clinical-card-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        background: #f8fafc;
        border-radius: 10px;
        padding: 9px 12px;
        margin-bottom: 10px;
        font-size: 0.76rem;
    }

    .clinical-card-grid .info-item {
        display: flex;
        flex-direction: column;
        min-width: 0;
    }

    .clinical-card-grid .info-label {
        font-size: 0.68rem;
        color: var(--text-muted, #64748b);
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.02em;
        margin-bottom: 1px;
    }

    .clinical-card-grid .info-value {
        font-weight: 700;
        color: var(--text-secondary, #334155);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .clinical-card-tags {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 12px;
    }

    .clinical-card-actions {
        display: flex;
        gap: 8px;
        align-items: center;
        padding-top: 10px;
        border-top: 1px solid var(--border-subtle, #f1f5f9);
    }

    .clinical-card-actions .btn {
        min-height: 40px;
        font-size: 0.82rem;
        font-weight: 700;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 1;
    }

    /* --- Stitch Filter Chips & View Mode Toggle --- */
    .view-mode-toggle {
        display: inline-flex;
        background: #f1f5f9;
        border-radius: 19px;
        padding: 2px;
        border: 1px solid #cbd5e1;
        height: 38px;
        box-sizing: border-box;
        align-items: center;
    }

    .view-mode-btn {
        border: none;
        background: transparent;
        padding: 0 10px;
        height: 100%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 0.74rem;
        font-weight: 700;
        color: #64748b;
        border-radius: 16px;
        cursor: pointer;
        transition: all 0.15s ease;
        white-space: nowrap;
        user-select: none;
    }

    .view-mode-btn.active {
        background: #ffffff;
        color: #0f172a;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    }

    .mobile-filter-chips {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 4px 0 8px 0;
        scrollbar-width: none;
        width: 100%;
    }

    .mobile-filter-chips::-webkit-scrollbar {
        display: none;
    }

    .filter-chip {
        white-space: nowrap;
        display: inline-flex;
        align-items: center;
        gap: 5px;
        padding: 6px 12px;
        border-radius: 20px;
        font-size: 0.75rem;
        font-weight: 700;
        background: #ffffff;
        border: 1px solid #cbd5e1;
        color: #475569;
        cursor: pointer;
        transition: all 0.15s ease;
        flex-shrink: 0;
    }

    .filter-chip.active {
        background: #0d9488 !important;
        border-color: #0d9488 !important;
        color: #ffffff !important;
        box-shadow: 0 2px 8px rgba(13, 148, 136, 0.28) !important;
    }

    .filter-chip-badge {
        background: rgba(0, 0, 0, 0.08);
        padding: 1px 6px;
        border-radius: 10px;
        font-size: 0.68rem;
    }

    .filter-chip.active .filter-chip-badge {
        background: rgba(255, 255, 255, 0.25);
        color: #ffffff;
    }

    .alert-compact-banner {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
        border: 1px solid #fde68a;
        border-radius: 12px;
        padding: 9px 12px;
        margin-bottom: 10px;
        box-shadow: 0 1px 4px rgba(245, 158, 11, 0.08);
        gap: 8px;
    }

    .alert-compact-banner .alert-left {
        display: flex;
        align-items: center;
        gap: 8px;
        min-width: 0;
    }

    .alert-compact-banner .alert-title {
        font-weight: 800;
        font-size: 0.78rem;
        color: #92400e;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .alert-compact-banner .alert-sub {
        font-size: 0.7rem;
        color: #b45309;
    }
}

/* Hide Cards / Table toggle on laptop & wide screens (>= 768px) */
@media (min-width: 768px) {
    .view-mode-toggle {
        display: none !important;
    }
}

/* ── QR Referral Flash Message Notification ────────────────────────────── */
.qr-flash-message {
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 50%, #fef9c3 100%);
    border: 1px solid #fde047;
    border-left: 5px solid #eab308;
    border-radius: 14px;
    padding: 10px 14px;
    margin-bottom: 12px;
    box-shadow: 0 4px 18px rgba(234, 179, 8, 0.16), 0 1px 3px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    animation: qrFlashSlide 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.qr-flash-message:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 22px rgba(234, 179, 8, 0.26);
    background: linear-gradient(135deg, #fefce8 0%, #fef08a 60%, #fed7aa 100%);
}

.qr-flash-message:active {
    transform: scale(0.99);
}

.qr-flash-icon-box {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 10px;
    background: #fde047;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    box-shadow: 0 2px 8px rgba(202, 138, 4, 0.25);
    flex-shrink: 0;
    position: relative;
}

.qr-flash-pulse-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 9px;
    height: 9px;
    background: #ef4444;
    border: 2px solid #ffffff;
    border-radius: 50%;
    animation: flashPulseDot 1.6s infinite ease-in-out;
}

@keyframes flashPulseDot {
    0% {
        transform: scale(0.9);
        opacity: 1;
    }

    50% {
        transform: scale(1.3);
        opacity: 0.8;
    }

    100% {
        transform: scale(0.9);
        opacity: 1;
    }
}

.qr-flash-content {
    flex: 1;
    min-width: 0;
}

.qr-flash-title {
    font-weight: 800;
    font-size: 0.86rem;
    color: #854d0e;
    line-height: 1.25;
    display: flex;
    align-items: center;
    gap: 4px;
}

.qr-flash-sub {
    font-size: 0.74rem;
    color: #a16207;
    font-weight: 500;
    margin-top: 2px;
    line-height: 1.25;
}

.qr-flash-action {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.qr-flash-cta {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    color: #ffffff !important;
    border: none;
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 0.74rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(180, 83, 9, 0.3);
    white-space: nowrap;
    transition: all 0.2s;
}

.qr-flash-cta:hover {
    background: linear-gradient(135deg, #b45309 0%, #92400e 100%);
    transform: scale(1.04);
}

.qr-flash-close {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: rgba(161, 98, 7, 0.12);
    color: #854d0e;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    line-height: 1;
    transition: all 0.2s;
}

.qr-flash-close:hover {
    background: rgba(161, 98, 7, 0.25);
    color: #713f12;
}

@keyframes qrFlashSlide {
    0% {
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ---------- Narrow Mobile Viewports (9:20 - 360px to 480px) ---------- */
@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    .kpi-card {
        padding: 10px 12px !important;
        border-radius: var(--radius-md) !important;
    }

    .kpi-label {
        font-size: 0.74rem !important;
        line-height: 1.25 !important;
    }

    .kpi-value {
        font-size: 1.24rem !important;
        margin: 3px 0 !important;
    }

    .kpi-meta {
        font-size: 0.72rem !important;
        line-height: 1.25 !important;
    }

    .topbar-breadcrumb {
        display: none !important;
    }

    /* Dashboard quick actions 1 column on <= 400px */
    .card-body div[style*="display:flex;flex-wrap:wrap;gap:12px"],
    .card-body div[style*="display: flex; flex-wrap: wrap; gap: 12px"] {
        grid-template-columns: 1fr !important;
    }
}

/* ---------- Very Small Phones (<= 360px, incl. 9:20 targets) ---------- */
@media (max-width: 360px) {

    /* Root font stays readable — see the note in the 768px block. */
    html {
        font-size: 15px;
    }

    .app-content {
        padding: 10px 8px !important;
        padding-top: calc(52px + 10px) !important;
        padding-bottom: calc(var(--bottombar-height) + env(safe-area-inset-bottom, 12px) + 16px) !important;
    }

    /* Keep the 2-up KPI grid: 4 stacked cards bury the dashboard head */
    .kpi-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 6px !important;
    }

    .kpi-card {
        padding: 9px 10px !important;
    }

    .page-title {
        font-size: 1.15rem !important;
    }

    .mobile-nav-item {
        font-size: 0.72rem !important;
    }

    .mobile-nav-item .nav-icon {
        font-size: 1.1rem !important;
    }
}

/* ---------- Utility Classes ---------- */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--text-muted);
}

.text-primary {
    color: var(--primary-700);
}

.text-success {
    color: var(--success-600);
}

.text-danger {
    color: var(--danger-600);
}

.text-warning {
    color: var(--warning-600);
}

.font-mono {
    font-family: var(--font-mono);
}

.fw-600 {
    font-weight: 600;
}

.fw-700 {
    font-weight: 700;
}

.mt-2 {
    margin-top: var(--space-2);
}

.mt-4 {
    margin-top: var(--space-4);
}

.mb-2 {
    margin-bottom: var(--space-2);
}

.mb-4 {
    margin-bottom: var(--space-4);
}

.gap-2 {
    gap: var(--space-2);
}

.gap-4 {
    gap: var(--space-4);
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.hidden {
    display: none !important;
}

.w-full {
    width: 100%;
}

/* ---------- Training MIS Pill Tabs ---------- */
.training-pill-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 0;
    align-items: center;
}

.training-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border-radius: var(--radius-full);
    padding: 3px 9px;
    font-size: 0.70rem;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-xs);
    background: var(--bg-card);
    user-select: none;
    white-space: nowrap;
    height: 27px;
    box-sizing: border-box;
}

.training-pill:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.training-pill:active {
    transform: translateY(0);
}

.training-pill .pill-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--radius-full);
    font-size: 0.64rem;
    font-weight: 700;
    transition: all 0.2s ease;
}

/* Pill 1: All Trainings (Slate/Dark) */
.training-pill.pill-all {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
}

.training-pill.pill-all .pill-count {
    background-color: #e2e8f0;
    color: #1e293b;
}

.training-pill.pill-all:hover {
    background-color: #e2e8f0;
    border-color: #94a3b8;
}

.training-pill.pill-all.active {
    background-color: #1e293b !important;
    border-color: #0f172a !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(30, 41, 59, 0.35);
}

.training-pill.pill-all.active .pill-count {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

/* Pill 2: Healthcare Providers (Primary Blue) */
.training-pill.pill-provider {
    background-color: #eff6ff;
    border-color: #bfdbfe;
    color: #1d4ed8;
}

.training-pill.pill-provider .pill-count {
    background-color: #dbeafe;
    color: #1e40af;
}

.training-pill.pill-provider:hover {
    background-color: #dbeafe;
    border-color: #93c5fd;
}

.training-pill.pill-provider.active {
    background-color: #2563eb !important;
    border-color: #1d4ed8 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.training-pill.pill-provider.active .pill-count {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

/* Pill 3: Onsite Sensitisation (OSS) (Teal) */
.training-pill.pill-oss {
    background-color: #f0fdfa;
    border-color: #99f6e4;
    color: #0f766e;
}

.training-pill.pill-oss .pill-count {
    background-color: #ccfbf1;
    color: #115e59;
}

.training-pill.pill-oss:hover {
    background-color: #ccfbf1;
    border-color: #5eead4;
}

.training-pill.pill-oss.active {
    background-color: #0d9488 !important;
    border-color: #0f766e !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}

.training-pill.pill-oss.active .pill-count {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

/* Pill 4: District/Block ToT (Purple) */
.training-pill.pill-tot {
    background-color: #faf5ff;
    border-color: #ddd6fe;
    color: #6d28d9;
}

.training-pill.pill-tot .pill-count {
    background-color: #ede9fe;
    color: #5b21b6;
}

.training-pill.pill-tot:hover {
    background-color: #ede9fe;
    border-color: #c4b5fd;
}

.training-pill.pill-tot.active {
    background-color: #7c3aed !important;
    border-color: #6d28d9 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.35);
}

.training-pill.pill-tot.active .pill-count {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

/* Pill 5: Down Training (Amber/Orange) */
.training-pill.pill-down {
    background-color: #fff7ed;
    border-color: #fed7aa;
    color: #c2410c;
}

.training-pill.pill-down .pill-count {
    background-color: #ffedd5;
    color: #9a3412;
}

.training-pill.pill-down:hover {
    background-color: #ffedd5;
    border-color: #fdba74;
}

.training-pill.pill-down.active {
    background-color: #ea580c !important;
    border-color: #c2410c !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(234, 88, 12, 0.35);
}

.training-pill.pill-down.active .pill-count {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

/* Subtab: QR Referrals Register (Teal / Medical Emerald) */
.training-pill.pill-qr-register {
    background-color: #f0fdf4;
    border-color: #bbf7d0;
    color: #15803d;
}

.training-pill.pill-qr-register .pill-count {
    background-color: #dcfce7;
    color: #166534;
}

.training-pill.pill-qr-register:hover {
    background-color: #dcfce7;
    border-color: #86efac;
}

.training-pill.pill-qr-register.active {
    background: linear-gradient(135deg, #059669 0%, #0d9488 100%) !important;
    border-color: #047857 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}

.training-pill.pill-qr-register.active .pill-count {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

/* Subtab: QR Referrals Pending (Glowing / Flashing Rose Red) */
@keyframes pulseGlowPending {
    0% {
        box-shadow: 0 0 0 0 rgba(225, 29, 72, 0.6), 0 2px 6px rgba(225, 29, 72, 0.2);
        border-color: #f43f5e;
    }
    50% {
        box-shadow: 0 0 14px 3px rgba(225, 29, 72, 0.7), 0 3px 10px rgba(225, 29, 72, 0.35);
        border-color: #e11d48;
    }
    100% {
        box-shadow: 0 0 0 0 rgba(225, 29, 72, 0.6), 0 2px 6px rgba(225, 29, 72, 0.2);
        border-color: #f43f5e;
    }
}

.training-pill.pill-qr-pending {
    background-color: #fff1f2;
    border-color: #fecdd3;
    color: #be123c;
    font-weight: 700;
    animation: pulseGlowPending 1.8s infinite ease-in-out;
    transition: all 0.2s ease;
}

.training-pill.pill-qr-pending .pill-count {
    background-color: #e11d48;
    color: #ffffff;
    font-weight: 800;
}

.training-pill.pill-qr-pending:hover {
    background-color: #ffe4e6;
    border-color: #f43f5e;
    color: #9f1239;
}

.training-pill.pill-qr-pending.active {
    background: linear-gradient(135deg, #e11d48 0%, #be123c 100%) !important;
    border-color: #9f1239 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(225, 29, 72, 0.45);
    animation: none;
}

.training-pill.pill-qr-pending.active .pill-count {
    background-color: rgba(255, 255, 255, 0.3) !important;
    color: #ffffff !important;
}

/* Subtab: QR District Posters (Royal Purple / Indigo) */
.training-pill.pill-qr-posters {
    background-color: #faf5ff;
    border-color: #e9d5ff;
    color: #7e22ce;
}

.training-pill.pill-qr-posters .pill-count {
    background-color: #f3e8ff;
    color: #6b21a8;
}

.training-pill.pill-qr-posters:hover {
    background-color: #f3e8ff;
    border-color: #d8b4fe;
}

.training-pill.pill-qr-posters.active {
    background: linear-gradient(135deg, #7c3aed 0%, #6366f1 100%) !important;
    border-color: #6d28d9 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.35);
}

.training-pill.pill-qr-posters.active .pill-count {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

/* Subtab: My Data (Emerald / Teal) */
.training-pill.pill-my-data {
    background-color: #f0fdf4;
    border-color: #bbf7d0;
    color: #15803d;
}

.training-pill.pill-my-data .pill-count {
    background-color: #dcfce7;
    color: #166534;
}

.training-pill.pill-my-data:hover {
    background-color: #dcfce7;
    border-color: #86efac;
}

.training-pill.pill-my-data.active {
    background: linear-gradient(135deg, #059669 0%, #0d9488 100%) !important;
    border-color: #047857 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}

.training-pill.pill-my-data.active .pill-count {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

/* Subtab: All Staff Data (Dark Slate / Royal Navy) */
.training-pill.pill-all-data {
    background-color: #f8fafc;
    border-color: #cbd5e1;
    color: #334155;
}

.training-pill.pill-all-data .pill-count {
    background-color: #e2e8f0;
    color: #1e293b;
}

.training-pill.pill-all-data:hover {
    background-color: #e2e8f0;
    border-color: #94a3b8;
}

.training-pill.pill-all-data.active {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%) !important;
    border-color: #0f172a !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(30, 41, 59, 0.35);
}

.training-pill.pill-all-data.active .pill-count {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

/* ── Digital Referral Slip — Fullscreen Mode ──────────────────────────────── */
/* Applied to .app-shell when the slip modal is open, hides the sidebar */
.app-shell.slip-fullscreen-mode .app-sidebar,
.app-shell.slip-fullscreen-mode .mobile-sidebar-btn {
    display: none !important;
}

.app-shell.slip-fullscreen-mode .app-main {
    margin-left: 0 !important;
}

/* Slip overlay itself covers full viewport */
.slip-modal-overlay {
    position: fixed !important;
    inset: 0 !important;
    z-index: 9999 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: rgba(15, 23, 42, 0.65) !important;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ── Print Styles for Referral Slip ──────────────────────────────────────── */
@media print {

    .app-sidebar,
    .app-main>*:not(#appContent),
    .mobile-sidebar-btn,
    .mobile-nav,
    .sidebar-backdrop,
    .page-header,
    .filter-bar {
        display: none !important;
    }

    .app-main {
        margin-left: 0 !important;
    }

    .app-content {
        padding: 0 !important;
    }

    .slip-modal-overlay {
        position: static !important;
        background: none !important;
        backdrop-filter: none !important;
        display: block !important;
    }

    #slipPrintable {
        box-shadow: none !important;
        border-radius: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    #slipPrintable button,
    #slipPrintable div[style*="Action Buttons"] {
        display: none !important;
    }
}

/* ── High-Performance Searchable Select Component ────────────────────────── */
.ss-wrap {
    position: relative;
    width: 100%;
}

.ss-wrap input[type="text"] {
    transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.ss-list {
    transform: translateZ(0);
    will-change: transform, opacity;
    scrollbar-width: thin;
    scrollbar-color: var(--border-medium) transparent;
}

.ss-opt {
    padding: 9px 14px;
    cursor: pointer;
    font-size: 0.84rem;
    color: var(--text-secondary, #374151);
    border-bottom: 1px solid #f1f5f9;
    transition: background-color 0.12s ease, color 0.12s ease;
    user-select: none;
}

.ss-opt:hover {
    background-color: #f0fdfa !important;
    color: #0f766e !important;
}

.ss-opt.active,
.ss-opt.selected {
    background-color: #ccfbf1 !important;
    color: #0f766e !important;
    font-weight: 700;
}

/* ── Hardware Accelerated Performance Layer ──────────────────────────────── */
.table-container,
.data-table-container {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.data-table tbody tr {
    transition: background-color 0.1s ease;
}

.modal-overlay {
    transform: translateZ(0);
    will-change: opacity;
}

.modal-card {
    transform: translateZ(0);
    will-change: transform, opacity;
}

/* ==============================================================================
   REFERRAL ENTRY — Mobile Responsive (9:20 & narrow viewports)
   ============================================================================== */

/* --- Base mobile resets for referral form --- */
.ref-page {
    min-height: 100vh;
    min-height: 100dvh;
    /* dynamic viewport height for mobile browsers */
    background: linear-gradient(160deg, #f0fdfa 0%, #e8f4f8 50%, #f5f7fa 100%);
    padding: 8px 6px 80px 6px;
    -webkit-tap-highlight-color: transparent;
}

.ref-page * {
    box-sizing: border-box;
}

.ref-container {
    max-width: 620px;
    margin: 0 auto;
    width: 100%;
}

/* Branding area */
.ref-brand {
    text-align: center;
    margin-bottom: 14px;
}

.ref-brand-logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: #fff;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    margin-bottom: 10px;
    max-width: 100%;
}

.ref-brand-logo img {
    max-height: 30px;
    flex-shrink: 0;
}

.ref-brand-title {
    font-weight: 800;
    font-size: 0.85rem;
    color: #0f766e;
    text-align: left;
    line-height: 1.3;
}

.ref-brand-subtitle {
    font-size: 0.76rem;
    color: #94a3b8;
    text-align: left;
}

.ref-district-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ccfbf1;
    color: #0f766e;
    font-weight: 700;
    font-size: 0.82rem;
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid #99f6e4;
    flex-wrap: wrap;
    justify-content: center;
}

/* Form card */
.ref-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
    overflow: hidden;
}

/* Card header */
.ref-card-header {
    background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
    padding: 14px 14px;
    color: #fff;
}

.ref-card-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.ref-card-title {
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.3;
}

.ref-card-desc {
    font-size: 0.76rem;
    opacity: 0.9;
    margin-top: 2px;
}

.ref-district-switcher {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ref-district-switcher label {
    font-size: 0.76rem;
    font-weight: 600;
    opacity: 0.9;
}

.ref-district-switcher select {
    font-size: 0.78rem;
    min-height: 36px;
    padding: 7px 10px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
    cursor: pointer;
    outline: none;
    max-width: 150px;
}

/* Form body */
.ref-form-body {
    padding: 16px 12px;
}

/* Section headers */
.ref-section-header {
    font-size: 0.82rem;
    font-weight: 800;
    border-left: 3px solid;
    padding-left: 8px;
    margin-bottom: 12px;
    text-transform: uppercase;
    line-height: 1.4;
}

.ref-section-a {
    color: #0f766e;
    border-left-color: #0d9488;
}

.ref-section-b {
    color: #1e40af;
    border-left-color: #3b82f6;
}

.ref-section-c {
    color: #7c3aed;
    border-left-color: #7c3aed;
}

/* Field groups */
.ref-field {
    margin-bottom: 12px;
}

.ref-field-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 4px;
    line-height: 1.4;
}

.ref-field-label .required {
    color: #ef4444;
}

.ref-field-hint {
    font-size: 0.74rem;
    font-weight: 500;
    color: #94a3b8;
}

/* Pre-filled district display */
.ref-district-display {
    padding: 8px 12px;
    background: #f0fdfa;
    border: 1px solid #5eead4;
    border-radius: 10px;
    font-weight: 700;
    color: #0f766e;
    font-size: 0.85rem;
    word-break: break-word;
}

/* Inputs and selects - mobile override */
.ref-page .form-input,
.ref-page .form-select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 16px;
    /* prevents iOS zoom */
    color: #0f172a;
    background: #fff;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.ref-page .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    cursor: pointer;
}

.ref-page .form-input:focus,
.ref-page .form-select:focus {
    border-color: #0d9488;
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
}

/* Symptom checklist container */
.ref-symptom-box {
    background: #fefce8;
    border: 1px solid #fde68a;
    border-radius: 10px;
    padding: 10px;
}

.ref-symptom-box label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 7px 8px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1.4;
}

.ref-symptom-box input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    accent-color: #0d9488;
}

/* Sputum radio grid */
.ref-sputum-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.ref-sputum-grid label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 10px;
    border-radius: 10px;
    border: 1.5px solid #e2e8f0;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.82rem;
    background: #fff;
    transition: all 0.15s;
    justify-content: center;
}

.ref-sputum-grid input[type="radio"] {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

/* Contact field with icon */
.ref-contact-wrap {
    position: relative;
}

.ref-contact-wrap .ref-contact-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    color: #64748b;
    pointer-events: none;
}

.ref-contact-wrap .form-input {
    padding-left: 32px;
}

/* Submit button */
.ref-submit-btn {
    width: 100%;
    margin-top: 20px;
    padding: 14px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(13, 148, 136, 0.35);
    transition: all 0.2s;
    letter-spacing: -0.2px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.ref-submit-btn:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(13, 148, 136, 0.25);
}

.ref-submit-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Footer */
.ref-footer {
    text-align: center;
    margin-top: 14px;
    font-size: 0.74rem;
    color: #94a3b8;
    padding: 0 10px;
}

/* Divider */
.ref-divider {
    border-top: 1px dashed #e2e8f0;
    margin: 14px 0;
}

/* Validation errors */
.ref-error-msg {
    display: none;
    font-size: 0.7rem;
    color: #ef4444;
    margin-top: 4px;
}

/* Searchable select mobile tweaks */
.ref-page .ss-wrap {
    position: relative;
}

.ref-page .ss-wrap input[type="text"] {
    font-size: 16px !important;
    /* prevent iOS zoom */
    padding: 10px 12px 10px 30px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    width: 100%;
}

.ref-page .ss-wrap>div:last-child {
    max-height: 200px;
}

.ref-page .ss-opt {
    padding: 10px 12px !important;
    font-size: 0.82rem !important;
    min-height: 40px;
    display: flex;
    align-items: center;
}

/* ── Receipt Modal — Mobile ─────────────────────────────────────────────── */
.ref-receipt-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.ref-receipt-card {
    background: #fff;
    width: 100%;
    max-width: 460px;
    max-height: 95vh;
    max-height: 95dvh;
    border-radius: 18px;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
    -webkit-overflow-scrolling: touch;
}

.ref-receipt-header {
    background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
    color: #fff;
    padding: 16px 14px;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 1;
}

.ref-receipt-header h2 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.4px;
    margin: 0;
}

.ref-receipt-header p {
    font-size: 0.75rem;
    margin: 3px 0 0;
    opacity: 0.88;
}

.ref-receipt-body {
    padding: 16px 12px;
}

.ref-receipt-slip {
    background: #f8fafc;
    border: 2px dashed #0d9488;
    border-radius: 14px;
    padding: 14px;
    text-align: center;
}

.ref-receipt-id {
    display: inline-block;
    background: #ccfbf1;
    color: #0f766e;
    font-weight: 800;
    font-size: 0.95rem;
    padding: 4px 14px;
    border-radius: 20px;
    font-family: monospace;
    margin-bottom: 10px;
    border: 1px solid #5eead4;
    word-break: break-all;
}

.ref-receipt-qr {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

.ref-receipt-qr>div {
    padding: 8px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
}

.ref-receipt-qr svg {
    max-width: 140px;
    height: auto;
}

.ref-receipt-summary {
    text-align: left;
    font-size: 0.78rem;
    line-height: 1.7;
    background: #fff;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    word-break: break-word;
}

.ref-receipt-actions {
    padding: 0 14px 14px;
    display: flex;
    gap: 8px;
    justify-content: center;
}

.ref-receipt-actions button {
    flex: 1;
    padding: 10px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.82rem;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.ref-receipt-actions .btn-print {
    border: none;
    background: linear-gradient(135deg, #0d9488, #0f766e);
    color: #fff;
}

.ref-receipt-actions .btn-new {
    border: 1.5px solid #e2e8f0;
    background: #fff;
    color: #475569;
    font-weight: 600;
}

/* ── Small Screen Overrides (width < 400px) ──────────────────────────── */
@media screen and (max-width: 400px) {
    .ref-page {
        padding: 6px 4px 70px 4px;
    }

    .ref-brand-logo {
        gap: 6px;
        padding: 6px 10px;
    }

    .ref-brand-logo img {
        max-height: 26px;
    }

    .ref-brand-title {
        font-size: 0.82rem;
    }

    .ref-district-badge {
        font-size: 0.76rem;
        padding: 4px 10px;
    }

    .ref-card-header {
        padding: 12px 10px;
    }

    .ref-card-title {
        font-size: 0.92rem;
    }

    .ref-form-body {
        padding: 12px 10px;
    }

    .ref-section-header {
        font-size: 0.8rem;
    }

    .ref-field-label {
        font-size: 0.78rem;
    }

    .ref-sputum-grid label {
        padding: 8px 6px;
        font-size: 0.78rem;
        gap: 4px;
    }

    .ref-submit-btn {
        padding: 12px;
        font-size: 0.92rem;
    }

    .ref-receipt-id {
        font-size: 0.82rem;
    }

    .ref-receipt-summary {
        font-size: 0.78rem;
    }
}

/* ── Very small screens (width < 340px) ────────────────────────────── */
@media screen and (max-width: 340px) {
    .ref-card-header-inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .ref-sputum-grid {
        grid-template-columns: 1fr;
    }

    .ref-receipt-actions {
        flex-direction: column;
    }
}

/* ==============================================================================
   TOUCH-DEVICE REFINEMENTS (9:20 phones & tablets)
   ============================================================================== */

/* Subtle teal tap flash instead of the browser's grey/blue box */
html {
    -webkit-tap-highlight-color: rgba(13, 148, 136, 0.14);
}

/* Remove the legacy 300ms double-tap-zoom delay on interactive elements */
button,
a,
label,
select,
input[type="checkbox"],
input[type="radio"],
.btn,
.mobile-nav-item,
.sidebar-link,
.training-pill,
.form-chip,
.pagination-btn {
    touch-action: manipulation;
}

/* Lock the page behind the mobile drawer so it can't scroll underneath it */
body.drawer-open {
    overflow: hidden;
}

.app-sidebar {
    overscroll-behavior: contain;
}

/*
 * Sticky-hover reset. On touch screens :hover styles latch after a tap (rows
 * and options stay highlighted until you tap elsewhere), so hover feedback is
 * only kept for pointers that can actually hover.
 */
@media (hover: none) and (pointer: coarse) {
    .data-table tbody tr:hover td {
        background: var(--bg-card);
    }

    .card:hover {
        box-shadow: var(--shadow-xs);
    }

    .kpi-card:hover {
        transform: none;
        box-shadow: var(--shadow-xs);
    }

    .training-pill:hover {
        transform: none;
        box-shadow: var(--shadow-xs);
    }

    .btn-primary:hover:not(:disabled),
    .btn-round-add:hover,
    .sidebar-logout-btn:hover,
    .pagination-btn:hover:not(:disabled) {
        transform: none;
    }

    .btn-primary:hover:not(:disabled) {
        box-shadow: none;
    }

    .sidebar-link:not(.active):hover {
        background: transparent;
        color: var(--text-secondary);
    }

    .form-chip:not(.selected):hover {
        background: transparent;
        border-color: var(--border-light);
    }

    .btn-ghost:hover:not(:disabled) {
        background: transparent;
    }

    .ss-opt:not(.active):not(.selected):hover {
        background-color: #ffffff !important;
        color: var(--text-secondary) !important;
    }
}

/* ---------- PWA Install Notification Banner (Laptop / Desktop & Mobile) ---------- */
.pwa-install-banner {
    display: flex;
    position: fixed;
    top: 16px;
    right: 24px;
    height: 44px;
    padding: 4px 8px 4px 10px;
    background: #ffffff;
    border: 1px solid #99f6e4;
    border-radius: 9999px;
    box-shadow: 0 8px 24px rgba(13, 148, 136, 0.22), 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 10001; /* Above headers and topbars */
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    animation: pwaSlideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    backdrop-filter: blur(10px);
    box-sizing: border-box;
    max-width: 380px;
}

@keyframes pwaSlideDown {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 768px) {
    .pwa-install-banner {
        top: calc(8px + env(safe-area-inset-top, 0px));
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: calc(100% - 16px);
        max-width: 440px;
        height: 42px;
        padding: 4px 6px 4px 8px;
        margin: 0;
        animation: pwaSlideDownMobile 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    }
}

@keyframes pwaSlideDownMobile {
    from {
        opacity: 0;
        transform: translate(-50%, -20px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0) scale(1);
    }
}

.pwa-banner-left {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
}

.pwa-banner-mini-icon {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    flex-shrink: 0;
    object-fit: contain;
}

.pwa-banner-text-single {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.pwa-banner-tag {
    background: #f0fdfa;
    color: #0d9488;
    border: 1px solid #ccfbf1;
    font-size: 0.62rem;
    font-weight: 700;
    padding: 0px 4px;
    border-radius: 4px;
}

.pwa-banner-actions {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}

.pwa-install-btn {
    background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
    color: #ffffff;
    border: none;
    border-radius: 9999px;
    padding: 4px 10px;
    height: 28px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    box-shadow: 0 2px 6px rgba(13, 148, 136, 0.35);
    white-space: nowrap;
}

.pwa-install-btn:active {
    transform: scale(0.95);
}

.pwa-dismiss-btn {
    background: none;
    border: none;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.pwa-dismiss-btn:active {
    background: #f1f5f9;
    color: #1e293b;
}

.sidebar-install-item {
    margin: 8px 12px 0 12px;
    padding: 8px 12px;
    background: #f0fdfa;
    border: 1px dashed #99f6e4;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s;
}

.sidebar-install-item:hover {
    background: #ccfbf1;
    border-color: #5eead4;
}

.sidebar-install-text {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #0f766e;
}

/* PWA Instructions Modal (e.g. for iOS / Safari) */
.pwa-guide-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.pwa-guide-card {
    background: #ffffff;
    border-radius: 20px;
    max-width: 440px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.2);
    position: relative;
    animation: pwaSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.pwa-guide-steps {
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pwa-guide-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 0.84rem;
    color: var(--text-secondary, #334155);
}

.pwa-step-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #0d9488;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}