@import url('https://fonts.cdnfonts.com/css/mona-sans');

html{
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

.body{
    /* fixed + margin 0: iOS no puede desplazar la página cuando sale el teclado */
    position: fixed;
    top: 0;
    left: 0;
    margin: 0;

    display: flex;
    justify-content: center;
    overflow: hidden;
    background: rgb(1, 7, 38);
    
    width: 100vw;
    height: 100vh;
    height: 100dvh;

    overscroll-behavior: none;
    overscroll-behavior-y: none;
}

/* Texto solo para buscadores y lectores de pantalla (títulos h1/h2) */
.visually_hidden{
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

#swipe_container {
    position: absolute;
    display: flex;

    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth; 
    scroll-snap-type: x mandatory; 

    left: 0;
    top: 0;
    height: 100vh;
    height: 100dvh;

    width: 100vw; 
    transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1);

    /* Fuerza el scroll fluido y elástico nativo en Safari/iOS */
    -webkit-overflow-scrolling: touch; 
}

.page {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    scroll-snap-align: start;
    height: 100vh;
    height: 100dvh;
    
    width: 100vw; 

    flex-shrink: 0; 
}


#home{
    background: #C1D1DB;
}

#stats,
#chats,
#user{
    background: #C1D1DB;
    align-items: flex-start;
}

#container_background{
    position: fixed;
    bottom: 0;
    margin-bottom: 30px;
    display: flex;
    justify-content: center;
    align-items: center;

    background: #0C243D;
    height: 70px;
    width: min(92vw, 380px); /* cabe la barra con 5 botones */

    left: 50%;
    transform: translateX(-50%);

    border-radius: 50px;
    z-index: 2;
}

#options_container{
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 30px;
    padding-left: 5px;
    padding-right: 5px;
    height: 40px;
    width: 100%;
}

#options_circle{
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 5px;

    background: rgb(49, 200, 255);
    height: 60px;
    width: 60px;

    border-radius: 50px;

    transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1);
}

.options_button{
    display: flex;
    justify-content: center;
    align-items: center;
    height: 60px;
    width: 60px;

    background: transparent;
    border: none;
    border-radius: 50px;
    z-index: 3;
}

.options_icon{
    height: 60%;
    width: 60%;

    fill: #d1f0ff;
}

#stats_icon{
    margin-bottom: 5px;
}

/* VENTANAS FLOTANTES (crear/editar y detalle) */

.floating_window{
    position: absolute;
    box-sizing: border-box;

    background: rgb(255, 255, 255);
    height: var(--app-height, 100vh); /* la pone el JS: zona visible sin teclado */
    width: 100vw;

    top: var(--app-top, 0px);
    left: 0;

    padding-top: env(safe-area-inset-top, 0px);

    transform: translateY(100vh);

    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;

    font-family: 'Mona Sans', sans-serif;

    z-index: 10;

    transition: transform 0.5s cubic-bezier(0.25, 1, 0.5, 1);
}

/* El creador se abre encima del detalle (al editar) */
#product_creator{
    z-index: 11;
}

