/*
 * Overvue Finance on Bootstrap 5.3, in the Overvue Email brand.
 * Loaded after Bootstrap and css/theme.css (the shared brand file copied from Overvue Email).
 * Everything here is layout and finance-specific components; colours come from the theme tokens
 * (--bs-* and --app-*) so light and dark mode follow automatically.
 */

/* ---------- app frame ---------- */

.fin-app {
    --fin-sidebar-w: 15.5rem;
    display: flex;
    min-height: 100vh;
}

.fin-content {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.fin-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 1rem;
    background: var(--bs-body-bg);
    border-bottom: 1px solid var(--bs-border-color);
}

.fin-crumb {
    color: var(--bs-secondary-color);
    padding-left: 0.75rem;
    border-left: 1px solid var(--bs-border-color);
}

.fin-main {
    flex: 1 1 auto;
    min-width: 0;
    padding: 1.25rem 1rem 2rem;
    max-width: 1400px;
    width: 100%;
    margin-inline: auto;
}

@media (min-width: 992px) {
    .fin-main {
        padding: 1.75rem 2rem 2.5rem;
    }
}

.fin-main:focus {
    outline: none;
}

.min-w-0 {
    min-width: 0;
}

/* ---------- sidebar ---------- */

.fin-sidebar {
    flex: 0 0 var(--fin-sidebar-w);
    width: var(--fin-sidebar-w);
    position: sticky;
    top: 0;
    height: 100vh;
    flex-direction: column;
    overflow-y: auto;
    padding: 1rem 0.75rem;
    background: var(--bs-tertiary-bg);
    border-right: 1px solid var(--bs-border-color);
}

.fin-sidebar > * {
    flex-shrink: 0;
}

.fin-company {
    padding: 0.35rem 0.75rem 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-bottom: 1px solid var(--bs-border-color);
    margin-bottom: 0.5rem;
}

.fin-nav-label {
    margin: 1rem 0 0.3rem;
    padding-left: 0.75rem;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
}

.fin-nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.1rem;
    border-radius: var(--bs-border-radius);
    color: var(--bs-body-color);
    font-size: 0.92rem;
    text-decoration: none;
}

.fin-nav-link .bi {
    flex: none;
    color: var(--bs-secondary-color);
}

.fin-nav-link:hover {
    background: var(--bs-secondary-bg);
    color: var(--bs-body-color);
}

.fin-nav-link.active {
    background: rgba(var(--app-clay-rgb), 0.1);
    box-shadow: inset 3px 0 0 var(--app-clay);
    font-weight: 600;
}

.fin-nav-link.active .bi {
    color: var(--app-clay);
}

.fin-offcanvas {
    --bs-offcanvas-bg: var(--bs-tertiary-bg);
    --bs-offcanvas-width: 18rem;
}

.fin-icon-btn {
    border: 0;
    background: transparent;
    color: var(--bs-secondary-color);
    font-size: 1.15rem;
    line-height: 1;
    padding: 0.35rem 0.5rem;
}

.fin-icon-btn:hover,
.fin-icon-btn:focus-visible {
    background: var(--bs-tertiary-bg);
    color: var(--bs-body-color);
}

/* The theme button shows the sun in dark mode (press for light) and the moon in light mode (press for dark). */
:root[data-bs-theme="dark"] .theme-moon,
:root[data-bs-theme="light"] .theme-sun {
    display: none;
}

.user-menu-toggle {
    border: 0;
    background: transparent;
    color: var(--bs-body-color);
}

.user-menu-toggle:hover,
.user-menu-toggle:focus-visible,
.user-menu-toggle.show {
    background: var(--bs-tertiary-bg);
}

/* ---------- page header ---------- */

.fin-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.fin-page-head h1 {
    margin: 0;
    font-size: 1.5rem;
}

.fin-page-head p {
    margin: 0.2rem 0 0;
    color: var(--bs-secondary-color);
    font-size: 0.9rem;
}

/* ---------- labels, numbers, KPI cards ---------- */

