/*
 * Flettons Chat: the Flettons One look of the CRM, Flettons Plus,
 * Flettons Partner and the client portal (charcoal canvas, layered
 * surfaces, off-white type, a white or black action, Inter), in dark and
 * light. <html data-theme="dark|light"> picks the palette; the little
 * script in each page's <head> sets it before anything draws, from the
 * choice saved on this device (dark to start with, like the apps).
 *
 * The chat page was written as a WhatsApp clone in Tailwind's greys and
 * WhatsApp green. Rather than touch every class in the markup and in the
 * JavaScript that draws messages, this file redraws those classes under
 * html[data-theme], so they all take the Flettons palette at once.
 */

:root,
html[data-theme="dark"] {
    --fl-canvas: #171a1c;
    --fl-deep: #121416;
    --fl-surface: #212528;
    --fl-surface-2: #292e32;
    --fl-surface-3: #31373c;
    --fl-text: #f7f7f5;
    --fl-text-2: #bec3c7;
    --fl-text-3: #8f979c;
    --fl-line: #3a4044;
    --fl-line-strong: #7f898f;
    --fl-action-bg: #f7f7f5;
    --fl-action-fg: #171a1c;
    --fl-action-hover: #e4e5e2;
    --fl-bubble-in: #212528;
    --fl-bubble-out: #3a4044;
    --fl-bubble-out-text: #f7f7f5;
    --fl-highlight: #6ea8fe;
    /* Done and online: the brand white, never green (owner, 1 Nov 2026). */
    --fl-ok: #f7f7f5;
    --fl-ok-soft: rgba(247, 247, 245, 0.10);
    --fl-warn: #e8c15a;
    --fl-warn-soft: rgba(232, 193, 90, 0.14);
    --fl-danger: #ff7b7b;
    --fl-danger-soft: rgba(255, 123, 123, 0.14);
    --fl-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
}

html[data-theme="light"] {
    --fl-canvas: #f4f4f2;
    --fl-deep: #ebebe8;
    --fl-surface: #ffffff;
    --fl-surface-2: #f4f4f2;
    --fl-surface-3: #e6e7e4;
    --fl-text: #171a1c;
    --fl-text-2: #4a5156;
    --fl-text-3: #6b7378;
    --fl-line: #d9dbd8;
    --fl-line-strong: #9aa1a5;
    --fl-action-bg: #171a1c;
    --fl-action-fg: #f7f7f5;
    --fl-action-hover: #3a4044;
    --fl-bubble-in: #ffffff;
    --fl-bubble-out: #171a1c;
    --fl-bubble-out-text: #f7f7f5;
    --fl-highlight: #1d4ed8;
    --fl-ok: #171a1c;
    --fl-ok-soft: rgba(23, 26, 28, 0.06);
    --fl-warn: #a16207;
    --fl-warn-soft: rgba(161, 98, 7, 0.1);
    --fl-danger: #c62828;
    --fl-danger-soft: rgba(198, 40, 40, 0.08);
    --fl-shadow: 0 8px 24px rgba(23, 26, 28, 0.12);
    color-scheme: light;
}

/* ---------------------------------------------------------------- Base */

