/* DESIGN 
   ------
   * The styling philosophy follows a "Metro UI" inspired direction, characterized by:
   * - High contrast and bold typography (Segoe UI/San Francisco stack)
   * - "Alive" interactivity: elements react with tactile feedback
   * - Mobile-First approach: The base CSS renders the mobile app to ensure
   *   maximum performance on weaker devices 
   *
   * The architecture is a "Utility-First Variables" system:
   * - All values (fonts, margins, sizes, colors) are centralized in :root variables,
   *   organized by UNIVERSAL and MOBILE (default) 
   * - The DESKTOP media query overrides these variables and applies the 
   *   CSS Grid structure for the dashboard layout.
*/


/* UNIVERSAL (Shared logic across all views) */

:root {
    /* Typography */
    --font-family: "Segoe UI", -apple-system, system-ui, sans-serif;
    --font-weight-light: 200;
    --font-weight-regular: 400;
    --font-weight-semibold: 600;

    /* Palette - Base (Light Mode Default) */
    --background-color: #FFF;
    --font-color: #000;
    --text-secondary: #787878;
    --text-disabled: #CCCCCC;
    --white: #FFF;
    --light-bg: #F5F5F5;
    --border-color: #E1E1E1;

    /* Palette - Controls (Neutral Gray Scale) */
    --control-color: #333333; /* Dark Gray for arrows/borders */
    --control-active-bg: #333333; /* Background when pressed */
    --control-active-text: #FFFFFF;

    /* Palette - Shifts (Immutable) */
    --color-mattino: #1196fd;
    --color-pomeriggio: #d99f00;
    --color-notte: #8764B8;

    /* Animations */
    --slide-animation: softPivot 0.25s ease-out;
}


/* MOBILE (Default View Configuration) */

:root {
    /* Layout & Spacing */
    --container-max-width: 480px;
    --container-padding: 0 24px;
    
    --title-margin-top: 32px;
    --section-margin-top: 32px;
    --element-margin-top: 20px;
    
    /* Font Sizes */
    --font-size-title: 42px;
    --font-size-section: 24px;
    --font-size-text: 18px;
    --font-size-result: 56px;

    /* Components */
    --button-height: 50px;
    --nav-btn-size: 40px;
    --calendar-min-height: auto; /* Flexible on mobile */
    
    /* Borders */
    --border-thickness: 1.5px;
    --button-border: 2.373px solid #373737;
    --result-border-top: 2px solid var(--border-color);
}


/* BASE RESET & GLOBAL STYLES */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: none; 
    -ms-overflow-style: none;
}

*::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
    background: transparent;
}

button, .nav-btn, .group-btn, .day, .today-btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--background-color);
    font-family: var(--font-family);
    color: var(--font-color);
    overflow-x: hidden;
}

.hidden {
    display: none !important;
}


/* LAYOUT STRUCTURE */

.container {
    padding: var(--container-padding);
    min-height: 100vh;
    min-height: 100dvh;
    max-width: var(--container-max-width); 
    margin: 0 auto;   
    width: 100%;      
}


/* TYPOGRAPHY COMPONENTS */

h1 {
    margin-top: var(--title-margin-top);
    font-size: var(--font-size-title);
    font-weight: var(--font-weight-light);
}

.section {
    margin-top: var(--section-margin-top);
}

.section-title {
    font-size: var(--font-size-section);
    font-weight: var(--font-weight-regular);
    margin-bottom: var(--element-margin-top);
}

.helper-text {
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
}


/* COMPONENT: ONBOARDING BUTTONS */

.onboarding-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.group-btn {
    width: 100%;
    height: var(--button-height);
    border: var(--button-border);
    background-color: var(--white);
    font-size: var(--font-size-text);
    font-weight: var(--font-weight-regular);
    cursor: pointer;
    transition: all 0.1s;
    display: grid; 
    place-items: center;
    grid-template-areas: "stack";
}

.group-btn:hover {
    border-color: var(--control-color);
}

.btn-text {
    grid-area: stack;
    transition: opacity 0.2s ease;
}

