/* ==========================================================================
   CRM Pro theme
   - Design tokens for the light and dark modes (html[data-theme])
   - App shell: sidebar, top bar and footer for LTR and RTL (html[dir])
   - Restyle of the shared page components (cards, tables, forms, alerts)
   Component selectors start with html[data-theme] so they win over the page
   stylesheets (create.css, clients.css, side.css ...) that load after this file.
   ========================================================================== */

/* ----------------------------------------------------------------- tokens */
:root {
    --brand: #189AB4;
    --brand-strong: #05445E;
    --brand-soft: rgba(24, 154, 180, 0.12);
    --brand-gradient: linear-gradient(135deg, #189AB4 0%, #05445E 100%);
    --accent: #c8a86b;
    --button-primary: linear-gradient(135deg, #189AB4 0%, #05445E 100%);
    --button-accent: #c8a86b;

    --bg: #f3f6f9;
    --surface: #ffffff;
    --surface-2: #f7f9fb;
    --surface-3: #eef2f6;
    --border: #e2e8ef;
    --row-hover: #f5f9fc;
    --input-bg: #ffffff;
    --topbar-bg: rgba(255, 255, 255, 0.86);

    --text: #1b2733;
    --text-muted: #5d6d7e;
    --text-soft: #8d9aa7;

    --success: #1c9a5f;
    --success-soft: #e3f6ec;
    --danger: #d64545;
    --danger-soft: #fdeaea;
    --warning: #c98300;
    --warning-soft: #fff4dc;
    --info: #1f86c9;
    --info-soft: #e5f2fb;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.07);
    --shadow-md: 0 10px 30px rgba(16, 24, 40, 0.08);
    --radius: 14px;
    --radius-sm: 10px;

    --sidebar-bg: linear-gradient(180deg, #053a4e 0%, #0b5b6d 100%);
    --sidebar-shadow: 0 0 30px rgba(5, 58, 78, 0.18);
    --sidebar-w: 300px;
    --sidebar-rail: 76px;
    --sidebar-current: var(--sidebar-w);
    --content-start: var(--sidebar-current);
    --topbar-h: 64px;

    --font: "Inter", "Cairo", "Segoe UI", system-ui, -apple-system, sans-serif;
    color-scheme: light;
}

/* Dark mode: neutral slate surfaces; the brand teal and gold are kept for accents only */
html[data-theme="dark"] {
    --brand: #3fb6cc;
    --brand-strong: #7fd3e2;
    --brand-soft: rgba(63, 182, 204, 0.16);
    --brand-gradient: linear-gradient(135deg, #1a2e38 0%, #142029 100%);
    --accent: #d4b77e;
    --button-primary: #1f8ea3;
    --button-accent: #b8975c;

    --bg: #0b1118;
    --surface: #111a23;
    --surface-2: #16212c;
    --surface-3: #1d2a37;
    --border: #243241;
    --row-hover: #18232f;
    --input-bg: #0e161e;
    --topbar-bg: rgba(17, 26, 35, 0.88);

    --text: #e6edf3;
    --text-muted: #9aabbb;
    --text-soft: #718396;

    --success: #34b27b;
    --success-soft: rgba(52, 178, 123, 0.16);
    --danger: #e26464;
    --danger-soft: rgba(226, 100, 100, 0.16);
    --warning: #e0a53a;
    --warning-soft: rgba(224, 165, 58, 0.16);
    --info: #4aa3dc;
    --info-soft: rgba(74, 163, 220, 0.16);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);
    --sidebar-bg: #0d141b;
    --sidebar-shadow: none;
    color-scheme: dark;
}

html[lang="ar"] {
    --font: "Cairo", "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

html.sidebar-collapsed {
    --sidebar-current: var(--sidebar-rail);
}

@media (max-width: 991.98px) {
    :root,
    html.sidebar-collapsed {
        --content-start: 0px;
    }
}

/* ------------------------------------------------------------------- base */
html[data-theme] body {
    background: var(--bg) !important;
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
}

/* Plain links only: links styled as buttons (a.btn, a.modern-button ...) keep their own colours */
html[data-theme] a:not([class]) {
    color: var(--brand);
}

html[data-theme] ::selection {
    background: var(--brand-soft);
}

html[data-theme] * {
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) transparent;
}

html[data-theme] ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

html[data-theme] ::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 8px;
}

/* -------------------------------------------------------- content areas */
html[data-theme] body :is(.modern-page-container, .dashboard-container, .content-wrapper, .main-content,
                          .clients-list-container, .clients-dashboard) {
    margin-left: var(--content-start) !important;
    margin-right: 0 !important;
    width: auto !important;
    max-width: none !important;
    min-height: calc(100vh - var(--topbar-h));
    direction: inherit;
    background: var(--bg) !important;
    padding: 1.5rem clamp(0.75rem, 2.2vw, 2rem) 2rem !important;
    transition: margin 0.25s ease;
}

html[dir="rtl"][data-theme] body :is(.modern-page-container, .dashboard-container, .content-wrapper, .main-content,
                                     .clients-list-container, .clients-dashboard) {
    margin-left: 0 !important;
    margin-right: var(--content-start) !important;
}

/* ---------------------------------------------------------------- sidebar */
html[data-theme] body .app-sidebar {
    position: fixed !important;
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: var(--sidebar-current) !important;
    height: 100vh;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg) !important;
    box-shadow: var(--sidebar-shadow);
    z-index: 1040 !important;
    overflow: hidden;
    transform: none;
    transition: width 0.25s ease, transform 0.25s ease;
}

html[dir="rtl"][data-theme] body .app-sidebar {
    left: auto;
    right: 0;
}

html[data-theme] body .app-sidebar .modern-brand-section {
    padding: 1.1rem 1rem;
    background: transparent;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

html[data-theme] body .app-sidebar .modern-brand-link:hover {
    transform: none;
}

html[data-theme] body .app-sidebar .brand-text {
    font-size: 1.05rem;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

html[data-theme] body .app-sidebar .modern-user-panel {
    padding: 0.9rem 1rem;
    margin: 0.75rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

html[data-theme] body .app-sidebar .modern-user-panel .user-avatar {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

html[data-theme] body .app-sidebar .sidebar-user-role {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.65);
}

html[data-theme] body .app-sidebar .modern-sidebar-content {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    padding: 0.25rem 0 1rem;
}

html[data-theme] body .app-sidebar .modern-nav-link {
    margin: 2px 0.75rem !important;
    padding: 0.65rem 0.85rem;
    gap: 0.75rem;
    border-radius: var(--radius-sm) !important;
    color: rgba(255, 255, 255, 0.78);
    transform: none !important;
    box-shadow: none;
}

html[data-theme] body .app-sidebar .modern-nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

html[data-theme] body .app-sidebar .modern-nav-link.active {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--accent);
}

html[dir="rtl"][data-theme] body .app-sidebar .modern-nav-link.active {
    box-shadow: inset -3px 0 0 var(--accent);
}

html[data-theme] body .app-sidebar .modern-nav-link.active::before {
    display: none;
}

html[data-theme] body .app-sidebar .modern-nav-text {
    font-size: 0.92rem;
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
}

html[data-theme] body .app-sidebar .modern-nav-arrow {
    transform: rotate(180deg);
    transition: transform 0.2s ease;
}

html[data-theme] body .app-sidebar .modern-nav-item.open > .modern-nav-link .modern-nav-arrow {
    transform: rotate(90deg);
}

html[data-theme] body .app-sidebar .modern-nav-submenu {
    margin: 2px 0.75rem 6px 1.6rem;
    padding: 4px 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.16);
}

html[dir="rtl"][data-theme] body .app-sidebar .modern-nav-submenu {
    margin: 2px 1.6rem 6px 0.75rem;
}

html[data-theme] body .app-sidebar .modern-nav-submenu .modern-nav-link {
    margin: 1px 0.4rem !important;
    padding: 0.5rem 0.75rem;
    font-size: 0.86rem;
}

html[data-theme] body .app-sidebar .nav-section-title {
    padding: 0.55rem 1rem 0.25rem;
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* Search box: filters the pages of the menu */
html[data-theme] body .app-sidebar .sidebar-search {
    position: relative;
    flex-shrink: 0;
    margin: 0 0.75rem 0.5rem;
}

html[data-theme] body .app-sidebar .sidebar-search .fa-search {
    position: absolute;
    top: 50%;
    inset-inline-start: 0.85rem;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.8rem;
    pointer-events: none;
}

html[data-theme] body .app-sidebar .sidebar-search-input {
    width: 100%;
    height: 38px;
    padding-block: 0;
    padding-inline: 2.25rem 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font: inherit;
    font-size: 0.86rem;
    outline: none;
    transition: border-color 0.2s ease, background 0.2s ease;
}

html[data-theme] body .app-sidebar .sidebar-search-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

html[data-theme] body .app-sidebar .sidebar-search-input:focus {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.12);
}

html[data-theme] body .app-sidebar .sidebar-search-empty {
    margin: 0;
    padding: 0.75rem 1.25rem;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.85rem;
}

/* Logout: always at the bottom of the sidebar */
html[data-theme] body .app-sidebar .sidebar-footer {
    flex-shrink: 0;
    padding: 0.6rem 0.75rem 0.8rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

html[data-theme] body .app-sidebar .sidebar-logout-form {
    margin: 0;
}

html[data-theme] body .app-sidebar .sidebar-logout {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.85);
    font: inherit;
    font-size: 0.92rem;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

html[data-theme] body .app-sidebar .sidebar-logout i {
    width: 1.25rem;
    text-align: center;
}

/* No dots pattern over the sidebar (side.css .modern-sidebar::before) */
html[data-theme] body .app-sidebar::before {
    display: none !important;
}

/* The sidebar's decorative layer (side.css) lay over the search box and Logout: clicks never reached them */
html[data-theme] body .app-sidebar :is(.sidebar-search, .sidebar-footer) {
    position: relative;
    z-index: 5;
}

html[data-theme] body .app-sidebar .sidebar-logout:hover,
html[data-theme] body .app-sidebar .sidebar-logout:focus-visible {
    background: rgba(239, 68, 68, 0.25);
    color: #fff;
}

@media (min-width: 992px) {
    html.sidebar-collapsed[data-theme] body .app-sidebar .sidebar-search {
        display: none;
    }

    html.sidebar-collapsed[data-theme] body .app-sidebar .sidebar-logout {
        justify-content: center;
        padding: 0.7rem 0;
    }
}

/* Collapsed to an icon rail (desktop) */
@media (min-width: 992px) {
    html.sidebar-collapsed[data-theme] body .app-sidebar :is(.brand-text, .user-info, .modern-nav-text,
                                                             .modern-nav-arrow, .modern-nav-submenu) {
        display: none !important;
    }

    html.sidebar-collapsed[data-theme] body .app-sidebar :is(.modern-brand-link, .modern-user-panel, .modern-nav-link) {
        justify-content: center;
    }

    html.sidebar-collapsed[data-theme] body .app-sidebar .modern-user-panel {
        margin: 0.75rem 0.5rem;
        padding: 0.6rem 0;
    }

    html.sidebar-collapsed[data-theme] body .app-sidebar .modern-nav-link {
        margin: 2px 0.6rem !important;
        padding: 0.7rem 0;
    }
}

/* Off-canvas (tablet / phone) */
@media (max-width: 991.98px) {
    html[data-theme] body .app-sidebar {
        width: var(--sidebar-w) !important;
        transform: translateX(-105%);
    }

    html[dir="rtl"][data-theme] body .app-sidebar {
        transform: translateX(105%);
    }

    html.sidebar-open[data-theme] body .app-sidebar {
        transform: none;
    }
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 17, 26, 0.5);
    z-index: 1035;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

@media (max-width: 991.98px) {
    html.sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ----------------------------------------------------------------- topbar */
html[data-theme] body .app-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--topbar-h);
    margin-left: var(--content-start);
    margin-right: 0;
    padding: 0 clamp(0.75rem, 2.2vw, 2rem);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--topbar-bg);
    backdrop-filter: saturate(160%) blur(10px);
    -webkit-backdrop-filter: saturate(160%) blur(10px);
    border-bottom: 1px solid var(--border);
    transition: margin 0.25s ease;
}

html[dir="rtl"][data-theme] body .app-topbar {
    margin-left: 0;
    margin-right: var(--content-start);
}

.app-topbar .topbar-start,
.app-topbar .topbar-end {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

html[data-theme] .app-topbar .topbar-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: start !important;
}

html[data-theme] .topbar-btn {
    height: 38px;
    min-width: 38px;
    padding: 0 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

html[data-theme] .topbar-btn:hover {
    background: var(--surface-2);
    border-color: var(--brand);
    color: var(--brand);
}

html[data-theme] .topbar-btn:focus-visible {
    outline: 3px solid var(--brand-soft);
    outline-offset: 1px;
}

html[data-theme="dark"] .theme-icon-dark,
html[data-theme="light"] .theme-icon-light {
    display: none;
}

html[data-theme] .topbar-logout:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: var(--danger-soft);
}

.topbar-lang-form {
    margin: 0;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding-inline: 0.35rem;
}

.topbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-gradient);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
    flex-shrink: 0;
}