.fin-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
}

.fin-num {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.fin-kpi {
    display: block;
    height: 100%;
    padding: 1.1rem 1.2rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 1rem;
    background: var(--app-surface);
    color: inherit;
    text-decoration: none;
}

a.fin-kpi:hover {
    border-color: var(--app-clay);
    color: inherit;
}

.fin-kpi-value {
    margin-top: 0.4rem;
    font-size: 1.6rem;
    font-weight: 600;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.fin-kpi-sm .fin-kpi-value {
    font-size: 1.25rem;
}

.fin-kpi-note {
    margin-top: 0.25rem;
    font-size: 0.78rem;
    color: var(--bs-secondary-color);
}

.fin-kpi-quiet {
    background: var(--bs-tertiary-bg);
}

/* money colours */
.fin-in {
    color: var(--app-badge-success-fg);
}

.fin-out {
    color: var(--bs-body-color);
}

.fin-warn {
    color: var(--app-badge-warning-fg);
}

.fin-bad {
    color: var(--app-badge-danger-fg);
}

/* ---------- tables ---------- */

.fin-table-wrap {
    border: 1px solid var(--bs-border-color);
    border-radius: 1rem;
    background: var(--app-surface);
    overflow: hidden;
}

.fin-table-wrap .table {
    --bs-table-bg: transparent;
    margin-bottom: 0;
}

.fin-table-wrap .table > thead th {
    background: var(--bs-tertiary-bg);
    border-bottom: 1px solid var(--bs-border-color);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
    white-space: nowrap;
}

.fin-table-wrap .table > tbody > tr > td {
    border-color: var(--bs-border-color);
}

.fin-table-wrap .table > tbody > tr:last-child > td {
    border-bottom: 0;
}

.fin-table-wrap .table-hover > tbody > tr:hover > * {
    --bs-table-bg-state: var(--bs-tertiary-bg);
}

.fin-row-click {
    cursor: pointer;
}

.fin-empty {
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--bs-secondary-color);
}

/* ---------- filter tabs ---------- */

.fin-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
}

.fin-tabs a {
    padding: 0.35rem 0.8rem;
    border-radius: var(--bs-border-radius);
    color: var(--bs-secondary-color);
    font-size: 0.9rem;
    text-decoration: none;
}

.fin-tabs a:hover {
    background: var(--bs-secondary-bg);
    color: var(--bs-body-color);
}

.fin-tabs a.active {
    background: rgba(var(--app-clay-rgb), 0.12);
    color: var(--bs-body-color);
    font-weight: 600;
}

/* ---------- selection bar for bulk actions ----------
   One dark pill on a single line, centred at the bottom (as in Finance V3). Shown by removing d-none. */

.fin-bulk-bar {
    position: fixed;
    bottom: 1.5rem;
    left: 0;
    right: 0;
    z-index: 1030;
    margin-inline: auto;
    width: max-content;
    max-width: calc(100vw - 1.5rem);
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.6rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 1rem;
    background: #1f1e1d;
    color: #faf9f5;
    box-shadow: 0 12px 32px rgba(20, 20, 19, 0.35);
    white-space: nowrap;
}

/* The sidebar is fixed on the left from lg up, so centre in the content column to its right, not on the whole page. */
@media (min-width: 992px) {
    .fin-bulk-bar {
        left: var(--fin-sidebar-w, 15.5rem);
        max-width: calc(100vw - var(--fin-sidebar-w, 15.5rem) - 1.5rem);
    }
}

.fin-bulk-count {
    flex: none;
    font-size: 0.85rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: rgba(250, 249, 245, 0.7);
}

.fin-bulk-sep {
    flex: none;
    align-self: stretch;
    width: 1px;
    margin-block: 0.15rem;
    background: rgba(255, 255, 255, 0.15);
}

.fin-bulk-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    overflow-x: auto;
    scrollbar-width: none;
}

.fin-bulk-actions::-webkit-scrollbar {
    display: none;
}

