/* Specific styles for Cita Nueva */
body {
    background: #f0f2f5;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    padding-bottom: 80px; /* Space for bottom navigation */
    overflow-x: hidden; /* Prevent horizontal scroll */
}

.container {
    max-width: 520px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    width: 100%;
    box-sizing: border-box;
}

/* Header Section */
.citas-header {
    background: #ffffff;
    padding: 1rem 1.5rem 0.5rem;
    border-bottom: 1px solid #f0f0f0;
    position: sticky;
    top: 0;
    z-index: 100;
    margin: -1rem -1.5rem 1rem -1.5rem;
    width: 100%;
    box-sizing: border-box;
}

.citas-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #2d5a3d;
    margin: 0;
    text-align: center;
    padding: 0 3rem; /* Space for buttons */
}

.back-button {
    position: absolute;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #2d5a3d;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s ease;
    z-index: 101;
}

.back-button:hover {
    background-color: #f3f4f6;
}

/* Form Sections */
.form-section {
    background: #ffffff;
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #e8e8e8;
    width: 100%;
    box-sizing: border-box;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2d5a3d;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title i {
    color: #007aff;
    font-size: 1rem;
}

/* Select Styles */
.form-select, #datepicker {
    border: 2px solid #e8e8e8;
    border-radius: 12px;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    background: #ffffff;
    transition: all 0.2s ease;
    width: 100%;
    box-sizing: border-box;
}

.form-select:focus, #datepicker:focus {
    border-color: #007aff;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
    outline: none;
}

/* --- Flatpickr Customization --- */
#calendar-container {
    display: none; /* Hidden by default, shown by JS */
    margin-top: 1rem;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
    text-align: center; /* Ensure content inside is centered */
}

.flatpickr-calendar {
    display: inline-block; /* Makes the calendar an inline element that can be centered */
    box-shadow: none;
    border: none;
    margin: 0 auto; /* Additional centering for the calendar itself */
}

.flatpickr-loading {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* --- Time Slot Redesign (Vertical Wheel) --- */
#horaList-container {
  position: relative;
}

#horaList {
  display: flex;
  flex-direction: column;
  height: 180px; /* Adjust height to show ~3 items */
  overflow-y: auto;
  padding: 0;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
}

/* To center the first and last items */
#horaList::before,
#horaList::after {
  content: '';
  display: block;
  height: 60px; /* (container_height - item_height) / 2 */
  flex-shrink: 0;
}


#horaList::-webkit-scrollbar {
  display: none; /* Hide scrollbar for a cleaner look */
}

.time-slot {
  flex: 0 0 60px; /* Fixed height for each item */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border: none;
  background-color: transparent;
  color: #888;
  font-weight: 500;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.3s ease-in-out;
  scroll-snap-align: center;
  opacity: 0.5;
  transform: scale(0.85);
}

/* The active/centered state */
.time-slot.active {
  color: #2d5a3d;
  font-weight: 600;
  font-size: 1.5rem;
  opacity: 1;
  transform: scale(1);
}

/* Selection indicator lines */
#horaList-container::before {
    content: '';
    position: absolute;
    top: 60px;  /* Position of the top line */
    left: 10%;
    right: 10%;
    height: 2px;
    background-color: #e0e0e0;
    z-index: 1;
}

#horaList-container::after {
    content: '';
    position: absolute;
    bottom: 60px; /* Position of the bottom line */
    left: 10%;
    right: 10%;
    height: 2px;
    background-color: #e0e0e0;
    z-index: 1;
}


#horaList .loading-container,
#horaList .empty-state {
    width: 100%;
    text-align: center;
    scroll-snap-align: center; /* Center these states as well */
}

/* Loading States */
.loading-container {
    text-align: center;
    padding: 2rem 1rem;
}

.spinner-border {
    color: #007aff;
    width: 1.5rem;
    height: 1.5rem;
}

.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: #6b7280;
    font-size: 0.9rem;
    font-style: italic;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 0.75rem;
    margin-top: 2rem;
}

