/* ---------- RESET ---------- */
/* v1.1 añadido 351 a 528 */


* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    font-family: Arial, Helvetica, sans-serif;
    background: #f3f5f8;
}


/* ---------- CABECERA ---------- */

header {
    height: 70px;
    background: #1f6feb;
    color: white;

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

    padding: 0 20px;

    box-shadow: 0 2px 10px rgba(0,0,0,.15);
}

header h1 {
    font-size: 24px;
}

header button {

    padding: 10px 18px;

    border: none;

    border-radius: 8px;

    background: white;

    color: #1f6feb;

    cursor: pointer;

    font-weight: bold;
}


/* ---------- CONTENEDOR ---------- */

textarea{
    width:100%;
    resize:vertical;
    padding:10px;
    border:1px solid #ccc;
    border-radius:6px;
}

#plannerContainer{

    position:relative;

    margin:20px;

    overflow:auto;

    background:white;

    border-radius:10px;

    border:1px solid #ddd;

    height:calc(100vh - 110px);

}


/* ---------- TABLA ---------- */

table{
    border-collapse: collapse;
    table-layout: fixed;
    min-width: calc(120px + (10 * 120px));
}

thead{

    position:sticky;

    top:0;

    z-index:30;

}

thead th{
    background:#edf2f7;
    height:50px;
    border:1px solid #ddd;
    width:120px;
    min-width:120px;
    text-align:center;
}

tbody th{
    position:sticky;
    left:0;
    z-index:20;
    background:#fafafa;
    width:120px;
    min-width:120px;
    border:1px solid #ddd;
}

tbody td{
    width:120px;
    min-width:120px;
    height:90px;
    border:1px solid #ececec;
}


/* ---------- EVENTO ---------- */

.appointment{

    position:absolute;

    height:72px;

    background:#1f6feb;

    color:white;

    border-radius:10px;

    padding:8px;

    cursor:move;

    pointer-events:auto;

    overflow:hidden;

    user-select:none;

    touch-action:none;

    box-shadow:0 4px 10px rgba(0,0,0,.15);

}


.appointment-title{

    font-size:14px;

    font-weight:bold;

}


.appointment-sub{

    margin-top:5px;

    font-size:12px;

}


/* ---------- HANDLE RESIZE ---------- */

.resize-right{

    position:absolute;

    top:0;

    right:0;

    width:12px;

    height:100%;

    cursor:ew-resize;

}


/* ---------- BOTÓN ELIMINAR ---------- */

.delete{

    position:absolute;

    top:5px;

    right:16px;

    width:18px;

    height:18px;

    border-radius:50%;

    background:#d62828;

    color:white;

    display:flex;

    justify-content:center;

    align-items:center;

    cursor:pointer;

    font-size:11px;

}

/* ==========================================
   MODAL
========================================== */

.modal {

    position: fixed;

    inset: 0;

    background: rgba(0,0,0,.45);

    display: none;

    justify-content: center;

 /* IMPORTANTE: El formulario NO se centra verticalmente.
    Se coloca arriba para que nunca desaparezca la parte superior en tablets/móviles. */

    align-items: flex-start;
    z-index: 1000;

    /*
    Espacio alrededor del formulario
    */

    padding: 12px;
    overflow-y: auto;

}


/* ==========================================
   CONTENIDO DEL MODAL
========================================== */

.modal-content {

    width: 430px;

    max-width: 100%;

    /*
    MUY IMPORTANTE PARA TABLET/MÓVIL
    */

    max-height: calc(100dvh - 24px);

    background: white;

    border-radius: 12px;

    padding: 20px;
        
    /* NUNCA superar la altura de la pantalla */
    max-height: calc(100dvh - 24px);

    /*    Si el formulario es más alto que la pantalla, aparece scroll */

    overflow-y: auto;

    overflow-x: hidden;
    
    /* Evita problemas con elementos largos */
    box-sizing: border-box;
}


/* ==========================================
   TÍTULO
========================================== */

.modal-content h2 {
    margin-bottom: 16px;
    font-size: 21px;
}


/* ==========================================
   CAMPOS
========================================== */

.form-group {

    margin-bottom: 11px;

}


.form-group label {

    display: block;

    margin-bottom: 4px;

    font-size: 14px;

    font-weight: 600;

}


.form-group input,
.form-group select,
.form-group textarea {

    width: 100%;
    box-sizing: border-box;
    padding: 9px 10px;
    min-height: 42px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-family: Arial, Helvetica, sans-serif;

    /*  16px es importante en dispositivos táctiles para evitar zoom automático  */

    font-size: 16px;

}


