/* ==========================================
   CSS Variables - Theme System
   ========================================== */
:root {
    /* Light Theme (default fallback) */
    --sidebar-bg: #f8f9fa;
    --sidebar-text: #1a1d29;
    --sidebar-section-label: #6c757d;
    --sidebar-hover: #e9ecef;
    --sidebar-active-bg: #3b82f6;
    --sidebar-active-text: #ffffff;
    
    --main-bg: #ffffff;
    --main-text: #1a1d29;
    --main-text-muted: #6c757d;
    
    --card-bg: #ffffff;
    --card-border: #dee2e6;
    --card-header-bg: #d4a017;
    --card-header-text: #1a1d29;
    
    --input-bg: #ffffff;
    --input-border: #ced4da;
    --input-text: #1a1d29;
    --input-placeholder: #6c757d;
    
    --btn-primary-bg: #3b82f6;
    --btn-primary-text: #ffffff;
    
    --alert-success-bg: #d1e7dd;
    --alert-success-text: #0f5132;
    --alert-success-border: #badbcc;
    
    --autocomplete-bg: #ffffff;
    --autocomplete-hover: #e9ecef;
    --autocomplete-text: #1a1d29;
    
    --scrollbar-track: #f1f1f1;
    --scrollbar-thumb: #c1c1c1;
}

[data-theme="dark"] {
    /* Dark Theme */
    --sidebar-bg: #1a1d29;
    --sidebar-text: #e0e0e0;
    --sidebar-section-label: #7a8599;
    --sidebar-hover: #2a2f3d;
    --sidebar-active-bg: #3b82f6;
    --sidebar-active-text: #ffffff;
    
    --main-bg: #2d3142;
    --main-text: #e0e0e0;
    --main-text-muted: #a0a8b8;
    
    --card-bg: #1e2130;
    --card-border: #3a3f50;
    --card-header-bg: #d4a017;
    --card-header-text: #1a1d29;
    
    --input-bg: #2a2f3d;
    --input-border: #3a3f50;
    --input-text: #e0e0e0;
    --input-placeholder: #7a8599;
    
    --btn-primary-bg: #3b82f6;
    --btn-primary-text: #ffffff;
    
    --alert-success-bg: #1e3a2f;
    --alert-success-text: #75d99e;
    --alert-success-border: #2d5a45;
    
    --autocomplete-bg: #2a2f3d;
    --autocomplete-hover: #3a3f50;
    --autocomplete-text: #e0e0e0;
    
    --scrollbar-track: #2a2f3d;
    --scrollbar-thumb: #4a4f5d;
}

/* ==========================================
   Base Styles
   ========================================== */
html {
    font-size: 14px;
    height: 100%;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background-color: var(--main-bg);
    color: var(--main-text);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ==========================================
   App Container Layout
   ========================================== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ==========================================
   Sidebar Styles
   ========================================== */
.sidebar {
    width: 220px;
    min-width: 220px;
    background-color: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, transform 0.3s ease;
    z-index: 1000;
}

.sidebar-header {
    padding: 1.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--card-border);
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 6px;
}

/* Show/hide logos based on theme */
[data-theme="dark"] .sidebar-logo-dark {
    display: block;
}

[data-theme="dark"] .sidebar-logo-light {
    display: none;
}

[data-theme="light"] .sidebar-logo-dark,
:root:not([data-theme]) .sidebar-logo-dark {
    display: none;
}

[data-theme="light"] .sidebar-logo-light,
:root:not([data-theme]) .sidebar-logo-light {
    display: block;
}

.sidebar-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--sidebar-text);
}

.sidebar-section-label {
    padding: 1.25rem 1rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--sidebar-section-label);
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 0.25rem 0.5rem;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin: 0.125rem 0;
    border-radius: 0.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s ease;
}

.sidebar-nav-item:hover {
    background-color: var(--sidebar-hover);
    color: var(--sidebar-text);
    text-decoration: none;
}

.sidebar-nav-item.active {
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
}

.sidebar-nav-item i {
    font-size: 1.1rem;
}

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

/* ==========================================
   Theme Toggle
   ========================================== */
.theme-toggle-container {
    display: flex;
    justify-content: flex-end;
}

.theme-toggle {
    background: transparent;
    border: 2px solid var(--input-border);
    border-radius: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    border-color: var(--btn-primary-bg);
    background-color: var(--sidebar-hover);
}

.theme-icon-dark,
.theme-icon-light {
    font-size: 1.1rem;
    color: var(--sidebar-text);
}

/* Show/hide icons based on theme */
[data-theme="dark"] .theme-icon-dark {
    display: none;
}

[data-theme="dark"] .theme-icon-light {
    display: inline;
}

[data-theme="light"] .theme-icon-dark,
:root:not([data-theme]) .theme-icon-dark {
    display: inline;
}

[data-theme="light"] .theme-icon-light,
:root:not([data-theme]) .theme-icon-light {
    display: none;
}