.topbar-user-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

html[data-theme] .topbar-user-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    text-align: start !important;
}

html[data-theme] .topbar-user-role {
    font-size: 0.74rem;
    color: var(--text-muted);
    text-align: start !important;
}

@media (max-width: 767.98px) {
    .topbar-user-text,
    .topbar-btn .btn-label {
        display: none;
    }
}

/* ----------------------------------------------------------------- footer */
html[data-theme] body .app-footer {
    margin-left: var(--content-start);
    margin-right: 0;
    width: auto;
    padding: 1rem clamp(0.75rem, 2.2vw, 2rem);
    background: var(--surface);
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    box-shadow: none;
    font-size: 0.85rem;
    transition: margin 0.25s ease;
}

html[dir="rtl"][data-theme] body .app-footer {
    margin-left: 0;
    margin-right: var(--content-start);
}

html[data-theme] body .app-footer::before {
    display: none;
}

html[data-theme] body .app-footer .footer-content {
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: center;
}

html[data-theme] body .app-footer a {
    color: var(--brand);
    border-bottom: 0;
}

/* ------------------------------------------------------------------ cards */
html[data-theme] :is(.modern-card, .card, .chart-card, .recent-card, .filter-section, .section-tabs,
                     .modern-user-card, .filter-bar) {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

html[data-theme] .card-header {
    background: transparent;
    border-bottom-color: var(--border);
}

html[data-theme] .modern-card-header,
html[data-theme] .modern-header-section {
    background: var(--brand-gradient);
}

html[data-theme] .card-footer {
    background: var(--surface-2);
    border-top-color: var(--border);
}

/* ----------------------------------------------------------------- tables */
html[data-theme] :is(.modern-table, .table, .responsive-table, .top-sales-table) {
    color: var(--text);
    background: var(--surface);
    box-shadow: none;
}

html[data-theme] :is(.modern-table, .table) :is(td, th) {
    border-color: var(--border);
}

html[data-theme] .modern-table td {
    background: var(--surface);
    color: var(--text);
}

html[data-theme] :is(.modern-table, .table) tbody tr:hover > td {
    background: var(--row-hover);
}

html[data-theme] .table thead th,
html[data-theme] .responsive-table th {
    background: var(--surface-2);
    color: var(--text-muted);
}

html[data-theme] .table-responsive {
    border-radius: var(--radius-sm);
}

/* ------------------------------------------------------------------ forms */
html[data-theme] :is(.form-control, .modern-form-control, .form-input, .custom-select,
                     .filter-group select, .filter-group input) {
    background-color: var(--input-bg);
    color: var(--text);
    border-color: var(--border);
}

html[data-theme] :is(.form-control, .modern-form-control, .form-input, .custom-select):focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
    color: var(--text);
    background-color: var(--input-bg);
}