html[data-theme] body {
    background: var(--fl-canvas) !important;
    color: var(--fl-text);
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif !important;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

html[data-theme] ::selection { background: var(--fl-text); color: var(--fl-canvas); }

html[data-theme] input,
html[data-theme] textarea,
html[data-theme] select,
html[data-theme] button {
    font-family: inherit;
}

html[data-theme] input::placeholder,
html[data-theme] textarea::placeholder {
    color: var(--fl-text-3) !important;
    opacity: 1;
}

/* The Flettons wordmark is white; on the light theme it is drawn black. */
html[data-theme="light"] .fl-wordmark { filter: invert(1); }

.fl-brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.fl-brand .fl-wordmark { display: block; height: 22px; width: auto; }
.fl-brand__label {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.32em;
    color: var(--fl-text-2);
    padding-top: 2px;
}

/* The light / dark switch. */
.fl-theme-toggle {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 0;
    background: transparent;
    color: var(--fl-text-2);
    cursor: pointer;
}
.fl-theme-toggle:hover { background: var(--fl-surface-2); color: var(--fl-text); }
.fl-theme-toggle svg { width: 20px; height: 20px; }
html[data-theme="dark"] .fl-theme-toggle .fl-icon-moon { display: none; }
html[data-theme="light"] .fl-theme-toggle .fl-icon-sun { display: none; }

.fl-powered {
    text-align: center;
    font-size: 11px;
    letter-spacing: 0.3px;
    color: var(--fl-text-3);
}

/* ------------------------------------------------- Tailwind, redrawn */

html[data-theme] .bg-white { background-color: var(--fl-surface) !important; }
html[data-theme] .bg-gray-50,
html[data-theme] .bg-gray-100 { background-color: var(--fl-surface-2) !important; }
html[data-theme] .bg-gray-200,
html[data-theme] .bg-gray-300 { background-color: var(--fl-surface-3) !important; }

html[data-theme] .text-gray-900,
html[data-theme] .text-gray-800,
html[data-theme] .text-gray-700 { color: var(--fl-text) !important; }
html[data-theme] .text-gray-600,
html[data-theme] .text-gray-500 { color: var(--fl-text-2) !important; }
html[data-theme] .text-gray-400 { color: var(--fl-text-3) !important; }

html[data-theme] .border,
html[data-theme] .border-b,
html[data-theme] .border-t,
html[data-theme] .border-l,
html[data-theme] .border-r,
html[data-theme] .border-2,
html[data-theme] .border-gray-200,
html[data-theme] .border-gray-300 { border-color: var(--fl-line) !important; }
html[data-theme] .border-white { border-color: var(--fl-canvas) !important; }

html[data-theme] .hover\:bg-gray-100:hover { background-color: var(--fl-surface-2) !important; }
html[data-theme] .hover\:bg-gray-200:hover { background-color: var(--fl-surface-3) !important; }

html[data-theme] .text-teal-600,
html[data-theme] .hover\:text-blue-600:hover { color: var(--fl-highlight) !important; }
html[data-theme] .focus\:ring-green-400:focus { --tw-ring-color: var(--fl-line-strong) !important; box-shadow: 0 0 0 2px var(--fl-line-strong) !important; }
html[data-theme] .placeholder-gray-500::placeholder { color: var(--fl-text-3) !important; }

/* Greens become the brand white (black in light), reds and yellows the Flettons states. */
html[data-theme] .bg-green-500 { background-color: var(--fl-ok) !important; }
html[data-theme] .bg-green-100,
html[data-theme] .hover\:bg-green-50:hover,
html[data-theme] .hover\:bg-green-200:hover { background-color: var(--fl-ok-soft) !important; }
html[data-theme] .text-green-400,
html[data-theme] .text-green-600,
html[data-theme] .text-green-700 { color: var(--fl-ok) !important; }
html[data-theme] .border-green-200,
html[data-theme] .border-green-500 { border-color: var(--fl-ok) !important; }
html[data-theme] .bg-red-100,
html[data-theme] .hover\:bg-red-200:hover { background-color: var(--fl-danger-soft) !important; }
html[data-theme] .text-red-500,
html[data-theme] .text-red-600,
html[data-theme] .hover\:text-red-600:hover { color: var(--fl-danger) !important; }
html[data-theme] .border-red-200 { border-color: var(--fl-danger) !important; }
html[data-theme] .bg-yellow-100 { background-color: var(--fl-warn-soft) !important; color: var(--fl-text) !important; }

/* Main buttons drawn in pink or green take the Flettons action colour. */
html[data-theme] .bg-pink-600,
html[data-theme] .hover\:bg-green-600:hover {
    background-color: var(--fl-action-bg) !important;
    color: var(--fl-action-fg) !important;
}

/* ------------------------------------------------- The chat page */

html[data-theme] .wa-bg-primary,
html[data-theme] .wa-bg-chat { background: var(--fl-canvas) !important; }
html[data-theme] .wa-text-primary { color: var(--fl-text) !important; }
html[data-theme] .wa-text-secondary { color: var(--fl-text-3) !important; }
html[data-theme] .wa-border { border-color: var(--fl-line) !important; }
html[data-theme] .wa-hover:hover { background: var(--fl-surface) !important; }

html[data-theme] #contactsPane { background: var(--fl-canvas) !important; border-color: var(--fl-line) !important; }
html[data-theme] .contact-item { border-radius: 12px !important; }
html[data-theme] .contact-item.active { background: var(--fl-surface-2) !important; }

html[data-theme] #searchInput {
    background: var(--fl-surface) !important;
    border: 1px solid var(--fl-line) !important;
    color: var(--fl-text) !important;
    border-radius: 10px !important;
}
html[data-theme] #searchInput:focus { border-color: var(--fl-line-strong) !important; }

