/* ============================================================
   Asset Tag Input — Tag Strip + Upload Controls
   ============================================================ */

.ati-container {
    flex: 1;
    min-width: 0;
    width: 100%;
}

/* Input row: textarea + upload button side by side */
.ati-input-row {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.ati-input-row textarea {
    flex: 1;
    min-width: 0;
    width: 100%;
    background: transparent;
    caret-color: var(--gray-900, #111827);
    position: relative;
    z-index: 1;
}

/* Backdrop sits behind textarea to show tag highlights */
.ati-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    pointer-events: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: transparent;
}

.ati-highlight {
    background: rgba(124, 58, 237, 0.10);
    border-radius: 4px;
    color: transparent;
}

@keyframes ati-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

.ati-spin {
    animation: ati-spin 1s linear infinite;
    display: inline-block;
}

/* ---- Hover preview tooltip ---- */
.ati-preview {
    position: fixed;
    z-index: 9999;
    background: var(--white, #fff);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 8px;
    display: none;
    max-width: 320px;
    pointer-events: none;
}

.ati-preview.ati-preview-visible {
    display: block;
}

.ati-preview-img {
    display: block;
    max-width: 280px;
    max-height: 200px;
    border-radius: 6px;
    object-fit: contain;
    background-image:
        linear-gradient(45deg, #f3f4f6 25%, transparent 25%),
        linear-gradient(-45deg, #f3f4f6 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f3f4f6 75%),
        linear-gradient(-45deg, transparent 75%, #f3f4f6 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.ati-preview-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-700, #374151);
    margin-top: 6px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ati-preview-error {
    font-size: 0.75rem;
    color: #b91c1c;
    padding: 6px 10px;
}

/* ---- Tag preview strip (below textarea, inside container) ---- */
.ati-tag-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 12px;
    min-height: 0;
    position: relative;
    z-index: 2;
    transition: min-height 0.2s ease, padding 0.2s ease;
}

.ati-tag-strip:empty {
    padding: 0;
    min-height: 0;
}

.ati-tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    cursor: default;
    transition: all 0.15s ease;
}

.ati-tag-chip-matched {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.10), rgba(168, 85, 247, 0.10));
    color: #7C3AED;
    border: 1px solid rgba(124, 58, 237, 0.25);
    box-shadow: 0 1px 4px rgba(124, 58, 237, 0.10);
}

.ati-tag-chip-matched:hover {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.16), rgba(168, 85, 247, 0.16));
    border-color: rgba(124, 58, 237, 0.40);
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.18);
}

.ati-tag-chip-check {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #7C3AED;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ati-tag-chip-check svg {
    width: 8px;
    height: 8px;
    fill: none;
    stroke: #fff;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ati-tag-chip-unmatched {
    background-color: rgba(239, 68, 68, 0.08);
    color: #b91c1c;
    border: 1px solid rgba(239, 68, 68, 0.20);
}

