/* ==================== IMPORTED FONTS ==================== */
@font-face {
    font-family: 'Poppins-Light';
    src: url('../assets/fonts/poppins-light.woff2') format('woff2');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Poppins-Regular';
    src: url('../assets/fonts/poppins-regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Poppins-Medium';
    src: url('../assets/fonts/poppins-medium.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Poppins-Bold';
    src: url('../assets/fonts/poppins-bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* ==================== VARIABLES ==================== */
:root {
    --primary-color: #1B7090;
    --primary-light-color: #4f89a0;
    --primary-dark-color: #194f6b;
    --secondary-color: #ffd166;
    --secondary-light-color: #ffe08a;
    --neutral-color: #757575;
    --negative-color: #972c24;
    --background-color: #fdfdfd;
    --progress-background-color: #eeeeee;
    --primary-font-regular: 'Poppins-Regular', sans-serif;
    --primary-font-light: 'Poppins-Light', sans-serif;
    --primary-font-medium: 'Poppins-Medium', sans-serif;
    --primary-font-bold: 'Poppins-Bold', sans-serif;
}

.dark-theme {
    --primary-dark-color: #a6e5fe;
    --secondary-light-color: #0f3c52;
    --negative-color: #cb453b;
    --background-color: #222222;
    --progress-background-color: #333333;
    --neutral-color: #bababa;

    svg {
        path:nth-of-type(1) {
            --primary-dark-color: #59cef8;
        }

        path:nth-of-type(2) {
            --primary-light-color: #a6e5fe;
        }
    }

    h2 {
        --primary-color: #3398bd;
    }

    #countdown {
        --primary-dark-color: #ffe08a;
    }

    #drink-form label {
        --primary-light-color: #78cff2;
    }

    #view-me button {
        &:nth-of-type(1) {
            --primary-color: #a6e5fe;
        }

        &:nth-of-type(2) {
            --primary-color: #ffe08a;
        }
    }

    footer {
        --primary-color: #8fcce4;
    }
}

/* ==================== GENERAL STYLES ==================== */
* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

html {
    display: flex;
    justify-content: center;
    background: #aaaaaa;
}

body {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 100dvh;
    width: 480px;
    max-width: 100%;
    /* Se fuerza la barra de scroll para que no descentre el body al cambiar de vista */
    overflow-y: scroll;
    font-family: var(--primary-font-regular);
    background: var(--background-color);
    transition: all 0.3s;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    padding: 0.5rem 1rem;
    background: var(--background-color);
    z-index: 1;

    svg {
        height: 2.2rem;

        path:nth-of-type(1) {
            fill: var(--primary-dark-color);
        }

        path:nth-of-type(2) {
            fill: var(--primary-light-color);
        }
    }

    #toggleButton {
        position: relative;
        appearance: none;
        -moz-appearance: none;
        -webkit-appearance: none;
        outline: none;
        cursor: pointer;
        height: 1.3rem;
        width: 3rem;
        margin-right: 1.5rem;
        box-shadow: 0.2rem 0.2rem 0.1rem #277B9A11;
        border: 0.05rem solid #277B9A66;
        border-radius: 2rem;

        &:before {
            position: absolute;
            content: "";
            width: 1rem;
            height: 1rem;
            top: 50%;
            left: 0.2rem;
            transform: translateY(-50%) translateX(0%);
            border-radius: 50%;
            background: var(--primary-color);
            transition: transform 0.3s;
        }

        &:after {
            position: absolute;
            content: "";
            background-image: url(../assets/images/bombilla-apagada.svg);
            background-size: cover;
            width: 1.6rem;
            height: 1.6rem;
            top: calc(50% - 0.1rem);
            transform: translateY(-50%);
            left: calc(100% + 0.3rem);
            white-space: nowrap;
            color: var(--primary-light-color);
            pointer-events: none;
        }
    }

    #toggleButton:checked {
        background: var(--primary-color);
        border: none;

        &:before {
            transform: translateY(-50%) translateX(1.6rem);
            background-color: #fdfdfd;
        }

        &:after {
            background-image: url(../assets/images/bombilla-encendida.svg);
        }
    }
}

