/**
 * Tag Input Component Styles
 * Alpine.js-basierte Tag-Eingabe-Komponente
 *
 * Design: "Refined Professional" - Elegant, modern, B2B-tauglich
 */

/* ============================================
   CSS Custom Properties (Theme)
   ============================================ */
:root {
    /* Primary Colors */
    --tag-primary: #4a6fa5;
    --tag-primary-light: #6b8cbe;
    --tag-primary-dark: #3a5a8a;

    /* Neutral Colors */
    --tag-bg: #f0f4f8;
    --tag-bg-hover: #e2e8f0;
    --tag-border: #cbd5e1;
    --tag-text: #334155;
    --tag-text-light: #64748b;

    /* Accent */
    --tag-accent: #0ea5e9;
    --tag-accent-light: rgba(14, 165, 233, 0.1);

    /* Shadows */
    --tag-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --tag-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --tag-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Transitions */
    --tag-transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --tag-transition-normal: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --tag-transition-smooth: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   Container
   ============================================ */
.tag-input-container {
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ============================================
   Wrapper (Input Container)
   ============================================ */
.tag-input-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-height: 34px;
    height: auto;
    padding: 4px 8px;
    background: #fff;
    border: 1px solid var(--tag-border);
    border-radius: 6px;
    cursor: text;
    transition:
        border-color var(--tag-transition-fast),
        box-shadow var(--tag-transition-fast),
        background-color var(--tag-transition-fast);
}

.tag-input-wrapper:hover {
    border-color: #94a3b8;
}

.tag-input-wrapper:focus-within {
    border-color: var(--tag-accent);
    background: #fff;
    box-shadow:
        0 0 0 3px var(--tag-accent-light),
        var(--tag-shadow-sm);
}

/* ============================================
   Tags - Compact Pill Design
   ============================================ */
.tag-input-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px 2px 8px;
    background: linear-gradient(135deg, var(--tag-primary) 0%, var(--tag-primary-dark) 100%);
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
    border-radius: 12px;
    white-space: nowrap;
    max-width: 100%;
    box-shadow: var(--tag-shadow-sm);
    transition:
        transform var(--tag-transition-fast),
        box-shadow var(--tag-transition-fast),
        background var(--tag-transition-fast);
    animation: tagAppear 150ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

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

.tag-input-tag:hover {
    background: linear-gradient(135deg, var(--tag-primary-light) 0%, var(--tag-primary) 100%);
    box-shadow: var(--tag-shadow-md);
}

.tag-input-tag > span {
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.01em;
}

/* Remove Button */
.tag-input-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 1px;
    padding: 0;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 11px;
    font-weight: 400;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    opacity: 0.7;
    transition:
        opacity var(--tag-transition-fast),
        background var(--tag-transition-fast);
}

.tag-input-remove:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.35);
    color: #fff;
    text-decoration: none;
}

/* ============================================
   Input Field
   ============================================ */
.tag-input-field {
    flex: 1;
    min-width: 100px;
    border: none;
    outline: none;
    background: transparent;
    padding: 2px 0;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.4;
    color: var(--tag-text);
}

.tag-input-field::placeholder {
    color: var(--tag-text-light);
    font-weight: 400;
}

/* ============================================
   Dropdown - Compact Style
   ============================================ */
.tag-input-dropdown {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    z-index: 1000;
    max-height: 220px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0;
    background: #fff;
    border: 1px solid var(--tag-border);
    border-radius: 6px;
    box-shadow: var(--tag-shadow-md);
    animation: dropdownAppear 100ms ease-out forwards;
}

@keyframes dropdownAppear {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Custom Scrollbar for Dropdown */
.tag-input-dropdown::-webkit-scrollbar {
    width: 6px;
}

.tag-input-dropdown::-webkit-scrollbar-track {
    background: transparent;
    margin: 4px 0;
}

.tag-input-dropdown::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.tag-input-dropdown::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ============================================
   Dropdown Options - Compact
   ============================================ */
.tag-input-option {
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 400;
    color: var(--tag-text);
    cursor: pointer;
    border-left: 3px solid transparent;
    transition:
        background var(--tag-transition-fast),
        border-color var(--tag-transition-fast),
        padding-left var(--tag-transition-fast);
}

/* Hover State */
.tag-input-option:hover {
    background: var(--tag-bg);
    padding-left: 14px;
    border-left-color: var(--tag-accent);
}

/* Highlighted (Keyboard Navigation) */
.tag-input-option.highlighted {
    background: var(--tag-accent-light);
    color: var(--tag-primary-dark);
    padding-left: 14px;
    border-left-color: var(--tag-accent);
}

/* Search Match Highlighting (optional class for future use) */
.tag-input-option .match {
    background: rgba(14, 165, 233, 0.2);
    border-radius: 2px;
    padding: 0 2px;
    margin: 0 -2px;
}

/* ============================================
   Empty State / No Matches
   ============================================ */
.tag-input-no-matches {
    padding: 16px 14px;
    color: var(--tag-text-light);
    font-size: 13px;
    font-style: italic;
    text-align: center;
}

/* ============================================
   Loading State
   ============================================ */
.tag-input-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 14px;
    color: var(--tag-text-light);
    font-size: 13px;
}

