/* =====================================================
   KARPAGAM CLINIC - Premium Design System v4
   Professional, Responsive, Modern
   ===================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
    --primary-color: #10b981;
    --primary-dark: #047857;
    --primary-light: #d1fae5;
    --secondary-color: #0f172a;
    --bg-color: #f1f5f9;
    --surface-color: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --radius-lg: 14px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.09);
    --shadow-lg: 0 12px 36px rgba(0,0,0,0.13);
    --sidebar-width: 230px;
    --topbar-height: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', sans-serif; }

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: 14px;
    line-height: 1.5;
}

/* =====================================================
   PIN LOCK SCREEN
   ===================================================== */
.pin-lock-overlay {
    position: fixed; inset: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
    display: flex; align-items: center; justify-content: center;
    z-index: 99999;
    flex-direction: column; gap: 0;
}
.pin-lock-overlay.hidden { display: none; }

.pin-card {
    background: rgba(255,255,255,0.06);
    backdrop-filter: blur(24px);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 22px;
    padding: 44px 38px;
    width: 360px;
    text-align: center;
    box-shadow: 0 30px 70px rgba(0,0,0,0.55);
}
.pin-logo { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 18px; border: 3px solid var(--primary-color); object-fit: cover; }
.pin-card h2 { color: white; font-size: 1.35rem; font-weight: 800; margin-bottom: 5px; letter-spacing: -0.3px; }
.pin-card p { color: #94a3b8; font-size: 0.83rem; margin-bottom: 26px; }

.pin-dots {
    display: flex; justify-content: center; gap: 14px; margin-bottom: 26px;
}
.pin-dot {
    width: 15px; height: 15px; border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.3);
    transition: all 0.2s;
}
.pin-dot.filled { background: var(--primary-color); border-color: var(--primary-color); transform: scale(1.18); box-shadow: 0 0 10px rgba(16,185,129,0.5); }

.pin-keypad {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}
.pin-key {
    background: rgba(255,255,255,0.08);
    color: white; border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px; padding: 15px; font-size: 1.15rem; font-weight: 600;
    cursor: pointer; transition: all 0.15s; user-select: none;
}
.pin-key:hover { background: rgba(255,255,255,0.16); transform: scale(1.05); }
.pin-key:active { transform: scale(0.95); }
.pin-key.del { background: rgba(239,68,68,0.15); color: #f87171; border-color: rgba(239,68,68,0.2); }
.pin-key.clr { background: rgba(251,191,36,0.15); color: #fbbf24; border-color: rgba(251,191,36,0.2); }

.pin-error { color: #f87171; font-size: 0.8rem; margin-top: 14px; min-height: 18px; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}
.shake { animation: shake 0.4s; }

/* =====================================================
   BRANCH SELECTION (index.html)
   ===================================================== */
.branch-selection-body {
    display: flex; justify-content: center; align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f0fdf4 0%, #e0f2fe 100%);
    padding: 20px;
}
.branch-container {
    text-align: center; background: var(--surface-color);
    padding: 44px 36px; border-radius: 22px;
    box-shadow: var(--shadow-lg); max-width: 880px; width: 100%;
}
.header-logo h2 { color: var(--primary-dark); margin-bottom: 6px; font-weight: 800; font-size: 1.7rem; letter-spacing: -0.5px; }
.header-logo p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 30px; }

.branch-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.branch-card {
    display: flex; align-items: center; justify-content: center; flex-direction: column;
    text-decoration: none; background: var(--bg-color); border: 2px solid var(--border-color);
    border-radius: var(--radius-lg); padding: 22px 14px; color: var(--text-main);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); cursor: pointer;
    font-weight: 700; font-size: 0.9rem; gap: 10px; position: relative; overflow: hidden;
}
.branch-card::before {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(16,185,129,0) 0%, rgba(16,185,129,0.05) 100%);
    opacity: 0; transition: opacity 0.25s;
}
.branch-card i { font-size: 1.5rem; color: var(--primary-color); }
.branch-card:hover {
    border-color: var(--primary-color); box-shadow: 0 8px 24px rgba(16,185,129,0.18);
    color: var(--primary-dark); transform: translateY(-4px);
}
.branch-card:hover::before { opacity: 1; }

/* =====================================================
   APP LAYOUT & SIDEBAR
   ===================================================== */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #0f172a 0%, #1a2540 100%);
    color: #fff;
    padding: 0;
    display: flex; flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid rgba(255,255,255,0.05);
    overflow-y: auto;
    z-index: 10;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}