.fin-bulk-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border: 0;
    border-radius: 0.7rem;
    background: rgba(255, 255, 255, 0.1);
    color: #faf9f5;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.4rem 0.75rem;
}

.fin-bulk-btn:hover,
.fin-bulk-btn:focus-visible {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.fin-bulk-btn-danger:hover,
.fin-bulk-btn-danger:focus-visible {
    background: #b4402d;
    color: #fff;
}

.fin-bulk-close {
    flex: none;
    border: 0;
    background: transparent;
    color: rgba(250, 249, 245, 0.55);
    padding: 0.3rem 0.4rem;
}

.fin-bulk-close:hover,
.fin-bulk-close:focus-visible {
    color: #fff;
}

/* ---------- file drop (drag files onto the page) ---------- */

.fin-drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 1090;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 0.5rem;
    background: rgba(var(--app-clay-rgb), 0.9);
    color: #fff;
    text-align: center;
    pointer-events: none;
}

.fin-drop-overlay.active {
    display: flex;
    pointer-events: all;
}

.fin-drop-overlay .bi {
    font-size: 3rem;
}

.fin-dropzone {
    padding: 2rem 1rem;
    border: 1.5px dashed var(--bs-border-color);
    border-radius: 1rem;
    background: var(--bs-tertiary-bg);
    text-align: center;
    color: var(--bs-secondary-color);
}

.fin-dropzone.is-over {
    border-color: var(--app-clay);
    background: rgba(var(--app-clay-rgb), 0.08);
}

/* ---------- toasts ----------
   Bootstrap Toast (js/core/toast.js); only the coloured edge and icon are added here. */

.fin-toast {
    border-left: 4px solid var(--app-clay);
}

.fin-toast-success { border-left-color: var(--app-badge-success-fg); }
.fin-toast-success .bi { color: var(--app-badge-success-fg); }
.fin-toast-danger  { border-left-color: var(--app-badge-danger-fg); }
.fin-toast-danger .bi { color: var(--app-badge-danger-fg); }
.fin-toast-warning { border-left-color: var(--app-badge-warning-fg); }
.fin-toast-warning .bi { color: var(--app-badge-warning-fg); }
.fin-toast-info .bi { color: var(--app-clay); }

/* ---------- form helpers ---------- */

.form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
}

.fin-select-sm {
    max-width: 16rem;
}

.fin-search {
    position: relative;
    width: 100%;
    max-width: 22rem;
}

.fin-search .form-control {
    padding-right: 2rem;
}

.fin-search .fin-search-clear {
    position: absolute;
    top: 50%;
    right: 0.35rem;
    transform: translateY(-50%);
    padding: 0.1rem 0.4rem;
    border: 0;
    background: transparent;
    color: var(--bs-secondary-color);
}

/* ---------- login ---------- */

.login-page {
    min-height: 100vh;
    background:
        radial-gradient(60rem 28rem at 50% -8rem, color-mix(in srgb, var(--bs-primary) 10%, transparent), transparent 70%),
        var(--bs-body-bg);
}

.login-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1rem;
}

.login-card {
    width: 100%;
    max-width: 26rem;
    padding: 2.4rem 2rem 2rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 1.2rem;
    background: var(--app-surface, var(--bs-body-bg));
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 18px 40px -18px rgb(0 0 0 / 0.35);
}

.login-card-head {
    text-align: center;
}

.login-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3.4rem;
    height: 3.4rem;
    margin-bottom: 1rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 1rem;
    background: var(--bs-tertiary-bg);
    font-size: 1.6rem;
}

