/**
 * ============================================================================
 * AUTOCOMPLETE DIRECTIVE CSS
 * ============================================================================
 * Estilos para a diretiva autocomplete do sistema PDV
 * Compatível com: Chrome 60+, Firefox 55+, Safari 12+, Edge 79+
 * Versão: 1.0.0
 */

/* ============================================================================
   BASE STYLES
   ============================================================================ */

   .autocomplete-container {
    position: relative;
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.autocomplete-container * {
    box-sizing: border-box;
}

/* Estados do container */
.autocomplete-container.disabled {
    opacity: 0.6;
    pointer-events: none;
    cursor: not-allowed;
}

/* ============================================================================
   INPUT WRAPPER
   ============================================================================ */

.autocomplete-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

/* ============================================================================
   INPUT FIELD
   ============================================================================ */

.autocomplete-input {
    width: 100%;
    padding: 12px 16px;
    padding-right: 80px;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    background: white;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    color: #374151;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

.autocomplete-input::placeholder {
    color: #9ca3af;
    font-weight: 400;
}

/* Estados do input */
.autocomplete-container.focused .autocomplete-input {
    border-color: #3b82f6;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
    background: #fefefe;
}

.autocomplete-container.has-value .autocomplete-input {
    border-color: #10b981;
    background: linear-gradient(135deg, #f0fdf4 0%, #f0fdf4 100%);
    color: #065f46;
    font-weight: 600;
}

.autocomplete-container.has-value.focused .autocomplete-input {
    border-color: #059669;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
}

.autocomplete-container.required .autocomplete-input {
    border-color: #ef4444;
    background: linear-gradient(135deg, #fef2f2 0%, #fef2f2 100%);
}

.autocomplete-container.required.focused .autocomplete-input {
    border-color: #dc2626;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1);
}

/* ============================================================================
   ICONS CONTAINER
   ============================================================================ */

.autocomplete-icons {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    z-index: 10;
}

.autocomplete-icons i {
    font-size: 14px;
    color: #9ca3af;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
}

/* Estados dos ícones */
.autocomplete-icons .search-icon {
    color: #6b7280;
}

.autocomplete-icons .loading-icon {
    color: #3b82f6;
    font-size: 16px;
}

.autocomplete-icons .selected-icon {
    color: #10b981;
    font-size: 16px;
}

.autocomplete-icons .clear-icon {
    color: #ef4444;
    cursor: pointer;
    pointer-events: all;
    padding: 2px;
    border-radius: 50%;
    transition: all 0.3s ease;
    font-size: 12px;
}

.autocomplete-icons .clear-icon:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    transform: scale(1.1);
}

.autocomplete-icons .dropdown-icon {
    color: #6b7280;
    cursor: pointer;
    pointer-events: all;
    padding: 2px;
    border-radius: 4px;
    transition: all 0.3s ease;
    font-size: 12px;
}

.autocomplete-icons .dropdown-icon:hover {
    background: rgba(107, 114, 128, 0.1);
    color: #374151;
}

.autocomplete-icons .dropdown-icon.rotated {
    transform: rotate(180deg);
    color: #3b82f6;
}

/* ============================================================================
   DROPDOWN CONTAINER
   ============================================================================ */

.autocomplete-dropdown {
    position: absolute;
    top: calc(100% - 2px);
    left: 0;
    right: 0;
    z-index: 1000;
    background: white;
    border: 2px solid #e5e7eb;
    border-top: none;
    border-radius: 0 0 16px 16px;
    box-shadow: 
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06),
        0 10px 40px rgba(0, 0, 0, 0.15);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
}

.autocomplete-dropdown.show {
    max-height: 320px;
    opacity: 1;
    transform: translateY(0) scale(1);
}

.autocomplete-container.focused .autocomplete-dropdown {
    border-color: #3b82f6;
}

.autocomplete-container.has-value .autocomplete-dropdown {
    border-color: #10b981;
}

/* ============================================================================
   DROPDOWN LIST
   ============================================================================ */

.autocomplete-list {
    max-height: 320px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Scrollbar personalizada */
.autocomplete-list::-webkit-scrollbar {
    width: 6px;
}

.autocomplete-list::-webkit-scrollbar-track {
    background: #f8fafc;
    border-radius: 3px;
}

.autocomplete-list::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #cbd5e1, #94a3b8);
    border-radius: 3px;
    transition: background 0.3s ease;
}

.autocomplete-list::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #94a3b8, #64748b);
}

/* ============================================================================
   LIST ITEMS
   ============================================================================ */

.autocomplete-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f8fafc;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    background: white;
    animation: fadeInItem 0.2s ease-out;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.highlighted {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-left: 4px solid #3b82f6;
    padding-left: 12px;
    transform: translateX(2px);
}

.autocomplete-item.selected {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border-left: 4px solid #10b981;
    padding-left: 12px;
}

.autocomplete-item.selected:hover {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
}

.autocomplete-item.selected-item {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border-left: 4px solid #10b981;
    padding-left: 12px;
    border-bottom: 2px solid #e5e7eb;
}

.autocomplete-item.selected-item:hover {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    transform: translateX(2px);
}

/* ============================================================================
   ITEM CONTENT
   ============================================================================ */

.item-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.item-icon {
    color: #9ca3af;
    font-size: 14px;
    flex-shrink: 0;
    transition: color 0.2s ease;
}

.autocomplete-item:hover .item-icon,
.autocomplete-item.highlighted .item-icon {
    color: #3b82f6;
}

.selected-check {
    color: #10b981;
    font-size: 14px;
    flex-shrink: 0;
}

.item-text {
    font-weight: 500;
    color: #374151;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}

.autocomplete-item:hover .item-text,
.autocomplete-item.highlighted .item-text {
    color: #1e293b;
    font-weight: 600;
}

.item-text mark {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #92400e;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: 700;
    text-shadow: none;
}

.item-meta {
    font-size: 12px;
    color: #9ca3af;
    font-weight: 500;
    flex-shrink: 0;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.autocomplete-item:hover .item-meta,
.autocomplete-item.highlighted .item-meta {
    color: #6b7280;
}

.item-badge {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
}

/* ============================================================================
   SEPARATOR
   ============================================================================ */

.autocomplete-separator {
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, #e5e7eb 20%, #e5e7eb 80%, transparent 100%);
    margin: 8px 16px;
    position: relative;
}

.autocomplete-separator::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
    border-radius: 2px;
}

/* ============================================================================
   LOADING STATE
   ============================================================================ */

.autocomplete-loading {
    padding: 24px 20px;
    text-align: center;
    color: #6b7280;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.autocomplete-loading i {
    font-size: 24px;
    color: #3b82f6;
    margin-bottom: 8px;
}

.autocomplete-loading span {
    font-weight: 600;
    font-size: 14px;
}

/* ============================================================================
   EMPTY STATE
   ============================================================================ */

.autocomplete-empty {
    padding: 32px 20px;
    text-align: center;
    color: #9ca3af;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.autocomplete-empty i {
    font-size: 32px;
    color: #d1d5db;
    margin-bottom: 12px;
}

.autocomplete-empty span {
    font-weight: 600;
    font-size: 16px;
    color: #6b7280;
    margin-bottom: 4px;
}

.autocomplete-empty small {
    font-size: 12px;
    color: #9ca3af;
    font-weight: 400;
}

/* ============================================================================
   MIN CHARS MESSAGE
   ============================================================================ */

.autocomplete-min-chars {
    padding: 24px 20px;
    text-align: center;
    color: #8b5cf6;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.autocomplete-min-chars i {
    font-size: 28px;
    color: #a78bfa;
    margin-bottom: 8px;
}

.autocomplete-min-chars span {
    font-weight: 600;
    font-size: 14px;
}

/* ============================================================================
   INSTRUCTIONS
   ============================================================================ */

.autocomplete-instructions {
    padding: 24px 20px;
    text-align: center;
    color: #06b6d4;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.autocomplete-instructions i {
    font-size: 24px;
    color: #67e8f9;
    margin-bottom: 8px;
}

.autocomplete-instructions span {
    font-weight: 500;
    font-size: 14px;
}

/* ============================================================================
   OVERLAY
   ============================================================================ */

.autocomplete-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    background: transparent;
    cursor: default;
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

@keyframes fadeInItem {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.fa-spin {
    animation: spin 1s linear infinite;
}

/* Animação suave para highlight */
@keyframes highlightPulse {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.autocomplete-item.highlighted {
    background-size: 200% 200%;
    animation: highlightPulse 2s ease infinite;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

/* Tablet */
@media (max-width: 1024px) {
    .autocomplete-dropdown {
        max-height: 280px;
    }
    
    .autocomplete-dropdown.show {
        max-height: 280px;
    }
    
    .autocomplete-list {
        max-height: 280px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .autocomplete-input {
        padding: 14px 16px;
        padding-right: 70px;
        font-size: 16px; /* Evita zoom no iOS */
        border-radius: 10px;
    }
    
    .autocomplete-icons {
        right: 10px;
        gap: 6px;
    }
    
    .autocomplete-icons i {
        font-size: 16px;
    }
    
    .autocomplete-dropdown {
        max-height: 250px;
        border-radius: 0 0 12px 12px;
    }
    
    .autocomplete-dropdown.show {
        max-height: 250px;
    }
    
    .autocomplete-list {
        max-height: 250px;
    }
    
    .autocomplete-item {
        padding: 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .item-content {
        width: 100%;
        gap: 16px;
    }
    
    .item-meta {
        max-width: none;
        width: 100%;
        text-align: left;
        margin-top: 4px;
    }
    
    .item-badge {
        align-self: flex-end;
        margin-top: -24px;
    }
    
    .autocomplete-empty,
    .autocomplete-loading,
    .autocomplete-min-chars,
    .autocomplete-instructions {
        padding: 28px 16px;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .autocomplete-input {
        padding: 12px 14px;
        padding-right: 60px;
        font-size: 16px;
    }
    
    .autocomplete-icons {
        right: 8px;
        gap: 4px;
    }
    
    .autocomplete-dropdown {
        max-height: 220px;
    }
    
    .autocomplete-dropdown.show {
        max-height: 220px;
    }
    
    .autocomplete-list {
        max-height: 220px;
    }
    
    .autocomplete-item {
        padding: 14px;
    }
    
    .item-text {
        font-size: 14px;
    }
    
    .item-meta {
        font-size: 11px;
    }
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

/* Focus visible para navegação por teclado */
.autocomplete-input:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.autocomplete-item:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .autocomplete-input {
        border-width: 3px;
    }
    
    .autocomplete-item:hover,
    .autocomplete-item.highlighted {
        background: #000;
        color: #fff;
    }
    
    .item-text mark {
        background: #ff0;
        color: #000;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .autocomplete-dropdown {
        transition: opacity 0.2s ease;
        transform: none;
    }
    
    .autocomplete-item {
        animation: none;
        transition: background-color 0.2s ease;
    }
    
    .autocomplete-icons i {
        transition: color 0.2s ease;
    }
    
    @keyframes highlightPulse {
        to { background-position: 0% 50%; }
    }
}

/* ============================================================================
   DARK MODE SUPPORT (opcional)
   ============================================================================ */

@media (prefers-color-scheme: dark) {
    .autocomplete-input {
        background: #1f2937;
        border-color: #374151;
        color: #f9fafb;
    }
    
    .autocomplete-input::placeholder {
        color: #6b7280;
    }
    
    .autocomplete-dropdown {
        background: #1f2937;
        border-color: #374151;
    }
    
    .autocomplete-item {
        background: #1f2937;
        border-bottom-color: #374151;
    }
    
    .autocomplete-item:hover,
    .autocomplete-item.highlighted {
        background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 100%);
    }
    
    .item-text {
        color: #f9fafb;
    }
    
    .item-meta {
        color: #9ca3af;
    }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
    .autocomplete-dropdown,
    .autocomplete-overlay {
        display: none !important;
    }
    
    .autocomplete-input {
        border: 1px solid #000;
        box-shadow: none;
    }
}