/* Modern Reset & Base */
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --primary-gradient-alt: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    --surface-glass: rgba(255, 255, 255, 0.95);
    --surface-glass-border: rgba(255, 255, 255, 0.8);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16), 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 12px 48px rgba(0, 0, 0, 0.2), 0 6px 24px rgba(0, 0, 0, 0.16);
    --gradient-bg: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #4facfe 75%, #00f2fe 100%);
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 50%, #e0e7ff 100%);
    background-attachment: fixed;
    color: #1e293b;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 50%, rgba(102, 126, 234, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(118, 75, 162, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(240, 147, 251, 0.08) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.container {
    position: relative;
    z-index: 1;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }

    100% {
        background-position: 1000px 0;
    }
}

.fade-in {
    animation: fadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Navbar Modernization (Glassmorphism) */
.navbar {
    background: var(--primary-gradient) !important;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    box-shadow: var(--shadow-lg) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding: 1rem 0;
    transition: all 0.3s ease;
}

.navbar:hover {
    box-shadow: var(--shadow-xl) !important;
}

.navbar-brand {
    font-weight: 700;
    letter-spacing: -0.5px;
    font-size: 1.5rem;
    background: linear-gradient(135deg, #ffffff 0%, #f0f0f0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.navbar-brand:hover {
    transform: scale(1.05);
}

.nav-link {
    transition: all 0.3s ease;
    border-radius: 8px;
    padding: 0.5rem 1rem !important;
    margin: 0 0.25rem;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

/* Card Modernization */
.card {
    border: 1px solid rgba(255, 255, 255, 0.8);
    background: var(--surface-glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    position: relative;
}

/* Legend card should allow overflow for scrolling */
#calendar-legend.card {
    overflow: visible;
}

@media (max-width: 768px) {
    #calendar-legend.card {
        overflow-x: visible;
        overflow-y: visible;
    }
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary-gradient);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-xl);
    border-color: rgba(255, 255, 255, 1);
}

.card:hover::before {
    opacity: 1;
}

/* Modern Card Header */
.card-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    font-weight: 600;
    border-bottom: none;
    padding: 1.25rem 1rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.card-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

.card-header h5 {
    position: relative;
    z-index: 1;
    letter-spacing: 0.5px;
}

/* Status Banner */
#statusBanner {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 255, 255, 0.95) 100%);
    border: none;
    border-left: 4px solid;
    border-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%) 1;
    color: #1e293b;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    font-size: 0.85rem;
    padding: 1rem 1.25rem;
    animation: slideUp 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 0.5rem !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

#statusBanner::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
    pointer-events: none;
}

/* Calendar Grid Styling */
.calendar-grid {
    margin: 0 -2px;
    /* Pull negative margin to allow borders to bleed slightly if needed */
}

.day-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    margin-bottom: 0.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0.4) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 0.5rem 0;
    border-radius: 12px;
    margin-bottom: 1rem;
}

.calendar-day {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    border-radius: 12px;
    margin: 3px 0;
    cursor: default;
    border: 2px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    position: relative;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.calendar-day:hover {
    transform: scale(1.1);
    z-index: 5;
    box-shadow: var(--shadow-md);
}

/* Weekend Styling - Soft Gray */
.is-weekend {
    background: linear-gradient(135deg, rgba(241, 245, 249, 0.8) 0%, rgba(226, 232, 240, 0.8) 100%);
    color: #94a3b8;
    opacity: 0.85;
}

/* Today Highlight */
.is-today {
    box-shadow: 0 0 0 3px #f59e0b inset, 0 4px 12px rgba(245, 158, 11, 0.3);
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    color: #b45309;
    font-weight: bold;
    z-index: 10;
    animation: pulse 2s ease-in-out infinite;
    border: 2px solid #f59e0b;
}

/* Pay Day - Modern pill style outline - Green */
.is-pay-day {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.1) 0%, rgba(22, 163, 74, 0.1) 100%);
    color: #15803d;
    font-weight: bold;
    border: 2px solid #22c55e;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.2);
}