html[data-theme] #chatPane,
html[data-theme] #messagesArea,
html[data-theme] .chat-bg-pattern { background: var(--fl-deep) !important; }

html[data-theme] #chat-header {
    background: var(--fl-canvas) !important;
    border-bottom: 1px solid var(--fl-line);
    box-shadow: none !important;
}

html[data-theme] #chat-composer {
    background: var(--fl-canvas) !important;
    border-top: 1px solid var(--fl-line);
    box-shadow: none !important;
}
html[data-theme] #chat-composer > div {
    background: var(--fl-surface) !important;
    border-color: var(--fl-line) !important;
    box-shadow: none !important;
}
html[data-theme] #messageInput { background: transparent !important; color: var(--fl-text) !important; }

html[data-theme] #sendBtn { background-color: var(--fl-action-bg) !important; }
html[data-theme] #sendBtn:hover { background-color: var(--fl-action-hover) !important; }
html[data-theme] #sendBtn svg { color: var(--fl-action-fg) !important; }

/* Bubbles: the client's on a raised surface, ours in the strong charcoal. */
html[data-theme] .wa-bg-message-in { background: var(--fl-bubble-in) !important; }
html[data-theme] .wa-bg-message-out { background: var(--fl-bubble-out) !important; }
html[data-theme] .wa-bg-message-out,
html[data-theme] .wa-bg-message-out .wa-text-primary { color: var(--fl-bubble-out-text) !important; }
html[data-theme] .wa-bg-message-out .wa-text-secondary { color: var(--fl-bubble-out-text) !important; opacity: 0.7; }
html[data-theme="light"] .wa-bg-message-in { box-shadow: 0 1px 1px rgba(23, 26, 28, 0.08) !important; }
html[data-theme] .message-tail-in::before { border-color: transparent var(--fl-bubble-in) transparent transparent !important; }
html[data-theme] .message-tail-out::before { border-color: transparent transparent transparent var(--fl-bubble-out) !important; }

html[data-theme] .unread-badge {
    background: var(--fl-action-bg) !important;
    color: var(--fl-action-fg) !important;
}

html[data-theme] .submenu,
html[data-theme] #messageActionMenu,
html[data-theme] .chat-menu-dropdown {
    background: var(--fl-surface) !important;
    border: 1px solid var(--fl-line) !important;
    box-shadow: var(--fl-shadow) !important;
    color: var(--fl-text);
}
html[data-theme] .submenu li { color: var(--fl-text); }
html[data-theme] .submenu li:hover { background: var(--fl-surface-2) !important; }

html[data-theme] #contactSidebar,
html[data-theme] #starredSidebar { background: var(--fl-surface) !important; color: var(--fl-text); }

html[data-theme] .custom-scrollbar::-webkit-scrollbar-thumb { background: var(--fl-line) !important; }
html[data-theme] .custom-scrollbar::-webkit-scrollbar-thumb:hover { background: var(--fl-line-strong) !important; }

