/*
 * TML Invoice Portal - UI layer
 *
 * Loaded after the template's core.css by layouts/main.blade.php and
 * customer/Layouts/main.blade.php. Everything is scoped under `body.tml-ui`
 * so third-party widgets, PDF views and e-mail templates are not affected.
 * No selectors/IDs used by scripts are renamed here - this file only styles them.
 *
 * Sections
 *   1. Design tokens
 *   2. Base
 *   3. App shell (sidebar, navbar, content area)
 *   4. Buttons
 *   5. Forms
 *   6. Tables, DataTables, listing cards
 *   7. Tabs, cards, badges, alerts, dropdowns, modals, pagination
 *   8. Toastr / SweetAlert2 / flatpickr
 *   9. Responsive
 */

/* 1. Design tokens ---------------------------------------------------- */
body.tml-ui {
    /* Brand + status */
    --tml-primary: #2f78a6;
    --tml-primary-hover: #276790;
    --tml-primary-soft: #e8f1f7;
    --tml-primary-ring: rgba(47, 120, 166, 0.22);
    --tml-success: #15803d;
    --tml-success-soft: #e6f4ea;
    --tml-warning: #b45309;
    --tml-warning-soft: #fef3c7;
    --tml-danger: #dc2626;
    --tml-danger-hover: #b91c1c;
    --tml-danger-soft: #fdecec;
    --tml-info: #0e7490;
    --tml-info-soft: #e0f2f7;

    /* Surfaces + text */
    --tml-bg: #f4f6f9;
    --tml-surface: #ffffff;
    --tml-surface-muted: #f8fafc;
    --tml-border: #e2e8f0;
    --tml-border-strong: #cbd5e1;
    --tml-text: #1e293b;
    --tml-text-muted: #64748b;
    --tml-placeholder: #8392a5;

    /* Shape + depth */
    --tml-radius-sm: 6px;
    --tml-radius: 8px;
    --tml-radius-lg: 12px;
    --tml-shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
    --tml-shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
    --tml-shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16);

    /* Sizing */
    --tml-control-h: 38px;
    --tml-control-h-sm: 32px;
    --tml-sidebar-w: 264px;
    --tml-navbar-h: 60px;
    --tml-gutter: 24px;

    /* Type */
    --tml-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    /* Re-point the template's colour variables at the tokens above so
       utilities such as .text-primary / .bg-success follow the palette. */
    --bs-primary: var(--tml-primary);
    --bs-primary-rgb: 47, 120, 166;
    --bs-success: var(--tml-success);
    --bs-success-rgb: 21, 128, 61;
    --bs-warning: var(--tml-warning);
    --bs-warning-rgb: 180, 83, 9;
    --bs-danger: var(--tml-danger);
    --bs-danger-rgb: 220, 38, 38;
    --bs-info: var(--tml-info);
    --bs-info-rgb: 14, 116, 144;
    --bs-body-bg: var(--tml-bg);
    --bs-body-color: var(--tml-text);
    --bs-heading-color: var(--tml-text);
    --bs-border-color: var(--tml-border);
    --bs-link-color: var(--tml-primary);
}

/* 2. Base -------------------------------------------------------------- */
body.tml-ui {
    font-family: var(--tml-font);
    font-size: 0.9rem;
    color: var(--tml-text);
    background-color: var(--tml-bg);
    -webkit-font-smoothing: antialiased;
}

body.tml-ui h1,
body.tml-ui h2,
body.tml-ui h3,
body.tml-ui h4,
body.tml-ui h5,
body.tml-ui h6 {
    color: var(--tml-text);
    font-weight: 600;
}

body.tml-ui a {
    color: var(--tml-primary);
}

body.tml-ui a:hover {
    color: var(--tml-primary-hover);
}

body.tml-ui .text-muted {
    color: var(--tml-text-muted) !important;
}

body.tml-ui :focus-visible {
    outline: 2px solid var(--tml-primary);
    outline-offset: 2px;
}

/* 3. App shell --------------------------------------------------------- */
/* 3a. Sidebar */
body.tml-ui .layout-menu {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--tml-sidebar-w);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    background-color: var(--tml-surface);
    border-right: 1px solid var(--tml-border);
    box-shadow: none;
    color: var(--tml-text);
    overflow-x: hidden;
    overflow-y: auto;
    transition: transform 0.25s ease;
}

body.tml-ui .layout-menu .app-brand {
    flex-shrink: 0;
    margin: 0;
    padding: 20px 20px 12px;
    border-bottom: 1px solid var(--tml-border);
    justify-content: center;
}

body.tml-ui .layout-menu .app-brand-link {
    text-decoration: none;
}

body.tml-ui .layout-menu .app-brand-logo {
    margin-bottom: 8px !important;
}

body.tml-ui .layout-menu .app-brand-logo .logo-img {
    width: 100%;
    max-width: 168px;
    height: auto;
    border-radius: var(--tml-radius);
}

body.tml-ui .layout-menu .app-brand-text {
    margin: 0;
    color: var(--tml-text);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0;
}

body.tml-ui .layout-menu .menu-inner-shadow {
    display: none;
}

body.tml-ui .layout-menu .menu-inner {
    flex: 1 1 auto;
    margin: 0;
    padding: 12px;
    list-style: none;
    overflow: visible;
}

body.tml-ui .layout-menu .menu-item {
    width: 100%;
    margin: 0 0 2px;
}