footer {
    position: sticky;
    bottom: 0;

    nav {
        display: flex;
        gap: 0.5rem;
        justify-content: space-between;
        padding: 0.5rem 0 0 0;
        margin-top: 0.5rem;
        background: var(--background-color);

        button {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 100%;
            padding: 0.5rem 0.5rem 0 0.5rem;
            border: 0;
            background: var(--background-color);
            cursor: pointer;

            &:nth-of-type(1) {
                svg {
                    transform: scale(1.2);
                }
            }

            svg {
                width: 1.5rem;
                height: auto;
                fill: var(--primary-color);
            }

            span {
                margin: 1rem 0;
                font-weight: 700;
                color: var(--primary-color);
            }
        }
    }
}


/* ==================== USER REGISTER & LOGIN ==================== */

body[data-page="login"] {
    display: flex;
    justify-content: center;
    align-items: center;

    .login-layout {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.9rem;
        width: 100%;
        max-width: 400px;
        padding: 1.25rem;

        svg {
            transform: scale(1.4);
        }

        h1 {
            margin-top: 0;
            color: var(--neutral-color);
            font-family: var(--primary-font-light);
            font-weight: 300;
            text-transform: uppercase;
            font-size: 0.95rem;
            text-align: center;
            letter-spacing: 0.1rem;
        }

        button {
            width: 100%;
            padding: 1rem 1.1rem;
            margin: 1rem 0;
            border: 0;
            border-radius: 10rem;
            font-family: var(--primary-font-bold);
            font-size: 0.9rem;
            cursor: pointer;
        }
    }

    .auth-tabs {
        display: flex;

        button {

            &:first-child {
                border-radius: 1.618rem 0 0 1.618rem;
            }

            &:last-child {
                border-radius: 0 1.618rem 1.618rem 0;
            }
        }

        .active {
            color: var(--primary-dark-color);
            background: var(--secondary-light-color);
            transition: all 1s ease;
        }
    }

    #auth-form {
        input {
            width: 100%;
            padding: 0.6rem 1.1rem;
            margin-bottom: 1rem;
            border: 0.1rem solid var(--primary-light-color);
            border-radius: 10rem;
            font-family: var(--primary-font-medium);
            color: var(--primary-dark-color);
            background: var(--background-color);
            outline: none;
            transition: all 0.3s ease;

            &:focus {
                border: 0.1rem solid var(--primary-dark-color);
                box-shadow: 0 0 0.3rem var(--primary-dark-color);
            }
        }

        button {
            color: var(--background-color);
            background: var(--primary-color);
        }
    }

    #auth-message {
        width: 100%;
        min-height: 3.5rem;
        margin: 0;
        padding: 1rem 2rem;
        border-radius: 3rem;
        color: var(--background-color);
        font-family: var(--primary-font-medium);
        font-size: 0.9rem;
        text-align: center;
        background: transparent;
        transition: all 0.5s ease;

        &:not(:empty) {
            background: var(--negative-color);
        }
    }
}

/* ==================== DASHBOARD MAIN WRAPPER ==================== */

main.app-layout {
    display: flex;

    h1 {
        display: none;
    }

    div {
        display: flex;
        align-items: stretch;

        .side-progress {
            appearance: none;
            width: 1.5rem;
            height: calc(100dvh - 10.5rem);
            margin: 0.5rem 0 0.5rem 1rem;
            border: none;
            border-radius: 2rem;
            background: #eee;
            writing-mode: vertical-lr;
            direction: rtl;

            &::-webkit-progress-bar {
                background-color: var(--progress-background-color);
                border-radius: 1rem;
            }

            &::-webkit-progress-value {
                background-color: var(--primary-dark-color);
                border-radius: 1rem;
                transition: 1s ease;
            }

            &::-moz-progress-bar {
                background: var(--primary-dark-color);
            }
        }
    }

    section {
        display: flex;
        flex-direction: column;
        align-items: center;
        flex-wrap: wrap;
        width: 100%;
        padding: 0.5rem;

        h2 {
            display: none;
        }

        h3 {
            margin: -0.8rem 0;
            font-family: var(--primary-font-medium);
            font-size: 0.9rem;
            font-weight: 500;
            color: var(--neutral-color);

            &:nth-of-type(1) {
                margin-top: 1rem;
            }
        }

        #daily-target {
            font-size: 3rem;
            font-family: var(--primary-font-medium);
            margin: 0;
            color: var(--primary-light-color);
        }

        #total {
            font-size: 3.7rem;
            font-family: var(--primary-font-bold);
            margin: 0;
            color: var(--primary-dark-color);
        }

        #countdown {
            padding: 1rem 1.5rem;
            border-radius: 3rem;
            font-family: var(--primary-font-medium);
            color: var(--primary-dark-color);
            text-transform: uppercase;
            background: var(--secondary-light-color);
            opacity: 0;
            transition: opacity 1s ease;
        }

        form {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 0.5rem;
            margin: auto 0.5rem 0.5rem 0.5rem;
            padding-bottom: 0.5rem;
            border: solid 0.1rem #277B9A11;
            border-radius: 2rem;
            box-shadow: 0.3rem 0.3rem 0.8rem #277B9A33;

            label {
                position: relative;
                left: 1rem;
                bottom: -1rem;
                width: 100%;
                font-family: var(--primary-font-bold);
                font-size: 0.9rem;
                color: var(--primary-light-color);
                text-transform: uppercase;
            }

            input,
            span {
                font-family: var(--primary-font-medium);
                color: var(--neutral-color);
                font-size: 1.7rem;
            }

            input {
                width: 40%;
                border: 0;
                text-align: right;
                background: var(--background-color);

                &::placeholder {
                    color: var(--neutral-color);
                }
            }

            span {
                width: 20%;
                text-align: left;
            }
        }

        button {
            width: 4rem;
            margin-left: auto;
            margin-right: 0.5rem;
            aspect-ratio: 1 / 1;
            border: none;
            border-radius: 50%;
            background-color: var(--primary-color);
            cursor: pointer;

            img {
                width: 3rem;
            }
        }
    }
}