/* Telecommute */
.is-telecommute {
    background: linear-gradient(135deg, #f3e8ff 0%, #e9d5ff 100%);
    color: #6b21a8;
    border: 2px solid #d8b4fe;
    box-shadow: 0 2px 8px rgba(168, 85, 247, 0.15);
}

/* Holiday */
.is-holiday {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(220, 38, 38, 0.1) 100%);
    color: #dc2626;
    font-weight: bold;
    border: 2px solid #ef4444;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}

/* Observance */
.is-observance {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(29, 78, 216, 0.1) 100%);
    color: #1d4ed8;
    font-weight: bold;
    border: 2px solid #3b82f6;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}

/* Conflict Resolution */
.is-telecommute.is-pay-day {
    background: linear-gradient(135deg, #f3e8ff 0%, rgba(34, 197, 94, 0.1) 100%);
    border: 2px solid #22c55e;
    color: #15803d;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.25);
}

.is-telecommute.is-holiday {
    background: linear-gradient(135deg, #f3e8ff 0%, rgba(239, 68, 68, 0.1) 100%);
    border: 2px solid #ef4444;
    color: #dc2626;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
}

.is-telecommute.is-observance {
    background: linear-gradient(135deg, #f3e8ff 0%, rgba(59, 130, 246, 0.1) 100%);
    border: 2px solid #3b82f6;
    color: #1d4ed8;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

/* Footer Adjustments */
.card-footer {
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.8) 100%) !important;
    border-top: 1px solid rgba(203, 213, 225, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Mobile Controls */
.btn-group .btn {
    border-radius: 50px !important;
    padding: 0.5rem 1.5rem;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

.btn-group .btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-outline-primary {
    border: 2px solid;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.btn-outline-primary:hover {
    background: var(--primary-gradient);
    border-color: transparent;
    color: white;
    transform: translateY(-2px) scale(1.05);
}

/* Icon-only buttons for mobile navigation */
#prevMonthBtn,
#nextMonthBtn {
    font-size: 1.3rem;
    padding: 0.6rem 1.2rem;
    min-width: 48px;
    font-weight: 700;
    line-height: 1;
}

/* Legend Styling */
#calendar-legend {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 255, 255, 0.95) 100%);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 20px;
    overflow: visible;
}

@media (max-width: 768px) {
    #calendar-legend {
        overflow-x: visible;
        overflow-y: visible;
    }
}

#calendar-legend .card-body {
    padding: 1.25rem 1.5rem;
    gap: 2rem;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    #calendar-legend {
        overflow-x: visible;
        overflow-y: visible;
    }
    
    #calendar-legend .card-body {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
        justify-content: flex-start;
        min-width: 100%;
    }
    
    #calendar-legend .card-body::-webkit-scrollbar {
        display: none;
    }
    
    #calendar-legend .card-body {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

.legend-item {
    gap: 0.75rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    cursor: default;
}

.legend-item:hover {
    background: rgba(102, 126, 234, 0.05);
    transform: translateY(-2px);
}

.legend-indicator {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: inline-block;
    flex-shrink: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    box-shadow: none;
}

.legend-item:hover .legend-indicator {
    transform: scale(1.1);
}

.legend-telecommute {
    background: linear-gradient(135deg, #f3e8ff 0%, #e9d5ff 100%);
    border: none;
}

.legend-payday {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2) 0%, rgba(22, 163, 74, 0.2) 100%);
    border: none;
}

.legend-holiday {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(220, 38, 38, 0.2) 100%);
    border: none;
}

.legend-observance {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(29, 78, 216, 0.2) 100%);
    border: none;
}

.legend-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e293b;
    letter-spacing: 0.3px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    border: 2px solid;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.legend-item:nth-child(1) .legend-text {
    border-color: #d8b4fe;
    color: #6b21a8;
}

.legend-item:nth-child(2) .legend-text {
    border-color: #22c55e;
    color: #15803d;
}

.legend-item:nth-child(3) .legend-text {
    border-color: #ef4444;
    color: #dc2626;
}

.legend-item:nth-child(4) .legend-text {
    border-color: #3b82f6;
    color: #1d4ed8;
}

.legend-item:hover .legend-text {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: rgba(255, 255, 255, 0.95);
}

/* Button Enhancements */
.btn-primary {
    background: var(--primary-gradient);
    border: none;
    box-shadow: var(--shadow-md);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    background: var(--primary-gradient-alt);
}

