/* Universal Glassmorphism Date Picker Styles */
/* Beautiful, themeable date picker component for any project */

/* CSS Variables for easy theming */
:root {
    --dp-width: 520px;
    --dp-height: 380px; /* legacy fallback used by some themes */
    --dp-bg: linear-gradient(135deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.05));
    --dp-sidebar-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.08));
    --dp-text-primary: rgba(0, 0, 0, 0.8);
    --dp-text-secondary: rgba(0, 0, 0, 0.6);
    --dp-text-muted: rgba(0, 0, 0, 0.5);
    --dp-accent: #3b82f6;
    --dp-border: rgba(255, 255, 255, 0.2);
    --dp-hover: rgba(255, 255, 255, 0.4);
    --dp-radius: 24px;
    --dp-shadow: 0 25px 50px rgba(0, 0, 0, 0.15), 0 15px 35px rgba(0, 0, 0, 0.1);
    --dp-backdrop-blur: 20px;
    --dp-transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Input styling */
.glassmorphism-datepicker-input {
    cursor: pointer !important;
    user-select: none;
    transition: var(--dp-transition);
}

.glassmorphism-datepicker-input:hover {
    transform: translateY(-1px);
}

.glassmorphism-datepicker-input:focus {
    transform: translateY(-1px);
    outline: none;
}

/* Main container */
.glassmorphism-datepicker {
    position: fixed;
    z-index: 10000;
    /* Responsive width */
    width: min(560px, 92vw);
    max-width: 560px;
    /* Make height flexible so months with 6 rows (e.g. March) are not clipped. Use max-height to avoid overflowing viewport. */
    height: auto;
    max-height: 90vh;
    background: var(--dp-bg);
    backdrop-filter: blur(var(--dp-backdrop-blur));
    -webkit-backdrop-filter: blur(var(--dp-backdrop-blur));
    border-radius: var(--dp-radius);
    border: 1px solid var(--dp-border);
    box-shadow: var(--dp-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transform: scale(0.95) translateY(-10px);
    opacity: 0;
    transition: var(--dp-transition);
    overflow: hidden; /* keep overall rounded corners */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Allow internal scrolling when viewport is too small */
.glassmorphism-datepicker .dp-scroll-area {
    display: flex;
    height: 100%;
}

/* Mobile helper class (added by JS when viewport < 520) */
.glassmorphism-datepicker.mobile {
    width: 100vw !important;
    max-width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
    border-radius: 0 0 24px 24px;
}

.glassmorphism-datepicker.open {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.glassmorphism-datepicker.inline {
    position: relative;
    transform: none;
    opacity: 1;
    z-index: auto;
}

/* Top highlight effect */
.glassmorphism-datepicker::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
}

/* Header Layout */
.dp-header {
    display: flex;
    /* let header size to its content; calendar area will scroll if necessary */
    position: relative;
}

/* Sidebar */
.dp-sidebar {
    width: 180px; /* Increased from 140px to fit all month names */
    background: var(--dp-sidebar-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-right: 1px solid var(--dp-border);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden; /* We'll allow the month list to scroll internally */
}

/* Make the month-list scroll independently so calendar grid can expand */
.dp-month-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    padding-right: 6px; /* extra breathing space on the right so rounded bg not cut */
    overflow-x: visible; /* allow the slight translateX hover to show fully */
}

.dp-sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 1px;
    height: 100%;
    background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.3), transparent);
}

.dp-year {
    font-size: 32px;
    font-weight: 300;
    color: var(--dp-text-primary);
    margin-bottom: 20px;
    text-align: left;
    letter-spacing: -0.5px;
    cursor: pointer;
    transition: var(--dp-transition);
    flex-shrink: 0;
}

.dp-year:hover {
    color: var(--dp-accent);
    transform: translateX(2px);
}

/* Calendar Area */
.dp-calendar-area {
    flex: 1 1 auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    position: relative;
    /* allow the calendar area to scroll independently when needed */
    max-height: calc(90vh - 48px); /* keep room for header/footer */
    overflow: auto;
}