/* ==================== DASHBOARD HISTORY & ME VIEWS ==================== */

#view-history {
    padding: 0 3rem;

    h2 {
        display: block;
        margin: 1rem 0;
        font-family: var(--primary-font-bold);
        color: var(--primary-color);
    }

    #history-container {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;

        p {
            color: var(--neutral-color);
        }

        span {
            &:nth-of-type(1) {
                color: var(--primary-dark-color) !important;
            }

            &:nth-of-type(2) {
                color: var(--neutral-color);
                margin-left: 1rem;
            }
        }
    }

    .trash-button {
        width: 2rem;
        height: 2rem;
        border: none;
        background: none;
        fill: var(--primary-dark-color);
        stroke: 2pt;
        transform: scale(1.2);
        cursor: pointer
    }
}

#view-me {
    height: calc(100dvh - 8.9rem);

    h2 {
        display: block;
        margin: 0 0 1rem 0;
        font-family: var(--primary-font-bold);
        color: var(--primary-color);
    }

    #profile-container {
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 1.5rem;
        gap: 0.6rem;
        margin: 1rem auto 0;
        box-sizing: border-box;
    }

    .user-info {
        display: flex;
        flex-direction: column;
        gap: 0.55rem;

        p {
            margin: 0;
            color: var(--neutral-color);
        }
    }

    .edit-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;

        input {
            width: 100%;
            padding: 0.65rem 0.75rem;
            border: solid 0.1rem #58B5E333;
            border-radius: 10rem;
            background: var(--background-color);

            &[type="number"] {
                color: var(--neutral-color);
            }
        }

        label {
            color: var(--neutral-color);
        }
    }

    button {
        width: 100%;
        height: 3.5rem;
        padding: 0.65rem 0.75rem;
        margin-bottom: 0.5rem;
        border: 0;
        border-radius: 10rem;
        font-size: 1rem;
        font-family: var(--primary-font-bold);
        cursor: pointer;

        &.save-btn {
            color: var(--background-color);
            background: var(--primary-color);
        }

        &.logout-btn {
            color: var(--primary-color);
            background: var(--secondary-light-color);
        }
    }
}


/* ==================== WEATHER CARD ==================== */

body[data-page="dashboard"] #weather-output .dashboard-weather-card {
    width: 100%;
    max-width: 31rem;
    padding: 1.2rem 0;
}

/* Se fuerza la ciudad visible dentro de la card porque el dashboard oculta los h2 generales. */
body[data-page="dashboard"] #weather-output .dashboard-weather-card h2 {
    display: block;
    max-width: none;
    font-size: clamp(0.96rem, 2.35vw, 1.14rem);
    font-family: var(--primary-font-bold);
    line-height: 1.1;
    color: #f9fdff;
}

body[data-page="dashboard"] #weather-output.weather-api {
    display: flex;
    justify-content: center;
    align-items: stretch;
    width: 100%;
    height: auto;
    min-height: 0;
    padding: 0;
    color: inherit;
    font-size: inherit;
    letter-spacing: normal;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
}

