/* Real Estate CRM - Modern Theme (brand primary RGB 133, 78, 242 — #854ef2) */

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --menu-primary: #854ef2;
    --brand-rgb: 133, 78, 242;
    --brand-600: #854ef2;
    --brand-500: #a270f8;
    --brand-700: #7240d8;
    --card-bg: rgba(30, 41, 59, 0.8);
    --card-border: rgba(148, 163, 184, 0.1);
    --rainbow-gradient: linear-gradient(90deg,
        #ff0000 0%, #ff8000 14%, #ffff00 28%, #80ff00 42%,
        #00ff00 57%, #00ff80 71%, #00ffff 85%, #0080ff 100%
    );
}

body.dark, .dark {
    background: #0f172a !important;
    color: #f8fafc !important;
}

html, body { overflow-x: hidden; }

.app-logo, .app-favicon { object-fit: contain !important; max-width: 100%; max-height: 100%; }

/* Rainbow Card - Animated border, dark theme */
.rainbow-card, .stat-card {
    position: relative;
    background: #1e293b !important;
    color: #f8fafc !important;
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid rgba(148, 163, 184, 0.12);
    overflow: hidden;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.rainbow-card h2, .rainbow-card h3, .rainbow-card p, .rainbow-card span, .rainbow-card a,
.rainbow-card td, .rainbow-card th, .rainbow-card label,
.stat-card h2, .stat-card h3, .stat-card p, .stat-card span, .stat-card a,
.stat-card td, .stat-card th, .stat-card label { color: #f8fafc !important; }

.rainbow-card .text-gray-400, .rainbow-card .text-gray-500, .rainbow-card th,
.stat-card .text-gray-400, .stat-card .text-gray-500, .stat-card th { color: #94a3b8 !important; }

.rainbow-card a:hover, .stat-card a:hover { color: #d4b8ff !important; }

.rainbow-card .text-purple-400, .stat-card .text-purple-400 { color: #bc97fb !important; }
.rainbow-card .text-blue-400, .stat-card .text-blue-400 { color: #60a5fa !important; }
.rainbow-card .text-green-500, .stat-card .text-green-500 { color: #34d399 !important; }
.rainbow-card .text-amber-400, .stat-card .text-amber-400 { color: #fbbf24 !important; }
.rainbow-card .text-emerald-400, .stat-card .text-emerald-400 { color: #34d399 !important; }

.rainbow-card::before, .stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--rainbow-gradient);
    background-size: 200% 100%;
    animation: rainbow-flow 3s linear infinite;
}

@keyframes rainbow-flow {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

.rainbow-card:hover, .stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
}

.rainbow-card:hover::before, .stat-card:hover::before {
    animation-duration: 1.5s;
    height: 2px;
}

.sidebar-gradient {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%) !important;
    border-right: 1px solid rgba(148, 163, 184, 0.1);
}

.sidebar-gradient .menu-heading { color: #bc97fb !important; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.75rem; }

body:not(.dark) .rainbow-card, body:not(.dark) .stat-card {
    background: #1e293b !important;
    color: #f8fafc !important;
    border: 1px solid rgba(148, 163, 184, 0.15);
}

.btn-primary {
    background: linear-gradient(135deg, rgba(var(--brand-rgb), 0.92) 0%, rgba(var(--brand-rgb), 0.72) 100%);
    color: white !important;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 50px;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.35),
        inset 0 -2px 4px rgba(0, 0, 0, 0.28),
        0 4px 14px rgba(0, 0, 0, 0.25);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.35),
        inset 0 -2px 4px rgba(0, 0, 0, 0.28),
        0 8px 20px rgba(var(--brand-rgb), 0.35);
    color: white !important;
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
}

.form-input {
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    color: #111827;
    padding: 0.75rem 1rem;
    width: 100%;
}

.dark .form-input { background: #374151; border-color: #4b5563; color: #f9fafb; }
.form-input:focus { outline: none; border-color: #854ef2; box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.22); }
select.form-input { appearance: menulist; cursor: pointer; min-height: 2.5rem; }

/* ── Draggable scrollbars ── */
:root {
    --scrollbar-size: 14px;
    --scrollbar-track: #1e293b;
    --scrollbar-thumb: #64748b;
    --scrollbar-thumb-hover: #94a3b8;
    --scrollbar-thumb-active: #cbd5e1;
}

html {
    scrollbar-width: auto;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

* {
    scrollbar-width: auto;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

::-webkit-scrollbar {
    width: var(--scrollbar-size);
    height: var(--scrollbar-size);
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}

::-webkit-scrollbar-thumb:active {
    background-color: var(--scrollbar-thumb-active);
}

::-webkit-scrollbar-corner {
    background: var(--scrollbar-track);
}

#main-content-scroll,
.sidebar-menu-scroll,
.app-footer,
.overflow-y-auto,
.feenix-scroll-y,
.team-chat-room-list,
.team-chat-messages,
.team-chat-emoji-panel,
#chat-messages,
#mobile-nav-wrap,
[style*="overflow-y: auto"],
[style*="overflow-y:scroll"] {
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.table-responsive,
.mobile-scroll-x,
.filter-chip-row,
.tab-scroll-row,
.mobile-tab-row,
#leads-board,
.app-header-toolbar,
.team-chat-filter-row,
.overflow-x-auto,
.overflow-auto,
.feenix-scroll-x,
.feenix-scroll,
[style*="overflow-x: auto"],
[style*="overflow-x:scroll"] {
    scrollbar-gutter: auto;
    -webkit-overflow-scrolling: touch;
}

.feenix-scroll-y {
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
}

.feenix-scroll-x {
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
}

.feenix-scroll {
    overflow: auto;
    touch-action: pan-x pan-y;
}

.scrollbar-drag-active {
    cursor: grabbing !important;
    user-select: none !important;
}

@media (pointer: coarse), (max-width: 768px) {
    :root { --scrollbar-size: 12px; }
}

@media (max-width: 640px) { .rainbow-card, .stat-card { padding: 1rem; } }

/* Dashboard stat grid — responsive layout & fluid type on all screen sizes */
.dashboard-stat-grid {
    width: 100%;
    min-width: 0;
}
.dashboard-stat-grid .stat-card {
    container-type: inline-size;
    container-name: dash-stat;
    min-width: 0;
    padding: clamp(0.75rem, 2.5vw, 1.25rem) !important;
}
.dashboard-stat-grid .stat-card > .flex.items-center {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    column-gap: clamp(0.25rem, 1.5vw, 0.5rem);
    row-gap: 0.125rem;
    align-items: start;
    min-width: 0;
}
.dashboard-stat-grid .stat-card > .flex > .min-w-0 {
    display: contents;
}
.dashboard-stat-grid .stat-card > .flex > .min-w-0 > .text-sm,
.dashboard-stat-grid .stat-card > .flex > .min-w-0 > .stat-card-label {
    grid-column: 1;
    grid-row: 1;
    font-size: clamp(0.6875rem, 2.8cqi, 0.8125rem);
    line-height: 1.25;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    align-self: center;
}
.dashboard-stat-grid .stat-card > .flex > .min-w-0 > .text-xs {
    grid-column: 1 / -1;
    grid-row: 3;
    font-size: clamp(0.625rem, 2.4cqi, 0.75rem);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dashboard-stat-grid .stat-card > .flex > .min-w-0 > .stat-card-value {
    grid-column: 1 / -1;
    grid-row: 2;
    margin-top: 0.125rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: clamp(15px, 6cqi, 20px);
    font-weight: 700;
    line-height: 1.25;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}
@supports not (container-type: inline-size) {
    .dashboard-stat-grid .stat-card > .flex > .min-w-0 > .stat-card-value {
        font-size: clamp(15px, 1.4vw + 0.65rem, 18px);
    }
}
.dashboard-stat-grid .stat-card > a {
    font-size: clamp(0.6875rem, 2.5cqi, 0.8125rem);
    margin-top: 0.5rem;
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dashboard-stat-grid .stat-card > .flex > div.w-12,
.dashboard-stat-grid .stat-card > .flex > .stat-card-icon {
    grid-column: 2;
    grid-row: 1;
    width: clamp(1.5rem, 8cqi, 1.875rem) !important;
    height: clamp(1.5rem, 8cqi, 1.875rem) !important;
    min-width: 1.5rem;
    min-height: 1.5rem;
    border-radius: 0.5rem;
    align-self: center;
    flex-shrink: 0;
}
.dashboard-stat-grid .stat-card > .flex > div.w-12 i,
.dashboard-stat-grid .stat-card > .flex > .stat-card-icon i {
    font-size: clamp(0.6875rem, 4cqi, 0.875rem) !important;
}
/* Viewport fallbacks when cards are very narrow (many columns) or very wide (mobile) */
@media (max-width: 639px) {
    .dashboard-stat-grid .stat-card > .flex > .min-w-0 > .stat-card-value {
        font-size: clamp(17px, 4.5vw, 20px);
    }
}
@media (min-width: 640px) and (max-width: 1023px) {
    .dashboard-stat-grid .stat-card > .flex > .min-w-0 > .stat-card-value {
        font-size: clamp(16px, 2.2vw, 18px);
    }
}
@media (min-width: 1024px) and (max-width: 1535px) {
    .dashboard-stat-grid .stat-card > .flex > .min-w-0 > .stat-card-value {
        font-size: clamp(15px, 1.1vw, 17px);
    }
}
@media (min-width: 1536px) {
    .dashboard-stat-grid .stat-card > .flex > .min-w-0 > .stat-card-value {
        font-size: clamp(16px, 5.5cqi, 18px);
    }
}
@media (max-width: 1023px) {
    .dashboard-stat-grid .stat-card:hover {
        transform: none;
        box-shadow: none;
    }
}
.sidebar-menu-scroll { flex: 1 1 0; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 768px) {
    .hero-slider .hero-prev, .hero-slider .hero-next { width: 40px; height: 40px; left: 8px; right: 8px; font-size: 0.875rem; }
}
@media (max-width: 640px) {
    .hero-slider .hero-prev, .hero-slider .hero-next { width: 36px; height: 36px; left: 4px; right: 4px; }
}
.table-responsive { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; max-width: 100%; }
.table-responsive table { min-width: 600px; width: 100%; }

/* ── Mobile-friendly admin shell ── */
.app-shell-height {
    height: 100dvh;
    height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
}

.app-header-toolbar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.375rem;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    min-width: 0;
}

.app-header-left {
    position: relative;
    z-index: 2;
}

.app-header-row {
    width: 100%;
    min-width: 0;
}

.app-header-toolbar > * {
    flex-shrink: 0;
}

@media (max-width: 1023px) {
    .app-header-toolbar {
        justify-content: flex-end;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        max-width: 100%;
    }

    .global-search-trigger {
        order: -1;
    }

    .app-header-left {
        overflow: hidden;
        min-width: 0;
    }

    .app-header-toolbar .header-action-label {
        display: none;
    }

    .app-header-toolbar .header-action-link,
    .app-header-toolbar .header-action-primary {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem !important;
        margin-right: 0.125rem !important;
    }

    .app-header-toolbar .header-action-link i,
    .app-header-toolbar .header-action-primary i {
        margin-right: 0 !important;
    }

    .app-header-toolbar > a.btn-primary:not(.header-action-primary) {
        font-size: 0;
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .app-header-toolbar > a.btn-primary:not(.header-action-primary) i {
        font-size: 0.875rem;
        margin-right: 0 !important;
    }

    .app-header-toolbar .btn-primary {
        white-space: nowrap;
        font-size: 0.8125rem;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

@media (max-width: 768px) {
    .btn-primary,
    .form-input,
    select.form-input,
    button[type="submit"],
    a.btn-primary {
        min-height: 44px;
    }

    #main-content-scroll .grid.grid-cols-2:not(.dashboard-stat-grid),
    #main-content-scroll .grid.grid-cols-3,
    #main-content-scroll .grid.grid-cols-4,
    #main-content-scroll .grid.md\:grid-cols-2,
    #main-content-scroll .grid.md\:grid-cols-3,
    #main-content-scroll .grid.lg\:grid-cols-3,
    #main-content-scroll .grid.lg\:grid-cols-4 {
        grid-template-columns: 1fr;
    }

    #main-content-scroll .flex.flex-wrap.gap-4 > .rainbow-card,
    #main-content-scroll .flex.flex-wrap.gap-4 > .stat-card {
        width: 100%;
    }

    .rainbow-card .overflow-x-auto,
    .stat-card .overflow-x-auto {
        margin-left: -0.25rem;
        margin-right: -0.25rem;
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }
}

@media screen and (max-width: 1023px) {
    #mobile-nav-wrap {
        max-height: min(70dvh, calc(100dvh - 5rem));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
}

.auth-page-body {
    min-height: 100dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

/* Global search modal — full viewport, clear input */
html.global-search-open,
html.global-search-open body {
    overflow: hidden !important;
}

.global-search-overlay {
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.global-search-modal-input {
    display: block !important;
    width: 100% !important;
    min-height: 56px !important;
    font-size: 16px !important;
    line-height: 1.4 !important;
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
    background-color: #ffffff !important;
    border: 2px solid #a855f7 !important;
    box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.25), 0 4px 20px rgba(0, 0, 0, 0.35) !important;
    border-radius: 12px !important;
    caret-color: #7c3aed;
}

.global-search-modal-input:focus {
    outline: none !important;
    border-color: #7c3aed !important;
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.35), 0 4px 24px rgba(0, 0, 0, 0.4) !important;
}

.global-search-modal-input::placeholder {
    color: #64748b !important;
    opacity: 1 !important;
}

.global-search-panel {
    max-height: min(90dvh, 640px);
    display: flex;
    flex-direction: column;
}

.global-search-panel .feenix-scroll-y {
    flex: 1 1 auto;
    min-height: 120px;
}

/* ── Global glass + embossed buttons ── */
button,
input[type="submit"],
input[type="button"],
input[type="reset"],
a.btn-primary {
    border-radius: 50px !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:not(.btn-primary):not([class*="bg-"]),
input[type="submit"]:not(.btn-primary):not([class*="bg-"]),
input[type="button"]:not([class*="bg-"]) {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.35),
        inset 0 -2px 4px rgba(0, 0, 0, 0.28),
        0 4px 14px rgba(0, 0, 0, 0.25);
}

button:not(.btn-primary)[class*="bg-"],
input[type="submit"]:not(.btn-primary)[class*="bg-"],
input[type="button"][class*="bg-"] {
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.25),
        inset 0 -2px 4px rgba(0, 0, 0, 0.22),
        0 4px 12px rgba(0, 0, 0, 0.2);
}

button:hover:not(:disabled),
input[type="submit"]:hover:not(:disabled),
input[type="button"]:hover:not(:disabled) {
    transform: translateY(-1px);
}

button:active:not(:disabled),
input[type="submit"]:active:not(:disabled),
input[type="button"]:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* ── Sidebar section headings: glass + emboss + individual shadow ── */
.sidebar-gradient summary.menu-heading {
    border-radius: 12px;
    margin: 0.35rem 0.5rem;
    padding: 0.5rem 0.75rem !important;
    background: rgba(255, 255, 255, 0.06) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.14),
        inset 0 -1px 0 rgba(0, 0, 0, 0.35),
        0 4px 10px rgba(0, 0, 0, 0.28);
    text-shadow:
        0 1px 0 rgba(255, 255, 255, 0.12),
        0 -1px 1px rgba(0, 0, 0, 0.45);
}

.sidebar-gradient summary.menu-heading:hover {
    background: rgba(var(--brand-rgb), 0.15) !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        inset 0 -1px 0 rgba(0, 0, 0, 0.3),
        0 6px 14px rgba(var(--brand-rgb), 0.25);
}

.sidebar-gradient .menu-item {
    border-radius: 50px;
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

.sidebar-gradient a.menu-item:hover,
.sidebar-gradient a[class*="menu-item"]:hover {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        0 2px 8px rgba(0, 0, 0, 0.2);
}

.sidebar-gradient a.text-white.bg-purple-600,
.sidebar-gradient a.bg-purple-600 {
    border-radius: 50px !important;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2),
        0 3px 10px rgba(var(--brand-rgb), 0.35);
}

/* Compact sidebar — tighter gaps so all section headers fit without scrolling */
.sidebar-gradient nav {
    margin-top: 0.375rem !important;
    padding-bottom: 0.375rem !important;
}
.sidebar-gradient nav > div.pt-4,
.sidebar-gradient nav details.pt-4,
.sidebar-gradient nav details.group {
    padding-top: 0.125rem !important;
}
.sidebar-gradient summary.menu-heading {
    margin: 0.08rem 0.35rem !important;
    padding: 0.28rem 0.55rem !important;
    border-radius: 8px;
    min-height: 0;
    line-height: 1.25;
}
.sidebar-gradient nav a[class*="py-2"],
.sidebar-gradient nav summary[class*="py-2"] {
    padding-top: 0.3rem !important;
    padding-bottom: 0.3rem !important;
}
.sidebar-gradient nav .mt-1 {
    margin-top: 0.125rem !important;
}