.cancel-button, .confirm-button {
    flex: 1;
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.cancel-button {
    border: 2px solid #e8e8e8;
    background: #ffffff;
    color: #6b7280;
}

.cancel-button:hover {
    border-color: #d1d5db;
    background: #f9fafb;
    color: #374151;
}

.confirm-button {
    border: none;
    background: #2d5a3d;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(45, 90, 61, 0.3);
}

.confirm-button:hover:not(:disabled) {
    background: #1e3c28;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(45, 90, 61, 0.4);
}

.confirm-button:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Propósito Section */
.purpose-grid {
    display: grid;
    /* Crea columnas responsivas: se ajustan automáticamente al espacio disponible,
       con un tamaño mínimo de 110px y máximo de 1fr (fracción del espacio sobrante) */
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem; /* Espacio entre botones */
    justify-content: center;
}

.purpose-button {
    display: flex;
    flex-direction: column;
    align-items: center; /* Centra el contenido horizontalmente */
    justify-content: flex-start; /* Alinea el contenido hacia arriba */
    text-align: center;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    background-color: #fff;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    text-decoration: none;
    color: #333;
    height: 140px; /* Altura fija para todos los botones */
    box-sizing: border-box; /* Asegura que padding y borde se incluyan en la altura */
    overflow: hidden; /* Oculta cualquier contenido que se desborde */
}

.purpose-button:hover {
    border-color: #2d5a3d;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.purpose-button.active {
    border-color: #2d5a3d;
    background-color: #eaf3eb;
    color: #2d5a3d;
    font-weight: 600;
}

.purpose-button img {
    width: 48px;
    height: 48px;
    margin-bottom: 0.5rem; /* Espacio entre el icono y el texto */
    flex-shrink: 0; /* Evita que el icono se encoja */
    object-fit: cover;
    border-radius: 8px;
}

.purpose-button span {
    font-size: 0.85rem;
    line-height: 1.3;
    font-weight: 500;
    /* El texto se ajustará y cortará si es necesario gracias al overflow:hidden del contenedor */
}




/* Responsive adjustments */
@media (max-width: 767px) {
    body {
        overflow-x: hidden;
    }
    
    .container {
        padding: 0.5rem 1rem;
        max-width: 100%;
    }
    
    .citas-header {
        padding: 0.75rem 0.75rem 0.5rem;
        margin: -0.5rem -0.75rem 1rem -0.75rem;
        width: 100%;
    }
    
    .citas-title {
        font-size: 1.1rem;
        padding: 0 2.5rem;
    }
    
    .back-button {
        left: 0.25rem;
        font-size: 1.1rem;
        padding: 0.4rem;
    }
    
    .form-section {
        padding: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .purpose-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
    }

    .purpose-button {
        height: 125px; /* Altura reducida para tabletas y móviles */
        padding: 0.6rem;
    }

    .purpose-button img {
        width: 40px;
        height: 40px;
    }

    .purpose-button span {
        font-size: 0.8rem;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
}

@media (max-width: 480px) {
    .container {
        padding: 0.5rem 0.75rem;
    }
    
    .citas-header {
        padding: 0.5rem 0.5rem 0.25rem;
        margin: -0.5rem -0.5rem 1rem -0.5rem;
    }
    
    .citas-title {
        font-size: 1rem;
        padding: 0 2rem;
    }
    
    .form-section {
        padding: 0.75rem;
    }
    
    .purpose-grid {
        /* Mantiene 3 columnas en la mayoría de móviles y 2 en los más pequeños */
        grid-template-columns: repeat(auto-fill, minmax(95px, 1fr));
        gap: 0.5rem;
    }

    .purpose-button {
        height: 120px; /* Altura más reducida para móviles pequeños */
        padding: 0.5rem;
    }

    .purpose-button img {
        width: 38px;
        height: 38px;
    }

    .purpose-button span {
        font-size: 0.75rem;
    }
    
}