body.tml-ui .layout-menu .menu-link {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    padding: 9px 12px;
    border-radius: var(--tml-radius);
    color: var(--tml-text);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.35;
    text-decoration: none;
    transform: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

body.tml-ui .layout-menu .menu-link:hover {
    background-color: var(--tml-surface-muted);
    color: var(--tml-primary);
    transform: none;
}

body.tml-ui .layout-menu .menu-item.active > .menu-link {
    background-color: var(--tml-primary-soft);
    color: var(--tml-primary) !important;
    font-weight: 600;
}

body.tml-ui .layout-menu .menu-icon {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    margin: 0;
    object-fit: contain;
    font-size: 17px;
    line-height: 20px;
    text-align: center;
    opacity: 0.85;
}

/* Font Awesome sidebar icons: core.css sets .menu-icon::before to 1.5rem; keep them at the 17px above */
body.tml-ui .layout-menu i.menu-icon::before {
    font-size: inherit;
}

body.tml-ui .layout-menu .menu-item.active > .menu-link .menu-icon {
    opacity: 1;
}

/* Admin sidebar: count pill next to each invoice type */
body.tml-ui .layout-menu .tml-menu-count {
    min-width: 28px;
    padding: 1px 8px;
    border-radius: 999px;
    background-color: var(--tml-surface-muted);
    border: 1px solid var(--tml-border);
    color: var(--tml-text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

body.tml-ui .layout-menu .menu-item.active .tml-menu-count {
    background-color: var(--tml-surface);
    border-color: transparent;
    color: var(--tml-primary);
}

/* Customer sidebar: nested "Customers" group */
body.tml-ui .layout-menu .menu-sub {
    display: none;
    margin: 2px 0 4px;
    padding: 0 0 0 32px;
    list-style: none;
}

body.tml-ui .layout-menu .menu-item.has-sub:hover > .menu-sub,
body.tml-ui .layout-menu .menu-item.has-sub:focus-within > .menu-sub {
    display: block;
}

body.tml-ui .layout-menu .menu-sub .menu-link {
    padding: 7px 12px;
    font-weight: 400;
}

/* Mobile overlay (created by the sidebar script) */
body.tml-ui .layout-overlay {
    position: fixed;
    inset: 0;
    z-index: 1049;
    display: none;
    background-color: rgba(15, 23, 42, 0.45);
}

body.tml-ui .layout-overlay.show {
    display: block;
}

/* 3b. Page column + navbar */
body.tml-ui .layout-page {
    min-height: 100vh;
    margin-left: var(--tml-sidebar-w);
    padding: 0;
    transition: margin-left 0.25s ease;
}

body.tml-ui .layout-navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    min-height: var(--tml-navbar-h);
    margin: 0;
    padding: 0 var(--tml-gutter);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background-color: var(--tml-surface);
    border: 0;
    border-bottom: 1px solid var(--tml-border);
    border-radius: 0;
    box-shadow: var(--tml-shadow-xs);
}

/* The template sizes .navbar-detached with !important calc() widths below the
   xl breakpoint (a floating card); the navbar here is a full-width bar. */
body.tml-ui .layout-navbar.navbar-detached {
    width: 100% !important;
    padding: 0 var(--tml-gutter);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

body.tml-ui .layout-navbar .tml-navbar-start,
body.tml-ui .layout-navbar .tml-navbar-end {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

body.tml-ui .layout-navbar .tml-navbar-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.tml-ui .layout-navbar .tml-navbar-version {
    color: var(--tml-text-muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

body.tml-ui .layout-navbar .tml-menu-open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tml-control-h);
    height: var(--tml-control-h);
    padding: 0;
    border: 1px solid var(--tml-border);
    border-radius: var(--tml-radius);
    background: var(--tml-surface);
    color: var(--tml-text);
    font-size: 1rem;
}

body.tml-ui .layout-navbar .tml-menu-open:hover {
    background: var(--tml-surface-muted);
}

body.tml-ui .layout-navbar .tml-navbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: var(--tml-radius);
    color: var(--tml-text);
    text-decoration: none;
}

body.tml-ui .layout-navbar .tml-navbar-user:hover {
    background: var(--tml-surface-muted);
    color: var(--tml-text);
}

body.tml-ui .layout-navbar .tml-navbar-user .avatar {
    margin: 0 !important;
}

body.tml-ui .layout-navbar .tml-navbar-user-name {
    font-size: 0.875rem;
    font-weight: 500;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 3c. Content area */
body.tml-ui .layout-page > .container-fluid,
body.tml-ui .layout-page > .container {
    max-width: 1760px;
    margin: 0 auto;
    padding: var(--tml-gutter);
}

body.tml-ui .layout-page .content-wrapper {
    padding: 0;
}

/* 4. Buttons ----------------------------------------------------------- */
body.tml-ui .btn {
    --bs-btn-box-shadow: none;
    min-height: var(--tml-control-h);
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: var(--tml-radius);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    box-shadow: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

/* The template adds a drop shadow to every solid button via a very specific selector; keep buttons flat. */
body.tml-ui .btn[class*=btn-]:not([class*=btn-label-]):not([class*=btn-outline-]):not([class*=btn-text-]):not(.btn-icon),
body.tml-ui .btn[class*=btn-]:not([class*=btn-label-]):not([class*=btn-outline-]):not([class*=btn-text-]):not(.btn-icon):hover,
body.tml-ui .btn[class*=btn-]:not([class*=btn-label-]):not([class*=btn-outline-]):not([class*=btn-text-]):not(.btn-icon):focus,
body.tml-ui .btn[class*=btn-]:not([class*=btn-label-]):not([class*=btn-outline-]):not([class*=btn-text-]):not(.btn-icon):active {
    box-shadow: none;
}

body.tml-ui .border-primary {
    border-color: var(--tml-primary) !important;
}

body.tml-ui .btn-sm {
    min-height: var(--tml-control-h-sm);
    padding: 0 12px;
    font-size: 0.8125rem;
}

/* "View" / "Logs" buttons in every table row and the "Filter" / "Clear" buttons above the tables:
   one small, rectangular size */
body.tml-ui .btn.btn-view,
body.tml-ui .btn.show-timeline,
body.tml-ui .btn.btn-tool {
    min-height: 26px;
    padding: 0 10px;
    gap: 4px;
    border-radius: 3px;
    font-size: 0.75rem;
    line-height: 1.2;
}

/* the toolbar buttons are exactly that height, whatever a page sets on its own buttons */
body.tml-ui .btn.btn-tool {
    height: 26px;
}

/* space between View and Logs, also between the two rows when the column is narrow and they wrap */
body.tml-ui .btn.btn-view,
body.tml-ui .btn.show-timeline {
    margin: 0 6px 6px 0;
}

body.tml-ui .btn-lg {
    min-height: 44px;
    padding: 0 22px;
    font-size: 1rem;
}

body.tml-ui .btn:focus-visible {
    box-shadow: 0 0 0 3px var(--tml-primary-ring);
}

body.tml-ui .btn:disabled,
body.tml-ui .btn.disabled {
    opacity: 0.55;
    cursor: not-allowed;
    box-shadow: none;
}

body.tml-ui .btn-primary {
    background-color: var(--tml-primary);
    border-color: var(--tml-primary);
    color: #fff;
}

body.tml-ui .btn-primary:hover,
body.tml-ui .btn-primary:focus,
body.tml-ui .btn-primary:active,
body.tml-ui .btn-primary.active {
    background-color: var(--tml-primary-hover);
    border-color: var(--tml-primary-hover);
    color: #fff;
    box-shadow: none;
}

body.tml-ui .btn-secondary {
    background-color: var(--tml-surface);
    border-color: var(--tml-border-strong);
    color: var(--tml-text);
}

body.tml-ui .btn-secondary:hover,
body.tml-ui .btn-secondary:focus,
body.tml-ui .btn-secondary:active,
body.tml-ui .btn-secondary.active {
    background-color: var(--tml-surface-muted);
    border-color: var(--tml-border-strong);
    color: var(--tml-text);
    box-shadow: none;
}

body.tml-ui .btn-success {
    background-color: var(--tml-success);
    border-color: var(--tml-success);
    color: #fff;
}

body.tml-ui .btn-success:hover,
body.tml-ui .btn-success:focus,
body.tml-ui .btn-success:active {
    background-color: #126a33;
    border-color: #126a33;
    color: #fff;
    box-shadow: none;
}

body.tml-ui .btn-danger {
    background-color: var(--tml-danger);
    border-color: var(--tml-danger);
    color: #fff;
}

body.tml-ui .btn-danger:hover,
body.tml-ui .btn-danger:focus,
body.tml-ui .btn-danger:active {
    background-color: var(--tml-danger-hover);
    border-color: var(--tml-danger-hover);
    color: #fff;
    box-shadow: none;
}

body.tml-ui .btn-warning {
    background-color: var(--tml-warning);
    border-color: var(--tml-warning);
    color: #fff;
}

body.tml-ui .btn-warning:hover,
body.tml-ui .btn-warning:focus,
body.tml-ui .btn-warning:active {
    background-color: #92400e;
    border-color: #92400e;
    color: #fff;
    box-shadow: none;
}

body.tml-ui .btn-info {
    background-color: var(--tml-info);
    border-color: var(--tml-info);
    color: #fff;
}

body.tml-ui .btn-info:hover,
body.tml-ui .btn-info:focus,
body.tml-ui .btn-info:active {
    background-color: #0b5d73;
    border-color: #0b5d73;
    color: #fff;
    box-shadow: none;
}

body.tml-ui .btn-outline-primary {
    background-color: transparent;
    border-color: var(--tml-primary);
    color: var(--tml-primary);
}

body.tml-ui .btn-outline-primary:hover,
body.tml-ui .btn-outline-primary:focus,
body.tml-ui .btn-outline-primary:active,
body.tml-ui .btn-outline-primary.active {
    background-color: var(--tml-primary);
    border-color: var(--tml-primary);
    color: #fff;
    box-shadow: none;
}

body.tml-ui .btn-outline-secondary {
    background-color: transparent;
    border-color: var(--tml-border-strong);
    color: var(--tml-text);
}

body.tml-ui .btn-outline-secondary:hover,
body.tml-ui .btn-outline-secondary:focus,
body.tml-ui .btn-outline-secondary:active {
    background-color: var(--tml-surface-muted);
    border-color: var(--tml-border-strong);
    color: var(--tml-text);
    box-shadow: none;
}

body.tml-ui .btn-outline-danger {
    background-color: transparent;
    border-color: var(--tml-danger);
    color: var(--tml-danger);
}

body.tml-ui .btn-outline-danger:hover,
body.tml-ui .btn-outline-danger:focus,
body.tml-ui .btn-outline-danger:active {
    background-color: var(--tml-danger);
    border-color: var(--tml-danger);
    color: #fff;
    box-shadow: none;
}

body.tml-ui .btn-outline-success {
    background-color: transparent;
    border-color: var(--tml-success);
    color: var(--tml-success);
}

body.tml-ui .btn-outline-success:hover,
body.tml-ui .btn-outline-success:focus,
body.tml-ui .btn-outline-success:active {
    background-color: var(--tml-success);
    border-color: var(--tml-success);
    color: #fff;
    box-shadow: none;
}

body.tml-ui .btn-link {
    min-height: 0;
    padding: 0;
    color: var(--tml-primary);
}

body.tml-ui .btn-close:focus {
    box-shadow: 0 0 0 3px var(--tml-primary-ring);
}

/* 5. Forms ------------------------------------------------------------- */
body.tml-ui .form-label,
body.tml-ui label {
    color: var(--tml-text);
    font-size: 0.8125rem;
    font-weight: 500;
}

body.tml-ui .form-control,
body.tml-ui .form-select {
    min-height: var(--tml-control-h);
    padding: 0 12px;
    border: 1px solid var(--tml-border-strong);
    border-radius: var(--tml-radius);
    background-color: var(--tml-surface);
    color: var(--tml-text);
    font-size: 0.875rem;
    box-shadow: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

body.tml-ui textarea.form-control {
    padding-top: 8px;
    padding-bottom: 8px;
}

body.tml-ui .form-control-sm,
body.tml-ui .form-select-sm {
    min-height: var(--tml-control-h-sm);
    padding: 0 10px;
    font-size: 0.8125rem;
    border-radius: var(--tml-radius-sm);
}

body.tml-ui .form-select {
    padding-right: 32px;
}

body.tml-ui .form-control::placeholder {
    color: var(--tml-placeholder);
    opacity: 1;
}

body.tml-ui .form-control:focus,
body.tml-ui .form-select:focus {
    border-color: var(--tml-primary);
    box-shadow: 0 0 0 3px var(--tml-primary-ring);
    outline: 0;
}

body.tml-ui .form-control:disabled,
body.tml-ui .form-control[readonly],
body.tml-ui .form-select:disabled {
    background-color: var(--tml-surface-muted);
    color: var(--tml-text-muted);
}

body.tml-ui .form-control.is-invalid,
body.tml-ui .form-select.is-invalid {
    border-color: var(--tml-danger);
}

body.tml-ui .invalid-feedback,
body.tml-ui .text-danger {
    color: var(--tml-danger) !important;
}

body.tml-ui .form-check-input:checked {
    background-color: var(--tml-primary);
    border-color: var(--tml-primary);
}

body.tml-ui .form-check-input:focus {
    border-color: var(--tml-primary);
    box-shadow: 0 0 0 3px var(--tml-primary-ring);
}

body.tml-ui .input-group-text {
    border-color: var(--tml-border-strong);
    border-radius: var(--tml-radius);
    background-color: var(--tml-surface-muted);
    color: var(--tml-text-muted);
}

/* 6. Tables, DataTables, listing cards --------------------------------- */
/* Page templates wrap listings in .table-container / .table-header / .table-title */
body.tml-ui .table-container {
    background-color: var(--tml-surface);
    border: 1px solid var(--tml-border);
    border-radius: var(--tml-radius-lg);
    box-shadow: var(--tml-shadow-xs);
}

body.tml-ui .table-container.container-fluid {
    max-width: none;
}

body.tml-ui .table-header {
    margin: 0;
    padding: 14px 20px;
    background-color: var(--tml-surface);
    border-bottom: 1px solid var(--tml-border);
    color: var(--tml-text);
    font-size: 1rem;
    font-weight: 600;
    text-align: left;
}

body.tml-ui .table-header .table-title,
body.tml-ui .table-header h1,
body.tml-ui .table-header h2,
body.tml-ui .table-header h3,
body.tml-ui .table-header h4,
body.tml-ui .table-header h5 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0;
}

/* Page markup uses the .text-white / .text-center utilities (both !important)
   on these titles for the old blue header bar; the header is now light. */
body.tml-ui .table-header .table-title {
    color: var(--tml-text) !important;
    text-align: left !important;
}

/* Filter / search strips above listings (Bootstrap .bg-light rows and the .filter-bar variant) */
body.tml-ui .bg-light {
    background-color: var(--tml-surface-muted) !important;
}

body.tml-ui .table-container .bg-light,
body.tml-ui .filter-bar {
    border-bottom: 1px solid var(--tml-border);
}

body.tml-ui .filter-bar {
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
    background-color: var(--tml-surface-muted);
}

/* One header for every table, the look of the dashboard list: a white strip under the title, the search box
   and the date control compact and on the left, no grey band. Written with !important because several
   pages still carry their own width / height / background rules for these elements, and without .table-container
   because some pages (Sage invoices, Deleted loads) are not inside one. */
body.tml-ui .row.bg-light.align-items-center,
body.tml-ui .filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start !important;
    gap: 12px;
    margin: 0 !important;
    padding: 12px 20px !important;
    background-color: var(--tml-surface) !important;
    border-bottom: 0;
}

body.tml-ui .row.bg-light.align-items-center > [class*="col-"],
body.tml-ui .filter-bar > * {
    flex: 0 0 auto;
    width: auto !important;
    max-width: none;
    padding: 0;
}

/* the global search box: the same size everywhere (custom boxes and DataTables' own) */
body.tml-ui input[id^="globalSearch"],
body.tml-ui .dataTables_wrapper .dataTables_filter input {
    width: 220px !important;
    min-height: var(--tml-control-h-sm);
    height: var(--tml-control-h-sm) !important;
    margin: 0;
    padding: 0 10px;
    border: 1px solid var(--tml-border-strong);
    border-radius: var(--tml-radius-sm);
    background-color: var(--tml-surface);
    font-size: 0.8125rem;
}

/* DataTables' own search (tables without a custom search box): on the left, the hidden "Show entries" column gives way */
body.tml-ui .dataTables_wrapper > .row:first-child {
    justify-content: flex-start;
}

body.tml-ui .dataTables_wrapper > .row:first-child > [class*="col-"] {
    flex: 0 0 auto;
    width: auto;
}

body.tml-ui .dataTables_wrapper > .row:first-child > [class*="col-"]:not(:has(.dataTables_filter)) {
    display: none;
}

body.tml-ui .dataTables_wrapper .dataTables_filter {
    margin: 12px 0;
    text-align: left;
}

/* the date-range button: the same height and corners as the search box next to it */
body.tml-ui .btn.tml-daterange-toggle {
    height: var(--tml-control-h-sm);
    min-height: var(--tml-control-h-sm);
    padding: 0 12px;
    border-radius: var(--tml-radius-sm);
    font-size: 0.8125rem;
}

/* table head: both rows (titles + search boxes) on the same light background and the same muted small-caps titles,
   whatever a page sets (some tables use .table-bordered / .table-striped and their own th colours) */
body.tml-ui table.dataTable > thead > tr > th,
body.tml-ui table.dataTable > thead > tr > td {
    background-color: var(--tml-surface-muted) !important;
    border-bottom: 1px solid var(--tml-border) !important;
    color: var(--tml-text-muted) !important;
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* no grid lines and no zebra stripes: rows are separated by one thin line, like the dashboard list */
body.tml-ui table.dataTable.table-bordered > :not(caption) > * > * {
    border-width: 0 0 1px !important;
}

body.tml-ui table.dataTable.table-striped {
    --bs-table-striped-bg: transparent;
}

/* a table inside a plain .card (System Logs) is inset like the others */
body.tml-ui .card-datatable {
    padding: 0 20px 16px;
}

/* a title in a plain .card header looks like a .table-title */
body.tml-ui .card-header .card-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--tml-text);
}

body.tml-ui .table {
    --bs-table-bg: transparent;
    --bs-table-hover-bg: var(--tml-surface-muted);
    --bs-table-striped-bg: var(--tml-surface-muted);
    margin-bottom: 0;
    color: var(--tml-text);
    border-color: var(--tml-border);
}

body.tml-ui .table > thead > tr > th {
    padding: 10px 12px;
    background-color: var(--tml-surface-muted);
    border-bottom: 1px solid var(--tml-border);
    color: var(--tml-text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    vertical-align: middle;
    white-space: nowrap;
}

body.tml-ui .table > tbody > tr > td,
body.tml-ui .table > tfoot > tr > td {
    padding: 10px 12px;
    border-color: var(--tml-border);
    vertical-align: middle;
    font-size: 0.875rem;
}

body.tml-ui .table-hover > tbody > tr:hover > * {
    background-color: var(--tml-surface-muted);
    color: var(--tml-text);
}

body.tml-ui .table-responsive {
    -webkit-overflow-scrolling: touch;
}

/* DataTables (bs5 wrapper) */
body.tml-ui .dataTables_wrapper {
    padding: 0;
}

body.tml-ui .dataTables_wrapper .dataTables_length,
body.tml-ui .dataTables_wrapper .dataTables_filter,
body.tml-ui .dataTables_wrapper .dataTables_info {
    color: var(--tml-text-muted);
    font-size: 0.8125rem;
}

/* no "Show N entries" box on any table (every table shows 100 rows per page) */
body.tml-ui .dataTables_wrapper .dataTables_length {
    display: none;
}

body.tml-ui .dataTables_wrapper .dataTables_filter input,
body.tml-ui .dataTables_wrapper .dataTables_length select {
    min-height: var(--tml-control-h-sm);
    border: 1px solid var(--tml-border-strong);
    border-radius: var(--tml-radius-sm);
    background-color: var(--tml-surface);
    color: var(--tml-text);
}

body.tml-ui .dataTables_wrapper .dataTables_filter input:focus,
body.tml-ui .dataTables_wrapper .dataTables_length select:focus {
    border-color: var(--tml-primary);
    box-shadow: 0 0 0 3px var(--tml-primary-ring);
    outline: 0;
}

body.tml-ui .dataTables_wrapper .dataTables_paginate {
    padding-top: 8px;
}

/* Sort arrows (all modules). The vendor theme draws them with the "Material Design
   Icons" font, which is not loaded here (shows a "box"), and hides them on unsorted
   columns until hover. Draw them with CSS borders instead: no font needed, an up+down
   pair on every sortable title cell, the active direction solid in the primary colour.
   !important is needed to beat the vendor rules, which are !important themselves. */
body.tml-ui table.dataTable > thead > tr > th.sorting,
body.tml-ui table.dataTable > thead > tr > th.sorting_asc,
body.tml-ui table.dataTable > thead > tr > th.sorting_desc {
    padding-right: 28px !important;
}

body.tml-ui table.dataTable > thead > tr > th.sorting:before,
body.tml-ui table.dataTable > thead > tr > th.sorting:after,
body.tml-ui table.dataTable > thead > tr > th.sorting_asc:before,
body.tml-ui table.dataTable > thead > tr > th.sorting_asc:after,
body.tml-ui table.dataTable > thead > tr > th.sorting_desc:before,
body.tml-ui table.dataTable > thead > tr > th.sorting_desc:after {
    content: "" !important;
    display: block !important;
    visibility: visible !important;
    position: absolute !important;
    right: 11px !important;
    left: auto !important;
    width: 0 !important;
    height: 0 !important;
    font-size: 0 !important;
    line-height: 0 !important;
    border-left: 4px solid transparent !important;
    border-right: 4px solid transparent !important;
    color: var(--tml-text-muted) !important;
    opacity: 0.35 !important;
}

body.tml-ui table.dataTable > thead > tr > th.sorting:before,
body.tml-ui table.dataTable > thead > tr > th.sorting_asc:before,
body.tml-ui table.dataTable > thead > tr > th.sorting_desc:before {
    top: auto !important;
    bottom: 50% !important;
    margin-bottom: 1px !important;
    border-top: 0 !important;
    border-bottom: 5px solid currentColor !important;
}

body.tml-ui table.dataTable > thead > tr > th.sorting:after,
body.tml-ui table.dataTable > thead > tr > th.sorting_asc:after,
body.tml-ui table.dataTable > thead > tr > th.sorting_desc:after {
    top: 50% !important;
    bottom: auto !important;
    margin-top: 1px !important;
    border-bottom: 0 !important;
    border-top: 5px solid currentColor !important;
}

body.tml-ui table.dataTable > thead > tr > th.sorting_asc:before,
body.tml-ui table.dataTable > thead > tr > th.sorting_desc:after {
    color: var(--tml-primary) !important;
    opacity: 1 !important;
}

/* No table has its own loading box: the one loader of the system (layouts/partials/app-loader) covers the first load. */
body.tml-ui div.dataTables_processing,
body.tml-ui div.dataTables_wrapper div.dataTables_processing {
    display: none !important;
}

/* Site name cells (every module list): wrap onto lines inside a fixed width, so a site name takes about 2 lines
   instead of one very long line that pushes the Action column out of view */
body.tml-ui table td.site-cell {
    min-width: 220px;
    max-width: 360px;
    white-space: normal;
    line-height: 1.35;
}

/* Date-range control (partials/date-range-filter): one small button, calendar popover with Clear / Apply inside ---- */
body.tml-ui .tml-daterange {
    position: relative;
    display: inline-flex;
    align-items: center;
}

body.tml-ui .tml-daterange-toggle {
    width: auto;
    white-space: nowrap;
}

body.tml-ui .tml-daterange-toggle::after {
    content: "";
    width: 0;
    height: 0;
    margin-left: 2px;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid currentColor;
    opacity: 0.6;
}

body.tml-ui .tml-daterange-toggle.is-active {
    border-color: var(--tml-primary);
    color: var(--tml-primary);
}

body.tml-ui .tml-daterange-pop {
    position: absolute;
    z-index: 2000;
    max-width: calc(100vw - 16px);
    padding: 8px;
    background: var(--tml-surface);
    border: 1px solid var(--tml-border-strong);
    border-radius: 6px;
    box-shadow: var(--tml-shadow-lg);
}

body.tml-ui .tml-daterange-pop .tml-daterange-cal {
    display: none;
}

body.tml-ui .tml-daterange-pop .flatpickr-calendar.inline {
    margin: 0 auto;
    border: 0;
    box-shadow: none;
}

body.tml-ui .tml-daterange-pop .flatpickr-day.selected,
body.tml-ui .tml-daterange-pop .flatpickr-day.startRange,
body.tml-ui .tml-daterange-pop .flatpickr-day.endRange {
    background: var(--tml-primary);
    border-color: var(--tml-primary);
    color: #fff;
}

body.tml-ui .tml-daterange-pop .flatpickr-day.inRange {
    background: var(--tml-primary-soft);
    border-color: var(--tml-primary-soft);
    box-shadow: -5px 0 0 var(--tml-primary-soft), 5px 0 0 var(--tml-primary-soft);
}

body.tml-ui .tml-daterange-foot {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--tml-border);
}

/* Module title cell ("Pre Invoice - Collection Without Tip Ticket (Loads)"): wide enough for two lines at most,
   instead of a narrow column that stacks the words into five or six lines and makes every row tall */
body.tml-ui table td.module-cell {
    min-width: 300px;
    max-width: 380px;
    white-space: normal;
    line-height: 1.35;
}

/* company name in the same table: two lines at most, so it does not set the row height either */
body.tml-ui table td.company-cell {
    min-width: 190px;
    max-width: 260px;
    white-space: normal;
    line-height: 1.35;
}

/* 7. Tabs, cards, badges, alerts, dropdowns, modals, pagination -------- */
body.tml-ui .nav-tabs {
    border-bottom: 1px solid var(--tml-border);
    gap: 2px;
}

body.tml-ui .nav-tabs .nav-link {
    margin: 0;
    padding: 10px 16px;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: none;
    color: var(--tml-text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
}

body.tml-ui .nav-tabs .nav-link:hover {
    border-bottom-color: var(--tml-border-strong);
    color: var(--tml-text);
}

body.tml-ui .nav-tabs .nav-link.active {
    border-bottom-color: var(--tml-primary);
    background: none;
    color: var(--tml-primary);
    font-weight: 600;
}

body.tml-ui .tab-container {
    padding: 0 12px;
}

body.tml-ui .card {
    border: 1px solid var(--tml-border);
    border-radius: var(--tml-radius-lg);
    background-color: var(--tml-surface);
    box-shadow: var(--tml-shadow-xs);
}

body.tml-ui .card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--tml-border);
    background-color: var(--tml-surface);
}

body.tml-ui .badge {
    padding: 0.35em 0.65em;
    border-radius: var(--tml-radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
}

/* Warning surfaces that carry dark text (badges with .text-dark, card headers) use a light amber so the text
   stays readable; white-text warning badges keep the darker amber from the palette tokens. */
body.tml-ui .bg-warning.text-dark,
body.tml-ui .card-header.bg-warning {
    background-color: #fbbf24 !important;
    color: var(--tml-text) !important;
}

body.tml-ui .alert {
    border-radius: var(--tml-radius);
    font-size: 0.875rem;
}

body.tml-ui .dropdown-menu {
    padding: 6px;
    border: 1px solid var(--tml-border);
    border-radius: var(--tml-radius);
    box-shadow: var(--tml-shadow-lg);
}

body.tml-ui .dropdown-item {
    border-radius: var(--tml-radius-sm);
    font-size: 0.875rem;
}

body.tml-ui .dropdown-item:hover,
body.tml-ui .dropdown-item:focus {
    background-color: var(--tml-surface-muted);
    color: var(--tml-text);
}

body.tml-ui .modal-content {
    border: 0;
    border-radius: var(--tml-radius-lg);
    box-shadow: var(--tml-shadow-lg);
}

body.tml-ui .modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--tml-border);
}

body.tml-ui .modal-title {
    font-size: 1.05rem;
    font-weight: 600;
}

body.tml-ui .modal-body {
    padding: 20px;
}

body.tml-ui .modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--tml-border);
    gap: 8px;
}