html[data-theme] :is(.form-control, .modern-form-control)[readonly],
html[data-theme] :is(.form-control, .modern-form-control):disabled {
    background-color: var(--surface-2);
}

html[data-theme] :is(.form-control, .modern-form-control, .form-input)::placeholder {
    color: var(--text-soft);
}

html[data-theme] select option {
    background: var(--surface);
    color: var(--text);
}

html[data-theme] :is(label, .modern-form-label, .control-label) {
    color: var(--text);
}

/* Card bodies follow the surface colour (the page CSS paints them light) */
html[data-theme] :is(.modern-form-body, .modern-card-body, .card-body) {
    background: var(--surface);
    color: var(--text);
}

/* Sidebar user panel: plain text (side.css styles .user-info as a pill for the old navbar) */
html[data-theme] body .app-sidebar .modern-user-panel .user-info {
    min-width: 0;
    gap: 0.1rem;
    padding: 0;
    background: none;
    border: 0;
}

html[data-theme] body .app-sidebar .modern-user-panel .user-name {
    color: #fff;
    font-size: 0.92rem;
}

/* ------------------------------------------------------- compact tables */
html[data-theme] .modern-table :is(th, td) {
    padding: 0.7rem 0.75rem;
    min-width: 150px;
    vertical-align: middle;
}