.dp-date-header {
    margin-bottom: 20px;
}

.dp-current-month {
    font-size: 28px;
    font-weight: 600;
    color: var(--dp-text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.3px;
}

.dp-selected-date {
    font-size: 14px;
    color: var(--dp-text-secondary);
    text-decoration: underline;
    text-decoration-color: var(--dp-text-muted);
    text-underline-offset: 2px;
}

/* Navigation */
.dp-nav {
    position: absolute;
    top: 24px;
    right: 28px;
    display: flex;
    gap: 8px;
    z-index: 10;
}

.dp-nav-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 50%;
    color: var(--dp-text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    transition: var(--dp-transition);
    border: 2px solid var(--dp-border);
    line-height: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.dp-nav-btn:hover {
    background: var(--dp-accent);
    color: white;
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
    border-color: var(--dp-accent);
}

.dp-nav-btn:active {
    transform: translateY(0) scale(1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Calendar Grid */
.dp-calendar {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0; /* allow scrolling when constrained */
}

.dp-day-headers {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 12px;
}

.dp-day-header {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--dp-text-muted);
    padding: 8px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Ensure days grid can have 5 or 6 rows and never clip — add bottom padding */
.dp-days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    flex: 0 0 auto;
    /* allow more rows if needed; don't constrain height here so the picker expands */
    padding-bottom: 12px;
    /* let rows be controlled by JS via --dp-day-size */
    grid-auto-rows: var(--dp-day-size, 40px);
}

.dp-day {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--dp-day-size, 40px);
    height: var(--dp-day-size, 40px);
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--dp-text-primary);
    transition: var(--dp-transition);
    position: relative;
    margin: 0 auto;
}

.dp-day:hover:not(.disabled) {
    background: var(--dp-hover);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dp-day.other-month {
    color: var(--dp-text-muted);
}

.dp-day.other-month:hover:not(.disabled) {
    color: var(--dp-text-secondary);
    background: color-mix(in srgb, var(--dp-hover) 50%, transparent);
}

.dp-day.today {
    background: var(--dp-text-primary);
    color: var(--dp-bg);
    font-weight: 600;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--dp-text-primary) 30%, transparent);
}

.dp-day.selected {
    background: linear-gradient(135deg, var(--dp-accent), color-mix(in srgb, var(--dp-accent) 80%, black));
    color: white;
    font-weight: 700;
    box-shadow: 0 6px 20px color-mix(in srgb, var(--dp-accent) 40%, transparent);
    transform: scale(1.05);
}

.dp-day.disabled {
    color: color-mix(in srgb, var(--dp-text-muted) 50%, transparent);
    cursor: not-allowed;
    background: none !important;
    transform: none !important;
    box-shadow: none !important;
}

/* Footer */
.dp-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--dp-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: color-mix(in srgb, var(--dp-sidebar-bg) 50%, transparent);
}