/* El contenido queda por encima de las capas decorativas. */
.dashboard-weather-card>* {
    position: relative;
    z-index: 1;
}

/* El rediseño se limita al dashboard y mantiene el montaje actual en #weather-output. */
.dashboard-weather-card {
    position: relative;
    display: block;
    width: 100%;
    max-width: 31rem;
    min-height: 0;
    margin: 0 auto;
    padding: 0.72rem 0.9rem;
    overflow: hidden;
    isolation: isolate;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 1.15rem;
    background:
        radial-gradient(circle at 14% 18%, rgba(255, 255, 255, 0.2), transparent 26%),
        radial-gradient(circle at 86% 0%, rgba(255, 226, 138, 0.22), transparent 24%),
        linear-gradient(150deg, #0a5b69 0%, #13829a 48%, #48bfd8 100%);
    color: #f7fcff;
    box-shadow:
        0 0.45rem 1rem rgba(7, 77, 96, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.18);

    /* Capas decorativas para una sensacion mas premium sin assets externos. */
    &::before,
    &::after {
        content: "";
        position: absolute;
        pointer-events: none;
        z-index: 0;
    }

    &::before {
        inset: auto -12% -44% 58%;
        height: 48%;
        border-radius: 999px;
        background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0 18%, transparent 56%);
        filter: blur(12px);
        opacity: 0.5;
    }

    &::after {
        top: -1.35rem;
        right: -0.9rem;
        width: 4.85rem;
        height: 4.85rem;
        border-radius: 50%;
        background: radial-gradient(circle, rgba(255, 248, 200, 0.78) 0 16%, rgba(255, 226, 138, 0.18) 36%, transparent 66%);
        opacity: 0.78;
    }

    h2,
    p {
        margin: 0;
    }

    /* Cabecera con jerarquia clara entre ciudad y estado. */
    .weather-card__top,
    .weather-card__header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.45rem;
        align-items: center;
    }

    .weather-card__heading {
        display: grid;
        gap: 0;
        min-width: 0;
    }

    .weather-card__eyebrow {
        font-size: 0.58rem;
        font-family: var(--primary-font-medium);
        letter-spacing: 0.14em;
        text-transform: uppercase;
        opacity: 0.72;
    }

    /* Composicion principal tipo app movil con temperatura destacada y panel auxiliar. */
    .weather-card__main,
    .weather-card__content {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.5rem;
        align-items: stretch;
        margin-top: 0.5rem;
    }

    .weather-card__temperature-block {
        display: grid;
        align-content: center;
        gap: 0;
        min-width: 0;
        padding: 0.56rem 0.72rem;
        border: 1px solid rgba(255, 255, 255, 0.14);
        border-radius: 0.95rem;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.05));
        backdrop-filter: blur(12px);
    }

    .weather-card__temperature-label {
        font-size: 0.56rem;
        font-family: var(--primary-font-medium);
        letter-spacing: 0.14em;
        text-transform: uppercase;
        opacity: 0.72;
    }

    .weather-card__temperature {
        font-size: clamp(1.85rem, 6vw, 2.45rem);
        font-family: var(--primary-font-bold);
        line-height: 0.95;
        letter-spacing: -0.04em;
        text-shadow: 0 0.14rem 0.45rem rgba(4, 74, 109, 0.14);
    }

    .weather-card__meta,
    .weather-card__datetime {
        display: grid;
        gap: 0.32rem;
        min-width: 8.65rem;
        padding: 0.54rem 0.65rem;
        border: 1px solid rgba(255, 255, 255, 0.12);
        border-radius: 0.95rem;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04));
        backdrop-filter: blur(10px);
    }

    .weather-card__meta-row {
        display: grid;
        gap: 0;
    }

    .weather-card__meta-row+.weather-card__meta-row {
        padding-top: 0.28rem;
        border-top: 1px solid rgba(255, 255, 255, 0.14);
    }

    /* Labels discretas y valores con mejor jerarquia. */
    .weather-card__meta-label {
        font-size: 0.52rem;
        font-family: var(--primary-font-medium);
        letter-spacing: 0.12em;
        text-transform: uppercase;
        opacity: 0.68;
    }

    .weather-card__meta-item {
        font-size: 0.7rem;
        font-family: var(--primary-font-medium);
        line-height: 1.15;
        text-align: left;
        white-space: nowrap;
        opacity: 0.96;
    }

    .weather-card__advice {
        display: -webkit-box;
        margin-top: 0.42rem;
        overflow: hidden;
        padding: 0.42rem 0.58rem;
        border: 1px solid rgba(255, 255, 255, 0.12);
        border-radius: 0.82rem;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.05));
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        color: #f4fbff;
        font-size: 0.63rem;
        font-family: var(--primary-font-medium);
        line-height: 1.24;
        letter-spacing: 0.01em;
    }

    /* Pill de estado con acabado glass y mejor contraste. */
    .weather-card__status {
        display: inline-flex;
        align-items: center;
        gap: 0.3rem;
        max-width: 11.75rem;
        padding: 0.24rem 0.5rem;
        border: 1px solid rgba(255, 255, 255, 0.16);
        border-radius: 999px;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.09));
        backdrop-filter: blur(10px);
        font-size: 0.64rem;
        font-family: var(--primary-font-medium);
        line-height: 1.18;
        text-align: right;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);

        /* Iconografia semantica sin nuevos assets. */
        &::before {
            content: "•";
            flex: 0 0 auto;
            color: #ffe18c;
        }
    }

    .weather-card__status[data-icon="sun"]::before {
        content: "☼";
    }

    .weather-card__status[data-icon="moon"]::before {
        content: "☾";
        color: #dcecff;
    }

    .weather-card__status[data-icon="cloud"]::before {
        content: "☁";
        color: #f2fbff;
    }

    .weather-card__status[data-icon="rain"]::before {
        content: "☂";
        color: #d2f2ff;
    }

    .weather-card__status[data-icon="storm"]::before {
        content: "ϟ";
        color: #ffe6a3;
    }

    .weather-card__status[data-icon="snow"]::before {
        content: "✦";
        color: #f2fbff;
    }

    .weather-card__status[data-icon="mist"]::before {
        content: "≋";
        color: #edf9ff;
    }

    .weather-card__status[data-icon="error"]::before {
        content: "!";
        color: #ffe2a3;
    }
}

