/**
 * Advanced Features CSS
 * Theme toggle, voice visualizer, file previews, command palette
 */

/* ========================================
   THEME TOGGLE
   ======================================== */

.theme-toggle-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--surface);
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
}

.theme-toggle-btn:hover {
    background: var(--surface-hover);
    transform: rotate(20deg) scale(1.1);
}

/* ========================================
   VOICE VISUALIZER
   ======================================== */

.voice-visualizer {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-elevated);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 100;
    animation: slideUp 0.3s ease;
}

#voiceCanvas {
    border-radius: 8px;
    background: var(--bg-raw);
}

.voice-timer {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    color: var(--text);
    font-weight: 600;
}

.voice-stop-btn {
    padding: 8px 24px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.voice-stop-btn:hover {
    background: #dc2626;
    transform: translateY(-2px);
}

/* ========================================
   FILE PREVIEWS
   ======================================== */

.file-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px;
    margin-top: 8px;
}

.file-preview-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    min-width: 200px;
    animation: slideIn 0.3s ease;
}

.file-preview-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.file-preview-info {
    flex: 1;
    min-width: 0;
}

.file-preview-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview-size {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.file-preview-remove {
    width: 24px;
    height: 24px;
    border: none;
    background: var(--surface-hover);
    color: var(--text-muted);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-preview-remove:hover {
    background: #ef4444;
    color: white;
}

.file-preview-image {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    max-width: 200px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    z-index: 50;
    display: none;
}

.file-preview-item:hover .file-preview-image {
    display: block;
    animation: fadeIn 0.2s ease;
}

.file-preview-image img {
    width: 100%;
    height: auto;
    display: block;
}

/* Drag and Drop Zone */
.input-area.drag-active {
    background: var(--primary-glow);
    border: 2px dashed var(--primary);
    border-radius: 16px;
}

/* ========================================
   PROGRESS INDICATORS
   ======================================== */

.progress-indicator {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    padding: 16px 24px;
    background: var(--surface-elevated);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 250px;
    z-index: 100;
    animation: slideUp 0.3s ease;
}

.progress-message {
    font-size: 0.9rem;
    color: var(--text);
}

.progress-bar {
    height: 4px;
    background: var(--surface);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

/* ========================================
   COMMAND PALETTE
   ======================================== */

.command-palette {
    position: fixed;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    background: var(--surface-elevated);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: scaleIn 0.2s ease;
    overflow: hidden;
}

.command-palette input {
    width: 100%;
    padding: 16px 20px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    outline: none;
}

.command-palette input::placeholder {
    color: var(--text-muted);
}

.command-list {
    max-height: 300px;
    overflow-y: auto;
}

.command-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.command-item:hover,
.command-item.selected {
    background: var(--surface-hover);
}

.command-item.selected {
    border-left: 3px solid var(--primary);
}

.command-name {
    font-size: 0.95rem;
    color: var(--text);
}

.command-item kbd {
    padding: 4px 8px;
    background: var(--bg-raw);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

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

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(20px);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: translateX(-50%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
}

/* ========================================
   RESPONSIVE IMPROVEMENTS
   ======================================== */

@media (max-width: 768px) {
    .voice-visualizer {
        left: 10px;
        right: 10px;
        transform: none;
    }

    #voiceCanvas {
        width: 100%;
    }

    .file-preview-item {
        min-width: 100%;
    }

    .command-palette {
        top: 10%;
        width: 95%;
    }

    .progress-indicator {
        left: 20px;
        right: 20px;
        transform: none;
    }
}

/* ========================================
   SCROLL BEHAVIOR
   ======================================== */

.smooth-scroll {
    scroll-behavior: smooth;
}

/* ========================================
   FOCUS STATES
   ======================================== */

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ========================================
   LOADING STATES
   ======================================== */

.pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

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

/* ========================================
   TOOLTIPS
   ======================================== */

[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 12px;
    background: var(--surface-elevated);
    color: var(--text);
    font-size: 0.75rem;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-md);
    z-index: 100;
}

[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
    bottom: calc(100% + 8px);
}


/* ============================================================
   NEW FEATURES STYLES
   Prompt Library, Smart Suggestions, Rating, Theme Picker,
   Formatting Toolbar, Token Estimator
   ============================================================ */

/* ========================================
   PROMPT LIBRARY MODAL
   ======================================== */

.pl-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.pl-modal {
    width: 100%;
    max-width: 680px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    overflow: hidden;
    animation: scaleIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pl-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: var(--glass-border);
    flex-shrink: 0;
}

.pl-modal-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.pl-header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.pl-add-btn {
    padding: 8px 16px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--trans-fast);
}

.pl-add-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.pl-close-btn {
    width: 32px;
    height: 32px;
    background: var(--surface);
    border: var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--trans-fast);
}

.pl-close-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.pl-categories {
    display: flex;
    gap: 8px;
    padding: 12px 24px;
    border-bottom: var(--glass-border);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.pl-cat-btn {
    padding: 6px 14px;
    background: var(--surface);
    border: var(--glass-border);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--trans-fast);
}

.pl-cat-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.pl-cat-btn.active {
    background: var(--primary);
    color: var(--bg-raw);
    border-color: var(--primary);
    font-weight: 600;
}

.pl-search-wrap {
    padding: 12px 24px;
    border-bottom: var(--glass-border);
    flex-shrink: 0;
}