.dp-footer-btn {
    padding: 8px 16px;
    border: 1px solid var(--dp-border);
    background: var(--dp-hover);
    color: var(--dp-text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: var(--dp-transition);
}

/* Month list items (sidebar) */
.dp-month-item {
    padding: 8px 10px;
    font-size: 14px;
    color: var(--dp-text-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--dp-transition);
    text-align: left;
    margin: 2px 0;
}

/* Hover/keyboard focus state */
.dp-month-item.hover,
.dp-month-item:hover,
.dp-month-item:focus {
    background: color-mix(in srgb, var(--dp-accent) 10%, transparent);
    transform: translateX(2px); /* was 4px; smaller shift to stay inside */
    color: var(--dp-accent);
    outline: none;
}

/* Active (current month) */
.dp-month-item.active {
    background: color-mix(in srgb, var(--dp-accent) 14%, transparent);
    font-weight: 700;
    color: var(--dp-accent);
}

/* Year-mode visuals */
.dp-month-list.year-mode {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
}
.dp-year-item {
    padding: 8px 10px;
    font-size: 15px;
    color: var(--dp-text-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--dp-transition);
}
.dp-year-item:hover,
.dp-year-item:focus {
    background: color-mix(in srgb, var(--dp-accent) 12%, transparent);
    color: var(--dp-accent);
    transform: translateX(4px);
}

/* Ensure sidebar keeps internal scrolling and month items fully visible */
.dp-sidebar {
    overflow: visible; /* allow subtle shadows/transform on hover to show */
}
.dp-month-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Theme Variations */
.glassmorphism-datepicker[data-theme="light"] {
    --dp-bg: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(248, 250, 252, 0.9));
    --dp-sidebar-bg: linear-gradient(180deg, rgba(241, 245, 249, 0.8), rgba(226, 232, 240, 0.6));
    --dp-text-primary: rgba(15, 23, 42, 0.9);
    --dp-text-secondary: rgba(51, 65, 85, 0.7);
    --dp-text-muted: rgba(100, 116, 139, 0.6);
    --dp-accent: #3b82f6;
    --dp-border: rgba(15, 23, 42, 0.1);
    --dp-hover: rgba(59, 130, 246, 0.1);
}

.glassmorphism-datepicker[data-theme="dark"] {
    --dp-bg: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.9));
    --dp-sidebar-bg: linear-gradient(180deg, rgba(15, 23, 42, 0.8), rgba(30, 41, 59, 0.6));
    --dp-text-primary: rgba(248, 250, 252, 0.95);
    --dp-text-secondary: rgba(226, 232, 240, 0.8);
    --dp-text-muted: rgba(148, 163, 184, 0.7);
    --dp-accent: #06b6d4;
    --dp-border: rgba(6, 182, 212, 0.3);
    --dp-hover: rgba(6, 182, 212, 0.15);
}

.glassmorphism-datepicker[data-theme="staff"] {
    --dp-bg: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.9));
    --dp-sidebar-bg: linear-gradient(180deg, rgba(15, 23, 42, 0.8), rgba(30, 41, 59, 0.6));
    --dp-text-primary: rgba(248, 250, 252, 0.95);
    --dp-text-secondary: rgba(226, 232, 240, 0.8);
    --dp-text-muted: rgba(148, 163, 184, 0.7);
    --dp-accent: #06b6d4;
    --dp-border: rgba(6, 182, 212, 0.3);
    --dp-hover: rgba(6, 182, 212, 0.15);
}

.glassmorphism-datepicker[data-theme="customer"] {
    --dp-bg: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(248, 250, 252, 0.9));
    --dp-sidebar-bg: linear-gradient(180deg, rgba(241, 245, 249, 0.8), rgba(226, 232, 240, 0.6));
    --dp-text-primary: rgba(15, 23, 42, 0.9);
    --dp-text-secondary: rgba(51, 65, 85, 0.7);
    --dp-text-muted: rgba(100, 116, 139, 0.6);
    --dp-accent: #fb923c;
    --dp-border: rgba(251, 146, 60, 0.2);
    --dp-hover: rgba(251, 146, 60, 0.1);
}

/* ============================================
   MOBILE / RESPONSIVE OPTIMIZATIONS
   ============================================ */

/* Tablet adjustments (medium screens) */
@media (max-width: 900px) {
    .glassmorphism-datepicker {
        width: min(500px, 94vw);
        max-height: 88vh;
    }

    .dp-sidebar {
        width: 140px;
        padding: 20px 16px;
    }

    .dp-calendar-area {
        padding: 20px 24px;
    }

    .dp-year {
        font-size: 28px;
        margin-bottom: 16px;
    }

    .dp-current-month {
        font-size: 24px;
    }

    .dp-day {
        font-size: 13px;
    }

    .dp-nav {
        top: 20px;
        right: 24px;
    }

    .dp-nav-btn {
        width: 34px;
        height: 34px;
        font-size: 18px;
    }
}

