// 🎯 RemoteSelect Component - Padrão PraFrota
// Seguindo o mesmo design do CustomInputComponent

.remote-select-wrapper {
  position: relative;
  width: 100%;
  margin: 0;

  &.disabled {
    opacity: 0.6;
    pointer-events: none;
  }

  // ========================================
  // 🔍 INPUT CONTAINER E FIELD
  // ========================================
  
  .remote-select-input-container {
    position: relative;
    
    input {
      width: 100%;
      padding: 12px 50px 12px 16px; // Espaço para ícones
      font-size: 14px;
      font-family: var(--font-primary);
      font-weight: 500; // Peso da fonte um pouco mais forte
      border: 1px solid var(--divider);
      border-radius: 8px;
      background: var(--surface);
      color: #1f2937; // Cor mais escura para melhor legibilidade
      transition: all 0.2s ease;
      box-sizing: border-box;

      &::placeholder {
        color: transparent; // Esconder placeholder para label flutuante funcionar
      }

      &:focus {
        outline: none;
        border-color: var(--idt-primary-color);
        box-shadow: 0 0 0 2px rgba(255, 200, 46, 0.1);
        background: var(--surface);
      }

      &:hover:not(:focus):not(:disabled) {
        background: var(--hover-bg, #f5f5f5);
        border-color: var(--text-secondary);
      }

      &:disabled {
        background: var(--surface-disabled, #f9fafb);
        color: #374151; // Cor mais escura mesmo quando disabled para melhor legibilidade
        cursor: not-allowed;
        border-color: var(--divider);
        opacity: 0.9; // Reduz opacidade mas mantém legibilidade
      }

      &.error {
        border-color: var(--error-color, #ef4444);
        background: #fef2f2;
        
        &:focus {
          border-color: var(--error-color, #ef4444);
          box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.1);
        }
      }
    }

    // ========================================
    // 🏷️ LABEL FLUTUANTE (Igual ao CustomInput)
    // ========================================
    
    label {
      position: absolute;
      left: 14px;
      top: 50%;
      transform: translateY(-50%);
      background-color: var(--surface);
      color: var(--text-secondary);
      font-size: 14px;
      font-weight: 600;
      transition: all 0.2s ease;
      pointer-events: none;
      padding: 0 4px;
      z-index: 1;

      .required-asterisk {
        color: var(--error-color, #ef4444);
        margin-left: 0.25rem;
      }
    }

    // Label flutuante quando focado ou com valor
    input:focus + label,
    input:not(:placeholder-shown) + label,
    &.has-value label {
      top: 0;
      font-size: 12px;
      color: var(--idt-primary-color);
      font-weight: 600;
    }

    // ========================================
    // 🏷️ FLOATING LABEL (igual ao custom-input)
    // ========================================
    
    .floating-label {
      position: absolute;
      left: 14px;
      top: 50%;
      transform: translateY(-50%);
      background-color: var(--surface);
      color: #374151; // Cinza mais escuro igual ao "Marca do Posto"
      font-size: 14px;
      font-weight: 600; // Mais forte/bold
      transition: all 0.2s ease;
      pointer-events: none;
      padding: 0 4px;
      z-index: 1;
      
      .required-indicator {
        color: var(--idt-danger, #dc3545);
        margin-left: 4px;
        font-weight: var(--font-weight-bold);
        font-size: 14px;
        line-height: 1;
      }
    }

    // Estados do label quando input tem foco ou valor
    input:focus + .floating-label,
    input:not(:placeholder-shown) + .floating-label,
    &.has-value .floating-label {
      top: 0;
      font-size: 12px;
      color: #374151; // Cinza mais escuro igual ao "Marca do Posto"
      font-weight: 700; // Ainda mais forte quando flutuando
    }

    // ========================================
    // 🌙 TEMA DARK - MELHOR LEGIBILIDADE
    // ========================================
    
    :host-context(.dark-theme) & {
      input {
        color: #f9fafb; // Texto mais claro no dark
        font-weight: 600; // Peso ainda mais forte no dark
        
        &:disabled {
          color: #d1d5db; // Cor mais clara para disabled no dark
          opacity: 1; // Remove opacidade para manter legibilidade
        }
      }
      
      .floating-label {
        color: #d1d5db; // Label mais claro no dark
        background-color: var(--surface); // Mantém background do tema
        
        .required-indicator {
          color: #fca5a5; // Asterisco mais claro no dark
        }
      }
      
      // Estados do label quando input tem foco ou valor (dark theme)
      input:focus + .floating-label,
      input:not(:placeholder-shown) + .floating-label,
      &.has-value .floating-label {
        color: #e5e7eb; // Label flutuante ainda mais claro no dark
        font-weight: 700; // Mantém peso forte
      }
    }

    // ========================================
    // 🎬 ÍCONES DE AÇÃO
    // ========================================
    
    .input-actions {
      position: absolute;
      right: 12px;
      top: 50%;
      transform: translateY(-50%);
      display: flex;
      align-items: center;
      gap: 4px;
      z-index: 2;

      .loading-spinner {
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--idt-primary-color);

        i {
          font-size: 14px;
          animation: spin 1s linear infinite;
        }
      }

      .action-button {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 20px;
        height: 20px;
        padding: 0;
        border: none;
        background: transparent;
        color: var(--text-secondary);
        cursor: pointer;
        border-radius: 4px;
        transition: all 0.2s ease;

        &:hover {
          background: var(--hover-bg);
          color: var(--text-primary);
        }

        &:disabled {
          opacity: 0.5;
          cursor: not-allowed;
        }

        i {
          font-size: 12px;
        }
      }

      .clear-button {
        color: var(--text-secondary);

        &:hover {
          color: var(--error-color);
        }
      }

      .f2-button {
        color: var(--idt-primary-color);

        &:hover {
          background: rgba(255, 200, 46, 0.1);
        }
      }

      .dropdown-arrow {
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        transition: transform 0.2s ease;

        &.open {
          transform: rotate(180deg);
        }

        i {
          font-size: 10px;
        }
      }
    }
  }

  // ========================================
  // 📋 DROPDOWN DE RESULTADOS
  // ========================================
  
  .remote-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--surface);
    border: 1px solid var(--divider);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;

    .dropdown-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 12px 16px;
      cursor: pointer;
      border-bottom: 1px solid var(--divider);
      transition: all 0.2s ease;

      &:last-child {
        border-bottom: none;
      }

      &:hover,
      &.selected {
        background: var(--hover-bg);
      }

      &.highlighted {
        background: var(--idt-primary-color);
        color: #000000;

        .item-id {
          color: rgba(0, 0, 0, 0.7);
        }
      }

      // ✅ NOVO: Estilo para itens selecionados em modo múltiplo
      &.multiple-selected {
        background: rgba(255, 200, 46, 0.1);
        border-left: 3px solid var(--idt-primary-color);
        
        .item-label {
          font-weight: 500;
          color: var(--idt-primary-color);
        }
        
        .selection-indicator {
          color: var(--idt-primary-color);
        }
      }

      .item-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 2px;

        .item-label {
          font-size: 14px;
          font-weight: 500;
          color: inherit;
        }

        .item-id {
          font-size: 12px;
          color: var(--text-secondary);
          opacity: 0.8;
        }
      }

      .selection-indicator {
        color: var(--success-color, #10b981);
        font-size: 14px;
        margin-left: 8px;
      }
    }

    // Estados especiais
    .dropdown-empty,
    .dropdown-hint {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      padding: 20px 16px;
      color: var(--text-secondary);
      text-align: center;
      font-size: 14px;
      font-style: italic;

      i {
        font-size: 16px;
        opacity: 0.7;
      }
    }

    .dropdown-hint {
      background: var(--info-bg, #f0f9ff);
      color: var(--info-color, #0369a1);
    }
  }

  // ========================================
  // ⚠️ MENSAGEM DE ERRO
  // ========================================
  
  .error-message {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--error-color, #ef4444);

    i {
      font-size: 12px;
    }
  }

  // ========================================
  // 🏷️ CHIPS DE SELEÇÃO MÚLTIPLA
  // ========================================
  
  .selection-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;

    .selection-chip {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 4px 8px;
      background: var(--idt-primary-color);
      color: #000000;
      border-radius: 16px;
      font-size: 12px;
      font-weight: 500;

      .chip-label {
        // Estilo já aplicado pelo container
      }

      .chip-remove {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 16px;
        height: 16px;
        padding: 0;
        border: none;
        background: rgba(0, 0, 0, 0.2);
        color: #000000;
        border-radius: 50%;
        cursor: pointer;
        transition: all 0.2s ease;

        &:hover {
          background: rgba(0, 0, 0, 0.3);
        }

        i {
          font-size: 8px;
        }
      }
    }
  }
}

// ========================================
// 🎨 MODAL DE SELEÇÃO
// ========================================

.remote-select-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;

  .remote-select-modal {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;

    .modal-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 20px 24px;
      border-bottom: 1px solid var(--divider);
      background: var(--hover-bg);

      h3 {
        margin: 0;
        font-size: 18px;
        font-weight: 600;
        color: var(--text-primary);
      }

      .modal-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        padding: 0;
        border: none;
        background: transparent;
        color: var(--text-secondary);
        border-radius: 6px;
        cursor: pointer;
        transition: all 0.2s ease;

        &:hover {
          background: var(--hover-bg);
          color: var(--text-primary);
        }

        i {
          font-size: 16px;
        }
      }
    }

    .modal-content {
      padding: 24px;

      .coming-soon {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 16px;
        padding: 40px 20px;
        text-align: center;
        color: var(--text-secondary);

        i {
          font-size: 48px;
          color: var(--idt-primary-color);
          opacity: 0.7;
        }

        p {
          margin: 0;
          font-size: 14px;
          line-height: 1.5;

          &:first-of-type {
            font-weight: 600;
            font-size: 16px;
            color: var(--text-primary);
          }
        }
      }
    }

    .modal-actions {
      display: flex;
      gap: 12px;
      justify-content: flex-end;
      padding: 16px 24px;
      border-top: 1px solid var(--divider);
      background: var(--hover-bg);

      .btn-cancel,
      .btn-confirm {
        padding: 8px 16px;
        border-radius: 6px;
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
        border: 1px solid transparent;
      }

      .btn-cancel {
        background: transparent;
        color: var(--text-secondary);
        border-color: var(--divider);

        &:hover {
          background: var(--hover-bg);
          color: var(--text-primary);
          border-color: var(--text-secondary);
        }
      }

      .btn-confirm {
        background: var(--idt-primary-color);
        color: #000000;

        &:hover {
          background: #FFD700;
          box-shadow: 0 2px 8px rgba(255, 200, 46, 0.3);
        }
      }
    }
  }
}

