/*
 * Perfex CRM - Light/Dark theme layer
 * Loaded last (after tailwind.css + style.css) via the core `custom.css` hook
 * in application/helpers/assets_helper.php. Safe to keep across core updates.
 *
 * Mechanism: <html data-theme="light|dark">, toggled by assets/js/theme-toggle.js
 * and persisted in localStorage. Falls back to the OS preference on first visit.
 */

/* ------------------------------------------------------------------ */
/* 1. Design tokens                                                    */
/* ------------------------------------------------------------------ */

/*
 * Almasa Advertising brand palette (exact, client-supplied):
 * Navy #031169, Gold #B78E3B, Light Grey #F5F7FA, with gold gradient
 * accents on primary actions and highlights.
 */
:root {
  --pf-bg: #f5f7fa;
  --pf-surface: #ffffff;
  --pf-surface-alt: #ebeef3;
  --pf-surface-hover: #e1e5ec;
  --pf-border: #e1e5ec;
  --pf-border-strong: #c9d1de;
  --pf-text: #031169;
  --pf-text-secondary: #1e2b5c;
  --pf-text-muted: #6b7280;
  --pf-primary: #b78e3b;
  --pf-primary-hover: #9c7830;
  --pf-primary-fg: #031169;
  --pf-accent: #031169;
  --pf-danger: #dc2626;
  --pf-warning: #d97706;
  --pf-ring: #b78e3b;
  --pf-scrollbar-thumb: #c9d1de;
  --pf-scrollbar-track: transparent;
  --pf-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --pf-navy: #031169;
  --pf-navy-light: #0c1c82;
  --pf-gold: #b78e3b;
  --pf-gold-light: #d4af6a;
  --pf-gold-dark: #9c7830;
  --pf-gold-gradient: linear-gradient(135deg, #d4af6a 0%, #b78e3b 55%, #9c7830 100%);
}

[data-theme="dark"] {
  --pf-bg: #031169;
  --pf-surface: #0c1c82;
  --pf-surface-alt: #020d52;
  --pf-surface-hover: #142694;
  --pf-border: #1b2e8c;
  --pf-border-strong: #2a3d9e;
  --pf-text: #f5f7fa;
  --pf-text-secondary: #c9d1de;
  --pf-text-muted: #8b95c4;
  --pf-primary: #d4af6a;
  --pf-primary-hover: #e3c285;
  --pf-primary-fg: #031169;
  --pf-accent: #d4af6a;
  --pf-danger: #f87171;
  --pf-warning: #fbbf24;
  --pf-ring: #d4af6a;
  --pf-scrollbar-thumb: #2a3d9e;
  --pf-scrollbar-track: transparent;
  --pf-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
  --pf-gold-gradient: linear-gradient(135deg, #e3c285 0%, #d4af6a 55%, #b78e3b 100%);
}

/* Smooth, cheap theme transition (background/color/border only - never layout props) */
html,
body,
#header,
#wrapper,
.sidebar,
.panel,
.panel_s,
.panel-heading,
.panel-body,
.panel-footer,
.dropdown-menu,
.modal-content,
.form-control,
table.dataTable,
.table {
  transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease;
}

@media (prefers-reduced-motion: reduce) {
  html, body, #header, #wrapper, .sidebar, .panel, .panel_s, .panel-heading,
  .panel-body, .panel-footer, .dropdown-menu, .modal-content, .form-control,
  table.dataTable, .table {
    transition: none;
  }
}

/* ------------------------------------------------------------------ */
/* 2. Structural layout                                                */
/* ------------------------------------------------------------------ */

/*
 * !important below: several other installed addon modules (e.g.
 * perfex_dark_theme, perfex_office_theme) load their own theme CSS
 * unconditionally on every page regardless of which theme is actually
 * active, and some of those files load after custom.css in the compiled
 * asset order. !important guarantees the toggle's own light/dark state
 * always wins over those unrelated, non-toggle-aware stylesheets.
 */

[data-theme="dark"] html,
[data-theme="dark"] body {
  background: var(--pf-bg) !important;
  color: var(--pf-text) !important;
}

[data-theme="light"] html,
[data-theme="light"] body {
  background: #f5f7fa !important;
  color: #031169 !important;
}

[data-theme="dark"] #header {
  background: var(--pf-surface) !important;
  border-bottom: 1px solid var(--pf-border);
  box-shadow: var(--pf-shadow);
}

[data-theme="light"] #header {
  background: #ffffff !important;
}

