/*
 * Command Palette Component
 * Keyboard-driven search interface (⌘K or Ctrl+K)
 *
 * Colours/typography use the Linear design tokens (--surface, --border, --fg,
 * --fg-muted, --accent, --accent-soft, --font-sans, --text-*) so the palette
 * matches the rest of the app in both light and dark themes. Structural tokens
 * (--space-*, --radius-*, --shadow-*, --transition-*, --z-modal) are shared.
 */

/* ===== Overlay ===== */
.command-palette-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
}

.command-palette-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ===== Command Palette Container ===== */
.command-palette {
    width: 100%;
    max-width: 640px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2xl);
    display: flex;
    flex-direction: column;
    max-height: 70vh;
    overflow: hidden;
    transform: scale(0.95) translateY(-20px);
    transition: transform var(--transition-base);
}

.command-palette-overlay.active .command-palette {
    transform: scale(1) translateY(0);
}

/* ===== Search Input ===== */
.command-palette-search {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.command-palette-search i {
    font-size: 1.25rem;
    color: var(--fg-muted);
}

.command-palette-search input {
    flex: 1;
    border: none;
    outline: none;
    font-size: var(--text-base);
    color: var(--fg);
    font-family: var(--font-sans);
    background: transparent;
}

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

.command-palette-search kbd {
    padding: var(--space-1) var(--space-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--fg-muted);
}

/* ===== Results List ===== */
.command-palette-results {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: var(--space-2);
}

.command-palette-results::-webkit-scrollbar {
    width: 6px;
}

.command-palette-results::-webkit-scrollbar-track {
    background: transparent;
}

.command-palette-results::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

/* ===== Result Groups ===== */
.result-group {
    margin-bottom: var(--space-3);
}

.result-group-title {
    padding: var(--space-2) var(--space-3);
    font-size: 0.75rem;
    font-weight: var(--font-weight-semibold);
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Result Items ===== */
.result-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    margin: var(--space-1) 0;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    color: var(--fg);
}

.result-item:hover {
    background: var(--surface-2);
    text-decoration: none;
}

.result-item.selected {
    background: var(--accent-soft);
    border-left: 2px solid var(--accent);
}

.result-item-icon {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    font-size: 1rem;
    color: var(--fg-muted);
    flex-shrink: 0;
}

.result-item.selected .result-item-icon {
    background: var(--accent);
    color: #fff;
}

.result-item-content {
    flex: 1;
    min-width: 0;
}

.result-item-title {
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    color: var(--fg);
    margin-bottom: var(--space-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-item-description {
    font-size: 0.75rem;
    color: var(--fg-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-item-badge {
    padding: 2px 8px;
    background: var(--surface-2);
    color: var(--fg-muted);
    font-size: 0.75rem;
    font-weight: var(--font-weight-medium);
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.result-item.selected .result-item-badge {
    background: var(--accent);
    color: #fff;
}

/* ===== Empty State ===== */
.command-palette-empty {
    padding: var(--space-8) var(--space-4);
    text-align: center;
    color: var(--fg-muted);
}

.command-palette-empty i {
    font-size: 3rem;
    margin-bottom: var(--space-4);
    opacity: 0.3;
}

.command-palette-empty p {
    font-size: var(--text-sm);
    margin: 0;
}

/* ===== Footer (Keyboard Hints) ===== */
.command-palette-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
    background: var(--bg);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    font-size: 0.75rem;
    color: var(--fg-muted);
    flex-shrink: 0;
}

.command-palette-footer .hint {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.command-palette-footer kbd {
    padding: 2px 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-family: var(--font-mono);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* ===== Highlight Matched Text ===== */
.result-item mark {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: var(--font-weight-semibold);
    padding: 0;
}

/* ===== Recent Searches ===== */
.recent-searches {
    padding: var(--space-2);
}

.recent-search-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    color: var(--fg-muted);
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.recent-search-item:hover {
    background: var(--surface-2);
    color: var(--fg);
}

.recent-search-item i {
    font-size: 0.875rem;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    .command-palette-overlay {
        padding-top: 5vh;
        padding-left: var(--space-4);
        padding-right: var(--space-4);
    }

    .command-palette {
        max-height: 80vh;
    }

    .command-palette-footer {
        display: none;
    }
}

/* ===== Animations ===== */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-item {
    animation: slideDown 0.2s ease-out;
}

.result-group:nth-child(1) .result-item { animation-delay: 0.02s; }
.result-group:nth-child(2) .result-item { animation-delay: 0.04s; }
.result-group:nth-child(3) .result-item { animation-delay: 0.06s; }