.pl-search-input {
    width: 100%;
    padding: 10px 16px;
    background: var(--surface);
    border: var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: var(--trans-fast);
}

.pl-search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.pl-list {
    overflow-y: auto;
    padding: 16px 24px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    flex: 1;
}

.pl-card {
    background: var(--surface);
    border: var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: var(--trans-base);
    position: relative;
}

.pl-card:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.pl-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.pl-card-cat {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 2px 8px;
    background: var(--primary-glow);
    color: var(--primary);
    border-radius: var(--radius-full);
}

.pl-card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}

.pl-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    opacity: 0.5;
    transition: var(--trans-fast);
    padding: 2px;
}

.pl-delete-btn:hover {
    opacity: 1;
}

.pl-card-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    flex: 1;
}

.pl-use-btn {
    padding: 8px 14px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--trans-fast);
    align-self: flex-start;
}

.pl-use-btn:hover {
    opacity: 0.9;
    transform: translateX(2px);
}

/* ========================================
   SMART SUGGESTIONS
   ======================================== */

.smart-suggestions {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}

.ss-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.ss-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ss-chip {
    padding: 6px 14px;
    background: var(--surface);
    border: var(--glass-border);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--trans-fast);
    white-space: nowrap;
}

.ss-chip:hover {
    background: var(--surface-hover);
    color: var(--primary);
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--primary-glow);
}

/* ========================================
   RESPONSE RATING BUTTONS
   ======================================== */

.rating-btns {
    display: flex;
    gap: 4px;
    align-items: center;
}

.rating-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-elevated);
    border: var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--trans-fast);
}

.rating-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
    transform: scale(1.1);
}

.rating-btn.thumbs-up.rated {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border-color: #10b981;
}

.rating-btn.thumbs-down.rated {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border-color: #ef4444;
}

.rating-btn:disabled {
    cursor: default;
    opacity: 0.7;
}

/* ========================================
   THEME PICKER
   ======================================== */

.theme-picker {
    min-width: 180px;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.2s ease;
}

.theme-picker-title {
    padding: 10px 14px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: var(--glass-border);
}

.theme-picker-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--trans-fast);
    text-align: left;
}

.theme-picker-btn:hover {
    background: var(--surface-hover);
}

.theme-picker-btn.active {
    background: var(--primary-glow);
    color: var(--primary);
    font-weight: 600;
}

.theme-picker-icon {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.theme-preview {
    width: 20px;
    height: 14px;
    border-radius: 3px;
    margin-left: auto;
    border: 1px solid var(--border);
}

.theme-preview-dark { background: linear-gradient(135deg, #020617, #0f172a); }
.theme-preview-light { background: linear-gradient(135deg, #f8fafc, #f1f5f9); }
.theme-preview-midnight { background: linear-gradient(135deg, #020617, #1e1b4b); }
.theme-preview-sunset { background: linear-gradient(135deg, #450a0a, #7c2d12); }
.theme-preview-cyberpunk { background: linear-gradient(135deg, #000, #001a1a); border-color: #00ffcc; }

/* ========================================
   FORMATTING TOOLBAR
   ======================================== */

.fmt-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px 0;
    flex-wrap: wrap;
}

.fmt-btn {
    padding: 4px 10px;
    background: var(--surface);
    border: var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--trans-fast);
    line-height: 1.4;
    min-height: 28px;
    display: flex;
    align-items: center;
}

.fmt-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-strong);
}

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

.fmt-btn b { font-weight: 800; }
.fmt-btn i { font-style: italic; }
.fmt-btn code { font-family: var(--font-mono); font-size: 0.75rem; }

.fmt-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
}

.fmt-library-btn {
    margin-left: auto;
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.fmt-library-btn:hover {
    background: var(--primary-glow);
    color: var(--primary);
    border-color: var(--primary);
}

/* ========================================
   TOKEN ESTIMATOR (enhanced char count)
   ======================================== */

#charCount {
    font-size: 0.72rem;
    color: var(--text-muted);
    transition: color 0.2s ease;
    white-space: nowrap;
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .pl-modal {
        max-height: 90vh;
        border-radius: var(--radius-md) var(--radius-md) 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-width: 100%;
    }

    .pl-modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .pl-list {
        grid-template-columns: 1fr;
    }

    .fmt-toolbar {
        gap: 3px;
        padding: 4px 8px 0;
    }

    .fmt-btn {
        padding: 4px 8px;
        font-size: 0.72rem;
    }

    .fmt-library-btn {
        margin-left: 0;
    }

    .ss-chips {
        gap: 6px;
    }

    .ss-chip {
        font-size: 0.75rem;
        padding: 5px 10px;
    }

    .theme-picker {
        position: fixed !important;
        top: auto !important;
        bottom: 80px !important;
        right: 16px !important;
    }
}

/* ========================================
   DARK MODE ADJUSTMENTS
   ======================================== */

html[data-theme="dark"] .pl-cat-btn.active {
    background: var(--primary);
    color: #000;
}

html[data-theme="cyberpunk"] .pl-card:hover {
    border-color: #00ffcc;
    box-shadow: 0 0 20px rgba(0, 255, 204, 0.3);
}

html[data-theme="cyberpunk"] .ss-chip:hover {
    border-color: #00ffcc;
    color: #00ffcc;
    box-shadow: 0 0 10px rgba(0, 255, 204, 0.4);
}

html[data-theme="cyberpunk"] .fmt-btn:hover {
    border-color: #00ffcc;
    color: #00ffcc;
}