[data-theme="dark"] #header li > a.active {
  background: var(--pf-surface-hover);
  color: var(--pf-text);
}

[data-theme="dark"] .navbar-nav > li > a {
  color: var(--pf-text-muted);
}

[data-theme="dark"] .navbar-nav > li > a:hover,
[data-theme="dark"] .navbar-nav > li > a:focus {
  color: var(--pf-text);
}

[data-theme="dark"] #wrapper {
  background: var(--pf-bg) !important;
}

[data-theme="light"] #wrapper {
  background: #f5f7fa !important;
}

/*
 * The sidebar stays permanently navy (Almasa's brand color, a fixed dark
 * nav rail like most modern admin dashboards) regardless of the light/dark
 * toggle - only the content area (topbar, cards, tables) switches with the
 * toggle. This also sidesteps a pre-existing Perfex quirk where the
 * sidebar's own light/dark text-color logic
 * (is_admin_sidebar_background_light()) can fall out of sync with its
 * actual background, producing near-invisible text.
 */
.sidebar {
  background-color: #031169 !important;
  border-right: 1px solid #1b2e8c;
}

.sidebar ul,
.sidebar ul.nav,
.sidebar .metismenu,
.sidebar ul.nav .nav-second-level,
.sidebar ul.nav li,
.sidebar ul.nav li ul {
  background-color: transparent !important;
}

[dir="rtl"] .sidebar {
  border-left: 1px solid #1b2e8c;
  border-right: 0;
}

.sidebar ul.nav li a {
  color: #8b95c4 !important;
  border-left: 2px solid transparent;
}

[dir="rtl"] .sidebar ul.nav li a {
  border-left: 0;
  border-right: 2px solid transparent;
}

.sidebar ul.nav > li:hover a:first-child,
.sidebar ul.nav > li > a:hover,
.sidebar ul.nav > li > a:focus {
  color: #f5f7fa !important;
  background: #0c1c82;
}

.sidebar ul.nav > li.active a:first-child,
.sidebar ul.nav li.active > a {
  color: #d4af6a !important;
  background: linear-gradient(90deg, rgb(183 142 59 / 0.22) 0%, rgb(183 142 59 / 0.03) 100%);
  border-left-color: #b78e3b;
}

[dir="rtl"] .sidebar ul.nav > li.active a:first-child,
[dir="rtl"] .sidebar ul.nav li.active > a {
  border-left-color: transparent;
  border-right: 2px solid #b78e3b;
}

.sidebar ul.nav li .nav-second-level li a {
  color: #8b95c4 !important;
}

.sidebar ul.nav li .nav-second-level li.active a {
  color: #d4af6a !important;
}

.sidebar ul.nav > li .nav-second-level > li:not(.active) > a:hover,
.sidebar ul.nav > li .nav-second-level > li:not(.active) > a:focus {
  color: #f5f7fa !important;
}

/*
 * The sidebar's main <ul> carries id="side-menu" (a DESCENDANT of
 * aside.sidebar, not the same element - a compound selector like
 * `.sidebar#side-menu` never matches anything real). One of the theme
 * addons uses ID-anchored selectors on it with !important, some qualified
 * with an extra `.admin` class on <body>
 * (e.g. `.admin #side-menu li .nav-second-level li.active a`) - that beats
 * a plain `body #side-menu ...` rule on class count, producing a stray
 * white/grey submenu highlight (e.g. the active "Proposals" row) that
 * clashes with the navy sidebar. Add both .admin and .sidebar as proper
 * ancestors so ours carries more classes than any variant of theirs.
 */