// ========================================
// 🌙 TEMA ESCURO
// ========================================

:host-context(.dark-theme) {
  .remote-select-wrapper {
    .remote-select-input-container {
      input {
        background: var(--surface);
        color: var(--text-primary);
        border-color: var(--divider);

        &::placeholder {
          color: var(--text-secondary);
        }

        &:focus {
          border-color: var(--idt-primary-color);
          box-shadow: 0 0 0 2px rgba(255, 200, 46, 0.2);
        }

        &:hover:not(:focus) {
          background: rgba(255, 255, 255, 0.05);
          border-color: var(--text-secondary);
        }
      }

      label {
        background-color: var(--surface);
        color: var(--text-secondary);
      }

      input:focus + label,
      input:not(:placeholder-shown) + label,
      &.has-value label {
        color: var(--idt-primary-color);
      }
    }

    .remote-select-dropdown {
      background: var(--surface);
      border-color: var(--divider);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);

      .dropdown-item {
        border-color: var(--divider);

        &:hover,
        &.selected {
          background: var(--hover-bg);
        }

        .item-content .item-id {
          color: var(--text-secondary);
        }
      }
    }
  }

  .remote-select-modal-backdrop {
    .remote-select-modal {
      background: var(--surface);

      .modal-header {
        background: var(--hover-bg);
        border-color: var(--divider);

        h3 {
          color: var(--text-primary);
        }
      }

      .modal-actions {
        background: var(--hover-bg);
        border-color: var(--divider);
      }
    }
  }
}