/* Pop-ups (SweetAlert). */
html[data-theme] .swal2-popup { background: var(--fl-surface) !important; color: var(--fl-text) !important; border-radius: 14px !important; }
html[data-theme] .swal2-title,
html[data-theme] .swal2-html-container { color: var(--fl-text) !important; }
html[data-theme] .swal2-input,
html[data-theme] .swal2-textarea { background: var(--fl-surface-2) !important; color: var(--fl-text) !important; border-color: var(--fl-line) !important; }
html[data-theme] .swal2-confirm { background: var(--fl-action-bg) !important; color: var(--fl-action-fg) !important; }
html[data-theme] .swal2-cancel-btn { color: var(--fl-text) !important; }
html[data-theme] .swal2-cancel-btn:hover { background: var(--fl-surface-2) !important; }
html[data-theme] .swal2-delete-btn { background: var(--fl-danger) !important; color: #ffffff !important; }

/* ------------------------------------------------- Sign-in page */

.fl-signin {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--fl-canvas);
    color: var(--fl-text);
}
.fl-signin__top { display: flex; justify-content: flex-end; padding: 16px; padding-top: calc(16px + env(safe-area-inset-top, 0px)); }
.fl-signin__main { flex: 1 0 auto; display: grid; place-items: center; padding: 24px 16px 32px; }
.fl-signin__col { width: min(420px, 100%); display: grid; gap: 32px; }
.fl-signin__brand { display: grid; gap: 12px; justify-items: start; }
.fl-signin__brand .fl-wordmark { height: 34px; width: auto; }
.fl-signin__brand .fl-brand__label { font-size: 14px; }
.fl-eyebrow { font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fl-text-2); }
.fl-signin__title { margin: 0; font-size: 2rem; line-height: 1.1; font-weight: 700; letter-spacing: -0.02em; }
.fl-signin form { display: grid; gap: 16px; }
.fl-field { display: grid; gap: 6px; }
.fl-field label { font-size: 14px; font-weight: 500; color: var(--fl-text-2); }
.fl-field input {
    box-sizing: border-box;
    width: 100%;
    min-height: 50px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1.5px solid var(--fl-line-strong);
    background: var(--fl-surface);
    color: var(--fl-text);
    font-size: 16px;
    outline: none;
}
.fl-field input:focus { border-color: var(--fl-text); }
.fl-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 52px;
    padding: 0 24px;
    border-radius: 8px;
    border: 1.5px solid var(--fl-action-bg);
    background: var(--fl-action-bg);
    color: var(--fl-action-fg);
    font-size: 1.02rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
}
.fl-btn:hover { background: var(--fl-action-hover); border-color: var(--fl-action-hover); }
.fl-signin__foot { display: grid; justify-items: center; gap: 4px; padding: 24px 16px 28px; padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)); font-size: 13px; color: var(--fl-text-3); }

/* ------------------------------------------------- Admin pages (Bootstrap) */

html[data-theme] .dashboard-main-wrapper,
html[data-theme] .dashboard-wrapper,
html[data-theme] .dashboard-ecommerce,
html[data-theme] .dashboard-content { background: var(--fl-deep) !important; color: var(--fl-text); }

html[data-theme] .dashboard-header .navbar {
    background: var(--fl-canvas) !important;
    border-bottom: 1px solid var(--fl-line);
    box-shadow: none !important;
    min-height: 64px;
}
html[data-theme] .dashboard-header .navbar-brand { display: inline-flex; align-items: center; }
html[data-theme] .dashboard-header .navbar-toggler-icon { filter: none; }
html[data-theme="dark"] .dashboard-header .navbar-toggler { border-color: var(--fl-line); }

html[data-theme] .nav-left-sidebar,
html[data-theme] .nav-left-sidebar.sidebar-dark { background: var(--fl-canvas) !important; border-right: 1px solid var(--fl-line); }
html[data-theme] .nav-left-sidebar .navbar { background: transparent !important; }
html[data-theme] .nav-left-sidebar .nav-divider { color: var(--fl-text-3) !important; }
html[data-theme] .nav-left-sidebar .navbar-nav .nav-link,
html[data-theme] .nav-left-sidebar .d-xl-none { color: var(--fl-text-2) !important; }
html[data-theme] .nav-left-sidebar .navbar-nav .nav-link:hover,
html[data-theme] .nav-left-sidebar .navbar-nav .nav-link.active {
    background: var(--fl-surface-2) !important;
    color: var(--fl-text) !important;
    border-radius: 8px;
}
html[data-theme] .nav-left-sidebar .navbar-nav .nav-link i { color: inherit !important; }
html[data-theme] .nav-left-sidebar .submenu { background: transparent !important; }

html[data-theme] .card {
    background: var(--fl-surface) !important;
    border: 1px solid var(--fl-line) !important;
    border-radius: 12px !important;
    box-shadow: none !important;
    color: var(--fl-text);
}
html[data-theme] .card-header {
    background: transparent !important;
    border-bottom: 1px solid var(--fl-line) !important;
    color: var(--fl-text) !important;
}
html[data-theme] .card-title,
html[data-theme] .section-title,
html[data-theme] .pageheader-title,
html[data-theme] h1, html[data-theme] h2, html[data-theme] h3,
html[data-theme] h4, html[data-theme] h5, html[data-theme] h6 { color: var(--fl-text) !important; font-family: inherit !important; }
html[data-theme] .text-muted,
html[data-theme] .col-form-label,
html[data-theme] label { color: var(--fl-text-2) !important; }

