/* ==========================================================================
   Global Filament Layout Overrides
   Applied on all admin pages via render hook
   ========================================================================== */

/* ── App shell layout ──────────────────────────────────────────── */
/* Header fixed across top. Sidebar, content, messenger are columns below. */
/* Only the content area scrolls. */
.fi-topbar {
    position: fixed !important;
    top: 0 !important;
    left: 13rem !important;
    right: 0 !important;
    z-index: 50 !important;
}
.fi-layout {
    height: 100vh !important;
    overflow: hidden !important;
}
.fi-main-ctn {
    display: flex !important;
    flex-direction: column !important;
    height: 100vh !important;
    overflow: hidden !important;
    padding-top: 4rem !important;
}
.fi-main {
    flex: 1 1 0% !important;
    overflow-y: auto !important;
    min-height: 0 !important;
}

/* Reduce gap between topbar and page content (Filament's py-8 → 1rem) */
.fi-page > section.py-8,
.fi-main section.py-8 {
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
}

/* Reduce content area padding */
.fi-layout .fi-main-ctn .md\:px-6 {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
}
.fi-layout .fi-main-ctn .lg\:px-8 {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
}

/* Tighten the left sidebar */
.fi-layout .fi-sidebar {
    width: 13rem !important;
}
.fi-layout .fi-sidebar .fi-sidebar-nav {
    padding-left: 1.5rem !important;
    padding-right: 0 !important;
}

/* Reduce vertical spacing between sidebar nav groups */
.fi-layout .fi-sidebar .fi-sidebar-group {
    gap: 0 !important;
}
.fi-layout .fi-sidebar .fi-sidebar-group + .fi-sidebar-group {
    margin-top: 0.5rem !important;
}
.fi-layout .fi-sidebar .fi-sidebar-nav > ul {
    gap: 0.5rem !important;
}

/* Quick-create "+" badges on CRM sidebar items */
.fi-sidebar-item a[href$="/leads"] .fi-badge,
.fi-sidebar-item a[href$="/deals"] .fi-badge,
.fi-sidebar-item a[href$="/contacts"] .fi-badge,
.fi-sidebar-item a[href$="/companies"] .fi-badge {
    cursor: pointer;
    transition: opacity 0.15s;
}
.fi-sidebar-item a[href$="/leads"] .fi-badge:hover,
.fi-sidebar-item a[href$="/deals"] .fi-badge:hover,
.fi-sidebar-item a[href$="/contacts"] .fi-badge:hover,
.fi-sidebar-item a[href$="/companies"] .fi-badge:hover {
    opacity: 0.7;
}

/* ==========================================================================
   Global Search — compact results with entity-type pills
   ========================================================================== */