body.tml-ui .pagination .page-link {
    min-width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--tml-border);
    border-radius: var(--tml-radius-sm);
    color: var(--tml-text);
    font-size: 0.8125rem;
}

body.tml-ui .pagination .page-link:hover {
    background-color: var(--tml-surface-muted);
}

body.tml-ui .pagination .page-item.active .page-link {
    background-color: var(--tml-primary);
    border-color: var(--tml-primary);
    color: #fff;
}

body.tml-ui .pagination .page-item.disabled .page-link {
    color: var(--tml-text-muted);
    opacity: 0.6;
}

/* 8. Toastr / SweetAlert2 / flatpickr ---------------------------------- */
/* Modals sit above everything else (existing behaviour), toasts above modals. */
body.tml-ui .modal-backdrop {
    z-index: 99999;
}

body.tml-ui .modal {
    z-index: 999999;
}

body.tml-ui #toast-container {
    z-index: 9999999;
}

body.tml-ui #toast-container > .toast {
    width: 360px;
    max-width: calc(100vw - 24px);
    padding: 14px 40px 14px 48px;
    border: 1px solid var(--tml-border);
    border-left-width: 4px;
    border-radius: var(--tml-radius);
    background-color: var(--tml-surface) !important;
    background-image: none !important;
    box-shadow: var(--tml-shadow-lg);
    color: var(--tml-text) !important;
    opacity: 1;
}