body.admin .sidebar #side-menu li.active > a {
  background: linear-gradient(90deg, rgb(183 142 59 / 0.22) 0%, rgb(183 142 59 / 0.03) 100%) !important;
  color: #d4af6a !important;
}

body.admin .sidebar #side-menu li .nav-second-level li a {
  background: transparent !important;
  color: #8b95c4 !important;
}

body.admin .sidebar #side-menu li .nav-second-level li.active a {
  background: transparent !important;
  color: #d4af6a !important;
}

/*
 * Sidebar item icons: Perfex's own core style.css colors these a mid-gray
 * (#6b7280) meant for a light sidebar background - low contrast against
 * navy, especially in the collapsed/icon-only responsive view. Icons don't
 * inherit color from their parent <a> here since core gives them their own
 * explicit rule, so fix them directly to match the link text treatment.
 */
.sidebar ul.nav li a i.menu-icon {
  color: #8b95c4 !important;
}

.sidebar ul.nav li.active > a .menu-icon,
.sidebar ul.nav > li > a:hover .menu-icon,
.sidebar ul.nav > li > a:focus .menu-icon,
body.admin .sidebar #side-menu li.active > a .menu-icon {
  color: #d4af6a !important;
}

.sidebar ul.nav > li .nav-second-level a .menu-icon {
  color: #8b95c4 !important;
}

.sidebar ul.nav li .nav-second-level a:hover .menu-icon,
.sidebar ul.nav li .nav-second-level a:focus .menu-icon {
  color: #f5f7fa !important;
}

.sidebar-user-profile .tw-text-neutral-500,
.sidebar-user-profile .tw-text-neutral-700 {
  color: #8b95c4 !important;
}

.sidebar-user-profile a.profile {
  color: #f5f7fa !important;
  border-color: rgb(183 142 59 / 0.3) !important;
  background: rgb(183 142 59 / 0.08) !important;
}

/* ------------------------------------------------------------------ */
/* 3. Cards / panels (primary content container across the whole app)  */
/* ------------------------------------------------------------------ */

[data-theme="dark"] .panel,
[data-theme="dark"] .panel_s,
[data-theme="dark"] .widget {
  background: var(--pf-surface) !important;
  border: 1px solid var(--pf-border);
  box-shadow: var(--pf-shadow);
}

[data-theme="dark"] .panel-heading,
[data-theme="dark"] .panel-footer {
  background: var(--pf-surface) !important;
  border-color: var(--pf-border);
  color: var(--pf-text) !important;
}

[data-theme="dark"] .panel-body,
[data-theme="dark"] .panel-table-full,
[data-theme="dark"] .dataTables_wrapper,
[data-theme="dark"] .table-responsive {
  background: var(--pf-surface) !important;
  color: var(--pf-text) !important;
}

[data-theme="light"] .panel,
[data-theme="light"] .panel_s,
[data-theme="light"] .widget,
[data-theme="light"] .panel-heading,
[data-theme="light"] .panel-footer,
[data-theme="light"] .panel-body,
[data-theme="light"] .panel-table-full,
[data-theme="light"] .dataTables_wrapper,
[data-theme="light"] .table-responsive {
  background: #ffffff !important;
  color: #031169 !important;
}

/*
 * Dashboard "quick stats" cards (Invoices Awaiting Payment, Converted
 * Leads, Projects in Progress, Tasks not Finished, etc). Core ships these
 * with a plain white background (style.css: `.top_stats_wrapper { background:
 * #fff }`), but perfex_dark_theme's theme_styles.css overrides it to a
 * hardcoded dark slate (#24344D) UNCONDITIONALLY - not gated by our
 * data-theme toggle at all. Combined with our light-mode text-color
 * safety net (which paints text navy), that produced navy-on-dark-slate:
 * technically rendered, practically invisible. Make the card follow our
 * theme toggle like every other card instead of staying permanently dark.
 */
body#wrapper .top_stats_wrapper,
body #wrapper .top_stats_wrapper {
  background: var(--pf-surface) !important;
}

[data-theme="light"] .top_stats_wrapper,
[data-theme="light"] .top_stats_wrapper * {
  color: #031169 !important;
}