/* ==========================================
   Main Content Area
   ========================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background-color: var(--main-bg);
    transition: background-color 0.3s ease;
}

/* ==========================================
   Content Top Bar with Theme Toggle
   ========================================== */
.content-topbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background-color: var(--main-bg);
    border-bottom: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-spacer {
    flex: 1;
}

.theme-toggle-topbar {
    background: transparent;
    border: 2px solid var(--input-border);
    border-radius: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    transition: all 0.2s ease;
}

.theme-toggle-topbar:hover {
    border-color: var(--btn-primary-bg);
    background-color: var(--sidebar-hover);
}

.theme-toggle-topbar .theme-icon-dark,
.theme-toggle-topbar .theme-icon-light {
    font-size: 1.25rem;
    color: var(--main-text);
}

.content-wrapper {
    padding: 1.5rem 2rem;
    max-width: 100%;
    margin: 0;
}

/* ==========================================
   Card Styles
   ========================================== */
.dashboard-card {
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 0.5rem;
    overflow: hidden;
    margin-bottom: 1.5rem;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.dashboard-card-header {
    background-color: var(--card-header-bg);
    color: var(--card-header-text);
    padding: 0.875rem 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dashboard-card-header.instructions-header {
    background-color: #6366f1;
    color: #ffffff;
}

.dashboard-card-body {
    padding: 1.25rem;
}

/* ==========================================
   Form Styles
   ========================================== */
.form-control {
    background-color: var(--input-bg);
    border-color: var(--input-border);
    color: var(--input-text);
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.form-control::placeholder {
    color: var(--input-placeholder);
}

.form-control:focus {
    background-color: var(--input-bg);
    border-color: var(--btn-primary-bg);
    color: var(--input-text);
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25);
}

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

.btn-primary:hover {
    background-color: #2563eb;
    border-color: #2563eb;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25);
}

/* ==========================================
   Alert Styles
   ========================================== */
.alert-success {
    background-color: var(--alert-success-bg);
    border-color: var(--alert-success-border);
    color: var(--alert-success-text);
}

/* ==========================================
   jQuery UI Autocomplete - Dark Theme Override
   ========================================== */
.ui-autocomplete {
    background-color: var(--autocomplete-bg) !important;
    border: 1px solid var(--input-border) !important;
    border-radius: 0.375rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1050 !important;
}

.ui-menu-item {
    padding: 0 !important;
}

.ui-menu-item-wrapper {
    padding: 0.5rem 1rem !important;
    color: var(--autocomplete-text) !important;
    cursor: pointer;
}

.ui-menu-item-wrapper:hover,
.ui-state-active,
.ui-widget-content .ui-state-active,
.ui-state-focus {
    background-color: var(--autocomplete-hover) !important;
    color: var(--autocomplete-text) !important;
    border: none !important;
    margin: 0 !important;
}

/* ==========================================
   Instructions List
   ========================================== */
.instructions-list {
    padding-left: 1.25rem;
    margin-bottom: 0;
}

.instructions-list li {
    margin-bottom: 0.75rem;
    line-height: 1.5;
}

.instructions-list li:last-child {
    margin-bottom: 0;
}

.instructions-list ul {
    margin-top: 0.5rem;
    padding-left: 1.25rem;
}

.instructions-list code {
    background-color: var(--sidebar-hover);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    color: var(--main-text);
}

/* ==========================================
   Page Header
   ========================================== */
.page-header {
    margin-bottom: 1rem;
}

/* ==========================================
   Full Height Cards
   ========================================== */
.h-100 {
    height: 100%;
}

.dashboard-card.h-100 {
    display: flex;
    flex-direction: column;
}

.dashboard-card.h-100 .dashboard-card-body {
    flex: 1;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--main-text);
    margin: 0;
}

.page-subtitle {
    color: var(--main-text-muted);
    margin: 0.25rem 0 0;
}

/* ==========================================
   Selected Medications Section
   ========================================== */
.selected-meds-section {
    margin-top: 1.5rem;
}

.selected-meds-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--main-text);
}

textarea.form-control[readonly] {
    background-color: var(--input-bg);
    opacity: 0.8;
}

/* ==========================================
   Mobile Styles
   ========================================== */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background-color: var(--sidebar-bg);
    border-bottom: 1px solid var(--card-border);
    padding: 0 1rem;
    align-items: center;
    justify-content: space-between;
    z-index: 999;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 1.5rem;
    padding: 0.25rem;
    cursor: pointer;
}

.mobile-title {
    font-weight: 600;
    color: var(--sidebar-text);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

@media (max-width: 767.98px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .mobile-header {
        display: flex;
    }
    
    .main-content {
        padding-top: 56px;
    }
    
    .content-topbar {
        display: none;
    }
    
    .content-wrapper {
        padding: 1rem;
    }
}

/* ==========================================
   Custom Scrollbar
   ========================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--sidebar-section-label);
}

/* ==========================================
   Utility Classes
   ========================================== */
.text-muted {
    color: var(--main-text-muted) !important;
}