.ati-tag-chip-loading {
    background-color: rgba(156, 163, 175, 0.10);
    color: var(--gray-400, #9CA3AF);
    border: 1px solid rgba(156, 163, 175, 0.20);
    animation: ati-pulse 1.2s ease-in-out infinite;
}

.ati-tag-chip-thumb {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid rgba(124, 58, 237, 0.15);
}

.ati-tag-chip i {
    font-size: 0.65rem;
}

/* ---- Autocomplete dropdown ---- */
.ati-autocomplete {
    position: fixed;
    z-index: 9999;
    background: var(--white, #fff);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    max-height: 300px;
    overflow-y: auto;
    display: none;
    min-width: 260px;
}

.ati-autocomplete.ati-autocomplete-visible {
    display: block;
}

.ati-ac-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background-color 0.1s ease;
    border-bottom: 1px solid var(--gray-100, #f3f4f6);
}

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

.ati-ac-item:hover,
.ati-ac-item.ati-ac-active {
    background-color: rgba(59, 130, 246, 0.06);
}

.ati-ac-thumb {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: cover;
    background-color: var(--gray-100, #f3f4f6);
    flex-shrink: 0;
}

.ati-ac-info {
    flex: 1;
    min-width: 0;
}

.ati-ac-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-800, #1f2937);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ati-ac-meta {
    font-size: 0.6875rem;
    color: var(--gray-400, #9CA3AF);
}

.ati-ac-tag {
    display: inline-block;
    background: var(--gray-100, #F3F4F6);
    color: var(--gray-600, #4B5563);
    font-family: monospace;
    font-size: 0.625rem;
    padding: 1px 5px;
    border-radius: 3px;
    margin-right: 4px;
}

.ati-ac-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--gray-400, #9CA3AF);
    border-bottom: 1px solid var(--gray-100, #f3f4f6);
    letter-spacing: 0.02em;
}

.ati-ac-header i {
    font-size: 0.75rem;
    color: #A855F7;
}

.ati-ac-empty {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 12px;
    font-size: 0.8125rem;
    color: var(--gray-400, #9CA3AF);
}

.ati-ac-empty i {
    font-size: 1rem;
    flex-shrink: 0;
}

/* ---- Upload button (purple accent, icon-only) ---- */
.ati-upload-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(124, 58, 237, 0.20);
    background: rgba(124, 58, 237, 0.06);
    border-radius: 0.5rem;
    color: #7C3AED;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.ati-upload-btn:hover {
    background: rgba(124, 58, 237, 0.12);
    border-color: rgba(124, 58, 237, 0.35);
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.15);
}

.ati-upload-btn:active {
    transform: scale(0.95);
}

.ati-upload-btn i {
    font-size: 1.125rem;
}

.ati-upload-wrapper {
    position: relative;
}

/* ---- Drag & drop overlay (covers input row only) ---- */
.ati-drop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    border-radius: inherit;
    background: rgba(59, 130, 246, 0.06);
    border: 2px dashed transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease, border-color 0.15s ease;
}

.ati-drop-overlay.ati-drop-active {
    opacity: 1;
    border-color: #3B82F6;
    pointer-events: auto;
}

.ati-drop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: #3B82F6;
    font-size: 0.875rem;
    font-weight: 600;
}

.ati-drop-content i {
    font-size: 1.5rem;
}

/* ---- Upload progress indicator ---- */
.ati-upload-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #3B82F6;
    z-index: 20;
    transition: all 0.15s ease;
}

.ati-upload-indicator i {
    font-size: 0.75rem;
}

.ati-upload-indicator.ati-upload-error {
    color: #b91c1c;
}

/* ---- Circular progress ring on upload button ---- */
.ati-upload-btn.ati-upload-uploading {
    position: relative;
    background: rgba(124, 58, 237, 0.08);
    border-color: rgba(124, 58, 237, 0.25);
}

.ati-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ati-ring-bg {
    fill: none;
    stroke: rgba(124, 58, 237, 0.12);
    stroke-width: 3;
}

.ati-ring-fill {
    fill: none;
    stroke: #7C3AED;
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.2s ease-out;
}

.ati-ring-stop {
    position: relative;
    z-index: 1;
    font-size: 0.75rem !important;
    color: #7C3AED;
}

.ati-upload-btn.ati-upload-finalizing .ati-ring-fill {
    animation: ati-ring-pulse 1.2s ease-in-out infinite;
}

@keyframes ati-ring-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.ati-upload-btn.ati-upload-indeterminate .ati-ring {
    animation: ati-ring-spin 1.2s linear infinite;
    transform: rotate(-90deg);
}

@keyframes ati-ring-spin {
    from { transform: rotate(-90deg); }
    to { transform: rotate(270deg); }
}

/* ---- Upload progress strip (between textarea and toolbar) ---- */
.ati-progress-strip {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 6px 14px;
}

.ati-progress-strip.ati-ps-visible {
    display: flex;
}

.ati-ps-track {
    width: 100%;
    height: 3px;
    background: var(--gray-100, #f3f4f6);
    border-radius: 99px;
    overflow: hidden;
}

.ati-ps-fill {
    height: 100%;
    background: linear-gradient(90deg, #7C3AED, #A855F7);
    border-radius: 99px;
    transition: width 0.2s ease-out;
}

.ati-ps-fill-indeterminate {
    width: 35% !important;
    animation: ati-ps-slide 1.2s ease-in-out infinite;
}

@keyframes ati-ps-slide {
    0% { transform: translateX(-110%); }
    100% { transform: translateX(380%); }
}

.ati-ps-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.6875rem;
    line-height: 1;
}

.ati-ps-left {
    color: var(--gray-600, #4B5563);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.ati-ps-right {
    color: var(--gray-400, #9CA3AF);
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 8px;
}

/* ---- Asset hint row ---- */
.ati-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.75rem;
    color: var(--gray-400, #9CA3AF);
    line-height: 1.4;
}

.ati-hint i {
    font-size: 0.875rem;
    color: #A855F7;
    flex-shrink: 0;
}

.ati-hint kbd {
    display: inline-block;
    padding: 1px 5px;
    font-size: 0.6875rem;
    font-family: inherit;
    font-weight: 600;
    color: #7C3AED;
    background: rgba(124, 58, 237, 0.08);
    border: 1px solid rgba(124, 58, 237, 0.15);
    border-radius: 4px;
}

.ati-hint.ds-hidden {
    display: none;
}

/* ---- Upgrade popover ---- */
.ati-upgrade-popover {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    z-index: 100;
    background: var(--white, #fff);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 16px;
    width: 280px;
    display: none;
}

.ati-upgrade-popover.ati-popover-visible {
    display: block;
}

.ati-upgrade-popover-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--gray-900, #111827);
    margin-bottom: 6px;
}

.ati-upgrade-popover-title i {
    font-size: 1rem;
    color: #7C3AED;
}

.ati-upgrade-popover-text {
    font-size: 0.8125rem;
    color: var(--gray-500, #6B7280);
    line-height: 1.5;
    margin-bottom: 14px;
}

.ati-upgrade-popover-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ati-upgrade-popover-cta {
    flex: 1;
    padding: 8px 16px;
    background: linear-gradient(135deg, #7C3AED, #A855F7);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: all 0.15s ease;
}

.ati-upgrade-popover-cta:hover {
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
    transform: translateY(-1px);
}

.ati-upgrade-popover-dismiss {
    padding: 8px 12px;
    background: none;
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 8px;
    font-size: 0.8125rem;
    color: var(--gray-500, #6B7280);
    cursor: pointer;
    transition: all 0.15s ease;
}

.ati-upgrade-popover-dismiss:hover {
    background: var(--gray-50, #f9fafb);
}

/* Arrow pointing down from popover */
.ati-upgrade-popover::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 16px;
    width: 12px;
    height: 12px;
    background: var(--white, #fff);
    border-right: 1px solid var(--gray-200, #e5e7eb);
    border-bottom: 1px solid var(--gray-200, #e5e7eb);
    transform: rotate(45deg);
}

/* ---- Upgrade nudge banner (above prompt box) ---- */
.upgrade-nudge {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.06), rgba(59, 130, 246, 0.06));
    border: 1px solid rgba(124, 58, 237, 0.12);
    border-radius: 12px;
    backdrop-filter: blur(8px);
}

.upgrade-nudge-content {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.upgrade-nudge-icon {
    font-size: 1rem;
    color: #7C3AED;
    flex-shrink: 0;
}

.upgrade-nudge-text {
    font-size: 0.8125rem;
    color: var(--gray-600, #4B5563);
    line-height: 1.4;
}

.upgrade-nudge-cta {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    background: linear-gradient(135deg, #7C3AED, #A855F7);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.upgrade-nudge-cta:hover {
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
    transform: translateY(-1px);
    color: #fff;
}

.upgrade-nudge-cta i {
    font-size: 0.75rem;
}

.upgrade-nudge-close {
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    color: var(--gray-400, #9CA3AF);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.upgrade-nudge-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--gray-600, #4B5563);
}

.upgrade-nudge-close i {
    font-size: 0.75rem;
}

@media (max-width: 640px) {
    .upgrade-nudge {
        padding: 8px 12px;
    }

    .upgrade-nudge-content {
        flex-wrap: wrap;
        gap: 6px;
    }

    .upgrade-nudge-text {
        font-size: 0.75rem;
        flex-basis: 100%;
        order: 2;
    }

    .upgrade-nudge-icon {
        order: 1;
    }

    .upgrade-nudge-cta {
        order: 3;
        width: 100%;
        justify-content: center;
        padding: 8px 14px;
    }
}

/* ---- Floating prompt stacked-card overrides ---- */
.prompt-input-section .ati-tag-strip,
.prompt-input-wrapper .ati-tag-strip {
    padding: 4px 0 0;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.prompt-input-section .ati-tag-strip::-webkit-scrollbar,
.prompt-input-wrapper .ati-tag-strip::-webkit-scrollbar {
    display: none;
}

.prompt-input-section .ati-tag-strip:empty,
.prompt-input-wrapper .ati-tag-strip:empty {
    display: none;
}

.prompt-input-section .ati-tag-chip,
.prompt-input-wrapper .ati-tag-chip {
    flex-shrink: 0;
}

.prompt-input-section .ati-upload-indicator {
    padding: 4px 0 0;
}

.prompt-input-wrapper .ati-upload-indicator {
    padding: 2px 0;
}

/* Constrain textarea height in floating prompt and prompt card */
.floating-prompt .prompt-input,
.floating-prompt .prompt-textarea,
.prompt-card .prompt-textarea {
    max-height: 120px;
    overflow-y: auto;
}

/* ============================================================
   Responsive — Mobile
   ============================================================ */

@media (max-width: 640px) {
    .ati-upload-btn {
        width: 32px;
        height: 32px;
    }

    .ati-upload-btn i {
        font-size: 1rem;
    }

    .ati-tag-strip {
        padding: 4px 8px;
        gap: 4px;
    }

    .ati-tag-chip {
        padding: 2px 8px;
        font-size: 0.6875rem;
    }

    .ati-tag-chip-thumb {
        width: 14px;
        height: 14px;
    }

    .ati-preview {
        max-width: 240px;
        left: 8px !important;
        right: 8px;
    }

    .ati-preview-img {
        max-width: 200px;
        max-height: 150px;
    }

    .ati-autocomplete {
        left: 8px !important;
        right: 8px;
        min-width: auto;
        max-width: calc(100vw - 16px);
    }

    .ati-ac-thumb {
        width: 28px;
        height: 28px;
    }

    .ati-ac-item {
        padding: 6px 10px;
        gap: 8px;
    }

    .ati-drop-content {
        font-size: 0.75rem;
    }

    .ati-drop-content i {
        font-size: 1.25rem;
    }

    .ati-upload-indicator {
        padding: 4px 8px;
        font-size: 0.6875rem;
    }

    .ati-hint {
        padding: 4px 8px;
        font-size: 0.6875rem;
    }

    .ati-hint kbd {
        font-size: 0.625rem;
        padding: 0 4px;
    }

    .ati-upgrade-popover {
        width: calc(100vw - 32px);
        right: -8px;
    }

    .ati-progress-strip {
        padding: 4px 10px;
    }

    .ati-ps-info {
        font-size: 0.625rem;
    }

    .ati-naming { flex-wrap: wrap; gap: 6px; }
    .ati-naming-thumb { width: 28px; height: 28px; }
    .ati-naming-input { font-size: 0.75rem; }
}

/* ── Tag Naming Strip (after upload) ──────────────────────── */
.ati-naming {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
}

.ati-naming-thumb {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--gray-100, #F3F4F6);
}

.ati-naming-body {
    flex: 1;
    min-width: 0;
}

.ati-naming-label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--gray-500, #6B7280);
    margin-bottom: 5px;
    letter-spacing: 0.01em;
}

.ati-naming-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ati-naming-input {
    flex: 1;
    min-width: 0;
    padding: 5px 8px;
    font-size: 0.8125rem;
    font-family: inherit;
    border: 1.5px solid var(--gray-200, #E5E7EB);
    border-radius: 6px;
    background: var(--gray-50, #F9FAFB);
    color: var(--gray-800, #1F2937);
    outline: none;
    transition: border-color 0.15s;
}

.ati-naming-input:focus {
    border-color: var(--primary, #6366f1);
    background: #fff;
}

.ati-naming-confirm,
.ati-naming-cancel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

.ati-naming-confirm {
    background: var(--primary, #6366f1);
    color: #fff;
}
.ati-naming-confirm:hover { opacity: 0.85; }
.ati-naming-confirm:disabled { opacity: 0.5; cursor: default; }

.ati-naming-cancel {
    background: var(--gray-100, #F3F4F6);
    color: var(--gray-500, #6B7280);
}
.ati-naming-cancel:hover { background: var(--gray-200, #E5E7EB); }

.ati-naming-tip {
    font-weight: 400;
    color: var(--gray-400, #9CA3AF);
}

.ati-naming-error {
    font-size: 0.6875rem;
    color: #ef4444;
    margin-top: 4px;
}