/* Loader Logic */
.loader {
    grid-area: stack;
    width: 20px;
    height: 20px;
    border: 2px solid var(--white);
    border-bottom-color: transparent;
    border-radius: 50%;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease;
    animation: rotation 0.6s linear infinite;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.group-btn.loading {
    pointer-events: none;
    cursor: wait;
}
.group-btn.loading .btn-text { 
    visibility: hidden; 
    opacity: 0; 
}
.group-btn.loading .loader { 
    visibility: visible; 
    opacity: 1; 
}

/* Shift Colors (Data Attributes) */
.group-btn[data-select-shift="Mattino"] { 
    color: var(--color-mattino);
    border-color: var(--color-mattino);
    font-weight: 600; 
}
.group-btn[data-select-shift="Mattino"]:hover { 
    background-color: rgba(17, 150, 253, 0.1); }
.group-btn[data-select-shift="Mattino"].loading { 
    background-color: var(--color-mattino); 
    color: #FFF; 
}

.group-btn[data-select-shift="Pomeriggio"] { 
    color: var(--color-pomeriggio); 
    border-color: var(--color-pomeriggio); 
    font-weight: 600; 
}
.group-btn[data-select-shift="Pomeriggio"]:hover { 
    background-color: rgba(217, 159, 0, 0.1); 
}
.group-btn[data-select-shift="Pomeriggio"].loading { 
    background-color: var(--color-pomeriggio); 
    color: #FFF; 
}

.group-btn[data-select-shift="Notte"] { 
    color: var(--color-notte); 
    border-color: var(--color-notte); 
    font-weight: 600; 
}
.group-btn[data-select-shift="Notte"]:hover { 
    background-color: rgba(135, 100, 184, 0.1); 
}
.group-btn[data-select-shift="Notte"].loading { 
    background-color: var(--color-notte); 
    color: #FFF; 
}


/* COMPONENT: CURRENT WEEK CARD */

.current-week-card {
    background-color: var(--light-bg);
    padding: 16px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-label { 
    font-size: var(--font-size-text); 
    color: var(--text-secondary); 
}
.card-value { 
    font-size: var(--font-size-text); 
    font-weight: var(--font-weight-semibold); 
}

.card-value.mattino { 
    color: var(--color-mattino); 
}
.card-value.pomeriggio { 
    color: var(--color-pomeriggio); 
}
.card-value.notte { 
    color: var(--color-notte); 
}


/* COMPONENT: CALENDAR CONTROLS */

.calendar-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 16px;
    gap: 8px;
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.month-picker-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 16px;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.month-year {
    font-size: var(--font-size-section);
    font-weight: var(--font-weight-regular);
    cursor: pointer; 
    transition: color 0.2s;
}

/* Native Picker Overlay */
#native-month-picker {
    position: absolute;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    opacity: 0; 
    cursor: default; 
    z-index: 10;
}

/* Nav Button Styling (Neutral Gray) */
.nav-btn {
    width: var(--nav-btn-size);
    height: var(--nav-btn-size);
    background-color: var(--white);
    border: var(--border-thickness) solid #b6b6b6; 
    color: var(--control-color); 
    font-size: 18px;
    cursor: pointer;
    
    /* Ensure smooth return animation */
    transition: background-color 0.1s, transform 0.1s ease-out;
}

/* Active State (3D Tactile Feedback) */
/* Applies the specific perspective tilt when pressed */
.nav-btn:active,
.nav-btn.clicked {
    transform: perspective(400px) rotateX(2deg) rotateY(-2deg) scale(0.98);
    
    /* Visual feedback coloring */
    background-color: var(--control-active-bg); 
    border-color: var(--control-active-bg);
    color: var(--control-active-text);
}

.today-btn {
    background: transparent;
    border: 1.5px solid #b6b6b6;
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    color: #5b5b5b;
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0;
    transform: translateY(-5px);
    pointer-events: none;
}

.today-btn.visible { opacity: 1; 
    transform: translateY(0); 
    pointer-events: auto; 
}
.today-btn:hover { 
    background-color: var(--control-color); 
    color: var(--white); 
    border-color: var(--control-color); 
}


/* COMPONENT: CALENDAR GRID */

.weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 8px;
}

.weekday {
    text-align: center;
    font-size: 12px;
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    padding: 8px 0;
}

.days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: var(--element-margin-top);
    min-height: var(--calendar-min-height);
    align-content: start;
}