body.tml-ui #toast-container > .toast::before {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free';
    font-weight: 900;
    font-size: 18px;
    line-height: 1;
}

body.tml-ui #toast-container > .toast-success {
    border-left-color: var(--tml-success);
}

body.tml-ui #toast-container > .toast-success::before {
    content: '\f058';
    color: var(--tml-success);
}

body.tml-ui #toast-container > .toast-error {
    border-left-color: var(--tml-danger);
}

body.tml-ui #toast-container > .toast-error::before {
    content: '\f057';
    color: var(--tml-danger);
}

body.tml-ui #toast-container > .toast-info {
    border-left-color: var(--tml-info);
}

body.tml-ui #toast-container > .toast-info::before {
    content: '\f05a';
    color: var(--tml-info);
}

body.tml-ui #toast-container > .toast-warning {
    border-left-color: var(--tml-warning);
}

body.tml-ui #toast-container > .toast-warning::before {
    content: '\f071';
    color: var(--tml-warning);
}

body.tml-ui #toast-container > .toast .toast-message {
    margin: 0;
    color: var(--tml-text) !important;
    font-size: 0.875rem;
    line-height: 1.4;
}

body.tml-ui #toast-container > .toast .toast-close-button {
    position: absolute;
    top: 8px;
    right: 12px;
    color: var(--tml-text-muted);
    font-weight: 400;
    text-shadow: none;
    opacity: 0.8;
}