.sidebar-brand img { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--primary-color); flex-shrink: 0; object-fit: cover; }
.sidebar-brand h3 { font-size: 0.82rem; font-weight: 700; color: #f1f5f9; line-height: 1.2; margin: 0; }
.sidebar-brand h4 { font-size: 0.68rem; color: #64748b; font-weight: 400; margin-top: 2px; }

.sidebar nav { display: flex; flex-direction: column; padding: 10px 8px; flex: 1; gap: 2px; }

.sidebar nav a {
    text-decoration: none; color: #94a3b8;
    padding: 9px 12px; border-radius: 10px;
    transition: all 0.18s; font-weight: 500;
    display: flex; align-items: center; gap: 10px;
    font-size: 0.82rem; white-space: nowrap;
}
.sidebar nav a i { font-size: 0.95rem; width: 18px; text-align: center; flex-shrink: 0; }
.sidebar nav a:hover { background: rgba(255,255,255,0.07); color: #e2e8f0; }
.sidebar nav a.active {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white; box-shadow: 0 3px 12px rgba(16,185,129,0.35); font-weight: 700;
}

.sidebar hr { border: none; height: 1px; background: rgba(255,255,255,0.07); margin: 6px 8px; }

.back-link { color: #f87171 !important; }
.back-link:hover { background: rgba(239,68,68,0.1) !important; color: #fca5a5 !important; }

/* =====================================================
   MAIN CONTENT
   ===================================================== */
.main-content { flex: 1; overflow-y: auto; background: var(--bg-color); display: flex; flex-direction: column; overflow-x: hidden; }

.topbar {
    background: var(--surface-color);
    padding: 0 24px;
    height: var(--topbar-height);
    border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
    gap: 8px;
    position: sticky; top: 0; z-index: 50;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}
.topbar h2 {
    font-weight: 700; font-size: 1rem; color: var(--secondary-color);
    display: flex; align-items: center; gap: 8px; white-space: nowrap;
    flex-shrink: 0;
}
.topbar h2 i { font-size: 0.95rem; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.container-fluid { padding: 18px 22px; max-width: 1440px; margin: 0 auto; width: 100%; }

/* =====================================================
   STAT CARDS — Premium redesign
   ===================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px; margin-bottom: 20px;
}
.stat-card {
    background: var(--surface-color); border-radius: var(--radius-lg);
    padding: 14px 16px; box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: flex; align-items: center; gap: 14px;
    transition: all 0.25s; cursor: default;
    position: relative; overflow: hidden;
}
.stat-card::after {
    content: ''; position: absolute; top: 0; left: 0;
    width: 3px; height: 100%; border-radius: 3px 0 0 3px;
    background: var(--primary-color); opacity: 0;
    transition: opacity 0.25s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card:hover::after { opacity: 1; }

.stat-icon { width: 44px; height: 44px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; flex-shrink: 0; }
.icon-blue { background: #e0f2fe; color: #0284c7; }
.icon-green { background: #dcfce7; color: #16a34a; }
.icon-yellow { background: #fef9c3; color: #b45309; }
.icon-purple { background: #f3e8ff; color: #9333ea; }
.icon-rose { background: #ffe4e6; color: #e11d48; }

.stat-info h4 { color: var(--text-muted); font-size: 0.67rem; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 3px; font-weight: 600; }
.stat-info h2 { color: var(--secondary-color); font-size: 1.3rem; font-weight: 800; line-height: 1; letter-spacing: -0.5px; }

/* =====================================================
   PANELS
   ===================================================== */
.panel {
    background: var(--surface-color); border-radius: var(--radius-lg);
    padding: 20px; margin-bottom: 16px;
    box-shadow: var(--shadow-sm); border: 1px solid var(--border-color);
}
.panel h3 { margin-bottom: 16px; color: var(--secondary-color); font-size: 0.97rem; display: flex; align-items: center; gap: 8px; font-weight: 700; }
.panel h3 i { color: var(--primary-color); }

/* =====================================================
   FORMS
   ===================================================== */
.form-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.form-group { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 150px; }
.form-group.flex-2 { flex: 2; }
.form-group label { font-size: 0.76rem; font-weight: 600; color: var(--text-muted); letter-spacing: 0.2px; }

input, select, textarea {
    padding: 9px 12px; border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md); font-size: 0.875rem;
    outline: none; transition: all 0.18s;
    background-color: var(--bg-color); color: var(--text-main); width: 100%;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(16,185,129,0.12);
    background: var(--surface-color);
}
.readonly-input { background: #f1f5f9 !important; cursor: not-allowed; }

/* =====================================================
   BUTTONS — Premium
   ===================================================== */
button, .btn {
    padding: 8px 16px; border: none; border-radius: var(--radius-md);
    font-weight: 600; cursor: pointer; transition: all 0.18s;
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px; font-size: 0.83rem; text-decoration: none; white-space: nowrap;
    position: relative; overflow: hidden;
}
.btn-primary { background: var(--primary-color); color: white; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(16,185,129,0.3); transform: translateY(-1px); }
.btn-success { background: linear-gradient(135deg, #10b981, #059669); color: white; font-size: 0.9rem; padding: 12px 22px; width: 100%; border-radius: var(--radius-md); font-weight: 700; }
.btn-success:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(16,185,129,0.4); }
.btn-danger { background: #fee2e2; color: #ef4444; padding: 6px 12px; font-size: 0.8rem; border-radius: var(--radius-sm); }
.btn-danger:hover { background: #fecaca; transform: scale(1.03); }
.btn-info { background: #e0f2fe; color: #0284c7; padding: 6px 12px; font-size: 0.8rem; border-radius: var(--radius-sm); }
.btn-info:hover { background: #bae6fd; }
.btn-whatsapp { background: #25D366; color: white; padding: 6px 12px; font-size: 0.8rem; border-radius: var(--radius-sm); }
.btn-whatsapp:hover { background: #128C7E; }
.btn-outline { background: transparent; border: 1.5px solid var(--border-color); color: var(--text-main); }
.btn-outline:hover { background: var(--bg-color); border-color: #94a3b8; }
.btn-sm { padding: 6px 11px; font-size: 0.78rem; border-radius: var(--radius-sm); }

/* =====================================================
   DATA TABLES — Premium
   ===================================================== */
.table-responsive { overflow-x: auto; width: 100%; border-radius: var(--radius-md); border: 1px solid var(--border-color); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; background: var(--surface-color); }
.data-table th, .data-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border-color); }
.data-table th { background: #f8fafc; color: var(--text-muted); font-weight: 700; text-transform: uppercase; font-size: 0.70rem; letter-spacing: 0.5px; }
.data-table tbody tr { transition: background 0.15s; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tfoot tr { background: var(--secondary-color); color: white; font-size: 0.85rem; }

.text-right { text-align: right !important; }
.text-center { text-align: center !important; }
.text-muted { color: var(--text-muted); }
.status-badge { padding: 3px 10px; border-radius: 20px; font-size: 0.71rem; font-weight: 700; background: #dcfce7; color: #16a34a; }

/* =====================================================
   MODALS — Premium bottom-sheet on mobile
   ===================================================== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,0.6); backdrop-filter: blur(4px);
    display: none; align-items: flex-start; justify-content: center;
    z-index: 100; opacity: 0; transition: opacity 0.25s;
    overflow-y: auto; padding: 20px;
}
.modal-overlay.active { display: flex; opacity: 1; }
.modal-content {
    background: var(--surface-color); border-radius: var(--radius-lg); padding: 24px;
    width: 100%; max-width: 600px; box-shadow: var(--shadow-lg);
    margin: auto; transform: translateY(20px); transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
.modal-overlay.active .modal-content { transform: translateY(0); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; border-bottom: 1px solid var(--border-color); padding-bottom: 14px; }
.modal-header h3 { font-size: 1.05rem; color: var(--secondary-color); font-weight: 700; }
.close-modal { cursor: pointer; color: var(--text-muted); font-size: 1.1rem; padding: 4px; border-radius: 6px; transition: all 0.15s; }
.close-modal:hover { color: #ef4444; background: #fee2e2; }

/* =====================================================
   VARIOUS UI ELEMENTS
   ===================================================== */
.empty-state { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.empty-state i { font-size: 2.8rem; color: var(--border-color); margin-bottom: 14px; display: block; }
.empty-state p { font-size: 0.9rem; }
.hidden { display: none !important; }

/* Patient cards */
.patient-profile-card {
    display: flex; gap: 16px; align-items: flex-start;
    background: linear-gradient(135deg, #fff 0%, #f0fdf4 100%);
    padding: 20px; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
    margin-bottom: 20px; border: 1px solid var(--primary-color);
}
.profile-photo { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; border: 3px solid white; box-shadow: var(--shadow-md); background: #e2e8f0; display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: 2rem; overflow: hidden; flex-shrink: 0; }
.profile-photo img { width: 100%; height: 100%; object-fit: cover; }
.profile-details { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.profile-header { display: flex; justify-content: space-between; align-items: flex-start; }
.profile-header h2 { color: var(--secondary-color); font-size: 1.35rem; margin: 0; font-weight: 800; }
.missing-badge { background: #fee2e2; color: #ef4444; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.upcoming-badge { background: #dcfce7; color: #16a34a; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }

/* Timeline */
.timeline-container { position: relative; padding-left: 24px; margin-top: 16px; }
.timeline-container::before { content: ''; position: absolute; left: 0; top: 0; height: 100%; width: 2px; background: var(--border-color); border-radius: 2px; }
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-dot { position: absolute; left: -29px; top: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--primary-color); border: 2px solid var(--bg-color); box-shadow: 0 0 0 2px var(--primary-color); }
.timeline-content { background: var(--surface-color); padding: 14px; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); }
.timeline-header { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--text-muted); font-size: 0.82rem; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.timeline-medicines { background: var(--bg-color); padding: 10px; border-radius: var(--radius-sm); border-left: 3px solid var(--primary-color); font-size: 0.87rem; line-height: 1.6; }

/* Cloud status badge — in topbar */
#cloudSyncContainer {
    font-size: 0.72rem !important;
    padding: 4px 10px !important;
}
#cloudSyncContainer span { font-size: 0.72rem; }

/* =====================================================
   PRINT
   ===================================================== */
@media print {
    body > * { display: none !important; }
    #finalPrintWrapper, #finalPrintWrapper * { visibility: visible !important; }
    #finalPrintWrapper {
        display: block !important;
        position: static !important;
        margin: 0 !important; padding: 0 !important;
        width: 100% !important; background: white !important;
        box-shadow: none !important;
    }
}

/* =====================================================
   ANIMATIONS
   ===================================================== */
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-15px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}
.shake { animation: shake 0.4s; }

/* =====================================================
   PAGINATION
   ===================================================== */
.pagination-container {
    display: flex; justify-content: center; align-items: center;
    gap: 8px; margin-top: 22px; padding: 14px 0;
    border-top: 1px solid var(--border-color);
}
.pagination-btn {
    padding: 7px 16px; border: 1.5px solid var(--border-color);
    background: #fff; color: var(--text-main);
    border-radius: 8px; font-weight: 600; font-size: 0.82rem;
    cursor: pointer; transition: all 0.2s;
    display: flex; align-items: center; gap: 6px;
}
.pagination-btn:hover:not(:disabled) {
    border-color: var(--primary-color); color: var(--primary-color);
    background: var(--primary-light);
}
.pagination-btn:disabled { opacity: 0.45; cursor: not-allowed; background: #f8fafc; }
.pagination-info { font-size: 0.82rem; color: var(--text-muted); font-weight: 500; margin: 0 8px; }

/* =====================================================
   TABLET (max 1024px)
   ===================================================== */
@media screen and (max-width: 1024px) {
    :root { --sidebar-width: 200px; }
    .container-fluid { padding: 16px 18px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
}

/* =====================================================
   TABLET NARROW (max 920px) - Icon-only sidebar
   ===================================================== */
@media screen and (max-width: 920px) {
    :root { --sidebar-width: 62px; }
    .sidebar-brand h3, .sidebar-brand h4 { display: none; }
    .sidebar-brand { padding: 12px 8px; justify-content: center; }
    .sidebar-brand img { width: 36px; height: 36px; margin: 0; }
    .sidebar nav { padding: 10px 6px; }
    .sidebar nav a { justify-content: center; padding: 10px 8px; }
    .sidebar nav a span { display: none; }
    .sidebar nav a i { font-size: 1.1rem; margin: 0; width: auto; }
}

/* =====================================================
   MOBILE (max 768px) — Bottom navigation
   ===================================================== */
@media screen and (max-width: 768px) {
    /* Layout: column stacking */
    .app-layout { flex-direction: column; height: auto; min-height: 100vh; overflow-x: hidden; }

    /* Sidebar → top mobile header */
    .sidebar {
        width: 100%; height: auto;
        flex-direction: row; align-items: center;
        justify-content: space-between;
        padding: 0 14px;
        min-height: 50px;
        position: sticky; top: 0; z-index: 100;
        border-right: none; border-bottom: 1px solid rgba(255,255,255,0.08);
        overflow: visible;
    }
    .sidebar-brand {
        flex-direction: row; padding: 0; border: none;
        margin: 0; gap: 8px; align-items: center;
    }
    .sidebar-brand img { width: 30px; height: 30px; margin: 0; }
    .sidebar-brand h3 { display: block; font-size: 0.78rem; color: #f1f5f9; }
    .sidebar-brand h4 { display: block; font-size: 0.64rem; color: #64748b; }

    /* Bottom Navigation Bar */
    .sidebar nav {
        position: fixed; bottom: 0; left: 0; right: 0;
        width: 100%; height: auto; flex-direction: row;
        justify-content: space-around; align-items: stretch;
        padding: 5px 0 env(safe-area-inset-bottom, 6px); z-index: 1000;
        background: #111827;
        box-shadow: 0 -3px 16px rgba(0,0,0,0.3);
        gap: 0; border-top: 1px solid rgba(255,255,255,0.08);
    }
    .sidebar nav a {
        flex-direction: column; gap: 3px; padding: 6px 4px;
        color: #94a3b8; flex: 1; text-align: center;
        white-space: nowrap; justify-content: flex-start;
        min-width: 0; border-radius: 0;
    }
    .sidebar nav a i { font-size: 1.1rem; color: #94a3b8; }
    .sidebar nav a span {
        display: block; font-size: 0.56rem; line-height: 1;
        color: #6b7280; letter-spacing: -0.2px;
        overflow: hidden; text-overflow: ellipsis; max-width: 100%;
    }
    .sidebar nav a.active {
        background: transparent; box-shadow: none;
        border-radius: 0; border-top: 2.5px solid var(--primary-color);
    }
    .sidebar nav a.active i, .sidebar nav a.active span { color: var(--primary-color); font-weight: 700; }
    .sidebar hr { display: none; }
    .sidebar nav .back-link { color: #f87171 !important; background: transparent !important; }
    .sidebar nav .back-link i, .sidebar nav .back-link span { color: #f87171 !important; }

    /* Main content — needs padding for bottom nav */
    .main-content {
        padding-bottom: 64px;
        flex: 1; overflow-x: hidden;
    }

    /* Topbar */
    .topbar {
        padding: 0 12px; height: 48px;
        flex-shrink: 0;
    }
    .topbar h2 { font-size: 0.88rem; gap: 6px; }
    .topbar h2 i { font-size: 0.85rem; }
    .topbar-actions { gap: 5px; }
    /* Hide button text labels on mobile, keep icons */
    .topbar-actions .btn span,
    .topbar-actions .btn-text { display: none; }
    .topbar-actions .btn { padding: 6px 10px; font-size: 0.78rem; }

    /* Content */
    .container-fluid { padding: 12px 12px 0; }

    /* Stats — 2 columns */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px; margin-bottom: 14px;
    }
    .stat-card { padding: 12px 10px; gap: 10px; }
    .stat-card::after { display: none; }
    .stat-icon { width: 38px; height: 38px; font-size: 1rem; flex-shrink: 0; border-radius: 9px; }
    .stat-info h2 { font-size: 1.15rem; }
    .stat-info h4 { font-size: 0.63rem; }

    /* Orders summary strip — 2 cols */
    .summary-strip { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
    .summary-card  { padding: 12px 14px; }
    .summary-card h3 { font-size: 1.1rem; }
    .summary-card h5 { font-size: 0.68rem; }

    /* Filter bar */
    .filter-bar { flex-direction: column; align-items: stretch; gap: 8px; }
    .filter-bar input, .filter-bar select { width: 100%; }
    .filter-bar .period-btn { flex: 1; text-align: center; }

    /* Panels */
    .panel { padding: 14px; margin-bottom: 12px; border-radius: 12px; }
    .panel h3 { font-size: 0.9rem; margin-bottom: 12px; }
    .panel canvas { max-width: 100% !important; }

    /* Stack grid divs vertically */
    .container-fluid [style*="grid-template-columns: 2fr 1fr"],
    .container-fluid [style*="grid-template-columns: 1fr 1fr"] {
        display: block !important;
    }
    .container-fluid [style*="grid-template-columns: 2fr 1fr"] > *,
    .container-fluid [style*="grid-template-columns: 1fr 1fr"] > * {
        margin-bottom: 12px;
    }

    /* Tables */
    .table-responsive { border-radius: 8px; }
    .data-table th, .data-table td { padding: 9px 10px; font-size: 0.78rem; }
    .data-table th { font-size: 0.64rem; }

    /* Forms */
    .form-row { flex-direction: column; gap: 10px; }
    .form-group { min-width: 0; width: 100%; }
    input, select, textarea { padding: 9px 11px; font-size: 0.875rem; }

    /* Modals — slide up from bottom */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal-content {
        border-radius: 18px 18px 0 0;
        padding: 20px 16px 28px;
        max-height: 94vh; overflow-y: auto;
        margin: 0; width: 100% !important;
        transform: translateY(100%);
    }
    .modal-overlay.active .modal-content { transform: translateY(0); }
    .modal-header h3 { font-size: 0.95rem; }

    /* Panel flex headers */
    .panel [style*="display:flex; justify-content:space-between"],
    .panel [style*="display: flex; justify-content: space-between"] {
        flex-direction: column; align-items: flex-start !important;
        gap: 10px;
    }
    .panel [style*="display:flex; justify-content:space-between"] > div,
    .panel [style*="display: flex; justify-content: space-between"] > div {
        margin-left: 0 !important; width: 100% !important;
    }
    .panel [style*="display:flex; justify-content:space-between"] input,
    .panel [style*="display: flex; justify-content: space-between"] input {
        width: 100% !important; max-width: 100% !important;
    }

    /* Buttons */
    .btn { padding: 8px 12px; font-size: 0.8rem; }
    .btn-success { font-size: 0.85rem; padding: 12px 16px; }

    /* Branch cards */
    .branch-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .branch-card { padding: 16px 10px; font-size: 0.82rem; gap: 8px; }
    .branch-card i { font-size: 1.2rem; }

    /* Branch container */
    .branch-container { padding: 26px 16px; border-radius: 16px; }
    .header-logo h2 { font-size: 1.15rem; }
    .header-logo p { font-size: 0.78rem; }

    /* PIN lock */
    .pin-card { width: 96vw; padding: 30px 22px; border-radius: 18px; }
    .pin-key { padding: 13px; font-size: 1.05rem; }

    /* Patient profile */
    .patient-profile-card { flex-direction: column; align-items: center; text-align: center; padding: 16px; gap: 12px; }
    .profile-photo { width: 68px; height: 68px; font-size: 1.7rem; }
    .profile-header { flex-direction: column; align-items: center; gap: 6px; }
    .profile-header h2 { font-size: 1.15rem; }

    /* Timeline */
    .timeline-container { padding-left: 18px; }
    .timeline-content { padding: 10px; }
    .timeline-header { font-size: 0.75rem; }

    /* Hide non-essential table columns */
    .mobile-hide { display: none !important; }

    /* Patient modal rows */
    #patientModal .form-row { flex-wrap: wrap; gap: 10px; }
    #patientModal .form-group[style*="min-width:80px"],
    #patientModal .form-group[style*="min-width: 80px"] {
        flex: 1 1 calc(50% - 10px) !important; min-width: 0 !important;
    }
    #patientModal .form-group[style*="min-width:90px"],
    #patientModal .form-group[style*="min-width: 90px"] {
        flex: 1 1 calc(50% - 10px) !important; min-width: 0 !important;
    }
    #patientModal .form-group[style*="flex:0"] {
        flex: 0 0 auto !important; align-self: flex-end;
    }
    #patientModal textarea { min-height: 60px; }
    #patientModal .modal-header { flex-wrap: wrap; gap: 6px; }
    #patientModal .modal-header h3 { flex: 1; }

    /* Cloud button on mobile — hide text to save space */
    #cloudSyncContainer span { display: none !important; }
    #cloudSyncContainer {
        padding: 5px 8px !important;
        border-radius: 50% !important;
        min-width: 32px; min-height: 32px;
        justify-content: center;
    }
    #cloudSyncContainer i { font-size: 13px !important; }
}

/* =====================================================
   SMALL PHONE (max 480px)
   ===================================================== */
@media screen and (max-width: 480px) {
    .stats-grid    { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card     { padding: 10px 8px; gap: 8px; }
    .stat-info h2  { font-size: 1.05rem; }
    .stat-info h4  { font-size: 0.6rem; }
    .branch-grid   { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .container-fluid { padding: 10px 10px 0; }
    .topbar        { padding: 0 10px; height: 44px; }
    .topbar h2     { font-size: 0.82rem; }
    .pin-card      { width: 98vw; padding: 22px 14px; }
    .data-table th, .data-table td { padding: 8px 8px; font-size: 0.73rem; }
    .summary-strip { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
    .summary-card  { padding: 10px 12px; }
    .filter-bar { gap: 6px; }
    .period-btn  { padding: 6px 8px; font-size: 0.78rem; }
    .modal-content { padding: 16px 14px 28px; }
}