.day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: var(--font-weight-regular);
    cursor: pointer;
    border: 2px solid transparent; 
    transition: transform 0.2s, background-color 0.2s;
}

.day.other-month { 
    color: var(--text-disabled); 
    cursor: default; 
}

/* Day Selection Logic */
.day.selected { 
    color: #FFF; 
    font-weight: var(--font-weight-semibold); 
    background-color: var(--control-color); 
    border-color: transparent; 
}
.day.selected.mattino { 
    background-color: var(--color-mattino); 
    color: #FFF; 
}
.day.selected.pomeriggio { 
    background-color: var(--color-pomeriggio); 
    color: #000; 
}
.day.selected.notte { 
    background-color: var(--color-notte); 
    color: #FFF; 
}

.day.today { 
    border-color: var(--control-color); 
}
.day.today.mattino { 
    border-color: var(--color-mattino); 
}
.day.today.pomeriggio { 
    border-color: var(--color-pomeriggio); 
}
.day.today.notte { 
    border-color: var(--color-notte); 
}


/* COMPONENT: RESULT AREA */

.result {
    text-align: center;
    padding: 32px 0;
    border-top: var(--result-border-top);
    animation: var(--slide-animation);
}

.result-date {
    font-size: var(--font-size-text);
    font-weight: var(--font-weight-regular);
    color: var(--text-secondary);
    margin-bottom: 16px;
    text-transform: capitalize;
}

.result-shift {
    font-size: var(--font-size-result);
    font-weight: var(--font-weight-light);
    margin-bottom: 8px;
}

.result-shift.mattino { 
    color: var(--color-mattino); 
}
.result-shift.pomeriggio { 
    color: var(--color-pomeriggio); 
}
.result-shift.notte { 
    color: var(--color-notte); 
}

/* Footer */
.footer-actions {
    margin-top: 20px;
    text-align: center;
    padding-bottom: 40px;
}

.text-btn {
    background: none; 
    border: none; 
    color: var(--text-secondary);
    text-decoration: underline; font-size: 14px; cursor: pointer;
}


/* GLOBAL COMPONENTS: TOAST & BANNER */

.install-banner, .update-toast {
    position: fixed; 
    left: 50%; 
    transform: translateX(-50%) translateY(150%);
    background-color: var(--white);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

/* Specific Banner Styles */
.install-banner {
    bottom: 20px; 
    left: 20px; 
    right: 20px; 
    width: auto; 
    transform: translateY(150%);
    border: var(--button-border); 
    border-radius: 12px; 
    padding: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

.update-toast {
    bottom: 80px; 
    width: max-content; 
    max-width: 90%;
    background-color: #323232; 
    color: #FFF;
    padding: 12px 20px; 
    border-radius: 50px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3); 
    z-index: 2000;
}

.install-banner.visible { 
    transform: translateY(0); 
}
.update-toast.visible { 
    transform: translateX(-50%) translateY(0); 
}

/* Toast/Banner Internals */
.install-content, .update-content { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
}
.install-icon { 
    width: 40px; 
    height: 40px; 
    border-radius: 8px; 
}
.install-text { flex: 1; 
    display: flex; 
    flex-direction: column; 
}
.install-title { 
    font-weight: 600; 
    font-size: 14px; 
}
.install-desc { 
    font-size: 12px; 
    color: var(--text-secondary); 
}
.update-text { 
    font-size: 14px; 
    font-weight: 500; 
    color: #FFF; 
}

.install-action-btn, .update-action-btn {
    background-color: var(--control-color); 
    color: #FFF; 
    border: none;
    padding: 6px 12px; 
    border-radius: 20px; 
    font-size: 12px; 
    font-weight: 600; 
    cursor: pointer;
}
.install-close { 
    background: transparent; 
    border: none; 
    color: var(--text-secondary); 
    cursor: pointer; 
    padding: 4px; 
}


/* ANIMATIONS */

.group-btn.clicked, .day.clicked {
    transform: perspective(400px) rotateX(2deg) rotateY(-2deg) scale(0.98);
    transition: transform 0.1s ease-out;
}

@keyframes softPivot {
    0% { 
        opacity: 0; 
        transform: perspective(400px) rotateX(7deg) translateY(-2px); 
    }
    100% { 
        opacity: 1; 
        transform: perspective(400px) rotateX(0deg) translateY(0); 
    }
}


/* MEDIA QUERY: DARK MODE */

@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #121212;
        --font-color: #FFFFFF;
        --white: #1C1C1E; 
        --light-bg: #2C2C2E;
        --border-color: #3A3A3C;
        --text-secondary: #98989F;
        --text-disabled: #474747;

        /* Controls shift to Light Gray for visibility */
        --control-color: #E1E1E1;
        --control-active-bg: #E1E1E1;
        --control-active-text: #000000;

        /* Adjustments for readability */
        --color-mattino: #209efe;
        --color-pomeriggio: #d99f00;
        --color-notte: #BF5AF2;
    }

    body { color-scheme: dark; }
    
    .day.selected { 
        color: #000; 
    }
    .today-btn { 
        color: #ababab; 
    }
    .install-banner { 
        background-color: #1C1C1E; 
        border-color: #333; 
    }
    .update-toast { background-color: #4A4A4A; 
        border: 1px solid #666; 
    }
    
    .group-btn[data-select-shift="Mattino"].loading .loader,
    .group-btn[data-select-shift="Pomeriggio"].loading .loader {
        border-color: #000; border-bottom-color: transparent;
    }
}


