/**
 * RedTRM global UI polish — slim scrollbars + modal widths
 */

/* ── Slim scrollbars (Firefox + WebKit) ─────────────────────────── */
html {
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.42) transparent;
}

.dark html {
    scrollbar-color: rgba(148, 163, 184, 0.38) transparent;
}

* {
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.42) transparent;
}

.dark * {
    scrollbar-color: rgba(148, 163, 184, 0.38) transparent;
}

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background-color: rgba(100, 116, 139, 0.38);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
    background-color: rgba(100, 116, 139, 0.55);
}

.dark *::-webkit-scrollbar-thumb {
    background-color: rgba(148, 163, 184, 0.32);
}

.dark *::-webkit-scrollbar-thumb:hover {
    background-color: rgba(148, 163, 184, 0.48);
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

/* ── Modal panel widths (use on inner panel div) ───────────────── */
.redtrm-modal-panel--wide {
    width: 100%;
    max-width: min(96vw, 72rem); /* ~max-w-6xl — ledger / summary tables */
}

.redtrm-modal-panel--xl {
    width: 100%;
    max-width: min(96vw, 80rem); /* ~max-w-7xl — very wide grids */
}

.redtrm-modal-panel--lg {
    width: 100%;
    max-width: min(92vw, 56rem); /* ~max-w-4xl */
}

.redtrm-modal-panel--md {
    width: 100%;
    max-width: min(90vw, 42rem); /* ~max-w-2xl — forms */
}

.redtrm-modal-body-scroll {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.redtrm-slim-scroll {
    scrollbar-width: thin;
    scrollbar-color: rgb(203 213 225) transparent;
}

.redtrm-slim-scroll::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.redtrm-slim-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.redtrm-slim-scroll::-webkit-scrollbar-thumb {
    background-color: rgb(203 213 225);
    border-radius: 9999px;
}

.dark .redtrm-slim-scroll::-webkit-scrollbar-thumb {
    background-color: rgb(75 85 99);
}

.redtrm-modal-table-wrap--scroll-y {
    overflow-y: auto;
    max-height: min(52vh, 480px);
}

.redtrm-modal-table-wrap--scroll-y .redtrm-modal-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgb(255 255 255);
    box-shadow: 0 1px 0 rgb(229 231 235);
}

.dark .redtrm-modal-table-wrap--scroll-y .redtrm-modal-table thead th {
    background: rgb(17 24 39);
    box-shadow: 0 1px 0 rgb(55 65 81);
}

/* Credit note primary actions — rose-* is not in compiled Tailwind; use explicit colors */
.redtrm-btn-credit-note {
    background-color: rgb(220 38 38);
    border-color: rgb(185 28 28);
    color: #fff;
}

.redtrm-btn-credit-note:hover {
    background-color: rgb(185 28 28);
}

/* Tall panel for embedded PDF iframes (flex child needs a definite parent height) */
.redtrm-modal-panel--pdf-preview {
    height: min(92vh, 920px);
    min-height: min(78vh, 720px);
}

.redtrm-modal-panel--pdf-preview .redtrm-modal-pdf-frame {
    display: block;
    width: 100%;
    height: 100%;
    min-height: min(68vh, 640px);
    border: 0;
}

/* ── Modal list tables (payment summary, allocation trail, ledgers) ─ */
.redtrm-modal-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0.75rem;
    border: 1px solid rgb(229 231 235);
}

.dark .redtrm-modal-table-wrap {
    border-color: rgb(55 65 81);
}

/* Portal overlays — above sticky table headers and the top bar */
.redtrm-portal-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 110;
    isolation: isolate;
}

body.redtrm-portal-modal-open .redtrm-modal-table thead th,
body.redtrm-portal-modal-open .redtrm-modal-table .redtrm-col-sticky-actions {
    z-index: 1;
}

.redtrm-modal-table {
    width: 100%;
    min-width: min(100%, 40rem);
    border-collapse: collapse;
    table-layout: fixed;
}

.redtrm-modal-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background-color: rgb(255 255 255);
    box-shadow: 0 1px 0 rgb(229 231 235);
}

.dark .redtrm-modal-table thead th {
    background-color: rgb(17 24 39);
    box-shadow: 0 1px 0 rgb(55 65 81);
}

.redtrm-modal-table tbody tr:hover {
    background-color: rgb(249 250 251);
}

.dark .redtrm-modal-table tbody tr:hover {
    background-color: rgb(31 41 55 / 0.45);
}

