/* =========================================
   CSS VARIABLES & TOKENS (Upchaar Setu)
   ========================================= */
:root {
    /* Light Mode */
    --bg-color: #F7F7F9;
    --surface-color: #FFFFFF;
    --surface-alt: #F0F0F4;
    --text-primary: #111111;
    --text-secondary: #555555;
    --text-muted: #888888;
    --accent: #0284c7; /* Healthcare Blue */
    --accent-hover: #0369a1;
    --danger: #E32929;
    --success: #17B26A;
    --warning: #c27800;
    --border: rgba(0, 0, 0, 0.08);
    --border-focus: rgba(2, 132, 199, 0.4);
    
    /* Shadows & Depth (Light) */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.02), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 8px 16px rgba(0,0,0,0.03), 0 4px 8px rgba(0,0,0,0.04);
    --shadow-lg: 0 24px 48px rgba(0,0,0,0.05), 0 12px 24px rgba(0,0,0,0.04);
    --shadow-inset: inset 0 2px 4px rgba(0,0,0,0.06);
    --input-inset: inset 0 1px 3px rgba(0,0,0,0.04);
    --surface-border: 1px solid rgba(0,0,0,0.05);
    --surface-highlight: none;
}

[data-theme="dark"] {
    /* Dark Mode (Subtle & Eye-Friendly) */
    --bg-color: #18181B; 
    --surface-color: #27272A; 
    --surface-alt: #3F3F46; 
    --text-primary: #F4F4F5; 
    --text-secondary: #A1A1AA;
    --text-muted: #71717A;
    --accent: #38bdf8; 
    --accent-hover: #7dd3fc;
    --danger: #F87171;
    --success: #34D399;
    --warning: #fbbf24;
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(56, 189, 248, 0.5);

    /* Shadows & Depth (Dark) */
    --shadow-sm: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-md: 0 10px 20px rgba(0,0,0,0.5);
    --shadow-lg: 0 30px 60px rgba(0,0,0,0.6);
    --shadow-inset: inset 0 3px 6px rgba(0,0,0,0.5);
    --input-inset: inset 0 2px 5px rgba(0,0,0,0.4);
    --surface-border: 1px solid rgba(255,255,255,0.05);
    --surface-highlight: inset 0 1px 0 rgba(255,255,255,0.04);
}

/* =========================================
   RESET & BASE
   ========================================= */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.4s ease, color 0.4s ease;
    font-size: 13px;
    height: 100vh;
    overflow: hidden;
}

/* Layout Grid */
.app-layout { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }

.sidebar {
    background-color: var(--surface-color);
    border-right: var(--surface-border);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    height: 100vh;
    z-index: 10;
}

.main-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    padding: 1.5rem;
    gap: 1.5rem;
}

/* Sidebar Components */
.logo-container { display: flex; align-items: center; gap: 10px; margin-bottom: 2rem; }
.logo-container img { height: 35px; }
.logo-container h1 { font-size: 1.25rem; font-weight: 700; margin: 0; }
.system-flag { font-size: 0.7rem; text-transform: uppercase; font-weight: 700; color: var(--text-muted); background: var(--surface-alt); padding: 2px 6px; border-radius: 4px; }

.user-profile { display: flex; align-items: center; gap: 10px; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.pfp { height: 40px; width: 40px; border-radius: 8px; object-fit: cover; box-shadow: var(--shadow-sm); }
.user-info { display: flex; flex-direction: column; }
#currentUsername { font-weight: 600; font-size: 0.9rem; }

.nav-menu { display: flex; flex-direction: column; gap: 0.5rem; flex: 1; }
.nav-section-title { font-size: 0.75rem; text-transform: uppercase; font-weight: 700; color: var(--text-muted); margin-top: 1rem; margin-bottom: 0.5rem; letter-spacing: 0.05em; }

/* Buttons */
.btn {
    font-family: inherit; font-size: 0.85rem; font-weight: 500;
    padding: 0.6rem 1.2rem; border-radius: 8px; border: none;
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    text-transform: capitalize;
}
.btn-primary { background-color: var(--accent); color: #FFF; box-shadow: 0 4px 10px rgba(2, 132, 199, 0.3), inset 0 1px 0 rgba(255,255,255,0.2); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 15px rgba(2, 132, 199, 0.4), inset 0 1px 0 rgba(255,255,255,0.2); }
.btn-primary:active { transform: translateY(1px); box-shadow: inset 0 3px 5px rgba(0,0,0,0.2); }

.btn-surface { background-color: var(--surface-color); color: var(--text-primary); border: var(--surface-border); box-shadow: var(--shadow-sm), var(--surface-highlight); }
.btn-surface:hover { transform: translateY(-2px); box-shadow: var(--shadow-md), var(--surface-highlight); }
.btn-surface:active { transform: translateY(1px); box-shadow: var(--shadow-inset); }

.btn-ghost { background: transparent; color: var(--text-secondary); width: 100%; justify-content: flex-start; }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text-primary); }