// ========================================
// 📱 RESPONSIVIDADE
// ========================================

@media (max-width: 768px) {
  .remote-select-wrapper {
    .remote-select-input-container {
      input {
        padding: 14px 50px 14px 16px;
        font-size: 16px; // Evita zoom no iOS
      }

      .input-actions {
        .action-button {
          width: 24px;
          height: 24px;

          i {
            font-size: 14px;
          }
        }
      }
    }

    .remote-select-dropdown {
      max-height: 160px;

      .dropdown-item {
        padding: 14px 16px;

        .item-content {
          .item-label {
            font-size: 15px;
          }

          .item-id {
            font-size: 13px;
          }
        }
      }
    }

    // Esconder botão F2 no mobile
    .desktop-only {
      display: none !important;
    }
  }

  .remote-select-modal-backdrop {
    padding: 10px;

    .remote-select-modal {
      max-height: 90vh;
      border-radius: 8px;

      .modal-header {
        padding: 16px 20px;

        h3 {
          font-size: 16px;
        }
      }

      .modal-content {
        padding: 20px;
      }

      .modal-actions {
        padding: 12px 20px;
        flex-direction: column;

        .btn-cancel,
        .btn-confirm {
          width: 100%;
          padding: 12px 16px;
        }
      }
    }
  }
}

// ========================================
// ⚡ ANIMAÇÕES
// ========================================

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

// Smooth transitions
.remote-select-wrapper *,
.remote-select-modal * {
  box-sizing: border-box;
}

// Debug info (desenvolvimento)
.debug-info {
  margin-top: 8px;
  padding: 8px;
  background: var(--info-bg, #f0f9ff);
  border: 1px solid var(--info-color, #0369a1);
  border-radius: 4px;
  font-family: monospace;

  small {
    font-size: 11px;
    color: var(--info-color, #0369a1);
  }
} 