html[data-theme] .modern-table th {
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

html[data-theme] .modern-table :is(.form-control, .modern-form-control, select, textarea) {
    min-height: 38px;
    height: auto;
    padding: 0.4rem 0.75rem;
    font-size: 0.9rem;
    border-radius: 10px !important;
}

/* Quick phone search (Create Client / Create Activities): wide enough for its placeholder,
   and the placeholder follows its own language while the digits stay left-to-right */
html[data-theme] #search_cctel {
    flex: 1 1 240px !important;
    min-width: 220px;
    unicode-bidi: plaintext;
}

/* ------------------------------------------------------ page filter bar */
html[data-theme] .filter-bar form.row {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(150px, 1fr)) auto;
    gap: 0.75rem 1rem;
    align-items: end;
    margin: 0;
}

html[data-theme] .filter-bar form.row > [class*="col-"] {
    flex: none;
    width: auto;
    max-width: none;
    padding: 0;
}

html[data-theme] .filter-bar .modern-form-label {
    margin-bottom: 0.35rem;
    font-size: 0.78rem;
}

html[data-theme] .filter-bar .modern-form-control {
    height: 42px;
    padding: 0 0.75rem;
}

html[data-theme] .filter-bar .modern-button {
    height: 42px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}

@media (max-width: 991.98px) {
    html[data-theme] .filter-bar form.row {
        grid-template-columns: 1fr 1fr;
    }

    html[data-theme] .filter-bar form.row > :first-child {
        grid-column: 1 / -1;
    }
}