/* El modo noche cambia tono sin tocar la estructura del dashboard. */
.dashboard-weather-card[data-period="night"] {
    background:
        radial-gradient(circle at 18% 20%, rgba(213, 227, 255, 0.14), transparent 24%),
        radial-gradient(circle at 84% 2%, rgba(255, 255, 255, 0.08), transparent 18%),
        linear-gradient(150deg, #0a3553 0%, #0f5877 50%, #1a7c9f 100%);
}


/* ==================== MEDIA QUERIES ==================== */

@media (max-width: 480px) {
    main.app-layout section form button {
        width: 4.05rem;
    }

    main.app-layout section form button img {
        width: 3.15rem;
    }

    main.app-layout section form button#remove-btn {
        font-size: 2.16rem;
    }

    /* --- Weather Card --- */

    .dashboard-weather-card {
        padding: 0.68rem 0.78rem;
        border-radius: 1rem;
    }

    .dashboard-weather-card::after {
        width: 3.9rem;
        height: 3.9rem;
        top: -0.95rem;
        right: -0.6rem;
    }

    .dashboard-weather-card .weather-card__status {
        max-width: 8.4rem;
        font-size: 0.6rem;
    }

    .dashboard-weather-card .weather-card__temperature-block,
    .dashboard-weather-card .weather-card__meta {
        width: 100%;
    }

    .dashboard-weather-card .weather-card__temperature {
        font-size: 1.9rem;
    }

    .dashboard-weather-card .weather-card__meta {
        min-width: 7.9rem;
        padding: 0.48rem 0.55rem;
    }

    .dashboard-weather-card .weather-card__meta-label {
        font-size: 0.49rem;
    }

    .dashboard-weather-card .weather-card__meta-item {
        font-size: 0.66rem;
    }

    .dashboard-weather-card .weather-card__advice {
        margin-top: 0.34rem;
        padding: 0.34rem 0.48rem;
        font-size: 0.58rem;
        line-height: 1.2;
    }
}

@media (max-width: 360px) {

    .dashboard-weather-card .weather-card__top,
    .dashboard-weather-card .weather-card__header {
        grid-template-columns: 1fr;
    }

    .dashboard-weather-card .weather-card__status {
        justify-self: start;
        max-width: none;
        text-align: left;
    }
}