.btn-secondary {
    background: rgba(148, 163, 184, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(148, 163, 184, 0.3);
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: rgba(148, 163, 184, 0.3);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Toggle Switch Styles */
.toggle-item {
    margin-bottom: 1rem;
    padding: 0.5rem 0;
}

.toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid rgba(203, 213, 225, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.toggle-label:hover {
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(102, 126, 234, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.toggle-label:active {
    transform: translateY(0);
}

.toggle-text {
    font-size: 0.95rem;
    font-weight: 500;
    color: #1e293b;
    flex: 1;
    padding-right: 1rem;
    transition: color 0.3s ease;
}

.toggle-switch {
    position: relative;
    width: 56px;
    height: 32px;
    flex-shrink: 0;
}

.toggle-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    cursor: pointer;
}

.toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    border-radius: 34px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    border-radius: 50%;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.toggle-input:checked + .toggle-slider {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.toggle-input:checked + .toggle-slider:before {
    transform: translateX(24px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.toggle-input:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.toggle-animate .toggle-slider {
    animation: togglePulse 0.3s ease;
}

@keyframes togglePulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

.toggle-input:checked ~ .toggle-text,
.toggle-label:has(.toggle-input:checked) .toggle-text {
    color: #667eea;
    font-weight: 600;
}

.toggle-label:has(.toggle-input:checked) {
    background: rgba(102, 126, 234, 0.08);
    border-color: rgba(102, 126, 234, 0.4);
}

/* Disabled toggle styles */
.toggle-disabled {
    opacity: 0.6;
    pointer-events: none;
}

.toggle-disabled .toggle-label {
    cursor: not-allowed;
    background: rgba(241, 245, 249, 0.8);
    border-color: rgba(203, 213, 225, 0.5);
}

.toggle-disabled .toggle-label:hover {
    transform: none;
    box-shadow: none;
    border-color: rgba(203, 213, 225, 0.5);
}

.toggle-disabled .toggle-text {
    color: #94a3b8;
    text-decoration: line-through;
}

.toggle-disabled .toggle-slider {
    background-color: #e2e8f0;
    cursor: not-allowed;
}

.toggle-disabled .toggle-input:checked + .toggle-slider {
    background: #cbd5e1;
    box-shadow: none;
}

.toggle-disabled .toggle-input:checked + .toggle-slider:before {
    background-color: #f1f5f9;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.toggle-disabled .toggle-input:focus + .toggle-slider {
    box-shadow: none;
}

/* Utilities */
.shadow-soft {
    box-shadow: var(--shadow-md);
}

/* Mobile Responsive Styles - Small Screens (320px - 414px) */
@media (max-width: 414px) {
    /* Container adjustments */
    .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Navbar adjustments */
    .navbar-brand {
        font-size: 1.1rem;
    }

    /* Calendar card adjustments */
    .month-card .card-body {
        padding: 0.75rem !important;
    }

    .month-card .card-header {
        padding: 0.75rem !important;
    }

    .month-card .card-header h5 {
        font-size: 1rem;
    }

    /* Calendar grid - compact sizing */
    .calendar-grid {
        margin: 0;
    }

    .day-header {
        font-size: 0.65rem;
        margin-bottom: 0.5rem;
    }

    .day-header .col {
        padding: 0.25rem !important;
    }

    .calendar-day {
        height: 32px;
        font-size: 0.8rem;
        margin: 2px 0;
        border-radius: 6px;
    }

    .calendar-day .day-number {
        font-size: 0.8rem;
    }

    /* Holiday footer adjustments */
    .card-footer {
        padding: 0.75rem !important;
        font-size: 0.75rem;
    }

    .card-footer h6 {
        font-size: 0.7rem;
    }

    .card-footer ul {
        font-size: 0.7rem;
    }

    /* Legend adjustments */
    #calendar-legend {
        border-radius: 16px;
    }

    #calendar-legend {
        overflow-x: visible !important;
        overflow-y: visible !important;
    }
    
    #calendar-legend .card-body {
        padding: 0.75rem 1rem !important;
        gap: 0.5rem !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch;
        min-width: 100%;
    }
    
    #calendar-legend .card-body::-webkit-scrollbar {
        display: none;
    }
    
    #calendar-legend .card-body {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .legend-item {
        padding: 0.35rem 0.5rem !important;
        gap: 0.5rem !important;
        flex-shrink: 0 !important;
        white-space: nowrap;
        min-width: fit-content;
    }

    .legend-indicator {
        width: 14px !important;
        height: 14px !important;
        flex-shrink: 0;
    }

    .legend-text {
        font-size: 0.7rem !important;
        padding: 0.25rem 0.5rem !important;
        white-space: nowrap;
    }

    /* Mobile controls */
    .btn-group .btn {
        padding: 0.4rem 1rem;
        font-size: 0.85rem;
    }

    #currentMonthLabel {
        min-width: 100px !important;
        font-size: 0.85rem;
    }

    /* Status banner */
    #statusBanner {
        font-size: 0.75rem;
        padding: 0.5rem;
    }

    /* Preferences form */
    .card-body p {
        font-size: 0.9rem;
    }

    .toggle-item {
        margin-bottom: 0.75rem;
    }

    .toggle-label {
        padding: 0.85rem 1rem;
        min-height: 56px;
    }

    .toggle-text {
        font-size: 0.9rem;
    }

    .toggle-switch {
        width: 52px;
        height: 30px;
    }

    .toggle-slider:before {
        height: 22px;
        width: 22px;
        left: 4px;
        bottom: 4px;
    }

    .toggle-input:checked + .toggle-slider:before {
        transform: translateX(22px);
    }
}