@media (max-width: 575.98px) {
    html[data-theme] .filter-bar form.row {
        grid-template-columns: 1fr;
    }
}

/* ---------------------------------------------------------------- alerts */
.app-alerts {
    position: fixed;
    top: calc(var(--topbar-h) + 12px);
    inset-inline-end: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(420px, calc(100vw - 32px));
}

html[data-theme] .app-alert {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    margin: 0;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-inline-start: 4px solid var(--info);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-md);
    text-align: start !important;
    animation: app-alert-in 0.25s ease;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.app-alert > i {
    margin-top: 2px;
    font-size: 1.05rem;
}

.app-alert-body {
    flex: 1;
    min-width: 0;
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

html[data-theme] .app-alert-close {
    border: 0;
    background: transparent;
    color: var(--text-soft);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

html[data-theme] .app-alert.alert-success { border-inline-start-color: var(--success); }
html[data-theme] .app-alert.alert-success > i { color: var(--success); }
html[data-theme] .app-alert.alert-danger { border-inline-start-color: var(--danger); }
html[data-theme] .app-alert.alert-danger > i { color: var(--danger); }
html[data-theme] .app-alert.alert-warning { border-inline-start-color: var(--warning); }
html[data-theme] .app-alert.alert-warning > i { color: var(--warning); }
html[data-theme] .app-alert.alert-info > i { color: var(--info); }

.app-alert.is-hiding {
    opacity: 0;
    transform: translateY(-6px);
}

@keyframes app-alert-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: none; }
}