/* ── Container ── */
.cb-search-results {
    max-height: 70vh !important;
    width: 42rem !important;
    max-width: 42rem !important;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
.cb-search-results::-webkit-scrollbar { width: 5px; }
.cb-search-results::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.cb-search-results::-webkit-scrollbar-track { background: transparent; }

/* ── Group list ── */
.cb-search-groups {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* ── Group header (sticky) ── */
.cb-search-group__header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}
.cb-search-group + .cb-search-group .cb-search-group__header {
    border-top: 1px solid #e2e8f0;
}

/* ── Type pills ── */
.cb-search-group__pill {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.025em;
    text-transform: uppercase;
    line-height: 1.4;
}
.cb-pill--deal {
    background: #dbeafe;
    color: #1e40af;
}
.cb-pill--contact {
    background: #dcfce7;
    color: #166534;
}
.cb-pill--company {
    background: #f3e8ff;
    color: #6b21a8;
}
.cb-pill--lead {
    background: #fef3c7;
    color: #92400e;
}

/* ── Result count badge ── */
.cb-search-group__count {
    font-size: 0.625rem;
    font-weight: 500;
    color: #94a3b8;
    line-height: 1;
}

/* ── Result list ── */
.cb-search-group__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* ── Individual result ── */
.cb-search-result {
    transition: background 100ms;
}
.cb-search-result:hover,
.cb-search-result:focus-within {
    background: #f1f5f9;
}

/* Color-coded left border per entity type */
.cb-search-group--deal .cb-search-result { border-left: 3px solid #3b82f6; }
.cb-search-group--contact .cb-search-result { border-left: 3px solid #22c55e; }
.cb-search-group--company .cb-search-result { border-left: 3px solid #a855f7; }
.cb-search-group--lead .cb-search-result { border-left: 3px solid #f59e0b; }

.cb-search-result + .cb-search-result {
    border-top: 1px solid #f1f5f9;
}

/* ── Result link ── */
.cb-search-result__link {
    display: block;
    padding: 0.5rem 0.75rem;
    text-decoration: none;
    outline: none;
}

/* ── Title ── */
.cb-search-result__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Details row (inline flow) ── */
.cb-search-result__details {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.125rem 0.375rem;
    margin-top: 0.125rem;
}

/* Plain text detail */
.cb-search-detail {
    font-size: 0.8125rem;
    line-height: 1.3;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Separator dot between plain details */
.cb-search-detail + .cb-search-detail::before {
    content: '\00b7';
    margin-right: 0.375rem;
    color: #cbd5e1;
    font-weight: 700;
}

/* Inline pill (stage, status) */
.cb-search-detail-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.0625rem 0.4rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1.4;
    background: #f1f5f9;
    color: #475569;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Dark mode ── */
.dark .cb-search-results {
    scrollbar-color: #475569 transparent;
}
.dark .cb-search-results::-webkit-scrollbar-thumb { background: #475569; }

.dark .cb-search-group__header {
    background: #1e293b;
    border-bottom-color: #334155;
}
.dark .cb-search-group + .cb-search-group .cb-search-group__header {
    border-top-color: #334155;
}

.dark .cb-pill--deal { background: #1e3a5f; color: #93c5fd; }
.dark .cb-pill--contact { background: #14532d; color: #86efac; }
.dark .cb-pill--company { background: #3b0764; color: #d8b4fe; }
.dark .cb-pill--lead { background: #451a03; color: #fcd34d; }

.dark .cb-search-group__count { color: #64748b; }

.dark .cb-search-result:hover,
.dark .cb-search-result:focus-within {
    background: #1e293b;
}
.dark .cb-search-result + .cb-search-result {
    border-top-color: #1e293b;
}

.dark .cb-search-result__title {
    color: #f1f5f9;
}

.dark .cb-search-detail {
    color: #94a3b8;
}
.dark .cb-search-detail + .cb-search-detail::before {
    color: #475569;
}

.dark .cb-search-detail-pill {
    background: #334155;
    color: #cbd5e1;
}

/* ── No results ── */
.fi-global-search-no-results-message {
    padding: 1.5rem 0.75rem;
    text-align: center;
    font-size: 0.8125rem;
    color: #94a3b8;
}

/* ---------------------------------------------------------------------------
   Chat Image Preview & Lightbox (used in entity chat + messenger)
   --------------------------------------------------------------------------- */
.chat-img-wrap {
    position: relative;
    display: inline-block;
    max-width: 400px;
}
.chat-img-preview {
    display: block;
    max-width: 400px;
    max-height: 300px;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    cursor: pointer;
    object-fit: cover;
    transition: opacity 0.15s;
}
.chat-img-preview:hover {
    opacity: 0.85;
}
.dark .chat-img-preview {
    border-color: #374151;
}
.chat-img-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.25rem;
    font-size: 0.6875rem;
    color: #9ca3af;
}
.chat-img-dl {
    color: #9ca3af;
    transition: color 0.15s;
}
.chat-img-dl:hover {
    color: #6b7280;
}

/* Lightbox */
.chat-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    cursor: pointer;
}
.chat-lightbox__img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 0.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    cursor: default;
}
.chat-lightbox__close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    padding: 0.5rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}
.chat-lightbox__close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ── Chat Message Bunching & Own/Other Styling ──────────────── */
.chat-msg {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}
.chat-msg__avatar {
    flex-shrink: 0;
}
.chat-msg__bubble {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
}
.chat-msg__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.chat-msg__actions {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-top: 0.25rem;
}

/* Other messages: avatar left, light gray bubble */
.chat-msg--other .chat-msg__bubble {
    background: #f9fafb;
    border: 1px solid #f3f4f6;
}
.dark .chat-msg--other .chat-msg__bubble {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.06);
}

/* Own messages: blue bubble, right-aligned actions */
.chat-msg--own .chat-msg__bubble {
    background: #eff6ff;
    border: 1px solid #dbeafe;
}
.dark .chat-msg--own .chat-msg__bubble {
    background: rgba(59, 130, 246, 0.08);
    border-color: rgba(59, 130, 246, 0.15);
}
.chat-msg--own .chat-msg__actions {
    justify-content: flex-end;
}

/* Grouped messages: tight spacing, hide repeated avatar/name */
.chat-msg--grouped {
    margin-top: 2px !important;
}
.chat-msg--grouped .chat-msg__header {
    display: none;
}
.chat-msg--grouped .chat-msg__avatar {
    visibility: hidden;
}
.chat-msg--grouped .chat-msg__bubble {
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
}

/* ── Chat Reactions & Toolbar ────────────────────────────────── */

/* Reaction pills below message content */
.chat-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 5px;
}
.chat-reaction-pill {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    border-radius: 999px;
    border: 1.5px solid #e5e7eb;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    line-height: 1;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.chat-reaction-pill:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
    border-color: #d1d5db;
}
.chat-reaction-pill:active {
    transform: scale(0.95);
}
.chat-reaction-pill--active {
    background: #eff6ff;
    border-color: #60a5fa;
    box-shadow: 0 1px 4px rgba(59, 130, 246, 0.15);
}
.chat-reaction-pill--active:hover {
    background: #dbeafe;
    box-shadow: 0 3px 8px rgba(59, 130, 246, 0.2);
}
.chat-reaction-pill__emoji {
    font-size: 0.875rem;
    line-height: 1;
}
.chat-reaction-pill__count {
    font-size: 0.625rem;
    color: #6b7280;
    font-weight: 600;
    min-width: 0.5rem;
    text-align: center;
}
.chat-reaction-pill--active .chat-reaction-pill__count {
    color: #2563eb;
}

/* Dark mode pills */
.dark .chat-reaction-pill {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.dark .chat-reaction-pill:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.18);
}
.dark .chat-reaction-pill--active {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(96, 165, 250, 0.4);
}
.dark .chat-reaction-pill--active:hover {
    background: rgba(59, 130, 246, 0.25);
}
.dark .chat-reaction-pill__count { color: #9ca3af; }
.dark .chat-reaction-pill--active .chat-reaction-pill__count { color: #60a5fa; }

/* ── Floating Toolbar (appears on message hover) ── */
.chat-toolbar {
    position: absolute;
    top: -4px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 1px;
    padding: 2px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.02);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
    transform: translateY(4px);
    z-index: 20;
}
.chat-msg:hover .chat-toolbar,
.chat-toolbar:has([x-show]:not([style*="display: none"])) {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
.dark .chat-toolbar {
    background: #1f2937;
    border-color: #374151;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Toolbar always right-aligned — messages are left-aligned so toolbar doesn't cover text */

.chat-toolbar__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 26px;
    border-radius: 6px;
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    transition: all 0.15s;
}
.chat-toolbar__btn:hover {
    background: #f3f4f6;
    color: #6b7280;
}
.chat-toolbar__btn--react:hover {
    color: #f59e0b;
    background: #fefce8;
}
.chat-toolbar__btn--danger:hover {
    color: #ef4444;
    background: #fef2f2;
}
.dark .chat-toolbar__btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #d1d5db;
}
.dark .chat-toolbar__btn--react:hover {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.1);
}
.dark .chat-toolbar__btn--danger:hover {
    color: #f87171;
    background: rgba(239, 68, 68, 0.1);
}
.chat-toolbar__icon {
    width: 0.875rem;
    height: 0.875rem;
}

/* ── Emoji Picker Popup ── */
.chat-reaction-picker {
    position: absolute;
    bottom: calc(100% + 4px);
    right: 0;
    display: flex;
    gap: 2px;
    padding: 5px 7px;
    background: #ffffff;
    border-radius: 24px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.04);
    z-index: 50;
    white-space: nowrap;
    backdrop-filter: blur(12px);
}
.dark .chat-reaction-picker {
    background: rgba(31, 41, 55, 0.95);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.chat-reaction-emoji {
    font-size: 1.375rem;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.15s;
    background: none;
    border: none;
    line-height: 1;
    position: relative;
}
.chat-reaction-emoji:hover {
    transform: scale(1.4) translateY(-4px);
    background: #f3f4f6;
}
.chat-reaction-emoji:active {
    transform: scale(1.1);
}
.dark .chat-reaction-emoji:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Dot indicator for emojis you've already picked */
.chat-reaction-emoji--picked::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #3b82f6;
}

/* Bubble needs relative positioning for toolbar */
.chat-msg__bubble {
    position: relative;
}

/* Hide old actions row — replaced by toolbar */
.chat-msg__actions {
    display: none;
}

/* ── Chat Priority Toggle ────────────────────────────────────── */
.chat-priority-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 16px;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    border-radius: 3px;
}
.chat-msg:hover .chat-priority-toggle,
.chat-priority-toggle:focus {
    opacity: 0.5;
}
.chat-priority-toggle:hover {
    opacity: 1 !important;
}
/* Always show the icon when priority is set (not normal) */
.chat-priority-toggle:has(svg) {
    opacity: 1;
}
/* The subtle dot shown for normal priority (only visible on hover) */
.chat-priority-dot {
    display: block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #d1d5db;
}
.dark .chat-priority-dot {
    background: #4b5563;
}
/* Non-clickable badge for non-owners */
.chat-priority-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 16px;
}

/* ── Victory AI Chat ─────────────────────────────────────────── */
/* Victory styling now applies to the bubble, not the outer flex container */
.chat-msg.victory-message .chat-msg__bubble {
    background: rgba(99, 102, 241, 0.04);
    border-color: rgba(99, 102, 241, 0.1);
}
.dark .chat-msg.victory-message .chat-msg__bubble {
    background: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.15);
}
.victory-bot-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    font-size: 10px;
    font-weight: 600;
    color: #6366f1;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.dark .victory-bot-badge {
    color: #818cf8;
    background: rgba(99, 102, 241, 0.2);
}
/* Markdown rendering inside Victory messages */
.victory-message p { margin: 0.25rem 0; }
.victory-message p:first-child { margin-top: 0; }
.victory-message p:last-child { margin-bottom: 0; }
.victory-message strong { font-weight: 600; }
.victory-message ul, .victory-message ol { margin: 0.25rem 0 0.75rem; padding-left: 0; list-style: none; }
.victory-message li { margin: 0.125rem 0; padding-left: 1rem; position: relative; }
.victory-message ul > li::before { content: '\203A'; position: absolute; left: 0; color: #6366f1; font-weight: 700; }
.victory-message ol { counter-reset: victory-ol; }
.victory-message ol > li { counter-increment: victory-ol; }
.victory-message ol > li::before { content: counter(victory-ol) '.'; position: absolute; left: 0; color: #6366f1; font-weight: 600; font-size: 0.8em; }
.victory-message h1, .victory-message h2, .victory-message h3 { font-weight: 600; margin: 0.5rem 0 0.25rem; }
.victory-message h3 { font-size: 0.875rem; }
.victory-message hr { border-color: rgba(99, 102, 241, 0.2); margin: 0.5rem 0; }
.victory-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    color: #6366f1;
    font-size: 13px;
    font-style: italic;
}
.dark .victory-typing-indicator {
    color: #818cf8;
}
.victory-typing-dot {
    width: 6px;
    height: 6px;
    background: #6366f1;
    border-radius: 50%;
    animation: victory-bounce 1.4s infinite ease-in-out;
}
.dark .victory-typing-dot {
    background: #818cf8;
}
.victory-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.victory-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes victory-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ── Address autocomplete (Google Places) ─────────────────────── */
.address-autocomplete-wrap {
    min-height: 2.25rem;
}
.address-autocomplete-wrap gmp-place-autocomplete {
    width: 100%;
    font-size: 0.875rem;
}
/* Google Places dropdown must render above Filament modals */
.pac-container {
    z-index: 99999 !important;
}

/* ── Dark mode: native form elements ─────────────────────────── */
/* Native selects, inputs, and textareas that aren't Filament-managed */
.dark select,
.dark input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not(.fi-input),
.dark textarea:not(.fi-input) {
    color-scheme: dark;
    background-color: #111827;
    color: #f9fafb;
    border-color: #374151;
}
.dark select option {
    background-color: #1f2937;
    color: #f9fafb;
}
.dark select:focus,
.dark input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not(.fi-input):focus,
.dark textarea:not(.fi-input):focus {
    border-color: var(--c-500, #6366f1);
}