/* DESKTOP DASHBOARD (Overriding variables & Structural Grid) */
/* Triggered on screens wider than 950px (Desktop & Large Tablets Landscape) */

@media (min-width: 950px) {

    :root {
        /* Override Base Colors for "Dashboard" Look */
        /* Note: We do not set the dark background here as a default
           We let the specific body rules below handle the mode distinction */
        
        /* Layout & Dimensions Overrides */
        --container-max-width: 900px;
        --container-padding: 50px 70px;
        --calendar-min-height: 290px; 
        
        /* Typography Overrides */
        --font-size-title: 36px;
        --font-size-result: 64px;
        --font-size-text: 16px;
        
        /* Remove Borders for desktop layout as the card provides the structure */
        --result-border-top: none;
    }

    /* 1. Global Background - LIGHT MODE DEFAULT */
    body {
        display: flex; 
        align-items: center; 
        justify-content: center; 
        height: 100vh;
        background-color: #00457a;
        background-image: radial-gradient(circle at top right, #051c2f 0%, rgb(0, 63, 110) 100%);
    }

    /* 2. Neutralize Phone Wrappers */
    /* We use 'display: contents' to make these divs virtually disappear from the DOM tree */
    .device-frame, .device-screen { 
        display: contents; 
    }

    /* 3. Main Card Style */
    .container {
        height: auto; min-height: 550px;
        background-color: var(--white);
        border-radius: 24px;
        margin: 0; position: relative;
        border: 1px solid #535353;
    }

    /* 4. GRID LAYOUT SYSTEM */
    #main-view {
        display: grid; 
        width: 100%; 
        height: 100%;
        grid-template-columns: 1fr 1.2fr;
        grid-template-rows: auto auto 1fr auto;
        grid-template-areas: 
            "title    calendar"
            "week     calendar"
            "result   calendar"
            "footer   calendar";
        gap: 0 60px;
        align-items: stretch; /* Prevents vertical resizing issues */
    }

    /* 5. Structural Adjustments (Grid Area assignments) */
    
    h1 { 
        grid-area: title; 
        margin-top: 0; 
        margin-bottom: 20px; 
        text-align: left; 
    }
    
    .section:nth-of-type(1) { /* Week Card */
        grid-area: week; 
        margin-top: 0;
        display: flex; 
        flex-direction: column; 
        justify-content: center;
    }
    
    .current-week-card { 
        height: 100%; 
    }

    .result {
        grid-area: result; 
        padding: 0; 
        margin: 0; 
        text-align: center; 
        animation: none;
        display: flex; 
        flex-direction: column; 
        justify-content: center;
    }
    .result-shift { 
        line-height: 1.1; 
        letter-spacing: -1px; 
    }

    .footer-actions {
        grid-area: footer; 
        text-align: left; 
        padding: 0; 
        margin: 0;
        display: flex; 
        flex-direction: column; 
        justify-content: center;
    }

    .section:nth-of-type(2) {
        grid-area: calendar; 
        margin-top: 0;
        height: auto; 
        min-height: 100%;
        display: flex; 
        flex-direction: column; 
        justify-content: center;
        border-left: 1px solid var(--border-color); 
        padding-left: 60px;
    }

    /* Desktop Interactions */
    /* Fix: We use :not(:active) and :not(.clicked) to ensure the hover color 
       doesn't override the dark click feedback color when pressed. */
    
    .nav-btn:hover:not(:active):not(.clicked) {
        background-color: var(--light-bg);
        border-color: #999;
    }
    
    .day:hover:not(.selected):not(.other-month):not(:active):not(.clicked) {
        background-color: var(--light-bg);
    }
    
    .days { gap: 8px; }

    /* Onboarding Overrides */
    #onboarding-view { 
        max-width: 400px; 
        margin: 0 auto; 
        padding-top: 40px; }
    .onboarding-buttons { 
        gap: 20px;
    }
    .group-btn { 
        height: 60px; 
        font-size: 20px; 
    }
    .group-btn:hover { 
        transform: translateY(-2px); 
        box-shadow: 0 4px 12px rgba(0,0,0,0.1); 
    }


    /* DARK MODE DESKTOP OVERRIDES */
    @media (prefers-color-scheme: dark) {
        body { 
            background-color: #1a1a1a; 
            background-image: radial-gradient(circle at top right, #000000 0%, #242424 100%);
        }
        
        .container {
            border: 1px solid #404040; 
        }
        .section:nth-of-type(2) { 
            border-left-color: #333; 
        }
        .month-picker-wrapper:hover, .day:hover:not(.selected):not(.other-month) { 
            background-color: #333; 
        }
    }
}