.login-title {
    margin: 0 0 0.25rem;
    font-size: 1.7rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.login-lead {
    margin: 0 0 1.6rem;
    color: var(--bs-secondary-color);
}

.login-card .alert {
    margin-bottom: 1.2rem;
}

.login-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.7rem;
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.8rem;
    background: var(--bs-body-color);
    color: var(--bs-body-bg);
    font-weight: 600;
    text-decoration: none;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.login-button:hover,
.login-button:focus-visible {
    color: var(--bs-body-bg);
    transform: translateY(-1px);
    box-shadow: 0 8px 18px -10px rgb(0 0 0 / 0.5);
}

.login-button:disabled {
    opacity: 0.7;
    transform: none;
}

.login-points {
    margin: 1.6rem 0 0;
    padding: 1.1rem 0 0;
    border-top: 1px solid var(--bs-border-color);
    list-style: none;
    text-align: left;
    font-size: 0.85rem;
    color: var(--bs-secondary-color);
}

.login-points li {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    margin-bottom: 0.55rem;
}

.login-points li:last-child {
    margin-bottom: 0;
}

.login-points .bi {
    flex: none;
    margin-top: 0.1rem;
}

.login-foot {
    margin: 1.2rem 0 0;
    font-size: 0.78rem;
    color: var(--bs-tertiary-color);
}

.login-theme {
    position: fixed;
    top: 0.75rem;
    right: 0.75rem;
}


/* ---------- invoice line items (invoice-new, invoice-edit) ----------
   Bootstrap has no fixed-width flex columns for a line-item grid. Below lg every field wraps. */

.inv-col-desc { flex: 1 1 100%; min-width: 0; }
.inv-col-qty, .inv-col-price, .inv-col-vat, .inv-col-total { flex: 1 1 6rem; min-width: 0; }
.inv-col-x { flex: 0 0 2rem; text-align: center; }

@media (min-width: 992px) {
    .inv-col-desc { flex: 1 1 0; }
    .inv-col-qty, .inv-col-vat { flex: 0 0 5rem; }
    .inv-col-price, .inv-col-total { flex: 0 0 7rem; }
}

/* ---------- Transactions pages (ledger, imports, review, editor, bulk bar) ----------
   Only what Bootstrap has no utility for: fixed column widths, the selected-row tint, the month grid. */

.selectable-card.is-selected {
    border-color: rgba(var(--app-clay-rgb), 0.35);
}

.fin-table-wrap .table > tbody > tr.selectable-card.is-selected > * {
    --bs-table-bg-state: rgba(var(--app-clay-rgb), 0.1);
}

.fin-col-check {
    width: 2.5rem;
}

.fin-cell-desc {
    min-width: 12rem;
    max-width: 19rem;
}

.fin-cell-cat {
    min-width: 9rem;
    max-width: 11rem;
}

.fin-cell-file {
    max-width: 17.5rem;
}

.fin-cell-bank {
    max-width: 8.75rem;
}

.fin-note {
    font-size: 0.72rem;
    color: var(--bs-secondary-color);
}

.fin-w-vat {
    width: 4.5rem;
    flex: none;
}

.fin-minw-sm {
    min-width: 9.5rem;
}

.fin-minw-md {
    min-width: 11.5rem;
}

.fin-search-wide {
    max-width: 18rem;
}

.fin-invoice-list {
    max-height: 13.75rem;
    overflow-y: auto;
}

.fin-split-amt {
    flex: 0 0 5.5rem;
}

.fin-split-vat {
    flex: 0 0 2.5rem;
    text-align: center;
}

.fin-split-del {
    flex: 0 0 2.25rem;
}

.fin-month-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 0.25rem;
}

.fin-month-grid > * {
    padding: 0.2rem 0;
    border-radius: var(--bs-border-radius-sm);
    font-size: 0.75rem;
    text-align: center;
    text-decoration: none;
}

.fin-month-missing {
    border: 1px solid var(--bs-border-color);
    background: var(--bs-tertiary-bg);
    color: var(--bs-tertiary-color);
}


/* ---------- reports and VAT (appended block) ---------- */

/* Expand carets: rotated by the page JS via inline transform. */
.fin-caret {
    display: inline-block;
    transition: transform 0.15s ease;
}

/* Clickable figure in the cashflow matrix. */
.fin-drill {
    cursor: pointer;
}

.fin-drill:hover {
    background: var(--bs-tertiary-bg);
    color: var(--app-clay);
}

