<style>
  :root {
    --azul-primario: #2A4E6D;
    --azul-secundario: #3B6EA5;
    --azul-destacado: #4A90E2;
    --azul-suave: #E3F2FD;
    --degradado-azul: linear-gradient(135deg, #4A90E2 0%, #2A4E6D 100%);
    --amarillo-primario: #FFD54F;
    --amarillo-secundario: #FFECB3;
    --naranja-destacado: #FF9800;
    --verde-exito: #4CAF50;
    --rojo-error: #F44336;
    --gris-claro: #F5F7FA;
    --gris-medio: #E1E5E9;
    --gris-oscuro: #6C757D;
    --borde-principal: #D0D7DE;
    --sombra-suave: 0 4px 12px rgba(0, 0, 0, 0.05);
    --sombra-media: 0 6px 16px rgba(0, 0, 0, 0.08);
    --sombra-hover: 0 8px 24px rgba(0, 0, 0, 0.12);
    --transicion: all 0.3s ease;
    --fuente-principal: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  }

  .fc-button-group > .fc-dayGridMonth-button, .fc-timeGridWeek-button, .fc-timeGridDay-button  {
    display:none !important;
  }

  /* Reset y estilos base */
  .appointment-form-container {
    font-family: var(--fuente-principal);
    color: #333;
    line-height: 1.5;
    box-sizing: border-box;
  }

  .appointment-form-container * {
    box-sizing: border-box;
  }

  /* Contenedor principal con animación sutil */
  .appointment-form-container {
    background: #fff;
    padding: 2rem;
    border-radius: 16px;
    box-shadow: var(--sombra-media);
    max-width: 1400px;
    margin: 0 auto;
    animation: fadeIn 0.5s ease-out;
  }

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

  /* Secciones con efecto de elevación al hover */
  .section-container {
    background: #fff;
    border-radius: 12px;
    margin-bottom: 25px;
    padding: 25px;
    border: 1px solid var(--gris-medio);
    box-shadow: var(--sombra-suave);
    transition: var(--transicion);
    position: relative;
    overflow: hidden;
  }
  
  .section-container:hover {
    box-shadow: var(--sombra-hover);
    transform: translateY(-2px);
  }

  /* Barra de color decorativa */
  .section-container::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 5px;
    background: var(--degradado-azul);
  }

  /* Títulos y cabeceras */
  .section-container h4 {
    color: var(--azul-primario);
    margin-bottom: 1.5rem;
    position: relative;
    padding-bottom: 12px;
    font-weight: 600;
    font-size: 1.2rem;
  }

  .section-container h4::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 50px;
    height: 3px;
    background: var(--azul-destacado);
  }

  /* Campos del formulario con animación */
  .form-label {
    font-weight: 600;
    color: var(--azul-primario);
    margin-bottom: 10px;
    display: block;
    font-size: 0.95rem;
    transition: var(--transicion);
  }

  .form-control:focus + .form-label,
  .form:focus + .form-label {
    color: var(--azul-destacado);
  }

  .form,
  .form-control {
    border: 2px solid  #fff !important;
    border-radius: 10px !important;
    padding: 12px 15px !important;
    margin-bottom: 20px;
    width: 100%;
    color: #333;
    font-size: 1rem;
    transition: var(--transicion);
    background-color: var(--gris-claro);
  }

  .form:hover,
  .form-control:hover {
    border-color: #fff !important;
    background-color: #fff;
  }
  
  .form:focus,
  .form-control:focus {
    border-color: #fff !important;
    box-shadow: 0 0 0 4px rgba(74,144,226,0.15);
    outline: none;
    background-color: #fff;
  }
  
  /* Estilizar selects con ícono personalizado */
  select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%234A90E2'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    padding-right: 35px !important;
    cursor: pointer;
  }

  /* Estados de los selects e inputs */
  .form-control:disabled, 
  .form:disabled {
    background-color: #f0f0f0;
    cursor: not-allowed;
    opacity: 0.7;
    border-color: #fff !important;
  }

  /* Estilizar selectpicker especificamente */
  .bootstrap-select .dropdown-toggle {
    border: 2px solid var(--borde-principal) !important;
    border-radius: 10px !important;
    padding: 12px 15px !important;
    background-color: var(--gris-claro) !important;
    transition: var(--transicion);
  }

  .bootstrap-select .dropdown-toggle:hover {
    border-color: var(--azul-secundario) !important;
    background-color: #fff !important;
  }

  .bootstrap-select.show .dropdown-toggle {
    border-color: var(--azul-destacado) !important;
    box-shadow: 0 0 0 4px rgba(74,144,226,0.15) !important;
    background-color: #fff !important;
  }

  /* Botones con efectos hover */
  .btn-submit {
    background: var(--degradado-azul);
    color: #fff;
    padding: 15px 30px;
    border-radius: 50px;
    border: none;
    transition: var(--transicion);
    width: 100%;
    max-width: 300px;
    cursor: pointer;
    margin-top: 30px;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(74,144,226,0.3);
  }

  .btn-submit:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(42,78,109,0.4);
  }

  .btn-submit:active {
    transform: translateY(1px);
    box-shadow: 0 3px 8px rgba(42,78,109,0.4);
  }

  /* Efecto de onda en botón */
  .btn-submit::after {
    content: "";
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    transform: scale(0);
    transition: transform 0.5s;
  }

  .btn-submit:active::after {
    transform: scale(2);
    opacity: 0;
    transition: transform 0s, opacity 0.5s;
  }

  .btn-00416A {
    background: var(--azul-primario);
    color: #fff;
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transicion);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    box-shadow: 0 3px 8px rgba(42,78,109,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .btn-00416A:hover {
    background: var(--azul-destacado);
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(42,78,109,0.3);
  }

  .btn-00416A:active {
    transform: translateY(0);
  }

  /* Días disponibles del doctor */
  .doctor-days-container {
    margin: 15px 0;
  }
  
  .doctor-days-container .form-check {
    padding: 12px 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    transition: var(--transicion);
    border: 2px solid transparent;
    background-color: var(--gris-claro);
    cursor: default;
  }
  
  .doctor-days-container .form-check.active {
    background-color: var(--azul-suave);
    border: 2px solid var(--azul-destacado);
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(74,144,226,0.15);
  }
  
  .doctor-days-container .form-check-input {
    margin-top: 3px;
  }
  
  .doctor-days-container .form-check-label {
    margin-left: 8px;
    font-weight: 500;
    font-size: 0.95rem;
  }

  /* Alertas y mensajes */
  .doctor-schedule-alert {
    border-radius: 10px;
    padding: 15px 20px;
    margin: 15px 0;
    font-size: 0.95rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border-left: 5px solid;
    animation: slideIn 0.3s ease-out;
  }

  @keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
  }
  
  .alert-warning {
    background-color: #FFF8E1;
    border-left-color: var(--naranja-destacado);
  }
  
  .alert-info {
    background-color: var(--azul-suave);
    border-left-color: var(--azul-destacado);
  }
  
  .alert-danger {
    background-color: #FFEBEE;
    border-left-color: var(--rojo-error);
  }
  
  .alert-success {
    background-color: #E8F5E9;
    border-left-color: var(--verde-exito);
  }
  
  .doctor-schedule-alert i {
    margin-right: 10px;
    font-size: 1.1rem;
  }

  /* Calendario */
  .calendar-wrapper {
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--sombra-suave);
    margin-bottom: 25px;
    border: 1px solid var(--gris-medio);
    overflow-x: auto;
    position: relative;
    padding:20px;
  }

  .calendar-wrapper::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 5px;
    background: var(--degradado-azul);
  }
  
  .fc-theme-standard td, 
  .fc-theme-standard th {
    border-color: var(--gris-medio) !important;
  }
  
  .fc-day-today {
    background-color: var(--azul-suave) !important;
  }
  
  .fc-button-primary {
    background-color: var(--azul-primario) !important;
    border-color: var(--azul-secundario) !important;
  }

  .fc-button-primary:hover {
    background-color: var(--azul-destacado) !important;
    border-color: var(--azul-destacado) !important;
  }

  /* Navegación por tabs */
  .mobile-tabs-nav {
    display: block;
    margin-bottom: 25px;
  }
  
  .mobile-tabs-nav ul {
    display: flex;
    list-style: none;
    padding: 0;
    margin: 0;
    border-radius: 10px;
    background: var(--gris-claro);
    border: 1px solid var(--gris-medio);
    overflow: hidden;
  }
  
  .mobile-tabs-nav li {
    flex: 1;
    text-align: center;
  }
  
  .mobile-tabs-nav a {
    display: block;
    padding: 15px;
    color: var(--gris-oscuro);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transicion);
    font-size: 0.95rem;
    position: relative;
  }
  
  .mobile-tabs-nav a:hover {
    color: var(--azul-destacado);
    background: rgba(74,144,226,0.05);
  }
  
  .mobile-tabs-nav a.active {
    color: var(--azul-destacado);
    background: #fff;
  }
  
  .mobile-tabs-nav a.active::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--azul-destacado);
  }

  /* Layout y organización */
  @media (min-width: 768px) {
    .mobile-tabs-nav {
      display: none;
    }
    
    #formSections {
      display: flex;
      gap: 30px;
    }
    
    #calendarSection {
      flex: 1;
    }
    
    #otherSections {
      flex: 1;
      display: flex;
      flex-direction: column;
      gap: 30px;
    }
  }

  /* Tabs: manejo de secciones */
  .tab-section {
    display: none;
    opacity: 0;
    transition: opacity 0.4s ease;
  }
  
  .tab-section.active {
    display: block;
    opacity: 1;
  }
  
  @media (min-width: 768px) {
    .tab-section {
      display: block !important;
      opacity: 1 !important;
    }
  }

  /* Responsive */
  @media (max-width: 767px) {
    .appointment-form-container {
      padding: 0;
      border-radius: 0;
      box-shadow: none;
    }
    
    .section-container {
      padding: 20px;
      margin-bottom: 20px;
    }
    
    .mobile-tabs-nav {
      margin: 0 -1rem 20px -1rem;
      width: calc(100% + 2rem);
    }
    
    .mobile-tabs-nav ul {
      border-radius: 0;
    }
    
    .form-label {
      font-size: 0.9rem;
    }
    
    .form, .form-control {
      padding: 10px 12px !important;
      font-size: 0.95rem;
    }
    
    .btn-submit, .btn-00416A {
      width: 100%;
      max-width: 100%;
    }
    
    .calendar-wrapper {
      margin: 0 -10px;
      width: calc(100% + 20px);
      border-radius: 0;
    }
    
    #submitButtonContainer {
      display: block;
      position: fixed;
      bottom: 0;
      left: 0;
      width: 100%;
      background: #fff;
      padding: 15px;
      box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
      z-index: 100;
    }
    
    #submitButtonContainer .btn-submit {
      margin: 0;
      border-radius: 8px;
    }
  }