body.tml-ui #toast-container > .toast .toast-close-button:hover {
    color: var(--tml-text);
    opacity: 1;
}

body.tml-ui #toast-container > .toast .toast-progress {
    opacity: 0.25;
}

/* SweetAlert2 renders into <body>, so it can be scoped the same way. */
body.tml-ui .swal2-popup {
    border-radius: var(--tml-radius-lg);
    font-family: var(--tml-font);
    font-size: 0.95rem;
}

body.tml-ui .swal2-title {
    color: var(--tml-text);
    font-size: 1.25rem;
    font-weight: 600;
}

body.tml-ui .swal2-styled {
    border-radius: var(--tml-radius);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: none !important;
}

body.tml-ui .swal2-styled.swal2-confirm {
    background-color: var(--tml-danger);
    color: #fff;
    border: 0;
}

body.tml-ui .swal2-styled.swal2-cancel {
    background-color: var(--tml-text-muted);
    color: #fff;
    border: 0;
}

/* flatpickr */
body.tml-ui .flatpickr-calendar {
    border-radius: var(--tml-radius);
    box-shadow: var(--tml-shadow-lg);
    font-family: var(--tml-font);
}

/* 8b. Sign-in page (welcome.blade.php) -------------------------------- */
body.tml-auth {
    min-height: 100vh;
}