.close_button{
    display: flex;
    justify-content: center;
    align-items: center;
    
    top: 0;
    left: 0;
    margin-top: 5px;
    margin-left: 5px;
    
    height: 35px;
    width: 35px;

    border: none;
    border-radius: 50px;

    background: rgb(197, 193, 193);

    transition: background 0.3s cubic-bezier(0.25, 1, 0.5, 1), height 0.3s cubic-bezier(0.25, 1, 0.5, 1), width 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

.close_button:hover{
    height: 40px;
    width: 40px;
    background: rgb(49, 200, 255);
}

.close_creator_icon{
    height: 60%;
    width: 60%;
}

.window_content{
    display: block;
    box-sizing: border-box;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    padding: 10px 20px 60px 20px;
}

.window_title{
    margin: 15px 0 10px 0;
    font-size: 1.6rem;
    color: #0C243D;
}

/* FORMULARIO */

.field_group{
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.field_label{
    display: block;
    margin: 22px 0 8px 0;
    padding: 0;
    font-weight: bold;
    color: #0C243D;
}

.text_input{
    box-sizing: border-box;
    width: 100%;
    padding: 12px 14px;

    font-family: inherit;
    font-size: 16px; /* evita el zoom automático de iOS al enfocar */
    color: #0C243D;

    background: #EEF3F6;
    border: 2px solid transparent;
    border-radius: 12px;
    outline: none;

    transition: border-color 0.2s;
}

.text_input:focus{
    border-color: rgb(49, 200, 255);
}

textarea.text_input{
    display: block;
    min-height: 96px;
    line-height: 1.4;
    resize: vertical;
}

.field_counter{
    margin: 4px 4px 0 0;
    text-align: right;
    font-size: 0.75rem;
    color: #7A8894;
}

#image_previews{
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.preview_item,
.add_image_tile{
    position: relative;
    box-sizing: border-box;
    width: calc((100% - 20px) / 3);
    aspect-ratio: 1 / 1;
    border-radius: 12px;
}

.preview_item img{
    width: 100%;
    height: 100%;
    border-radius: 12px;
    object-fit: cover;
}

.add_image_tile{
    display: flex;
    background: #EEF3F6;
    border: 2px dashed #9FB4C2;
}

.add_image_tile label{
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;

    font-size: 2rem;
    color: #0C243D;
    cursor: pointer;
}

.remove_badge{
    position: absolute;
    top: -6px;
    right: -6px;
    height: 24px;
    width: 24px;
    padding: 0;

    display: flex;
    justify-content: center;
    align-items: center;

    font-size: 16px;
    line-height: 1;
    color: white;
    background: #D8453B;
    border: 2px solid white;
    border-radius: 50%;
}

.tag_row{
    display: flex;
    gap: 8px;
}

.tag_list{
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

#tag_list{
    margin-top: 10px;
}

.tag_chip{
    padding: 4px 10px;

    font-size: 0.8rem;
    color: #0C243D;
    background: #D1F0FF;
    border-radius: 20px;
}

.tag_remove{
    margin: 0;
    padding: 0;

    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

.error_text{
    min-height: 1.2em;
    margin: 16px 0 0 0;
    color: #D8453B;
    font-size: 0.9rem;
}

.primary_button,
.secondary_button,
.danger_button{
    padding: 13px 18px;

    font-family: inherit;
    font-size: 1rem;
    font-weight: bold;

    border: none;
    border-radius: 14px;
}

.primary_button{
    width: 100%;
    margin-top: 10px;
    color: white;
    background: #0C243D;
}

.secondary_button{
    flex-shrink: 0;
    color: #0C243D;
    background: rgb(49, 200, 255);
}

.danger_button{
    width: 100%;
    margin-top: 10px;
    color: white;
    background: #D8453B;
}

/* DETALLE */

#detail_gallery{
    display: flex;
    gap: 10px;
    margin-top: 10px;

    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

#detail_gallery img{
    flex: 0 0 100%;
    aspect-ratio: 1 / 1;
    border-radius: 15px;
    object-fit: cover;
    scroll-snap-align: center;
}

.detail_desc{
    margin: 0 0 14px 0;
    line-height: 1.5;
    color: #3B4F61;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.detail_actions{
    margin-top: 28px;
}

/* LISTA DE PRODUCTOS */

#product_grid{
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* con "center" los primeros items quedaban cortados al hacer scroll */
    align-items: center;
    gap: 16px;

    box-sizing: border-box;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    top: 0;
    left: 0;

    padding-top: calc(30px + env(safe-area-inset-top, 0px));
    padding-bottom: 130px; /* espacio para la barra de navegación */

    overflow-x: hidden;
    overflow-y: auto;
}

.empty_text{
    margin: auto 40px;
    text-align: center;
    font-family: 'Mona Sans', sans-serif;
    color: #0C243D;
}

.product{
    position: relative;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    width: 80vw;
    padding: 15px;
    box-sizing: border-box;

    background: white;
    border-radius: 15px;
}

.product_info{
    margin-left: 15px;
    min-width: 0;
}

.product_name{
    margin: 0 0 8px 0;
    font-family: 'Mona Sans', sans-serif;
    font-size: 1rem;
    font-weight: bold;
    color: #0C243D;
}

.product_img{
    flex-shrink: 0;
    width: 15vh;
    height: 15vh;
    border-radius: 15px;

    object-fit: cover;
    object-position: center;
}

.product_input_overlay{
    position: absolute;

    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    padding: 0;

    background: transparent;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    z-index: 1;
}

/* ESTADÍSTICAS */

#stats_content,
#chats_content,
#user_content{
    display: flex;
    flex-direction: column;
    gap: 16px;

    box-sizing: border-box;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    padding: calc(24px + env(safe-area-inset-top, 0px)) 5vw 130px 5vw;

    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;

    font-family: 'Mona Sans', sans-serif;
}