.btn-danger { background-color: var(--danger); color: #FFF; }
.btn-danger:hover { opacity: 0.9; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; margin-bottom: 0.4rem; color: var(--text-secondary); }
.form-control {
    width: 100%; padding: 0.7rem 1rem;
    background-color: var(--surface-color); color: var(--text-primary);
    border: var(--surface-border); border-radius: 8px;
    box-shadow: var(--input-inset); font-family: inherit; font-size: 0.85rem;
    transition: all 0.3s ease;
}
.form-control:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.1), var(--input-inset); }

/* Grid Forms (Modals) */
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-form-large { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }

/* Data Table */
.table-wrapper {
    background-color: var(--surface-color); border: var(--surface-border);
    border-radius: 12px; overflow: auto; box-shadow: var(--shadow-sm), var(--surface-highlight);
    flex: 1;
}
table { width: max-content; border-collapse: collapse; text-align: left; }
th, td { padding: 0.8rem 1.2rem; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); font-size: 0.85rem; white-space: nowrap; }
th { font-weight: 600; color: var(--text-secondary); background-color: var(--surface-alt); position: sticky; top: 0; z-index: 10; }
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: var(--surface-alt); }

.sticky-col { position: sticky; right: 0; background-color: var(--surface-color); z-index: 5; border-left: 2px solid var(--border); }
th.sticky-col { background-color: var(--surface-alt); z-index: 11; }
tr:hover td.sticky-col { background-color: var(--surface-alt); }

/* Modals */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease; z-index: 200;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal {
    background-color: var(--surface-color); border: var(--surface-border);
    border-radius: 16px; width: 90%; max-width: 500px; max-height: 90vh;
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg), var(--surface-highlight);
    transform: translateY(20px); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal.large-modal { max-width: 900px; }

.modal-header { padding: 1.5rem; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 1.2rem; font-weight: 600; }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 1rem; }

/* Tags / Badges (Replaces strict text colors) */
.tag {
    display: inline-block; padding: 0.25rem 0.6rem; border-radius: 20px;
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.tag-success { background-color: rgba(23, 178, 106, 0.1); color: var(--success); }
.tag-danger { background-color: rgba(227, 41, 41, 0.1); color: var(--danger); }
.tag-warning { background-color: rgba(194, 120, 0, 0.1); color: var(--warning); }
.tag-neutral { background-color: var(--surface-alt); color: var(--text-secondary); }

/* Y/N/WAIT Toggle Groups */
.yn-group { display: flex; width: 100%; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.yn-group .btn { border-radius: 0; flex: 1; border: none; padding: 0.6rem 0; font-size: 0.75rem; background: var(--surface-color); }
.yn-group .btn:not(:last-child) { border-right: 1px solid var(--border); }
.yn-group .btn.active-y { background-color: rgba(23, 178, 106, 0.15); color: var(--success); font-weight: 700; }
.yn-group .yn-group-n.active-n { background-color: rgba(227, 41, 41, 0.15); color: var(--danger); font-weight: 700; }
.yn-group .yn-group-w.active-w { background-color: rgba(194, 120, 0, 0.15); color: var(--warning); font-weight: 700; }

textarea.form-control { resize: none; height: 350px; font-family: monospace; }

/* =========================================
   MOBILE RESPONSIVENESS PATCH
   ========================================= */

.mobile-header {
    display: none;
    padding: 1rem 1.5rem;
    background-color: var(--surface-color);
    border-bottom: var(--surface-border);
    align-items: center;
    gap: 1rem;
    z-index: 90;
    box-shadow: var(--shadow-sm);
}

@media (max-width: 900px) {
    /* Collapse the main grid to a vertical stack */
    .app-layout { 
        display: flex; 
        flex-direction: column; 
    }
    
    /* Reveal the mobile header */
    .mobile-header { 
        display: flex; 
    }
    
    /* Convert sidebar to an off-canvas drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 100; /* Must be above overlay */
        box-shadow: var(--shadow-lg);
    }
    
    /* Active state for drawer */
    .sidebar.active { 
        transform: translateX(0); 
    }
    
    /* Adjust main content area */
    .main-content { 
        padding: 1rem; 
        height: calc(100vh - 70px); /* Account for mobile header height */
    }
    
    /* Ensure table wrapper scrolls horizontally on mobile */
    .table-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Mobile Modal Adjustments */
    .grid-form, .grid-form-large { grid-template-columns: 1fr; }
}