[data-theme="dark"] .top_stats_wrapper,
[data-theme="dark"] .top_stats_wrapper * {
  color: #f5f7fa !important;
}

[data-theme="dark"] .panel_s .hr-panel-heading,
[data-theme="dark"] .panel_s .hr-panel-separator,
[data-theme="dark"] .panel .hr-panel-heading,
[data-theme="dark"] .panel .hr-panel-separator {
  border-color: var(--pf-border);
}

/* ------------------------------------------------------------------ */
/* 3b. Brand primary color (Almasa gold)                               */
/* Perfex's real default .btn-primary is neutral-800 (near-black); the */
/* blue/purple seen before came from another installed theme addon     */
/* overriding it unconditionally. Replace with the Almasa gold brand   */
/* color, in both light and dark mode.                                 */
/* ------------------------------------------------------------------ */

.btn-primary,
.btn-primary:not(:disabled):not(.disabled) {
  background-color: var(--pf-primary) !important;
  background-image: var(--pf-gold-gradient) !important;
  border-color: var(--pf-gold-dark) !important;
  color: var(--pf-primary-fg) !important;
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary.focus,
.btn-primary:active,
.btn-primary.active,
.open > .dropdown-toggle.btn-primary {
  background-color: var(--pf-primary-hover) !important;
  background-image: linear-gradient(135deg, var(--pf-gold) 0%, var(--pf-gold-dark) 100%) !important;
  border-color: var(--pf-gold-dark) !important;
  color: var(--pf-primary-fg) !important;
}

/* Thin gold-gradient accent line under the topbar and above card headers,
   echoing the diagonal gold accent in Almasa's marketing materials. */
#header {
  border-bottom: 2px solid transparent !important;
  border-image: var(--pf-gold-gradient) 1 !important;
}

.panel-heading {
  border-top: 3px solid transparent !important;
  border-image: var(--pf-gold-gradient) 1 !important;
}

.content a:not(.btn),
a.text-primary,
.dropdown-menu > li > a:hover .fa,
.dt-buttons .btn:hover {
  color: var(--pf-primary);
}

[data-theme="dark"] .content a:not(.btn) {
  color: var(--pf-primary);
}

.label-primary,
.badge-primary,
[class*="tw-bg-primary-6"],
[class*="tw-bg-primary-5"],
[class*="tw-bg-primary-7"] {
  background-color: var(--pf-primary) !important;
  color: var(--pf-primary-fg) !important;
}

[class*="tw-text-primary-6"],
[class*="tw-text-primary-5"] {
  color: var(--pf-primary) !important;
}

.form-control:focus,
.pf-theme-toggle:focus-visible {
  border-color: var(--pf-ring) !important;
}

::selection {
  background: var(--pf-gold);
  color: var(--pf-navy);
}

/* ------------------------------------------------------------------ */
/* 4. Tables & DataTables                                              */
/* ------------------------------------------------------------------ */

[data-theme="dark"] .table {
  color: var(--pf-text);
}

[data-theme="dark"] .table > thead > tr > th,
[data-theme="dark"] .table > tbody > tr > th,
[data-theme="dark"] .table > tfoot > tr > th,
[data-theme="dark"] .table > thead > tr > td,
[data-theme="dark"] .table > tbody > tr > td,
[data-theme="dark"] .table > tfoot > tr > td {
  border-color: var(--pf-border);
}

[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) {
  background-color: var(--pf-surface-alt);
}

[data-theme="dark"] .table-hover > tbody > tr:hover {
  background-color: var(--pf-surface-hover);
}

[data-theme="dark"] .dataTables_wrapper .dataTables_info,
[data-theme="dark"] .dataTables_wrapper .dataTables_length,
[data-theme="dark"] .dataTables_wrapper .dataTables_filter {
  color: var(--pf-text-muted);
}

[data-theme="dark"] .dataTables_wrapper .pagination > li > a,
[data-theme="dark"] .dataTables_wrapper .pagination > li > span {
  background: var(--pf-surface);
  border-color: var(--pf-border);
  color: var(--pf-text);
}