/* Extra small screens - larger touch targets */
@media (max-width: 360px) {
    .toggle-item {
        margin-bottom: 0.6rem;
    }

    .toggle-label {
        padding: 1rem;
        min-height: 60px;
    }

    .toggle-text {
        font-size: 0.85rem;
        line-height: 1.4;
    }

    .toggle-switch {
        width: 56px;
        height: 32px;
    }

    .toggle-slider:before {
        height: 24px;
        width: 24px;
    }

    .toggle-input:checked + .toggle-slider:before {
        transform: translateX(24px);
    }
}

/* Preferences section mobile optimization */
@media (max-width: 768px) {
    #section-preferences .row {
        flex-direction: column;
    }

    #section-preferences .col-md-6 {
        width: 100%;
        margin-bottom: 1.5rem;
    }

    #section-preferences h6 {
        font-size: 1.1rem;
        margin-bottom: 1rem;
        color: #667eea;
        font-weight: 600;
    }
}

/* Extra small screens (320px - 360px) */
@media (max-width: 360px) {
    .calendar-day {
        height: 28px;
        font-size: 0.75rem;
    }

    .day-header {
        font-size: 0.6rem;
    }

    .day-header .col {
        padding: 0.2rem !important;
    }

    .month-card .card-header h5 {
        font-size: 0.9rem;
    }

    #calendar-legend {
        overflow-x: visible !important;
        overflow-y: visible !important;
    }
    
    #calendar-legend .card-body {
        gap: 0.4rem !important;
        padding: 0.6rem 1rem !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch;
        min-width: 100%;
    }
    
    #calendar-legend .card-body::-webkit-scrollbar {
        display: none;
    }
    
    #calendar-legend .card-body {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .legend-item {
        padding: 0.3rem 0.4rem !important;
        gap: 0.4rem !important;
        flex-shrink: 0 !important;
        white-space: nowrap;
        min-width: fit-content;
    }

    .legend-indicator {
        width: 12px !important;
        height: 12px !important;
        flex-shrink: 0;
    }

    .legend-text {
        font-size: 0.65rem !important;
        padding: 0.2rem 0.4rem !important;
        white-space: nowrap;
    }
}

/* Ensure calendar fits on mobile viewport */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    .month-card {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
        margin-bottom: 0 !important;
    }

    .month-card .card {
        margin: 0;
        margin-bottom: 0 !important;
    }

    /* Remove gap between calendar and legend */
    #calendarGrid {
        margin-bottom: 0;
    }

    /* Prevent horizontal scroll */
    .calendar-grid .row {
        margin-left: 0;
        margin-right: 0;
    }

    .calendar-grid .col {
        padding-left: 2px;
        padding-right: 2px;
    }

    /* Ensure section calendar doesn't overflow */
    #section-calendar {
        padding-bottom: 1rem;
    }

    /* Reduce gaps between status banner, navigation, and calendar */
    #statusBanner {
        margin-bottom: 0.5rem !important;
    }

    .d-md-none.text-center {
        margin-bottom: 0.5rem !important;
    }

    /* Make sure legend stays at bottom - no gap */
    #calendar-legend {
        position: relative;
        margin-top: 0 !important;
        margin-bottom: 1rem;
    }
}

/* Additional mobile optimizations for very small screens */
@media (max-width: 414px) {
    /* Reduce navbar height on mobile */
    .navbar {
        padding: 0.5rem 0;
    }

    /* Compact status banner */
    #statusBanner {
        margin-bottom: 0.75rem;
    }

    /* Ensure calendar month fits in viewport */
    .month-card .card-body {
        min-height: auto;
    }

    /* Compact holiday list */
    .card-footer ul li {
        margin-bottom: 0.25rem;
    }
}