.stats_title{
    margin: 0;
    font-size: 1.6rem;
    color: #0C243D;
}

.stat_card{
    flex-shrink: 0;
    box-sizing: border-box;
    padding: 16px;

    background: white;
    border-radius: 15px;
}

.stat_header{
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 12px;
}

.stat_header h3{
    margin: 0;
    font-size: 1rem;
    color: #0C243D;
}

.stat_total{
    flex-shrink: 0;
    margin: 0;
    font-size: 0.9rem;
    font-weight: bold;
    color: #0C243D;
}

/* Gráficas */

.chart{
    margin: 0;
}

.chart svg{
    display: block;
    width: 100%;
    height: auto;
}

.chart_grid{
    stroke: #E1E8ED;
    stroke-width: 1;
}

.chart_text{
    font-family: 'Mona Sans', sans-serif;
    font-size: 10px;
    fill: #5B7284;
}

.chart_value{
    font-size: 9px;
    fill: #0C243D;
}

.chart_line{
    fill: none;
    stroke: rgb(49, 200, 255);
    stroke-width: 2;
    stroke-linejoin: round;
}

.chart_point{
    fill: #0C243D;
    stroke: white;
    stroke-width: 1.5;
}

.chart_bar{
    fill: rgb(49, 200, 255);
}

.chart_bar.current{
    fill: #0C243D;
}

/* Dinero ganado: scroll horizontal dentro de la tarjeta */

#money_scroller{
    display: flex;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;

    overflow-x: auto;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain; /* el scroll de la tarjeta no arrastra la pestaña entera */
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

#money_scroller::-webkit-scrollbar{
    display: none;
}

.money_item{
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 0 0 72%; /* el siguiente mes asoma por la derecha e invita a deslizar */
    box-sizing: border-box;
    padding: 16px;

    color: #0C243D;
    background: #EEF3F6;
    border-radius: 12px;
    scroll-snap-align: start;
}

.money_item.current{
    color: #D1F0FF;
    background: #0C243D;
}

.money_month{
    margin: 0;
    font-size: 0.9rem;
}

.money_amount{
    font-size: 2rem;
}


/* PÁGINA DE CHATS */

#chats_status{
    margin: 12px 0;
    text-align: center;
    color: #3B4F61;
}

#chats_status:empty{
    display: none;
}

.card_text{
    margin: 0 0 6px 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #3B4F61;
}

#chat_list{
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.chat_avatar{
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 48px;
    height: 48px;

    font-weight: bold;
    font-size: 1.1rem;
    color: #D1F0FF;
    background: #0C243D;
    border-radius: 50%;
}

.chat_item{
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;

    text-align: left;
    font-family: inherit;
    color: inherit;
    background: white;
    border: none;
    border-radius: 15px;
    cursor: pointer;
}

.chat_item_text{
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.chat_item_name,
.chat_preview{
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat_item_name{
    font-size: 1rem;
    color: #0C243D;
}

.chat_preview{
    font-size: 0.85rem;
    color: #6B7A87;
}

.chat_time{
    align-self: start;
    font-size: 0.72rem;
    color: #7A8894;
}

/* PÁGINA DE USUARIO */

#login_form .field_label,
#register_form .field_label{
    margin-top: 16px;
}

.account_header{
    display: flex;
    align-items: center;
    gap: 14px;
}

.account_avatar{
    width: 56px;
    height: 56px;
    font-size: 1.4rem;
}

#account_name{
    margin: 0;
    font-size: 1.05rem;
    color: #0C243D;
    overflow-wrap: anywhere;
}

#account_email{
    margin: 2px 0 0 0;
    font-size: 0.85rem;
    color: #6B7A87;
    overflow-wrap: anywhere;
}

.admin_badge{
    display: inline-block;
    margin: 14px 0 4px 0;
    padding: 4px 10px;

    font-size: 0.8rem;
    font-weight: bold;
    color: #0C243D;
    background: #D1F0FF;
    border-radius: 20px;
}