.tag-input-loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--tag-border);
    border-top-color: var(--tag-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   Alternative Tag Variants
   ============================================ */

/* Subtle/Light Tags (for secondary use) */
.tag-input-tag.tag-subtle {
    background: var(--tag-bg);
    color: var(--tag-text);
    box-shadow: var(--tag-shadow-sm);
}

.tag-input-tag.tag-subtle:hover {
    background: var(--tag-bg-hover);
}

.tag-input-tag.tag-subtle .tag-input-remove {
    background: rgba(0, 0, 0, 0.1);
    color: var(--tag-text);
}

/* Success Tags (green) */
.tag-input-tag.tag-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

/* Warning Tags (amber) */
.tag-input-tag.tag-warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

/* Danger Tags (red) */
.tag-input-tag.tag-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

/* Deprecated Tags (amber/orange - for values no longer in whitelist) */
.tag-input-tag.tag-deprecated {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    position: relative;
    cursor: help;
}

.tag-input-tag.tag-deprecated::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 4px,
        rgba(255, 255, 255, 0.1) 4px,
        rgba(255, 255, 255, 0.1) 8px
    );
    pointer-events: none;
}

.tag-input-tag.tag-deprecated:hover {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

/* Deprecated icon indicator */
.tag-input-tag.tag-deprecated .tag-deprecated-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    margin-right: 2px;
    font-size: 10px;
    opacity: 0.9;
}

/* ============================================
   Size Variants
   ============================================ */

/* Small Tags */
.tag-input-container.tag-input-sm .tag-input-wrapper {
    min-height: 32px;
    padding: 4px 8px;
    gap: 4px;
}

.tag-input-container.tag-input-sm .tag-input-tag {
    padding: 3px 8px 3px 10px;
    font-size: 12px;
    border-radius: 16px;
}

.tag-input-container.tag-input-sm .tag-input-remove {
    width: 16px;
    height: 16px;
    font-size: 12px;
}

.tag-input-container.tag-input-sm .tag-input-field {
    font-size: 13px;
}

/* Large Tags */
.tag-input-container.tag-input-lg .tag-input-wrapper {
    min-height: 46px;
    padding: 8px 12px;
    gap: 8px;
}

.tag-input-container.tag-input-lg .tag-input-tag {
    padding: 7px 14px 7px 16px;
    font-size: 14px;
    border-radius: 24px;
}

.tag-input-container.tag-input-lg .tag-input-remove {
    width: 22px;
    height: 22px;
    font-size: 16px;
}

/* ============================================
   Disabled State
   ============================================ */
.tag-input-container.disabled .tag-input-wrapper {
    background: #f8fafc;
    cursor: not-allowed;
    opacity: 0.7;
}

.tag-input-container.disabled .tag-input-tag {
    pointer-events: none;
}

.tag-input-container.disabled .tag-input-field {
    cursor: not-allowed;
}

/* ============================================
   Error State
   ============================================ */
.tag-input-container.has-error .tag-input-wrapper {
    border-color: #ef4444;
}

.tag-input-container.has-error .tag-input-wrapper:focus-within {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* ============================================
   Alpine.js Utilities
   ============================================ */
[x-cloak] {
    display: none !important;
}

/* Smooth transition for tag list changes */
.tag-input-wrapper > template + * {
    transition: margin var(--tag-transition-fast);
}

/* ============================================
   Bootstrap 3 Override (remove default label styles)
   ============================================ */
.tag-input-tag.label {
    display: inline-flex;
    padding: 5px 10px 5px 12px;
    font-size: 13px;
    font-weight: 500;
    text-shadow: none;
    border-radius: 20px;
}

.tag-input-tag.label.label-primary {
    background: linear-gradient(135deg, var(--tag-primary) 0%, var(--tag-primary-dark) 100%);
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 768px) {
    .tag-input-wrapper {
        gap: 4px;
        padding: 5px 8px;
    }

    .tag-input-tag {
        padding: 4px 8px 4px 10px;
        font-size: 12px;
    }

    .tag-input-dropdown {
        max-height: 180px;
    }

    .tag-input-option {
        padding: 8px 10px;
    }
}

/* ============================================
   Modal Overflow Fix
   ============================================ */
/* Ensure dropdowns are visible in modals */
.modal-body {
    overflow: visible !important;
}

.modal-content {
    overflow: visible !important;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .tag-input-dropdown {
        display: none !important;
    }

    .tag-input-remove {
        display: none !important;
    }

    .tag-input-field {
        display: none !important;
    }

    .tag-input-tag {
        background: #e2e8f0 !important;
        color: #334155 !important;
        box-shadow: none !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
