:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-hover: #4f46e5;
    --bg-main: #f8fafc;
    --bg-sidebar: #0f172a;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #f1f5f9;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.5);
    /* Premium Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --shadow-premium: 0 12px 40px -12px rgba(0, 0, 0, 0.08);
    --radius: 20px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Sidebar Refinement */
.sidebar {
    width: 280px;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: white;
    display: flex;
    flex-direction: column;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 30px rgba(0,0,0,0.05);
}

.brand {
    padding: 2.5rem 2rem;
    font-size: 1.6rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    letter-spacing: -0.5px;
}

.brand i {
    color: var(--primary-light);
    filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.4));
}

.nav-menu {
    flex: 1;
    padding: 1rem 1rem;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.9rem 1.25rem;
    color: #94a3b8;
    text-decoration: none;
    transition: all 0.3s ease;
    gap: 1rem;
    border-radius: 12px;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.15);
    color: white;
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.2);
}

.nav-item.active i {
    color: var(--primary-light);
}

/* Submenu Styles */
.nav-item-wrapper {
    position: relative;
    margin-bottom: 0.25rem;
}

.submenu {
    list-style: none;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    background: #1e293b;
    border-radius: 12px;
    position: absolute;
    left: calc(100% + 5px); /* Reduced gap */
    top: 0;
    min-width: 180px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.1);
    z-index: 9999;
    
    /* Animation & Stability */
    visibility: hidden;
    opacity: 0;
    transform: translateX(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transition-delay: 0.3s; /* Buffer time before disappearing */
}

/* Bridge the gap so the menu doesn't close when moving the mouse from item to submenu */
.submenu::after {
    content: '';
    position: absolute;
    top: 0;
    left: -15px; /* Cover the gap */
    width: 15px;
    bottom: 0;
}

.nav-item-wrapper:hover .submenu {
    visibility: visible;
    opacity: 1;
    transform: translateX(0);
    transition-delay: 0s; /* Appear immediately */
}

.submenu-item {
    padding: 0.5rem 1rem;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.submenu-item:hover {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}

.submenu-item.active {
    color: var(--primary-light);
    font-weight: 700;
}

.submenu-item i {
    font-size: 0.75rem;
    width: 12px;
}

/* Glassmorphism Top Bar */
.top-bar {
    height: 80px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 3rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: all 0.3s ease;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.search-wrapper {
    position: relative;
    width: 320px;
    display: none; /* Hidden on mobile by default */
}

@media (min-width: 1024px) {
    .search-wrapper { display: block; }
}

.search-wrapper i {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 0.9rem;
}

.search-bar {
    width: 100%;
    background: #f1f5f9;
    border: 1px solid transparent;
    padding: 0.75rem 1.25rem 0.75rem 2.8rem;
    border-radius: 14px;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.search-bar:focus {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.08);
    outline: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all 0.2s;
    position: relative;
    border: none;
    background: transparent;
    cursor: pointer;
}

.icon-btn:hover {
    background: #f1f5f9;
    color: var(--primary);
}

.icon-btn .badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 10px;
    height: 10px;
    background: #ef4444;
    border: 2px solid white;
    border-radius: 50%;
}

.user-profile-dropdown {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0.5rem 0.5rem 1.25rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
}

.user-profile-dropdown:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}

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

.user-name {
    display: block;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-main);
}

.user-role {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.avatar-wrapper {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
}

.avatar-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.content-body {
    padding: 2.5rem;
    flex: 1;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Premium Cards */
.card {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    padding: 2rem;
    box-shadow: var(--glass-shadow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
    box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.05);
}

/* Specialized Checkbox Cards */
.medical-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.25rem;
}

.checkbox-card {
    position: relative;
    cursor: pointer;
    background: white;
    border: 2px solid #f1f5f9;
    border-radius: 12px;
    padding: 1.25rem;
    text-align: center;
    transition: all 0.2s;
    user-select: none;
}

.checkbox-card input {
    position: absolute;
    opacity: 0;
}

.checkbox-card i {
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
    color: #cbd5e1;
    display: block;
    transition: all 0.2s;
}

.checkbox-card.selected,
.checkbox-card:has(input:checked) {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.03);
}

.checkbox-card.selected i,
.checkbox-card:has(input:checked) i {
    color: var(--primary);
}

.checkbox-card .label-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}

/* UI Elements Enhancement */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.95rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.form-input {
    width: 100%;
    padding: 0.85rem 1.2rem;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    font-size: 1rem;
    transition: all 0.2s;
}

.form-input:focus {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
    outline: none;
}

/* Alerts */
.alert {
    padding: 1rem 1.5rem;
    border-radius: 14px;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 600;
    font-size: 0.95rem;
    animation: slideDown 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow);
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.table th {
    padding: 1.25rem 1rem;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05rem;
    color: var(--text-muted);
    font-weight: 700;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        z-index: 1000;
        height: 100vh;
    }
    .sidebar.open { left: 0; }
    .content-body { padding: 1.5rem; }
}

/* Utilities */
.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.truncate-select {
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: middle;
}