[data-theme="dark"] .dataTables_wrapper .pagination > .active > a {
  background: var(--pf-primary);
  border-color: var(--pf-primary);
  color: var(--pf-primary-fg);
}

/* ------------------------------------------------------------------ */
/* 5. Forms                                                             */
/* ------------------------------------------------------------------ */

[data-theme="dark"] .form-control,
[data-theme="dark"] select.form-control,
[data-theme="dark"] textarea.form-control,
[data-theme="dark"] .bootstrap-select .dropdown-toggle,
[data-theme="dark"] .input-group-addon {
  background-color: var(--pf-surface);
  border-color: var(--pf-border);
  color: var(--pf-text);
}

[data-theme="dark"] .form-control:focus {
  border-color: var(--pf-ring);
  box-shadow: 0 0 0 3px rgb(212 178 106 / 0.25);
}

[data-theme="light"] .form-control:focus {
  box-shadow: 0 0 0 3px rgb(183 142 59 / 0.2);
}

[data-theme="dark"] .form-control::placeholder {
  color: var(--pf-text-muted);
}

[data-theme="dark"] .control-label,
[data-theme="dark"] label {
  color: var(--pf-text-secondary);
}

[data-theme="dark"] .text-muted {
  color: var(--pf-text-muted) !important;
}

/* ------------------------------------------------------------------ */
/* 6. Dropdowns & modals                                               */
/* ------------------------------------------------------------------ */

[data-theme="dark"] .dropdown-menu {
  background: var(--pf-surface);
  border-color: var(--pf-border);
  box-shadow: var(--pf-shadow);
}

[data-theme="dark"] .dropdown-menu > li > a {
  color: var(--pf-text);
}

[data-theme="dark"] .dropdown-menu > li > a:hover,
[data-theme="dark"] .dropdown-menu > li > a:focus {
  background: var(--pf-surface-hover);
  color: var(--pf-text);
}

[data-theme="dark"] .dropdown-menu .divider {
  background-color: var(--pf-border);
}

[data-theme="dark"] .modal-content {
  background: var(--pf-surface);
  border-color: var(--pf-border);
}

[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer {
  border-color: var(--pf-border);
}

/* ------------------------------------------------------------------ */
/* 7. Tailwind utility-class retrofit                                  */
/* Perfex ships many views with Tailwind utilities hardcoded in markup */
/* (tw-bg-white, tw-text-neutral-800, ...). Remap the common surface/  */
/* text/border ones so dark mode reaches those views without editing   */
/* every template.                                                     */
/* ------------------------------------------------------------------ */

/*
 * :not(body) below: these are meant to retrofit dark mode onto inner
 * content cards/widgets styled with a raw Tailwind utility class, not
 * the page root - a couple of pages (e.g. login) put a tw-bg-* class
 * directly on <body>, which these would otherwise hijack via a higher
 * specificity than page-specific body rules further down this file.
 */
[data-theme="dark"] [class*="tw-bg-white"]:not(body) {
  background-color: var(--pf-surface) !important;
}

[data-theme="dark"] [class*="tw-bg-neutral-50"]:not(body),
[data-theme="dark"] [class*="tw-bg-neutral-100"]:not(body) {
  background-color: var(--pf-surface-alt) !important;
}

[data-theme="dark"] [class*="tw-bg-neutral-200"]:not(body) {
  background-color: var(--pf-surface-hover) !important;
}

[data-theme="dark"] [class*="tw-text-neutral-800"],
[data-theme="dark"] [class*="tw-text-neutral-900"],
[data-theme="dark"] [class*="tw-text-neutral-700"] {
  color: var(--pf-text) !important;
}

[data-theme="dark"] [class*="tw-text-neutral-600"],
[data-theme="dark"] [class*="tw-text-neutral-500"] {
  color: var(--pf-text-muted) !important;
}

[data-theme="dark"] [class*="tw-border-neutral-300"],
[data-theme="dark"] [class*="tw-border-neutral-200"] {
  border-color: var(--pf-border) !important;
}

/* ------------------------------------------------------------------ */
/* 8. Scrollbars                                                       */
/* ------------------------------------------------------------------ */

[data-theme="dark"] * {
  scrollbar-color: var(--pf-scrollbar-thumb) var(--pf-scrollbar-track);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background-color: var(--pf-scrollbar-thumb);
  border-radius: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
  background-color: var(--pf-scrollbar-track);
}

/* ------------------------------------------------------------------ */
/* 9. Theme toggle control                                             */
/* ------------------------------------------------------------------ */

.pf-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-top: -6px;
  border: 0;
  border-radius: 9999px;
  background: transparent;
  color: var(--pf-text-muted);
  cursor: pointer;
}