/* ----------------------------------------------------- dark mode extras */
html[data-theme="dark"] :is(.bg-white, .bg-light, .dropdown-menu, .modal-content, .list-group-item, .popover, .page-link) {
    background-color: var(--surface) !important;
    color: var(--text);
    border-color: var(--border);
}

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

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

html[data-theme="dark"] hr {
    border-color: var(--border);
}

html[data-theme="dark"] :is(h1, h2, h4, h6):not(.modern-card-header *):not(.modern-header-section *) {
    color: var(--text);
}

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

html[data-theme="dark"] .close {
    color: var(--text);
    text-shadow: none;
}

/* Dark mode: headers and table heads are quiet surfaces instead of the teal gradient */
html[data-theme="dark"] :is(.modern-card-header, .modern-header-section) {
    background: var(--surface-2);
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

html[data-theme="dark"] :is(.modern-card-header, .modern-header-section)::before {
    display: none;
}

html[data-theme="dark"] :is(.modern-card-header, .modern-header-section) :is(h1, h2, h3, h4, h5, h6, p) {
    color: var(--text);
}

html[data-theme="dark"] :is(.modern-card-header, .modern-header-section) :is(h1, h2, h3, h4, h5, h6) > i {
    color: var(--brand);
}

html[data-theme="dark"] .modern-table th {
    background: var(--surface-3);
    color: var(--text-muted);
    border-color: var(--border);
}

html[data-theme="dark"] body .app-sidebar {
    border-right: 1px solid var(--border);
}

html[dir="rtl"][data-theme="dark"] body .app-sidebar {
    border-right: 0;
    border-left: 1px solid var(--border);
}

html[data-theme="dark"] body .app-sidebar .modern-nav-link.active {
    background: var(--brand-soft);
}

html[data-theme="dark"] body :is(.auth-submit, .btn-filter-primary) {
    background: #1f8ea3;
    box-shadow: none;
}

/* Dark mode: page sections and controls that the page stylesheets paint white */
html[data-theme="dark"] :is(.modern-footer, .modern-search-section, .modern-table-section, .table-container,
                            .modern-form-container, .modern-users-grid, .selection-card, .tip-item,
                            .upload-area-wrapper, .modern-logo-preview-container, .modern-image-upload,
                            .modern-checkbox-container, .kanban-column) {
    background: var(--surface) !important;
    color: var(--text);
    border-color: var(--border) !important;
}

/* Dark mode: client cards on the clients dashboard (Kanban and sales views) */
html[data-theme="dark"] :is(.client-card, .team-client-card) {
    background: var(--surface-2) !important;
    color: var(--text);
    border-color: var(--border) !important;
}

html[data-theme="dark"] :is(.client-card, .team-client-card) :is(h1, h2, h3, h4, h5, h6, p, span, strong, small, div):not([class*="badge"]):not([class*="text-"]) {
    color: var(--text);
}

html[data-theme="dark"] :is(.modern-search-input, .sales-select, .form-select-custom) {
    background-color: var(--input-bg) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

html[data-theme="dark"] :is(.modern-print-btn, .btn-filter-secondary) {
    background: var(--surface-2) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

html[data-theme="dark"] th {
    background-color: var(--surface-3);
    color: var(--text-muted);
}

/* Dark mode: headings and labels that the page stylesheets colour dark */
html[data-theme="dark"] :is(.filter-title, .column-title),
html[data-theme="dark"] :is(.modern-form-container, .upload-area-wrapper, .tip-item, .selection-card, .modern-users-grid)
    :is(h1, h2, h3, h4, h5, h6, p, span, strong, label, small):not([class*="text-"]):not(.badge) {
    color: var(--text) !important;
}

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

/* Popups built in JavaScript with inline light backgrounds */
html[data-theme="dark"] :is([style*="background: white"], [style*="background:white"], [style*="background-color: white"],
                            [style*="background: #fff;"], [style*="background:#fff;"], [style*="background: #ffffff"],
                            [style*="background-color: #fff"]) {
    background: var(--surface) !important;
    color: var(--text) !important;
}

html[data-theme="dark"] :is([style*="background: #f8f9fa"], [style*="background: #e9ecef"], [style*="background: #f3f4f6"],
                            [style*="background: #f9fafb"], [style*="background:#f8f9fa"]) {
    background: var(--surface-2) !important;
    color: var(--text) !important;
}

/* ---------------------------------------------- one look on every page */
/* Page banners: the brand banner everywhere (the clients dashboard and list had a dark navy one) */
html[data-theme] body :is(.welcome-header, .clients-list-container > .page-header) {
    background: var(--brand-gradient) !important;
    color: #fff;
}

/* Main actions (Apply, Upload, Add row) in the brand colour, like Generate Report / Save on the other
   pages (some pages painted them blue or green) */
html[data-theme] body :is(.btn-filter-primary, .btn-upload-primary, .modern-button-success) {
    background: var(--button-primary) !important;
    border-color: transparent !important;
    color: #fff !important;
    box-shadow: none;
}

/* Add buttons in the accent gold, like the Create button of the entry pages (they were green) */
html[data-theme] body a.modern-add-btn {
    background: var(--button-accent) !important;
    border-color: transparent !important;
    color: #fff !important;
    box-shadow: none;
}

html[data-theme] body :is(.btn-filter-primary, .btn-upload-primary, .modern-button-success, a.modern-add-btn):hover {
    filter: brightness(1.08);
}

/* Secondary actions (Print, Reset, Clear): one quiet outline style (they were teal, grey or light grey) */
html[data-theme] body :is(.modern-print-btn, .btn-filter-secondary) {
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    color: var(--brand-strong) !important;
    box-shadow: none;
}

html[data-theme] body :is(.modern-print-btn, .btn-filter-secondary):hover {
    background: var(--brand-soft) !important;
    border-color: var(--brand) !important;
}

/* ----------------------------------------- one size for every control */
/* Inputs, lists and the page buttons had 9 / 8 / 16 different heights, corners and font sizes across the
   pages (40-60px fields, 10-25px corners, buttons up to 104px when their text wrapped). One size for all,
   outside tables (the row fields of the entry tables keep their compact size). */
html[data-theme] body :is(.modern-page-container, .dashboard-container, .content-wrapper, .main-content,
                          .clients-list-container, .clients-dashboard)
    :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="range"]):not([type="color"]),
        select:not([multiple]):not([size])):not(table *) {
    height: 44px !important;
    min-height: 44px;
    padding-block: 0 !important;
    padding-inline: 0.85rem !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px !important;
    background-color: var(--input-bg);
    color: var(--text);
    font-size: 0.95rem !important;
    line-height: 1.4;
    box-shadow: none;
    /* fields stay in place on focus (some pages lifted them, which also moved the list's search window) */
    transform: none !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
}