html[data-theme] .form-control,
html[data-theme] .custom-select,
html[data-theme] .select2-container--default .select2-selection--single,
html[data-theme] .select2-container--default .select2-selection--multiple {
    background: var(--fl-surface-2) !important;
    color: var(--fl-text) !important;
    border: 1px solid var(--fl-line) !important;
    border-radius: 8px !important;
}
html[data-theme] .form-control:focus { border-color: var(--fl-line-strong) !important; box-shadow: none !important; }

html[data-theme] .btn-primary,
html[data-theme] .btn-success {
    background: var(--fl-action-bg) !important;
    border-color: var(--fl-action-bg) !important;
    color: var(--fl-action-fg) !important;
    border-radius: 8px !important;
    font-weight: 600;
}
html[data-theme] .btn-primary:hover,
html[data-theme] .btn-success:hover { background: var(--fl-action-hover) !important; border-color: var(--fl-action-hover) !important; }
html[data-theme] .btn-danger { background: var(--fl-danger) !important; border-color: var(--fl-danger) !important; color: #ffffff !important; border-radius: 8px !important; }
html[data-theme] .btn-secondary,
html[data-theme] .btn-light,
html[data-theme] .btn-outline-primary,
html[data-theme] .dt-buttons .btn {
    background: transparent !important;
    border: 1.5px solid var(--fl-line-strong) !important;
    color: var(--fl-text) !important;
    border-radius: 8px !important;
}

html[data-theme] .table,
html[data-theme] .table th,
html[data-theme] .table td { color: var(--fl-text) !important; border-color: var(--fl-line) !important; }
html[data-theme] .table thead th { background: var(--fl-surface-2) !important; color: var(--fl-text-2) !important; }
html[data-theme] .table-striped tbody tr:nth-of-type(odd) { background: var(--fl-surface-2) !important; }
html[data-theme] .table-bordered { border-color: var(--fl-line) !important; }
html[data-theme] .dataTables_wrapper,
html[data-theme] .dataTables_wrapper label,
html[data-theme] .dataTables_info { color: var(--fl-text-2) !important; }
html[data-theme] .page-link { background: var(--fl-surface) !important; border-color: var(--fl-line) !important; color: var(--fl-text) !important; }
html[data-theme] .page-item.active .page-link { background: var(--fl-action-bg) !important; color: var(--fl-action-fg) !important; }

html[data-theme] .dropdown-menu { background: var(--fl-surface) !important; border: 1px solid var(--fl-line) !important; box-shadow: var(--fl-shadow) !important; }
html[data-theme] .dropdown-item { color: var(--fl-text) !important; }
html[data-theme] .dropdown-item:hover { background: var(--fl-surface-2) !important; }
html[data-theme] .nav-user-info { background: var(--fl-surface-2) !important; }
html[data-theme] .nav-user-name { color: var(--fl-text) !important; }

html[data-theme] .badge-success { background: var(--fl-action-bg) !important; color: var(--fl-action-fg) !important; }

html[data-theme] .footer { background: transparent !important; border-color: var(--fl-line) !important; color: var(--fl-text-3) !important; }

html[data-theme] .navbar-right-top .nav-item { border-color: var(--fl-line) !important; }
html[data-theme] .nav-user-img { color: var(--fl-text-2) !important; font-weight: 500; }
html[data-theme] .nav-user-img:hover { color: var(--fl-text) !important; }

/* The loading spinner is dark grey: drawn light on the dark theme. */
html[data-theme="dark"] .loading-image { filter: invert(1); }

/* The scroll-to-latest button: the brand action, white on charcoal or black on white, no green. */
html[data-theme] #scrollToBottomBtn { background-color: var(--fl-action-bg) !important; color: var(--fl-action-fg) !important; }
html[data-theme] #scrollToBottomBtn:hover { background-color: var(--fl-action-hover) !important; }