.form-group textarea {

    min-height: 70px;
    resize: vertical;

}


/* ==========================================
   BOX / HORA / DURACIÓN
========================================== */

.appointment-options {

    display: grid;

    grid-template-columns:
        1fr 1fr 1fr;

    gap: 8px;

}


/* ==========================================
   BOTONES
========================================== */

.actions {

    display: flex;
    gap: 10px;
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid #eee;

}


.actions button {

    flex: 1;
    min-height: 44px;
    padding: 10px;
    border: none;
    border-radius: 7px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;

}


/* ==========================================
   TABLET
========================================== */

@media (max-width: 900px) {

    .modal {

        /*
        Siempre empezamos arriba.
        */

        align-items: flex-start;

        padding: 10px;

    }


    .modal-content {

        width: 600px;

        max-width: 100%;

        max-height: calc(100dvh - 20px);

        padding: 18px;

    }

}


/* =====================================================
   MÓVIL
===================================================== */

@media (max-width: 600px) {

    .modal {

        padding: 6px;

        align-items: flex-start;

    }


    .modal-content {

        width: 100%;

        max-width: none;

        max-height: calc(100dvh - 12px);

        padding: 14px;

        border-radius: 10px;

    }


    .modal-content h2 {

        font-size: 19px;

        margin-bottom: 12px;

    }


    .form-group {

        margin-bottom: 8px;

    }


    .form-group label {

        font-size: 13px;

        margin-bottom: 3px;

    }


    .form-group input,
    .form-group select,
    .form-group textarea {

        min-height: 40px;

        padding: 8px;

        font-size: 16px;

    }


    .form-group textarea {

        min-height: 60px;

    }


    /*
    BOX - HORA - DURACIÓN
    */

    .appointment-options {

        grid-template-columns:
            1fr 1fr 1fr;

        gap: 6px;

    }


    .actions {

        margin-top: 10px;

        padding-top: 8px;

    }


    .actions button {

        min-height: 44px;

        font-size: 15px;

    }

}


/* =====================================================
   MÓVIL MUY PEQUEÑO
===================================================== */

@media (max-width: 380px) {

    /*
    En una pantalla muy estrecha,
    ponemos estos tres campos verticales.
    */

    .appointment-options {

        grid-template-columns: 1fr;

        gap: 6px;

    }

}


/*
=====================================================
CONTENEDOR DEL PLANNER
=====================================================
*/

.planner-wrapper {
    --hour-width: 120px;
    --row-height: 90px;
    position: relative;
}

/*
=====================================================
CAPA DE CITAS
=====================================================
*/

#eventsLayer {
    position: absolute;
    top: 50px;
    left: 120px;
    width: calc(10 * var(--hour-width));
    height: calc(7 * var(--row-height));
    pointer-events: none;
    z-index: 10;
}


/*
=====================================================
CITA
=====================================================
*/

.appointment {

    position: absolute;

    box-sizing: border-box;

    pointer-events: auto;

    min-height: 70px;

    padding: 8px;

    border-radius: 6px;

    color: white;

    overflow: hidden;

    cursor: grab;

    z-index: 20;

}


/*
Cuando estamos arrastrando
*/

.appointment.dragging {

    cursor: grabbing;

    opacity: 0.85;

    z-index: 100;

}


/*
Cuando hacemos resize
*/

.appointment.resizing {

    z-index: 100;

}


/*
=====================================================
TEXTO CITA
=====================================================
*/

.appointment-title {

    font-weight: bold;

    font-size: 14px;

    white-space: nowrap;

    overflow: hidden;

    text-overflow: ellipsis;

}


.appointment-sub {

    font-size: 12px;

    margin-top: 4px;

}


/*
=====================================================
BOTÓN ELIMINAR
=====================================================
*/

.appointment .delete {

    position: absolute;

    top: 4px;

    right: 5px;

    cursor: pointer;

    font-weight: bold;

}


/*
=====================================================
HANDLE RESIZE
=====================================================
*/

.resize-right {

    position: absolute;

    right: 0;

    top: 0;

    width: 8px;

    height: 100%;

    cursor: ew-resize;

}

/* Los huecos libres son clicables para crear una cita */
.planner-cell {
    cursor: pointer;
}

.planner-cell:hover {
    background: #f5f9ff;
}


/* Días anteriores: visibles pero no utilizables para crear nuevas citas */
.day-button.past-day { opacity: 0.55; }