/* Lists: one arrow on the reading side (some pages drew their own arrow over the text) */
html[data-theme] body :is(.modern-page-container, .dashboard-container, .content-wrapper, .main-content,
                          .clients-list-container, .clients-dashboard) select:not([multiple]):not([size]):not(table *) {
    -webkit-appearance: none;
    appearance: none;
    padding-inline: 0.85rem 2.25rem !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238d9aa7' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.85rem center !important;
    background-size: 12px 8px !important;
}

html[dir="rtl"][data-theme] body :is(.modern-page-container, .dashboard-container, .content-wrapper, .main-content,
                                     .clients-list-container, .clients-dashboard) select:not([multiple]):not([size]):not(table *) {
    background-position: left 0.85rem center !important;
}

/* Form fields take the width of their column, as on the other pages (the user form had narrow fields) */
html[data-theme] body :is(.modern-form-control, .modern-select):not(table *) {
    width: 100% !important;
}

html[data-theme] body :is(.modern-page-container, .dashboard-container, .content-wrapper, .main-content,
                          .clients-list-container, .clients-dashboard) textarea:not(table *) {
    padding: 0.6rem 0.85rem !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px !important;
    font-size: 0.95rem !important;
}

html[data-theme] body :is(.modern-page-container, .dashboard-container, .content-wrapper, .main-content,
                          .clients-list-container, .clients-dashboard)
    :is(input, select, textarea):not(table *):focus {
    border-color: var(--brand) !important;
    box-shadow: 0 0 0 3px var(--brand-soft) !important;
    outline: none;
}