/* Mobile breakpoint: Stack layout vertically for better touch UX */
@media (max-width: 640px) {
    .glassmorphism-datepicker {
        width: 100vw !important;
        max-width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        border-radius: 24px 24px 0 0;
        max-height: 85vh;
        transform: translateY(20px);
        opacity: 0;
    }

    .glassmorphism-datepicker.open {
        transform: translateY(0);
        opacity: 1;
    }

    /* Stack sidebar horizontally below header on mobile for better space usage */
    .dp-scroll-area {
        flex-direction: column;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .dp-header {
        flex-direction: column;
    }

    /* Sidebar becomes a horizontal scrollable row */
    .dp-sidebar {
        width: 100%;
        max-width: 100%;
        flex-direction: row;
        padding: 12px 16px;
        border-right: none;
        border-bottom: 1px solid var(--dp-border);
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .dp-sidebar::before {
        display: none;
    }

    /* Year becomes compact and inline */
    .dp-year {
        font-size: 22px;
        margin-bottom: 0;
        margin-right: 16px;
        flex-shrink: 0;
        white-space: nowrap;
        align-self: center;
    }

    /* Month list horizontal on mobile */
    .dp-month-list {
        flex-direction: row;
        gap: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        padding-right: 0;
        padding-bottom: 4px;
        flex: 1 1 auto;
        min-width: 0;
    }

    .dp-month-item {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 6px 12px;
        font-size: 13px;
    }

    /* Calendar area full width below sidebar */
    .dp-calendar-area {
        width: 100%;
        padding: 16px 20px 20px;
        max-height: none;
        overflow: visible;
    }

    .dp-date-header {
        margin-bottom: 16px;
    }

    .dp-current-month {
        font-size: 22px;
    }

    .dp-selected-date {
        font-size: 13px;
    }

    /* Navigation buttons smaller on mobile */
    .dp-nav {
        top: 16px;
        right: 20px;
        gap: 6px;
    }

    .dp-nav-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    /* Day headers more compact */
    .dp-day-headers {
        gap: 3px;
        margin-bottom: 10px;
    }

    .dp-day-header {
        font-size: 11px;
        padding: 6px 0;
    }

    /* Days grid with tighter spacing */
    .dp-days-grid {
        gap: 6px;
        padding-bottom: 8px;
    }

    /* Day cells: larger touch targets */
    .dp-day {
        width: var(--dp-day-size, 38px);
        height: var(--dp-day-size, 38px);
        font-size: 13px;
    }

    /* Year selector in sidebar stays horizontal */
    .dp-month-list.year-mode {
        flex-direction: row;
    }

    .dp-year-item {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 6px 12px;
        font-size: 14px;
    }
}

/* Extra small phones (portrait) */
@media (max-width: 420px) {
    .glassmorphism-datepicker {
        max-height: 82vh;
    }

    .dp-sidebar {
        padding: 10px 12px;
    }

    .dp-year {
        font-size: 20px;
        margin-right: 12px;
    }

    .dp-month-item {
        padding: 5px 10px;
        font-size: 12px;
    }

    .dp-calendar-area {
        padding: 12px 16px 16px;
    }

    .dp-current-month {
        font-size: 20px;
    }

    .dp-selected-date {
        font-size: 12px;
    }

    .dp-nav {
        top: 12px;
        right: 16px;
        gap: 4px;
    }

    .dp-nav-btn {
        width: 30px;
        height: 30px;
        font-size: 15px;
    }

    .dp-day-headers {
        gap: 2px;
        margin-bottom: 8px;
    }

    .dp-day-header {
        font-size: 10px;
        padding: 5px 0;
    }

    .dp-days-grid {
        gap: 4px;
        padding-bottom: 6px;
    }

    .dp-day {
        width: var(--dp-day-size, 34px);
        height: var(--dp-day-size, 34px);
        font-size: 12px;
    }

    .dp-year-item {
        padding: 5px 10px;
        font-size: 13px;
    }
}

/* Fullscreen variant applied by JS on very small viewports */
.glassmorphism-datepicker.gdp-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    overflow: auto !important;
    transform: none !important;
    opacity: 1 !important;
}

.glassmorphism-datepicker.gdp-fullscreen .dp-scroll-area {
    flex-direction: column;
    height: 100%;
}

.glassmorphism-datepicker.gdp-fullscreen .dp-sidebar {
    width: 100% !important;
    max-width: 100%;
    flex-direction: row;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--dp-border);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.glassmorphism-datepicker.gdp-fullscreen .dp-month-list {
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-right: 8px;
}

.glassmorphism-datepicker.gdp-fullscreen .dp-calendar-area {
    padding: 12px 16px 20px !important;
    flex: 1 1 auto;
    overflow: auto;
    max-height: none;
}

/* Adjust fullscreen nav so it doesn't cover month/day grid */
.glassmorphism-datepicker.gdp-fullscreen .dp-nav {
    position: absolute; /* keep it inside picker flow instead of fixed */
    top: 16px; /* leave space for the header / month strip */
    right: 12px;
    z-index: 12000;
}

/* Add extra top padding to calendar area in fullscreen so nav and header don't overlap days */
.glassmorphism-datepicker.gdp-fullscreen .dp-calendar-area {
    padding-top: 72px !important; /* ensure month header and nav have room */
}

/* Reduce nav size slightly on very small fullscreen to be less intrusive */
.glassmorphism-datepicker.gdp-fullscreen .dp-nav-btn {
    width: 36px;
    height: 36px;
}

/* Fix: ensure nav controls are not flush to the right edge in fullscreen (adds internal padding and moves nav left) */
.glassmorphism-datepicker.gdp-fullscreen {
    box-sizing: border-box; /* ensure padding doesn't increase visual overflow */
    padding-left: 12px !important;
    padding-right: 20px !important; /* give breathing room on the right for nav */
}

.glassmorphism-datepicker.gdp-fullscreen .dp-nav {
    right: 20px; /* move nav slightly left from the viewport edge */
}

/* Respect safe-area on devices with rounded corners/notches */
@media (max-width: 420px) {
    .glassmorphism-datepicker.gdp-fullscreen {
        padding-right: max(env(safe-area-inset-right, 12px), 12px) !important;
    }
    .glassmorphism-datepicker.gdp-fullscreen .dp-nav {
        right: calc(max(env(safe-area-inset-right, 12px), 12px) + 8px);
    }
}

/* Animation Variants */
.glassmorphism-datepicker[data-animation="slide-up"] { transform: translateY(20px); opacity: 0; }
.glassmorphism-datepicker[data-animation="slide-up"].open { transform: translateY(0); opacity: 1; }
.glassmorphism-datepicker[data-animation="slide-down"] { transform: translateY(-20px); opacity: 0; }
.glassmorphism-datepicker[data-animation="slide-down"].open { transform: translateY(0); opacity: 1; }
.glassmorphism-datepicker[data-animation="fade"] { transform: none; opacity: 0; }
.glassmorphism-datepicker[data-animation="fade"].open { transform: none, opacity: 1; }

/* High contrast support */
@media (prefers-contrast: high) {
    .glassmorphism-datepicker { --dp-border: rgba(0, 0, 0, 0.8); --dp-backdrop-blur: 5px; border-width: 2px; }
    .dp-day { border: 1px solid transparent; }
    .dp-day:hover:not(.disabled) { border-color: var(--dp-accent); }
    .dp-day.selected { border: 2px solid var(--dp-accent); }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .glassmorphism-datepicker, .dp-day, .dp-month-item, .dp-nav-btn, .dp-footer-btn { transition: none; }
    .dp-day:hover:not(.disabled) { transform: none; }
    .dp-day.selected { transform: none; }
}

/* Print styles */
@media print { .glassmorphism-datepicker { display: none !important; } }
