/* ============================================= */
/* Category Command Palette - Inline Search UI   */
/* Scoped to cashbook page                       */
/* ============================================= */

/* --- Palette Container --- */
body[data-page-context="cashbook"] .cb-category-palette {
    position: relative;
    width: 100%;
}

/* --- Trigger Input (Combobox) --- */
body[data-page-context="cashbook"] .cb-palette-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    border: 1.5px solid var(--gray-300, #d1d5db);
    border-radius: 10px;
    background: var(--white, #fff);
    cursor: text;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    min-height: 44px;
}

body[data-page-context="cashbook"] .cb-palette-trigger:focus-within {
    border-color: var(--primary-color, #0071E3);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

/* Selected category chip inside trigger */
body[data-page-context="cashbook"] .cb-palette-selected {
    display: none;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem;
    background: var(--gray-100, #f3f4f6);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-800, #1f2937);
    white-space: nowrap;
    flex-shrink: 0;
}

body[data-page-context="cashbook"] .cb-palette-selected.visible {
    display: flex;
}

body[data-page-context="cashbook"] .cb-palette-selected .cb-sel-icon {
    font-size: 1rem;
    line-height: 1;
}

body[data-page-context="cashbook"] .cb-palette-selected .cb-sel-code {
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary-color, #0071E3);
}

body[data-page-context="cashbook"] .cb-palette-selected .cb-sel-name {
    color: var(--gray-700, #374151);
}

body[data-page-context="cashbook"] .cb-palette-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    background: var(--gray-300, #d1d5db);
    color: var(--gray-600, #4b5563);
    border-radius: 50%;
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: background 0.15s;
    flex-shrink: 0;
}

body[data-page-context="cashbook"] .cb-palette-clear:hover {
    background: var(--gray-400, #9ca3af);
    color: var(--white, #fff);
}

/* Search input */
body[data-page-context="cashbook"] .cb-palette-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.9375rem;
    color: var(--gray-800, #1f2937);
    min-width: 60px;
    padding: 0;
}

body[data-page-context="cashbook"] .cb-palette-input::placeholder {
    color: var(--gray-400, #9ca3af);
}

/* Keyboard shortcut hint */
body[data-page-context="cashbook"] .cb-palette-kbd {
    display: none;
    padding: 0.125rem 0.375rem;
    background: var(--gray-100, #f3f4f6);
    border: 1px solid var(--gray-300, #d1d5db);
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
    font-size: 0.7rem;
    color: var(--gray-500, #6b7280);
    white-space: nowrap;
    flex-shrink: 0;
}

@media (min-width: 768px) {
    body[data-page-context="cashbook"] .cb-palette-kbd {
        display: inline-block;
    }
}

/* --- Dropdown Panel --- */
body[data-page-context="cashbook"] .cb-palette-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--white, #fff);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
    max-height: 360px;
    overflow: hidden;
    flex-direction: column;
    opacity: 0;
    transform: translateY(-4px);
}

body[data-page-context="cashbook"] .cb-palette-dropdown.open {
    display: flex;
    animation: cbPaletteSlideIn 0.18s ease-out forwards;
}

@keyframes cbPaletteSlideIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Suggestion Banner (inside dropdown) --- */
body[data-page-context="cashbook"] .cb-palette-suggestion {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    border-bottom: 1px solid #a7f3d0;
    font-size: 0.8125rem;
    color: #065f46;
    cursor: pointer;
    transition: background 0.15s;
}

body[data-page-context="cashbook"] .cb-palette-suggestion.visible {
    display: flex;
}

body[data-page-context="cashbook"] .cb-palette-suggestion:hover {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
}

body[data-page-context="cashbook"] .cb-palette-suggestion .cb-sug-label {
    font-weight: 600;
    color: #047857;
    margin-right: 0.25rem;
}

body[data-page-context="cashbook"] .cb-palette-suggestion .cb-sug-btn {
    margin-left: auto;
    padding: 0.125rem 0.5rem;
    background: #059669;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

body[data-page-context="cashbook"] .cb-palette-suggestion .cb-sug-btn:hover {
    background: #047857;
}

/* --- Status Bar --- */
body[data-page-context="cashbook"] .cb-palette-status {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    color: var(--gray-500, #6b7280);
    border-bottom: 1px solid var(--gray-100, #f3f4f6);
}

/* --- Results Area --- */
body[data-page-context="cashbook"] .cb-palette-results {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

/* Group header (sticky) */
body[data-page-context="cashbook"] .cb-palette-group-header {
    position: sticky;
    top: 0;
    padding: 0.375rem 0.75rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500, #6b7280);
    background: var(--gray-50, #f9fafb);
    border-bottom: 1px solid var(--gray-100, #f3f4f6);
    z-index: 1;
}

/* Result item */
body[data-page-context="cashbook"] .cb-palette-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--gray-50, #f9fafb);
}

body[data-page-context="cashbook"] .cb-palette-item:last-child {
    border-bottom: none;
}

body[data-page-context="cashbook"] .cb-palette-item:hover,
body[data-page-context="cashbook"] .cb-palette-item.highlighted {
    background: var(--gray-100, #f3f4f6);
}

body[data-page-context="cashbook"] .cb-palette-item.highlighted {
    background: rgba(0, 113, 227, 0.08);
}

/* Favorite star button */
body[data-page-context="cashbook"] .cb-palette-item .cb-item-star {
    background: none;
    border: none;
    font-size: 0.875rem;
    cursor: pointer;
    padding: 2px;
    opacity: 0.25;
    transition: opacity 0.15s, transform 0.15s;
    flex-shrink: 0;
    line-height: 1;
}

body[data-page-context="cashbook"] .cb-palette-item:hover .cb-item-star,
body[data-page-context="cashbook"] .cb-palette-item .cb-item-star.active {
    opacity: 1;
}

body[data-page-context="cashbook"] .cb-palette-item .cb-item-star:hover {
    transform: scale(1.2);
}

/* Icon */
body[data-page-context="cashbook"] .cb-palette-item .cb-item-icon {
    font-size: 1rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
    line-height: 1;
}

/* Code (monospace) */
body[data-page-context="cashbook"] .cb-palette-item .cb-item-code {
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--primary-color, #0071E3);
    min-width: 36px;
    flex-shrink: 0;
}

/* Name */
body[data-page-context="cashbook"] .cb-palette-item .cb-item-name {
    flex: 1;
    font-size: 0.875rem;
    color: var(--gray-800, #1f2937);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Group badge */
body[data-page-context="cashbook"] .cb-palette-item .cb-item-group {
    display: none;
    padding: 0.0625rem 0.375rem;
    background: var(--gray-100, #f3f4f6);
    border-radius: 4px;
    font-size: 0.6875rem;
    color: var(--gray-500, #6b7280);
    white-space: nowrap;
    flex-shrink: 0;
}

@media (min-width: 480px) {
    body[data-page-context="cashbook"] .cb-palette-item .cb-item-group {
        display: inline-block;
    }
}

/* Checkmark for selected */
body[data-page-context="cashbook"] .cb-palette-item .cb-item-check {
    display: none;
    color: #059669;
    font-size: 0.875rem;
    flex-shrink: 0;
}

body[data-page-context="cashbook"] .cb-palette-item.selected .cb-item-check {
    display: inline;
}

/* Search text highlighting */
body[data-page-context="cashbook"] .cb-palette-item mark {
    background: rgba(16, 185, 129, 0.2);
    color: inherit;
    padding: 0 1px;
    border-radius: 2px;
}

/* --- Empty State --- */
body[data-page-context="cashbook"] .cb-palette-empty {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    color: var(--gray-500, #6b7280);
    text-align: center;
    gap: 0.5rem;
}

body[data-page-context="cashbook"] .cb-palette-empty.visible {
    display: flex;
}

body[data-page-context="cashbook"] .cb-palette-empty .cb-empty-icon {
    font-size: 1.75rem;
    opacity: 0.5;
}

body[data-page-context="cashbook"] .cb-palette-empty .cb-empty-text {
    font-size: 0.875rem;
}

body[data-page-context="cashbook"] .cb-palette-empty .cb-empty-hint {
    font-size: 0.75rem;
    color: var(--gray-400, #9ca3af);
}

/* --- Keyboard Footer --- */
body[data-page-context="cashbook"] .cb-palette-footer {
    display: none;
    align-items: center;
    gap: 1rem;
    padding: 0.375rem 0.75rem;
    border-top: 1px solid var(--gray-100, #f3f4f6);
    background: var(--gray-50, #f9fafb);
    font-size: 0.6875rem;
    color: var(--gray-400, #9ca3af);
    border-radius: 0 0 12px 12px;
}

@media (min-width: 768px) {
    body[data-page-context="cashbook"] .cb-palette-footer {
        display: flex;
    }
}

body[data-page-context="cashbook"] .cb-palette-footer kbd {
    padding: 0.0625rem 0.25rem;
    background: var(--white, #fff);
    border: 1px solid var(--gray-300, #d1d5db);
    border-radius: 3px;
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
    font-size: 0.625rem;
}

/* --- Auto-Suggest Banner (below palette) --- */
body[data-page-context="cashbook"] .cb-palette-auto-suggest {
    display: none;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    border: 1px solid #a7f3d0;
    border-radius: 8px;
    font-size: 0.8125rem;
    color: #065f46;
    opacity: 0;
    animation: cbAutoSuggestFadeIn 0.3s ease-out forwards;
}

body[data-page-context="cashbook"] .cb-palette-auto-suggest.visible {
    display: flex;
}

@keyframes cbAutoSuggestFadeIn {
    to {
        opacity: 1;
    }
}

body[data-page-context="cashbook"] .cb-palette-auto-suggest .cb-as-label {
    font-weight: 600;
    color: #047857;
}

body[data-page-context="cashbook"] .cb-palette-auto-suggest .cb-as-cat {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

body[data-page-context="cashbook"] .cb-palette-auto-suggest .cb-as-btn {
    margin-left: auto;
    padding: 0.25rem 0.625rem;
    background: #059669;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

body[data-page-context="cashbook"] .cb-palette-auto-suggest .cb-as-btn:hover {
    background: #047857;
}

/* --- Mobile: Bottom Sheet (< 480px) --- */
@media (max-width: 479px) {
    body[data-page-context="cashbook"] .cb-palette-dropdown.open {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        max-height: 70vh;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
        animation: cbPaletteSlideUp 0.25s ease-out forwards;
    }

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

    /* Drag handle for bottom sheet */
    body[data-page-context="cashbook"] .cb-palette-dropdown.open::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: var(--gray-300, #d1d5db);
        border-radius: 2px;
        margin: 0.5rem auto 0.25rem;
        flex-shrink: 0;
    }
}

/* --- Dark Mode --- */
[data-theme="dark"] body[data-page-context="cashbook"] .cb-palette-trigger {
    background: var(--gray-800, #1f2937);
    border-color: var(--gray-600, #4b5563);
    color: var(--gray-200, #e5e7eb);
}

[data-theme="dark"] body[data-page-context="cashbook"] .cb-palette-input {
    color: var(--gray-200, #e5e7eb);
}

[data-theme="dark"] body[data-page-context="cashbook"] .cb-palette-dropdown {
    background: var(--gray-800, #1f2937);
    border-color: var(--gray-600, #4b5563);
}

[data-theme="dark"] body[data-page-context="cashbook"] .cb-palette-item:hover,
[data-theme="dark"] body[data-page-context="cashbook"] .cb-palette-item.highlighted {
    background: var(--gray-700, #374151);
}

[data-theme="dark"] body[data-page-context="cashbook"] .cb-palette-group-header {
    background: var(--gray-900, #111827);
}

[data-theme="dark"] body[data-page-context="cashbook"] .cb-palette-footer {
    background: var(--gray-900, #111827);
}

[data-theme="dark"] body[data-page-context="cashbook"] .cb-palette-selected {
    background: var(--gray-700, #374151);
    color: var(--gray-200, #e5e7eb);
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    body[data-page-context="cashbook"] .cb-palette-dropdown.open {
        animation: none;
        opacity: 1;
        transform: none;
    }

    body[data-page-context="cashbook"] .cb-palette-auto-suggest {
        animation: none;
        opacity: 1;
    }
}