.pf-theme-toggle:hover,
.pf-theme-toggle:focus {
  background: rgb(0 0 0 / 0.05);
  color: var(--pf-text);
}

[data-theme="dark"] .pf-theme-toggle:hover,
[data-theme="dark"] .pf-theme-toggle:focus {
  background: rgb(255 255 255 / 0.08);
}

.pf-theme-toggle:focus-visible {
  outline: 2px solid var(--pf-ring);
  outline-offset: 2px;
}

.pf-theme-toggle svg {
  width: 18px;
  height: 18px;
}

.pf-theme-toggle .pf-icon-sun {
  display: none;
}

[data-theme="dark"] .pf-theme-toggle .pf-icon-sun {
  display: block;
}

[data-theme="dark"] .pf-theme-toggle .pf-icon-moon {
  display: none;
}

/* ------------------------------------------------------------------ */
/* 10. Login / auth pages                                              */
/* Three other installed theme addons each ship their own              */
/* staff_login_styles.css for this page (one even sets a hardcoded     */
/* background IMAGE), all loading at once and fighting for control -   */
/* that's the mismatched purple background / faded labels seen before. */
/* This page has no toggle control, so give it one consistent,         */
/* unconditional Almasa-branded look rather than tying it to           */
/* [data-theme]. Selectors carry enough weight to beat those foreign   */
/* stylesheets regardless of their load order.                         */
/* ------------------------------------------------------------------ */

/*
 * html-prefixed selectors below: the three foreign staff_login_styles.css
 * files are injected via the same `app_admin_authentication_head` hook
 * this file also uses for the FOUC guard, and hook registration order
 * (not file load order) decides who ends up last - so they can legally
 * load AFTER custom.css and win a plain specificity tie. Prefixing with
 * `html` raises specificity above their bare `body`/`.class` selectors
 * so ours wins unconditionally, regardless of registration order.
 */

html body.login_admin,
html body.authentication {
  background-image: none !important;
  background-color: #f5f7fa !important;
  position: relative;
}

html body.login_admin::before,
html body.authentication::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: linear-gradient(90deg, #9c7830 0%, #d4af6a 45%, #b78e3b 100%);
  z-index: 30;
}

html .authentication-form-wrapper.authentication-form-wrapper h1 {
  color: #031169 !important;
}

html .authentication-form-wrapper.authentication-form-wrapper p,
html .authentication-form-wrapper.authentication-form-wrapper [class*="tw-text-neutral-600"] {
  color: #6b7280 !important;
}

html .authentication-form-wrapper.authentication-form-wrapper [class*="tw-bg-white"] {
  background-color: #ffffff !important;
  border-color: #e1e5ec !important;
  box-shadow: 0 4px 16px 0 rgb(3 17 105 / 0.08) !important;
}

html .authentication-form-wrapper.authentication-form-wrapper .control-label,
html .authentication-form-wrapper.authentication-form-wrapper label {
  color: #031169 !important;
  opacity: 1 !important;
}

html .authentication-form-wrapper.authentication-form-wrapper .form-control {
  background-color: #ffffff !important;
  border-color: #c9d1de !important;
  color: #031169 !important;
}

html .authentication-form-wrapper.authentication-form-wrapper .form-control:focus {
  border-color: #b78e3b !important;
  box-shadow: 0 0 0 3px rgb(183 142 59 / 0.2) !important;
}