</style>

<div class="appointment-form-container">
  @if($isExternal === true)
    <form id="appointment" class="form-control" action="{{ URL::route('/create-external') }}" method="POST">
  @else  
    <form id="appointment" class="form-control" action="{{ ($new === true) ? URL::route('/admin/create-appointment') : URL::route('/admin/update-appointment') }}" method="POST">
  @endif

    <!-- Navegación por Tabs (solo mobile) -->
    <div class="mobile-tabs-nav d-md-none">
      <ul id="mobileTabNav">
        <li>
          <a href="#" data-tab="appointmentSection" onclick="showTab(event, 'appointmentSection')">
            <i class="fas fa-calendar-check me-2"></i> Cita
          </a>
        </li>
        <li>
          <a href="#" class="active" data-tab="calendarSection" onclick="showTab(event, 'calendarSection')">
            <i class="fas fa-calendar-alt me-2"></i> Calendario
          </a>
        </li>
      </ul>
    </div>

    <!-- Contenedor de Secciones -->
    <div id="formSections">
      <!-- Calendario -->
      <div id="calendarSection" class="tab-section section-container active">
        <h4 class="mb-3"><i class="fas fa-calendar-alt me-2"></i> Calendario de disponibilidad</h4>
        <!-- Calendar Wrapper con scroll horizontal -->
        <div class="calendar-wrapper">
          {!! $calendar->calendar() !!}
        </div>
        
        @if(isset($_GET["date"]))
          <input type="hidden" name="date" id="date" value="{{ $_GET['date'] }}">
        @else
          <input type="hidden" name="date" id="date">
        @endif
        
        <div class="alert alert-info mt-3">
          <i class="fas fa-info-circle"></i> Seleccione una fecha en el calendario para ver las horas disponibles.
        </div>
      </div>

      <!-- Secciones agrupadas para desktop -->
      <div id="otherSections">

        <!-- Datos de la Cita -->
        <div id="appointmentSection" class="tab-section section-container">
          <h4 class="mb-3"><i class="fas fa-clipboard-list me-2"></i> Detalles de la cita</h4>
          @if($isExternal === true)
            <div class="row">
              <div class="col-12">
                <label for="patientIdentificationNumber" class="form-label">
                  {{ __("com-form-appointment.patientIdentificationNumber") }}
                </label>
                <input id="patientIdentificationNumber" name="patientIdentificationNumber" type="text" class="form">
              </div>
            </div>
          @else
            <div class="row mb-3">
              <div class="col-12 col-lg-8 col-md-7">
                <label for="patients_id" class="form-label">
                  {{ __("com-form-appointment.patient") }}
                </label>
                <select data-style="bootstrap-select-color" data-live-search="true" class="form-control show-tick selectpicker" id="patients_id" name="patients_id">
                  <option value="SELECT" style="background-color:#fff !important; color:#000">
                    {{ __('com-form-appointment.selectValue') }}
                  </option>
                  @foreach($patients as $patient)
                    @if((isset($patientSelected)) && ($patient['id'] === $patientSelected->id))
                      <option data-tokens="{{ $patient['representative'] }}" value="{{ $patient['id'] }}" selected>{{ $patient['name'] }}</option>
                    @else
                      <option data-tokens="{{ $patient['representative'] }}" value="{{ $patient['id'] }}" {{ old('patients_id') === $patient['id'] ? 'selected' : '' }}>
                        {{ $patient['name'] }}
                      </option>
                    @endif
                  @endforeach
                </select>
              </div>
              <div class="col-12 col-lg-4 col-md-5 d-flex align-items-end">
                <a id="RegisterPatient" class="btn btn-00416A w-100">
                  <i class="fas fa-user-plus me-2"></i> {{ __("com-form-appointment.registerPatient") }}
                </a>
              </div>
            </div>
          @endif

          <div class="row mb-4">
            <div class="col-12 col-lg-6 col-md-6 mb-3">
              <label for="especiality" class="form-label">
                {{ __("com-form-appointment.especiality") }}
              </label>
              <select class="form-control" name="especiality" id="especiality">
                <option value="SELECT">{{ __('com-form-appointment.selectValue') }}</option>
                @foreach($especialities as $key => $option)
                  @if(isset($_GET["especiality"]) && $key === $_GET["especiality"])
                    <option value="{{ $key }}" selected>{{ $option }}</option>
                  @else
                    <option value="{{ $key }}" {{ old('especiality') === $key ? 'selected' : '' }}>{{ $option }}</option>
                  @endif
                @endforeach
              </select>
            </div>
            <div class="col-12 col-lg-6 col-md-6 mb-3">
              <label for="doctorname" class="form-label">
                {{ __('com-form-payment.doctor') }}
              </label>
              <select class="form-control" name="doctorname" id="doctorId">
                <option value="">Seleccione una especialidad primero</option>
              </select>
            </div>
          </div>

          <div class="card mb-4">
            <div class="card-header bg-light">
              <h5 class="mb-0"><i class="fas fa-calendar-week me-2"></i> Días disponibles del doctor</h5>
            </div>
            <div class="card-body">
              <div class="doctor-days-container">
                <div class="row">
                  @foreach(['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado', 'Domingo'] as $index => $day)
                    <div class="col-6 col-md-4 col-lg-3 mb-2">
                      <div class="form-check">
                        <input class="form-check-input doctor-day-checkbox" type="checkbox" disabled 
                               id="day-{{ $index + 1 }}" data-day="{{ $index + 1 }}">
                        <label class="form-check-label" for="day-{{ $index + 1 }}">
                          {{ $day }}
                        </label>
                      </div>
                    </div>
                  @endforeach
                </div>
              </div>
            </div>
          </div>

          <div class="row mb-4">
            <div class="col-12">
              <label for="available-hours" class="form-label">
                <i class="fas fa-clock me-2"></i> Horas disponibles
              </label>
              <select class="form-control" id="available-hours" name="available_hours">
                <option value="">Seleccione un doctor y una fecha primero</option>
              </select>
              <div class="form-text text-muted">Seleccione una fecha en el calendario para ver las horas disponibles</div>
            </div>
          </div>

          <!-- Selector de etiquetas de cita -->
          @include('components.appointment-tags-selector', ['appointment' => isset($model) ? $model : null])

          <div class="row">
            <div class="col-12">
              <label for="summary" class="form-label">
                <i class="fas fa-comment-medical me-2"></i> {{ __('com-form-appointment.reason') }}
              </label>
              @if(isset($_GET["summary"]))
                <textarea id="summary" name="summary" rows="4" class="form" placeholder="Describa brevemente el motivo de la consulta...">{{ $_GET["summary"] }}</textarea>
              @else
                <textarea id="summary" name="summary" rows="4" class="form" placeholder="Describa brevemente el motivo de la consulta...">{{ old('summary') }}</textarea>
              @endif
            </div>
          </div>
          
          <!-- Botón móvil visible solo cuando está en el tab de Cita -->
          <div class="d-md-none mt-4 mb-5">
            <input class="btn btn-submit" type="submit" value="{{ ($new === true) ? __('create-appointment.btnSubmit') : __('update-appointment.btnSubmit') }}">
          </div>
        </div>
      </div><!-- /#otherSections -->
    </div><!-- /#formSections -->

    <!-- Botón de envío (visible solo en desktop; en mobile se muestra en "Cita") -->
    <div id="submitButtonContainer" class="row mt-4 d-none d-md-block">
      <div class="col-12 text-center">
        <input class="btn btn-submit" type="submit" value="{{ ($new === true) ? __('create-appointment.btnSubmit') : __('update-appointment.btnSubmit') }}">
        @csrf
      </div>
    </div>

  </form>