/* Cashflow matrix: keep the category column visible while scrolling sideways. */
.fin-matrix .fin-sticky-col {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--app-surface);
    white-space: nowrap;
}

.fin-matrix thead .fin-sticky-col {
    background: var(--bs-tertiary-bg);
}

.fin-matrix tr.table-active .fin-sticky-col {
    background: var(--bs-secondary-bg);
}

.fin-matrix tr.table-active > * {
    background-color: var(--bs-secondary-bg);
}

/* Clickable transaction line inside a report drill-down. */
.fin-drill-line {
    cursor: pointer;
    border-bottom: 1px solid var(--bs-border-color-translucent);
}

.fin-drill-line:last-child {
    border-bottom: 0;
}

.fin-drill-line:hover {
    color: var(--app-clay);
}

/* VAT sense-check findings: severity edge and label colours follow the theme badge tokens. */
.vat-finding {
    border-left-width: 3px !important;
}

.vat-sev-high { border-left-color: var(--app-badge-danger-fg) !important; }
.vat-sev-medium { border-left-color: var(--app-badge-warning-fg) !important; }
.vat-sev-low { border-left-color: var(--bs-secondary-color) !important; }
.vat-sev-high-text { color: var(--app-badge-danger-fg); }
.vat-sev-medium-text { color: var(--app-badge-warning-fg); }
.vat-sev-low-text { color: var(--bs-secondary-color); }

/* Allocate (play mode): a single card on a small stack. */
.fin-play-stack {
    position: relative;
    max-width: 38rem;
}

.fin-play-stack::before,
.fin-play-stack::after {
    content: "";
    position: absolute;
    left: 1rem;
    right: 1rem;
    height: 100%;
    border: 1px solid var(--bs-border-color);
    border-radius: 1rem;
    background: var(--app-surface);
    z-index: 0;
}

.fin-play-stack::before { top: 0.5rem; opacity: 0.7; }
.fin-play-stack::after { top: 1rem; left: 2rem; right: 2rem; opacity: 0.4; }

.fin-play-card {
    position: relative;
    z-index: 1;
    border-radius: 1rem;
    background: var(--app-surface);
}

.fin-play-amount {
    font-size: 2.1rem;
    font-weight: 600;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.fin-play-suggest > div {
    display: flex;
    gap: 0.75rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--bs-border-color);
}

.fin-play-suggest > div:last-child { border-bottom: 0; }
.fin-play-suggest dt { flex: 0 0 5.5rem; margin: 0; font-weight: 400; color: var(--bs-secondary-color); font-size: 0.85rem; }
.fin-play-suggest dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

.fin-play-card kbd {
    margin-left: 0.25rem;
    padding: 0.05rem 0.35rem;
    font-size: 0.7rem;
    opacity: 0.7;
}

.fin-play-in { animation: fin-play-in 0.18s ease-out; }
.fin-play-out { transform: translateX(3rem) rotate(3deg); opacity: 0; transition: transform 0.18s ease-in, opacity 0.18s ease-in; }
.fin-play-skip { transform: translateX(-3rem) rotate(-3deg); opacity: 0; transition: transform 0.18s ease-in, opacity 0.18s ease-in; }

@keyframes fin-play-in {
    from { transform: translateY(0.6rem) scale(0.98); opacity: 0; }
    to { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .fin-play-in { animation: none; }
    .fin-play-out, .fin-play-skip { transition: none; }
}

@media (max-width: 575.98px) {
    .fin-play-amount { font-size: 1.7rem; }
    #pc-actions .btn { flex: 1 1 45%; }
    .fin-play-card kbd { display: none; }
}

/* Allocate: similar transactions waiting behind the current card. */
.fin-play-group {
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.75rem;
    background: var(--bs-tertiary-bg);
    font-size: 0.9rem;
}

.fin-play-group li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.15rem 0;
}

.fin-play-group li span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Classification confidence shown as a small pill next to the category. */
.fin-conf {
    padding: 0.28em 0.6em;
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
}