html .authentication-form-wrapper.authentication-form-wrapper a {
  color: #b78e3b !important;
}

html .authentication-form-wrapper.authentication-form-wrapper .text-muted,
html .authentication-form-wrapper.authentication-form-wrapper [class*="tw-text-neutral"]:not(h1):not(h2):not(h3) {
  color: #475569 !important;
}

/* ------------------------------------------------------------------ */
/* 11. Light-mode text-color safety net                                */
/* Some other installed theme addons (not toggle-aware) apply a fixed  */
/* near-white text color to headings/prose everywhere. Force readable  */
/* dark text back on light backgrounds without touching links/buttons/ */
/* badges, which already carry their own semantic colors.              */
/* ------------------------------------------------------------------ */

[data-theme="light"] h1,
[data-theme="light"] h2,
[data-theme="light"] h3,
[data-theme="light"] h4,
[data-theme="light"] h5,
[data-theme="light"] h6,
[data-theme="light"] .content,
[data-theme="light"] .panel-body p,
[data-theme="light"] .panel-body span:not([class*="label"]):not([class*="badge"]) {
  color: #031169 !important;
}

/*
 * One of the installed theme addons ships `div { color: rgba(225,235,245,.9)
 * !important }` - a bare-element, site-wide rule assuming every div sits on
 * a dark background. In light mode that makes plain text inside any <div>
 * without its own color class (headings, labels, page titles, etc.)
 * near-invisible. Match it broadly too, but exclude common
 * color/semantic-carrying class patterns so status badges, alerts and
 * brand-colored buttons keep their own intentional colors.
 */
[data-theme="light"] div:not([class*="label"]):not([class*="badge"]):not([class*="alert"]):not([class*="btn"]):not([class*="text-"]):not([class*="bg-primary"]):not([class*="bg-danger"]):not([class*="bg-success"]):not([class*="bg-warning"]):not([class*="bg-info"]):not([class*="progress"]):not([class*="circle"]) {
  color: #031169 !important;
}

/*
 * :not(#frame a) below matches a very broad, high-specificity rule from one
 * of the installed theme addons (theme_styles.css: `a:not(#frame a) { color:
 * rgba(225,235,245,.9) !important }`) that forces near-white text onto
 * virtually every plain <a> site-wide, assuming a permanently dark page.
 * That's invisible against light-mode's light backgrounds (e.g. the client
 * profile page's left nav and tab links). Match its selector shape so ours
 * carries at least the same specificity and reliably wins in light mode.
 */
[data-theme="light"] a:not(#frame a) {
  color: #031169 !important;
}

[data-theme="light"] .content a:not(.btn):not(#frame a) {
  color: #b78e3b !important;
}

/*
 * The broad rule above (ID-level specificity via :not(#frame a)) also beats
 * the sidebar's own link-color rule, which has no ID and so always loses.
 * That made sidebar text render navy-on-navy (invisible). Re-scope to
 * .sidebar with the same ID-trick so this wins back over the rule above.
 */
[data-theme="light"] .sidebar a:not(#frame a) {
  color: #8b95c4 !important;
}

[data-theme="light"] .sidebar ul.nav li.active > a:not(#frame a),
[data-theme="light"] .sidebar ul.nav li.active > a:not(#frame a) span,
[data-theme="light"] .sidebar ul.nav li a:not(#frame a):hover {
  color: #b78e3b !important;
}

/* ------------------------------------------------------------------ */
/* 12. Employee chat widget (prchat addon)                             */
/* Its own stylesheet hardcodes a generic periwinkle blue (#546bf2)    */
/* for the floating widget's header/footer bars - bring it onto brand. */
/* ------------------------------------------------------------------ */

#pusherChat .topInfo,
#pusherChat .chat-footer {
  background: var(--pf-gold-gradient) !important;
  color: #031169 !important;
}

#pusherChat .topInfo *,
#pusherChat .chat-footer * {
  color: #031169 !important;
}