.redtrm-cell-truncate {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.redtrm-modal-table .redtrm-col-sticky-actions {
    position: sticky;
    right: 0;
    z-index: 2;
    width: 7.5rem;
    min-width: 7.5rem;
    background-color: rgb(255 255 255);
    box-shadow: -8px 0 14px -10px rgba(15, 23, 42, 0.22);
}

.redtrm-modal-table .redtrm-col-sticky-actions--pay {
    width: 5.75rem;
    min-width: 5.75rem;
}

.redtrm-modal-table .redtrm-col-sticky-actions--wide {
    width: 7.5rem;
    min-width: 7.5rem;
}

.redtrm-ps-actions {
    display: inline-flex;
    flex-flow: row nowrap;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    white-space: nowrap;
}

.redtrm-ps-icon-btn {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 0.5rem;
    border: 1px solid transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.redtrm-ps-icon-btn--edit {
    color: rgb(35 70 133);
    border-color: rgb(188 208 236);
    background-color: rgb(239 244 251);
}

.redtrm-ps-icon-btn--edit:hover {
    color: rgb(31 58 107);
    border-color: rgb(144 176 222);
    background-color: rgb(219 230 245);
}

.redtrm-ps-icon-btn--delete {
    color: rgb(185 28 28);
    border-color: rgb(254 202 202);
    background-color: rgb(254 242 242);
}

.redtrm-ps-icon-btn--delete:hover {
    color: rgb(153 27 27);
    border-color: rgb(252 165 165);
    background-color: rgb(254 226 226);
}

.dark .redtrm-ps-icon-btn--edit {
    color: rgb(188 208 236);
    border-color: rgb(35 70 133);
    background-color: rgb(28 50 88);
}

.dark .redtrm-ps-icon-btn--edit:hover {
    color: rgb(219 230 245);
    border-color: rgb(59 107 184);
    background-color: rgb(31 58 107);
}

.dark .redtrm-ps-icon-btn--delete {
    color: rgb(252 165 165);
    border-color: rgb(127 29 29);
    background-color: rgb(69 10 10);
}

.dark .redtrm-ps-icon-btn--delete:hover {
    color: rgb(254 202 202);
    border-color: rgb(153 27 27);
    background-color: rgb(127 29 29);
}

.dark .redtrm-modal-table .redtrm-col-sticky-actions {
    background-color: rgb(17 24 39);
    box-shadow: -8px 0 14px -10px rgba(0, 0, 0, 0.45);
}

.redtrm-modal-table tbody tr:hover .redtrm-col-sticky-actions {
    background-color: rgb(249 250 251);
}

.dark .redtrm-modal-table tbody tr:hover .redtrm-col-sticky-actions {
    background-color: rgb(31 41 55);
}

/* Travel invoice wide tables — remove control pinned right (always visible / clickable) */
.redtrm-travel-table-scroll {
    -webkit-overflow-scrolling: touch;
    scroll-padding-right: 3.25rem;
}

.redtrm-travel-table-scroll tbody tr {
    position: relative;
}

.redtrm-travel-table-scroll .redtrm-travel-row-remove,
.redtrm-travel-table-scroll .redtrm-travel-row-actions {
    position: sticky;
    right: 0;
    left: auto;
    z-index: 6;
    width: 2.75rem;
    min-width: 2.75rem;
    max-width: 2.75rem;
    background-color: rgb(255 255 255);
    box-shadow: -4px 0 10px -6px rgba(15, 23, 42, 0.18);
    vertical-align: top;
}

.dark .redtrm-travel-table-scroll .redtrm-travel-row-remove,
.dark .redtrm-travel-table-scroll .redtrm-travel-row-actions {
    background-color: rgb(17 24 39);
    box-shadow: -4px 0 10px -6px rgba(0, 0, 0, 0.4);
}

.redtrm-travel-table-scroll tbody tr:hover .redtrm-travel-row-remove,
.redtrm-travel-table-scroll tbody tr:hover .redtrm-travel-row-actions {
    background-color: rgb(249 250 251);
}

.dark .redtrm-travel-table-scroll tbody tr:hover .redtrm-travel-row-remove,
.dark .redtrm-travel-table-scroll tbody tr:hover .redtrm-travel-row-actions {
    background-color: rgb(31 41 55);
}

.redtrm-travel-table-scroll .js-travel-remove-row,
.redtrm-travel-table-scroll .redtrm-travel-remove-btn {
    position: relative;
    z-index: 7;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    min-height: 2.25rem;
    touch-action: manipulation;
    cursor: pointer !important;
    pointer-events: auto;
}

/* Refund actions — explicit colors so light theme always shows label + fill */
.redtrm-btn-refund {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.5rem;
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1rem;
    border: 1px solid rgb(190 18 60);
    background-color: rgb(255 228 230);
    color: rgb(136 19 55) !important;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.redtrm-btn-refund:hover {
    background-color: rgb(254 205 211);
    border-color: rgb(159 18 57);
    color: rgb(127 29 29) !important;
}

.dark .redtrm-btn-refund {
    border-color: rgb(251 113 133);
    background-color: rgb(76 5 25);
    color: rgb(254 205 211) !important;
}

.dark .redtrm-btn-refund:hover {
    background-color: rgb(136 19 55);
    color: rgb(255 255 255) !important;
}

.redtrm-btn-refund-process {
    border-color: rgb(217 119 6);
    background-color: rgb(254 243 199);
    color: rgb(120 53 15) !important;
}

.redtrm-btn-refund-process:hover {
    background-color: rgb(253 230 138);
    color: rgb(69 26 3) !important;
}

.dark .redtrm-btn-refund-process {
    border-color: rgb(245 158 11);
    background-color: rgb(69 26 3);
    color: rgb(254 243 199) !important;
}

.dark .redtrm-btn-refund-process:hover {
    background-color: rgb(120 53 15);
}

/* Collapsible alert lists — fixed 2-item viewport with slim scroll (dashboard travel alerts + invoice finance requests) */
.redtrm-alert-list-scroll {
    --redtrm-alert-row-min-h: 5.25rem;
    --redtrm-alert-visible-rows: 2;
    max-height: calc(
        var(--redtrm-alert-visible-rows) * var(--redtrm-alert-row-min-h)
        + (var(--redtrm-alert-visible-rows) - 1) * 0.5rem
    );
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgb(156 163 175) transparent;
}

.redtrm-alert-list-scroll::-webkit-scrollbar {
    width: 6px;
}

.redtrm-alert-list-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.redtrm-alert-list-scroll::-webkit-scrollbar-thumb {
    background-color: rgb(209 213 219);
    border-radius: 9999px;
}

.redtrm-alert-list-scroll::-webkit-scrollbar-thumb:hover {
    background-color: rgb(156 163 175);
}

.dark .redtrm-alert-list-scroll {
    scrollbar-color: rgb(75 85 99) transparent;
}

.dark .redtrm-alert-list-scroll::-webkit-scrollbar-thumb {
    background-color: rgb(75 85 99);
}

.dark .redtrm-alert-list-scroll::-webkit-scrollbar-thumb:hover {
    background-color: rgb(107 114 128);
}

.redtrm-alert-list-scroll .redtrm-alert-list-item,
.redtrm-collapsible-alert-panel .redtrm-alert-list-item {
    min-height: var(--redtrm-alert-row-min-h);
}

/* Invoice list — credit note sub-rows (light red; works without Tailwind purge) */
tr.inv-list-row-credit-note > td,
.dark tr.inv-list-row-credit-note > td {
    background-color: rgba(254, 205, 211, 0.55) !important;
    border-top-color: rgba(244, 63, 94, 0.15);
}
tr.inv-list-row-credit-note > td:first-child,
.dark tr.inv-list-row-credit-note > td:first-child {
    box-shadow: inset 4px 0 0 0 rgb(244, 63, 94);
}
html.dark tr.inv-list-row-credit-note > td {
    background-color: rgba(136, 19, 55, 0.38) !important;
    border-top-color: rgba(244, 63, 94, 0.2);
}
html.dark tr.inv-list-row-credit-note > td:first-child {
    box-shadow: inset 4px 0 0 0 rgb(251, 113, 133);
}
.dark tr.inv-list-row-credit-note > td {
    background-color: rgba(136, 19, 55, 0.38) !important;
    border-top-color: rgba(244, 63, 94, 0.2);
}
.dark tr.inv-list-row-credit-note > td:first-child {
    box-shadow: inset 4px 0 0 0 rgb(251, 113, 133);
}
tr.inv-list-row-credit-note:hover > td,
.dark tr.inv-list-row-credit-note:hover > td {
    background-color: rgba(254, 205, 211, 0.72) !important;
}
html.dark tr.inv-list-row-credit-note:hover > td,
.dark tr.inv-list-row-credit-note:hover > td {
    background-color: rgba(136, 19, 55, 0.52) !important;
}

/* Supplier payments — credit note / supplier credit lines */
tr.sp-row-credit-note > td,
.dark tr.sp-row-credit-note > td,
html.dark tr.sp-row-credit-note > td {
    background-color: rgba(136, 19, 55, 0.32) !important;
}
tr.sp-row-credit-note > td:first-child,
.dark tr.sp-row-credit-note > td:first-child,
html.dark tr.sp-row-credit-note > td:first-child {
    box-shadow: inset 4px 0 0 0 rgb(251, 113, 133);
}

/* Page back navigation — subtle link sits above page content, not in the header bar */
.redtrm-page-back-wrap {
    display: block;
    line-height: 1.25;
}
.redtrm-page-back-wrap .redtrm-page-back {
    text-decoration: none;
}
.redtrm-page-back-wrap .redtrm-page-back:hover {
    text-decoration: none;
}
.redtrm-page-back--prominent {
    white-space: nowrap;
}