body.tml-auth .authentication-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background-color: var(--tml-bg);
}

body.tml-auth .auth-cover-brand,
body.tml-auth .tml-auth-aside {
    display: none !important;
}

body.tml-auth .authentication-inner {
    width: 100%;
    max-width: 440px;
    margin: 0 auto !important;
}

body.tml-auth .authentication-inner > .authentication-bg {
    flex: 0 0 100%;
    max-width: 100%;
    padding: 32px 28px !important;
    border: 1px solid var(--tml-border);
    border-radius: var(--tml-radius-lg);
    background-color: var(--tml-surface);
    box-shadow: var(--tml-shadow-sm);
}

body.tml-auth .authentication-inner > .authentication-bg > div {
    width: 100%;
    max-width: none;
    padding-top: 0 !important;
}

body.tml-auth .authentication-wrapper .authentication-inner {
    min-height: 0;
    height: auto;
}

body.tml-auth .authentication-inner > .authentication-bg {
    height: auto;
    align-self: center;
}

/* The template paints floating-label focus states in its own purple */
body.tml-auth .form-floating-outline > .form-control:focus {
    border-color: var(--tml-primary) !important;
    box-shadow: 0 0 0 3px var(--tml-primary-ring);
}

body.tml-auth .form-floating-outline > .form-control:focus ~ label {
    color: var(--tml-primary);
}