#pusherChat .dropdown-menu {
  background: #ffffff !important;
  color: #031169 !important;
}

/* ------------------------------------------------------------------ */
/* 13. Arabic font                                                     */
/* IBM Plex Sans Arabic (Google Fonts) - free, professionally designed */
/* for UI text; stand-in for Bahij (paid foundry, no license held).    */
/* Applied whenever the page is RTL, independent of the light/dark     */
/* toggle. Form controls get it explicitly since browsers don't        */
/* inherit font-family onto inputs/buttons/selects by default.         */
/* ------------------------------------------------------------------ */

html[dir="rtl"] body,
html[dir="rtl"] .btn,
html[dir="rtl"] input,
html[dir="rtl"] textarea,
html[dir="rtl"] select,
html[dir="rtl"] button,
html[dir="rtl"] .selectpicker,
html[dir="rtl"] .dropdown-menu,
html[dir="rtl"] .form-control {
  font-family: 'IBM Plex Sans Arabic', 'Inter', 'Segoe UI', Tahoma, Arial, sans-serif !important;
}

/* Arabic numerals/latin text (invoice totals, dates, code) read better in
   the Latin font even inside an RTL page - excluded from the swap above. */
html[dir="rtl"] .tw-font-mono,
html[dir="rtl"] code,
html[dir="rtl"] pre {
  font-family: 'Inter', Menlo, Consolas, monospace !important;
}

/* ------------------------------------------------------------------ */
/* 14. RTL layout fixes                                                */
/* Perfex's own core CSS + bootstrap-arabic.min.css (loaded by core    */
/* when is_rtl() is true) already mirror most of the base layout. These*/
/* patch the pieces this custom theme layer added on top, which are    */
/* LTR-only by default: the topbar dashboard-options button, dropdown  */
/* caret/menu alignment some addons hardcode, and modal close buttons. */
/* ------------------------------------------------------------------ */

/* Dropdown menus anchored to a right-aligned trigger should open      */
/* growing to the left in RTL, not clip off-screen to the right.       */
html[dir="rtl"] .dropdown-menu-right,
html[dir="rtl"] .dropdown-menu.pull-right {
  right: auto !important;
  left: 0 !important;
}

html[dir="rtl"] .dropdown-menu-left {
  left: auto !important;
  right: 0 !important;
}

/* Bootstrap 3 modal close "x" defaults to float:right (correct in LTR,
   wrong in RTL where the close control reads better on the visual left
   only if the whole header is mirrored - Bootstrap-arabic already
   mirrors .modal-header, this just keeps our custom panel headers and
   third-party addon modals that don't use .modal-header consistent). */
html[dir="rtl"] .panel-heading .close,
html[dir="rtl"] .panel-actions {
  float: left !important;
}

/* Icons that sit before label text (buttons, sidebar, nav pills) need
   their margin flipped so the gap lands between icon and text either
   way, instead of pushing the icon further from the text. */
html[dir="rtl"] .btn i.fa,
html[dir="rtl"] .btn i[class*="fa-"],
html[dir="rtl"] .dt-buttons .btn i {
  margin-right: 0;
  margin-left: 0.4em;
}

/* Notification/quick-action badges positioned via absolute left/right
   on icons (topbar bell, chat unread count) - mirror to the icon's new
   visual corner. */
html[dir="rtl"] .icon .label-count,
html[dir="rtl"] .icon .badge {
  right: auto !important;
  left: -6px !important;
}

/* Chat widget floats bottom-right in LTR; keep it reachable at
   bottom-left in RTL so it doesn't collide with the mirrored sidebar. */
html[dir="rtl"] #pusherChat {
  right: auto !important;
  left: 20px !important;
}

/* Theme toggle + notification bell in the topbar already reorder via
   Tailwind's rtl: variants in the markup (see my_hooks.php); this just
   corrects the icon-to-label gap on the "Dashboard Options" button and
   similar inline-icon buttons injected by dashboard widgets. */
html[dir="rtl"] .btn .fa + span,
html[dir="rtl"] .btn span + .fa {
  margin-right: 0.35em;
}