/* VENTANA DE CONVERSACIÓN */

.chat_window{
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: var(--app-height, 100vh);
    background: rgb(245, 244, 242);
}

#chat_header{
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px 10px 0;
    background: white;
    border-bottom: 1px solid #E1E5E9;
}

#chat_header .close_button{
    flex-shrink: 0;
    margin: 0 0 0 8px;
}

#chat_header .chat_avatar{
    width: 40px;
    height: 40px;
    font-size: 1rem;
}

#chat_heading{
    min-width: 0;
}

#chat_title{
    margin: 0;
    font-size: 1rem;
    color: #0C243D;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

#chat_subtitle{
    margin: 0;
    font-size: 0.8rem;
    color: #6B7A87;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

#chat_subtitle:empty{
    display: none;
}

#chat_messages{
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: 0;
    padding: 16px;
    list-style: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.chat_hint{
    margin: auto;
    max-width: 260px;
    text-align: center;
    font-size: 0.9rem;
    color: #6B7A87;
}

.day_separator{
    align-self: center;
    margin: 16px 0 4px 0;
    padding: 3px 12px;
    font-size: 0.72rem;
    color: #5B7284;
    background: #E3E6EA;
    border-radius: 12px;
}

.message{
    display: flex;
    flex-direction: column;
    max-width: 80%;
    margin-top: 14px;
}

.message.new{
    animation: bubbleIn 0.18s ease-out;
}

@keyframes bubbleIn{
    from{ opacity: 0; transform: translateY(6px); }
    to{ opacity: 1; transform: translateY(0); }
}

.message.mine{
    align-self: flex-end;
    align-items: flex-end;
}

.message.theirs{
    align-self: flex-start;
    align-items: flex-start;
}

.message.mine + .message.mine,
.message.theirs + .message.theirs{
    margin-top: 3px;
}

/* Mensajes seguidos de la misma persona: solo se ve la hora del último */
.message.mine:has(+ .message.mine) .message_time,
.message.theirs:has(+ .message.theirs) .message_time{
    display: none;
}

.bubble{
    margin: 0;
    padding: 9px 14px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.mine .bubble{
    color: white;
    background: #0B76C2;
    border-bottom-right-radius: 5px;
}

.theirs .bubble{
    color: #1B2A38;
    background: #E3E6EA;
    border-bottom-left-radius: 5px;
}

.message_time{
    margin-top: 3px;
    padding: 0 4px;
    font-size: 0.7rem;
    color: #7A8894;
}

.chat_error{
    min-height: 0;
    margin: 0 18px;
}

#chat_form{
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px)) 12px;
    padding: 5px 6px 5px 14px;

    background: rgb(244, 253, 255);
    border: 1px solid #C5D3DB;
    border-radius: 26px;

    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#chat_form:focus-within{
    border-color: rgb(49, 200, 255);
    box-shadow: 0 0 0 3px rgba(49, 200, 255, 0.25);
}

#chat_text{
    flex: 1;
    min-width: 0;
    height: 36px;
    min-height: 36px;
    max-height: 120px;
    padding: 7px 0;

    font-family: inherit;
    font-size: 16px; /* evita el zoom automático de iOS */
    line-height: 22px;
    color: #0C243D;

    background: transparent;
    border: none;
    outline: none;
    resize: none;
}

#chat_send{
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 36px;
    height: 36px;

    color: white;
    background: #0B76C2;
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

#chat_send svg{
    width: 18px;
    height: 18px;
}

#chat_send:disabled{
    background: #C5D3DB;
    cursor: default;
}

@media (prefers-reduced-motion: reduce){
    .message.new{
        animation: none;
    }
}

/* REGISTRO */

.notice_text{
    margin: 12px 0 0 0;
    padding: 10px 12px;
    font-size: 0.9rem;
    line-height: 1.4;
    color: #0B5C34;
    background: #E3F5EA;
    border-radius: 10px;
}

.notice_text:empty{
    display: none;
}

.link_button{
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 8px;

    font-family: inherit;
    font-size: 0.9rem;
    font-weight: bold;
    color: #0B76C2;
    background: none;
    border: none;
    cursor: pointer;
}