/* A card's buttons sit over its title (position: absolute), and the title is lifted above the header's grain
   (z-index 1): it covered all but the buttons' bottom edge, so a click only took there (Create on GHCL11 / GHA11) */
html[data-theme] .modern-card-header :is(.modern-button, a.btn, button) {
    z-index: 2;
}

html[data-theme] body :is(.modern-button, .btn-filter, .modern-print-btn, .modern-add-btn, .btn-upload-primary):not(table *) {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 44px !important;
    min-height: 44px;
    padding: 0 1.25rem !important;
    border-radius: 10px !important;
    font-size: 0.95rem !important;
    font-weight: 600;
    line-height: 1 !important;
    white-space: nowrap;
    transform: none;
}

/* ------------------------------------------------ searchable dropdowns */
/* The window opened by a list (app-shell.js): a search box above the list's options */
.select-picker {
    position: fixed;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    max-height: 320px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    font-family: var(--font);
}

.select-picker-search {
    flex-shrink: 0;
    height: 38px;
    margin: 8px;
    padding: 0 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
    outline: none;
}

.select-picker-search:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.select-picker-list {
    margin: 0;
    padding: 0 6px 6px;
    list-style: none;
    overflow-y: auto;
}

.select-picker-option {
    padding: 0.45rem 0.75rem;
    border-radius: 6px;
    font-size: 0.88rem;
    line-height: 1.4;
    text-align: start;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.select-picker-option.is-active {
    background: var(--brand-soft);
}

.select-picker-option.is-selected {
    font-weight: 700;
    color: var(--brand-strong);
}

.select-picker-option.is-disabled {
    opacity: 0.45;
    cursor: default;
}

.select-picker-group {
    padding: 0.5rem 0.75rem 0.2rem;
    color: var(--text-soft);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
}

.select-picker-empty {
    padding: 0.6rem 0.75rem;
    color: var(--text-soft);
    font-size: 0.85rem;
}

/* ------------------------------------------- reading direction fixes */
/* Header buttons are pinned to the right inline; in Arabic they move to the left */
html[dir="rtl"] [style*="right: 2rem"] {
    right: auto !important;
    left: 2rem !important;
}

/* Popups built in JavaScript were written right-to-left; follow the page language */
html[dir="ltr"] [style*="direction: rtl"] {
    direction: ltr !important;
}

/* Some tables force left-to-right inline; follow the page language */
html[dir="rtl"] table[style*="direction: ltr"] {
    direction: rtl !important;
}

/* ------------------------------------------------------ reduced motion */
@media (prefers-reduced-motion: reduce) {
    html[data-theme] body :is(.app-sidebar, .app-topbar, .app-footer, .modern-page-container, .dashboard-container),
    .app-alert,
    .sidebar-backdrop {
        transition: none !important;
        animation: none !important;
    }
}

/* ------------------------------------------------------------------ print */
@media print {
    html[data-theme] body :is(.app-sidebar, .app-topbar, .app-footer, .app-alerts) {
        display: none !important;
    }

    html[data-theme] body :is(.modern-page-container, .dashboard-container, .content-wrapper, .main-content) {
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* Page links under the complaint / quality records (GHCL18, GHCL19, GHA19, GHA20) */
.records-pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    list-style: none;
    margin: 1rem 0 0;
    padding: 0;
}
.records-pagination .page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    margin: 0;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
}
.records-pagination .page-link:hover {
    background: var(--brand-soft);
    color: var(--brand-strong);
}
.records-pagination .page-item.active .page-link {
    background: var(--brand-gradient);
    border-color: transparent;
    color: #fff;
}
html[dir="rtl"] .records-pagination .fas {
    transform: scaleX(-1);
}