/* TABLET TWEAKS (Intermediate view) */
/* Bridging the gap between Mobile and Desktop Card */

@media (min-width: 550px) and (max-width: 949px) {

    :root {
        /* Relaxed spacing for larger touch screens */
        --container-max-width: 530px; 
        
        /* Slightly larger typography to fill the space */
        --font-size-title: 48px;
        --font-size-result: 72px;
        
        /* Bigger touch targets for easier interaction */
        --button-height: 60px;
    }

    /* Center the vertical container for elegance */
    .container {
        margin-top: 5vh; 
        border-radius: 24px; /* Introduces a polished rounded look */
    }
}


/* MEDIA QUERY: LANDSCAPE MOBILE (Dashboard Mode) */

@media (orientation: landscape) and (max-height: 600px) {
    .container {
        max-width: 100%; 
        padding: 10px 40px; 
        height: 100vh;      
        display: flex; 
        align-items: center; 
        overflow: hidden;    
    }
    #main-view {
        width: 100%; 
        height: 100%; 
        display: grid;
        grid-template-columns: 0.8fr 1.2fr; 
        grid-template-rows: auto auto 1fr auto; 
        grid-template-areas: "title calendar" "week calendar" "result calendar" "footer calendar";
        gap: 0 40px; align-content: center; 
    }
    h1 { 
        grid-area: title; 
        margin-top: 0; 
        font-size: 28px; 
        text-align: left; 
    }
    .section:nth-of-type(1) { 
        grid-area: week; 
        margin-top: 10px; 
    }
    .result {
        grid-area: result; 
        border-top: none; 
        padding: 20px 0; 
        text-align: left; 
        display: flex; 
        flex-direction: column; 
        align-items: flex-start; 
        justify-content: center;
    }
    .result-date { 
        margin-bottom: 5px; 
    }
    .result-label { 
        order: -1; 
        margin-bottom: 5px; 
        font-size: 12px;
    } 
    .result-shift { font-size: 42px; 
        line-height: 1; 
    }
    .footer-actions { grid-area: footer; 
        text-align: left; 
        margin-top: 0; 
        padding-bottom: 0; 
    }
    .section:nth-of-type(2) {
        grid-area: calendar; 
        margin-top: 0; 
        height: auto; 
        min-height: 100%;
        display: flex; 
        flex-direction: column; 
        justify-content: center;
        border-left: 1px solid var(--border-color); 
        padding-left: 60px;
    }
    .days { 
        gap: 2px; 
    }
    .day { 
        font-size: 13px; 
        width: 100%; 
        max-width: 40px; 
        margin: 0 auto; 
    }
    #onboarding-view { 
        overflow-y: auto; 
        max-height: 100vh; 
    }
}