/* ===== Command Palette ===== */

/* Backdrop */
.cmd-palette-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9999;
    justify-content: center;
    padding-top: 8vh;
    backdrop-filter: blur(4px);
    animation: cmdFadeIn 0.15s ease-out;
}
.cmd-palette-backdrop.active { display: flex; }

@keyframes cmdFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes cmdSlideIn {
    from { opacity: 0; transform: translateY(-12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Modal container */
.cmd-palette {
    width: 100%;
    max-width: 740px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    align-self: flex-start;
    animation: cmdSlideIn 0.2s ease-out;
}

/* Search input area */
.cmd-palette-input-wrap {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid #e5e7eb;
    gap: 12px;
}
.cmd-palette-input-wrap > i {
    color: #2E86C1;
    font-size: 17px;
    flex-shrink: 0;
}
.cmd-palette-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    font-weight: 400;
    background: transparent;
    color: #1a1a1a;
    letter-spacing: -0.01em;
}
.cmd-palette-input::placeholder { color: #b0b7c0; }
.cmd-palette-kbd {
    font-size: 11px;
    color: #9ca3af;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    padding: 2px 7px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    flex-shrink: 0;
    background: #f9fafb;
}

/* Results area */
.cmd-palette-results {
    overflow-y: auto;
    padding: 8px 0;
    max-height: 460px;
}
.cmd-palette-results::-webkit-scrollbar { width: 6px; }
.cmd-palette-results::-webkit-scrollbar-track { background: transparent; }
.cmd-palette-results::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

/* Grid mode (initial grouped view) */
.cmd-palette-results--grid {
    padding: 6px 8px 12px;
    overflow-y: visible;
    max-height: none;
}
.cmd-palette-columns {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0 6px;
}
.cmd-palette-col {
    min-width: 0;
}

/* Section headers */
.cmd-palette-section {
    padding: 10px 12px 4px;
    font-size: 10px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: flex;
    align-items: center;
    gap: 5px;
}
.cmd-palette-section-icon {
    font-size: 9px;
    opacity: 0.6;
}

/* ---- Compact items (grid view) ---- */
.cmd-palette-item--compact {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    margin: 1px 0;
    border-radius: 8px;
    cursor: pointer;
    gap: 8px;
    text-decoration: none;
    color: inherit;
    transition: background 0.1s ease;
}
.cmd-palette-item--compact:hover,
.cmd-palette-item--compact.active {
    background: #f0f5ff;
}
.cmd-palette-compact-icon {
    width: 16px;
    text-align: center;
    color: #94a3b8;
    font-size: 12px;
    flex-shrink: 0;
}
.cmd-palette-item--compact:hover .cmd-palette-compact-icon,
.cmd-palette-item--compact.active .cmd-palette-compact-icon {
    color: #2E86C1;
}
.cmd-palette-item--compact .cmd-palette-item-name {
    font-size: 13px;
    font-weight: 450;
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cmd-palette-item--compact:hover .cmd-palette-item-name,
.cmd-palette-item--compact.active .cmd-palette-item-name {
    color: #1e293b;
}

/* ---- Full items (search results view) ---- */
.cmd-palette-item {
    display: flex;
    align-items: center;
    padding: 8px 20px;
    margin: 0 8px;
    border-radius: 10px;
    cursor: pointer;
    gap: 12px;
    text-decoration: none;
    color: inherit;
    transition: background 0.12s ease;
}
.cmd-palette-item:hover,
.cmd-palette-item.active {
    background: #f0f5ff;
}

/* Icon container (search results) */
.cmd-palette-item-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.cmd-palette-item-icon i {
    color: #64748b;
    font-size: 14px;
}
.cmd-palette-item.active .cmd-palette-item-icon,
.cmd-palette-item:hover .cmd-palette-item-icon {
    background: #2E86C1;
}
.cmd-palette-item.active .cmd-palette-item-icon i,
.cmd-palette-item:hover .cmd-palette-item-icon i {
    color: #fff;
}

/* Asset icon variant */
.cmd-palette-item-icon--asset {
    background: #eef6ff;
}
.cmd-palette-ticker {
    font-size: 10px;
    font-weight: 700;
    color: #2E86C1;
    letter-spacing: 0.02em;
}
.cmd-palette-item.active .cmd-palette-ticker,
.cmd-palette-item:hover .cmd-palette-ticker {
    color: #fff;
}

/* Text content */
.cmd-palette-item-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}
.cmd-palette-item-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cmd-palette-item-meta {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 400;
}

/* Arrow indicator (search results) */
.cmd-palette-item-arrow {
    font-size: 11px;
    color: #cbd5e1;
    opacity: 0;
    transition: opacity 0.12s, transform 0.12s;
    flex-shrink: 0;
}
.cmd-palette-item.active .cmd-palette-item-arrow,
.cmd-palette-item:hover .cmd-palette-item-arrow {
    opacity: 1;
    color: #2E86C1;
    transform: translateX(2px);
}

/* Empty state */
.cmd-palette-empty {
    padding: 36px 20px;
    text-align: center;
    color: #94a3b8;
    font-size: 14px;
}
.cmd-palette-empty-icon {
    font-size: 28px;
    color: #d1d5db;
    margin-bottom: 10px;
    display: block;
}
.cmd-palette-empty-hint {
    font-size: 12px;
    color: #b0b7c0;
    margin-top: 4px;
}

/* ===== Navbar trigger ===== */
.cmd-palette-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 14px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    font-size: 13px;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
    background: rgba(255, 255, 255, 0.04);
    white-space: nowrap;
    margin-left: 15px;
    text-decoration: none;
}
.cmd-palette-trigger:hover {
    border-color: rgba(255, 255, 255, 0.35);
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
    text-decoration: none;
}
.cmd-palette-trigger i { font-size: 12px; }
.cmd-palette-trigger .cmd-trigger-text { opacity: 0.65; font-size: 12px; }

/* ===== Dark mode ===== */
html.dark .cmd-palette,
body.dark-theme .cmd-palette,
body.premium-dark-theme .cmd-palette {
    background: var(--premium-bg-secondary, #161b22);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.06);
}
html.dark .cmd-palette-input-wrap,
body.dark-theme .cmd-palette-input-wrap,
body.premium-dark-theme .cmd-palette-input-wrap {
    border-bottom-color: var(--premium-border-color, #30363d);
}
html.dark .cmd-palette-input,
body.dark-theme .cmd-palette-input,
body.premium-dark-theme .cmd-palette-input {
    color: var(--premium-text-primary, #e6edf3);
}
html.dark .cmd-palette-item:hover,
html.dark .cmd-palette-item.active,
body.dark-theme .cmd-palette-item:hover,
body.dark-theme .cmd-palette-item.active,
body.premium-dark-theme .cmd-palette-item:hover,
body.premium-dark-theme .cmd-palette-item.active {
    background: rgba(46, 134, 193, 0.12);
}
html.dark .cmd-palette-item--compact .cmd-palette-item-name,
body.dark-theme .cmd-palette-item--compact .cmd-palette-item-name,
body.premium-dark-theme .cmd-palette-item--compact .cmd-palette-item-name {
    color: var(--premium-text-secondary, #b0b7c0);
}
html.dark .cmd-palette-item--compact:hover .cmd-palette-item-name,
html.dark .cmd-palette-item--compact.active .cmd-palette-item-name,
body.dark-theme .cmd-palette-item--compact:hover .cmd-palette-item-name,
body.dark-theme .cmd-palette-item--compact.active .cmd-palette-item-name,
body.premium-dark-theme .cmd-palette-item--compact:hover .cmd-palette-item-name,
body.premium-dark-theme .cmd-palette-item--compact.active .cmd-palette-item-name {
    color: var(--premium-text-primary, #e6edf3);
}
html.dark .cmd-palette-compact-icon,
body.dark-theme .cmd-palette-compact-icon,
body.premium-dark-theme .cmd-palette-compact-icon {
    color: var(--premium-text-muted, #8b949e);
}
html.dark .cmd-palette-item--compact:hover .cmd-palette-compact-icon,
html.dark .cmd-palette-item--compact.active .cmd-palette-compact-icon,
body.dark-theme .cmd-palette-item--compact:hover .cmd-palette-compact-icon,
body.dark-theme .cmd-palette-item--compact.active .cmd-palette-compact-icon,
body.premium-dark-theme .cmd-palette-item--compact:hover .cmd-palette-compact-icon,
body.premium-dark-theme .cmd-palette-item--compact.active .cmd-palette-compact-icon {
    color: #2E86C1;
}
html.dark .cmd-palette-item-icon,
body.dark-theme .cmd-palette-item-icon,
body.premium-dark-theme .cmd-palette-item-icon {
    background: var(--premium-bg-tertiary, #21262d);
}
html.dark .cmd-palette-item-icon i,
body.dark-theme .cmd-palette-item-icon i,
body.premium-dark-theme .cmd-palette-item-icon i {
    color: var(--premium-text-muted, #8b949e);
}
html.dark .cmd-palette-item.active .cmd-palette-item-icon,
html.dark .cmd-palette-item:hover .cmd-palette-item-icon,
body.dark-theme .cmd-palette-item.active .cmd-palette-item-icon,
body.dark-theme .cmd-palette-item:hover .cmd-palette-item-icon,
body.premium-dark-theme .cmd-palette-item.active .cmd-palette-item-icon,
body.premium-dark-theme .cmd-palette-item:hover .cmd-palette-item-icon {
    background: #2E86C1;
}
html.dark .cmd-palette-item.active .cmd-palette-item-icon i,
html.dark .cmd-palette-item:hover .cmd-palette-item-icon i,
body.dark-theme .cmd-palette-item.active .cmd-palette-item-icon i,
body.dark-theme .cmd-palette-item:hover .cmd-palette-item-icon i,
body.premium-dark-theme .cmd-palette-item.active .cmd-palette-item-icon i,
body.premium-dark-theme .cmd-palette-item:hover .cmd-palette-item-icon i {
    color: #fff;
}
html.dark .cmd-palette-item-icon--asset,
body.dark-theme .cmd-palette-item-icon--asset,
body.premium-dark-theme .cmd-palette-item-icon--asset {
    background: rgba(46, 134, 193, 0.15);
}
html.dark .cmd-palette-item-name,
body.dark-theme .cmd-palette-item-name,
body.premium-dark-theme .cmd-palette-item-name {
    color: var(--premium-text-primary, #e6edf3);
}
html.dark .cmd-palette-item-meta,
body.dark-theme .cmd-palette-item-meta,
body.premium-dark-theme .cmd-palette-item-meta {
    color: var(--premium-text-muted, #8b949e);
}
html.dark .cmd-palette-kbd,
body.dark-theme .cmd-palette-kbd,
body.premium-dark-theme .cmd-palette-kbd {
    border-color: var(--premium-border-color, #30363d);
    color: var(--premium-text-muted, #8b949e);
    background: var(--premium-bg-tertiary, #21262d);
}
html.dark .cmd-palette-section,
body.dark-theme .cmd-palette-section,
body.premium-dark-theme .cmd-palette-section {
    color: var(--premium-text-muted, #8b949e);
}
html.dark .cmd-palette-item-arrow,
body.dark-theme .cmd-palette-item-arrow,
body.premium-dark-theme .cmd-palette-item-arrow {
    color: var(--premium-text-muted, #8b949e);
}
html.dark .cmd-palette-results::-webkit-scrollbar-thumb,
body.dark-theme .cmd-palette-results::-webkit-scrollbar-thumb,
body.premium-dark-theme .cmd-palette-results::-webkit-scrollbar-thumb {
    background: var(--premium-border-color, #30363d);
}

/* ===== Mobile ===== */
@media (max-width: 767px) {
    .cmd-palette-backdrop { padding-top: 3vh; }
    .cmd-palette { max-width: calc(100% - 16px); border-radius: 14px; }
    .cmd-palette-columns { grid-template-columns: 1fr; }
    .cmd-palette-results--grid { max-height: 70vh; overflow-y: auto; }
    .cmd-palette-results { max-height: 70vh; }
    .cmd-palette-trigger .cmd-trigger-text,
    .cmd-palette-trigger .cmd-palette-kbd { display: none; }
    .cmd-palette-trigger { padding: 4px 10px; margin-left: 8px; }
    .cmd-palette-item { padding: 8px 14px; margin: 0 6px; }
    .cmd-palette-input-wrap { padding: 12px 14px; }
}