</div>

<script>
  // Función para cambiar de pestaña en mobile
  function showTab(event, tabId) {
    event.preventDefault();
    // Ocultar todas las secciones
    document.querySelectorAll('.tab-section').forEach(function(section) {
      section.classList.remove('active');
    });
    // Mostrar la sección seleccionada
    document.getElementById(tabId).classList.add('active');

    // Actualizar estado de los links
    document.querySelectorAll('#mobileTabNav a').forEach(function(link) {
      link.classList.remove('active');
    });
    event.currentTarget.classList.add('active');
  }

  // Inicialización
  document.addEventListener("DOMContentLoaded", function() {
    // Ajustar estilos de botones y elementos según sea necesario
    if (window.innerWidth < 768) {
      document.querySelector('#calendarSection').classList.add('active');
      
      // Manejar tab con scroll automático
      document.querySelectorAll('#mobileTabNav a').forEach(function(link) {
        link.addEventListener('click', function() {
          setTimeout(function() {
            window.scrollTo(0, 0);
          }, 100);
        });
      });
    }
    
    // Animación para form-checks de días
    document.querySelectorAll('.form-check').forEach(function(check) {
      check.addEventListener('transitionend', function(e) {
        if (e.propertyName === 'transform') {
          check.classList.add('transition-done');
        }
      });
    });
  });
</script>