body.tml-auth .input-group-merge:has(.form-floating-outline):focus-within > .input-group-text {
    border-color: var(--tml-primary);
}

body.tml-auth .tml-auth-logo {
    display: block;
    width: 148px;
    max-width: 60%;
    height: auto;
    margin: 0 auto 20px;
    border-radius: var(--tml-radius);
}

body.tml-auth h4 {
    text-align: center;
    font-size: 1.35rem;
}

body.tml-auth h4 + p {
    text-align: center;
    color: var(--tml-text-muted);
}

body.tml-auth .btn.login {
    min-height: 42px;
    width: 100%;
}

/* 9. Responsive -------------------------------------------------------- */
@media (max-width: 1199.98px) {
    body.tml-ui .layout-menu {
        transform: translateX(-100%);
        box-shadow: none;
    }

    body.tml-ui .layout-menu.show {
        transform: translateX(0);
        box-shadow: var(--tml-shadow-lg);
    }

    body.tml-ui .layout-page {
        margin-left: 0;
    }
}

/* Wide listings stay readable on tablets/phones: the card scrolls sideways
   instead of clipping columns (page styles set overflow-x: hidden on it). */
@media (max-width: 991.98px) {
    body.tml-ui .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 767.98px) {
    body.tml-ui {
        --tml-gutter: 14px;
    }

    /* Two-group tab bars (e.g. tip-ticket tabs + invoice-status tabs) wrap instead of clipping */
    body.tml-ui .nav-tabs {
        justify-content: flex-start;
    }

    body.tml-ui .nav-tabs > .d-flex,
    body.tml-ui .nav-tabs > .d-flex-new {
        flex-wrap: wrap;
    }

    body.tml-ui .nav-tabs .nav-link {
        padding: 8px 12px;
    }

    /* Filter strips: stack their groups full-width (page markup gives some inline widths) */
    body.tml-ui .filter-bar > * {
        width: 100% !important;
        flex-wrap: wrap;
    }

    body.tml-ui .layout-navbar .tml-navbar-version,
    body.tml-ui .layout-navbar .tml-navbar-user-name {
        display: none;
    }

    body.tml-ui .layout-navbar .tml-navbar-title {
        font-size: 0.95rem;
    }

    body.tml-ui .table-header {
        padding: 12px 14px;
    }

    body.tml-ui .modal-dialog {
        margin: 12px;
    }

    body.tml-ui #toast-container > .toast {
        width: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.tml-ui * {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* 9. Footers ------------------------------------------------------------ */
/* Pages after login: copyright left, product + version right, pinned to the
   bottom of the page column when the content is short. */
body.tml-ui .layout-page {
    display: flex;
    flex-direction: column;
}

body.tml-ui .layout-page > .container-fluid,
body.tml-ui .layout-page > .container {
    flex: 1 0 auto;
    width: 100%;
}

body.tml-ui .tml-footer {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 24px;
    padding: 14px var(--tml-gutter);
    border-top: 1px solid var(--tml-border);
    background-color: var(--tml-surface);
    color: var(--tml-text-muted);
    font-size: 0.8125rem;
}

body.tml-ui .tml-footer-right {
    text-align: right;
}

@media (max-width: 767.98px) {
    body.tml-ui .tml-footer {
        flex-direction: column;
        align-items: flex-start;
    }

    body.tml-ui .tml-footer-right {
        text-align: left;
    }
}

/* Sign-in page: three centred lines under the card */
body.tml-auth .authentication-wrapper {
    padding-bottom: 96px;
}

body.tml-auth .tml-auth-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 12px 16px;
    text-align: center;
    color: var(--tml-text-muted);
    font-size: 0.8125rem;
    line-height: 1.5;
}

/* User avatar (header + user menu): photo or initials badge */
body.tml-ui .tml-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--tml-border);
}

body.tml-ui .tml-avatar-sm {
    width: 34px;
    height: 34px;
}

body.tml-ui .tml-avatar-lg {
    width: 42px;
    height: 42px;
}

body.tml-ui .tml-avatar-initials {
    background: var(--tml-primary-soft);
    border-color: transparent;
    color: var(--tml-primary);
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1;
    user-select: none;
}

body.tml-ui .tml-avatar-sm.tml-avatar-initials {
    font-size: 0.8125rem;
}

body.tml-ui .tml-avatar-lg.tml-avatar-initials {
    font-size: 1rem;
}

/* Log Out entry in the user menu: red text and icon */
body.tml-ui .dropdown-item.tml-logout-item,
body.tml-ui .dropdown-item.tml-logout-item i {
    color: var(--tml-danger);
}

body.tml-ui .dropdown-item.tml-logout-item:hover,
body.tml-ui .dropdown-item.tml-logout-item:focus {
    background-color: var(--tml-danger-soft);
    color: var(--tml-danger-hover);
}

body.tml-ui .dropdown-item.tml-logout-item:hover i,
body.tml-ui .dropdown-item.tml-logout-item:focus i {
    color: var(--tml-danger-hover);
}
