/* Invoicing workspace: the parts every invoicing list shares (page frame, figures ribbon,
   view switcher, search, table, skeletons, empty state, bulk bar, toast). Global rather than
   scoped so Invoices, Payments, Credits and Refunds read as one place. Page-only rules stay in
   each page's .razor.css. */

.inv {
    max-width: 1320px;
    margin: 0 auto;
    padding: 1.75rem 1.5rem 6rem;
}

.inv-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.inv-title {
    margin: 0;
    font-size: 2.1rem;
}

.inv-head__actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.inv-link-btn {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--crm-text-2);
    text-decoration: none;
    padding: 0.3rem 0.5rem;
    border-radius: var(--crm-r-sm);
}

.inv-link-btn:hover { color: var(--crm-navy); background: var(--crm-surface-2); }

/* ── The ribbon ───────────────────────────────────────────────────────────── */

.inv-ribbon {
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-r-lg);
    padding: 1.1rem 1.25rem 1rem;
    margin-bottom: 1.25rem;
}

.inv-ribbon__figures {
    display: flex;
    align-items: stretch;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.inv-ribbon__quiet {
    margin-left: auto;
    display: flex;
    gap: 0.25rem;
}

.inv-fig {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: var(--crm-r);
    padding: 0.45rem 0.85rem 0.55rem;
    color: var(--crm-text);
    transition: background var(--crm-fast) var(--crm-ease);
}

.inv-fig:not(:disabled):hover { background: var(--crm-bg); }
.inv-fig:disabled { cursor: default; opacity: 0.55; }
.inv-fig.is-on { background: var(--crm-bg); box-shadow: inset 0 0 0 1px var(--crm-border); }

.inv-fig__label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--crm-text-2);
}

.inv-fig__value {
    font-size: 1.25rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

.inv-fig--lead .inv-fig__value {
    font-family: 'Instrument Serif', Georgia, serif;
    font-weight: 400;
    font-size: 2.35rem;
    line-height: 1.05;
    color: var(--crm-navy);
}

.inv-fig--late .inv-fig__value {
    font-family: 'Instrument Serif', Georgia, serif;
    font-weight: 400;
    font-size: 2.35rem;
    line-height: 1.05;
    color: #B4232A;
}

.inv-fig--late .inv-fig__label { color: #B4232A; }

.inv-fig--quiet .inv-fig__value { font-size: 1.05rem; color: var(--crm-text-2); }

.inv-fig__sub {
    font-size: 0.75rem;
    color: var(--crm-text-3);
}

.inv-bar {
    display: flex;
    height: 10px;
    margin: 0.85rem 0.85rem 0;
    border-radius: 999px;
    overflow: hidden;
    background: var(--crm-surface-2);
    transform-origin: left center;
}

.inv-bar__late {
    background: #C8323A;
    flex-shrink: 0;
}

.inv-bar__current {
    flex: 1;
    background: #3B6FD8;
}

.inv-bar__late + .inv-bar__current { margin-left: 2px; }

.inv-bar--clear { background: var(--crm-teal-50); }

.inv-bar__legend {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin: 0.4rem 0.85rem 0;
    font-size: 0.75rem;
    color: var(--crm-text-3);
}

.inv-bar__key--late { color: #B4232A; font-weight: 600; }

/* The one choreographed moment: the bar draws in from the left on first load. */
@media (prefers-reduced-motion: no-preference) {
    .inv:not(.is-drawn) .inv-bar { transform: scaleX(0); }
    .inv.is-drawn .inv-bar { transition: transform 900ms var(--crm-ease); }
}

.inv-skel {
    border-radius: var(--crm-r);
    background: linear-gradient(90deg, var(--crm-bg), var(--crm-surface-2), var(--crm-bg));
    background-size: 200% 100%;
    animation: inv-shimmer 1.4s ease-in-out infinite;
}

.inv-skel--figs { height: 72px; }
.inv-skel--bar { height: 10px; margin-top: 0.85rem; border-radius: 999px; }

/* ── Toolbar ──────────────────────────────────────────────────────────────── */

.inv-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.85rem;
}

.inv-seg {
    position: relative;
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--crm-surface-2);
    border-radius: var(--crm-r);
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}

.inv-seg__item {
    position: relative;
    z-index: 1;
    border: 0;
    background: transparent;
    color: var(--crm-text-2);
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    padding: 0.38rem 0.85rem;
    border-radius: var(--crm-r-sm);
    transition: color var(--crm-fast);
}

.inv-seg__item:hover { color: var(--crm-text); }

.inv-seg__item.is-on {
    color: var(--crm-navy);
    background: var(--crm-white);
    box-shadow: var(--crm-shadow-xs);
}

/* With the glide script, the pill travels instead of jumping. */
.inv-seg.has-ink .inv-seg__item.is-on { background: transparent; box-shadow: none; }

.inv-ink {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 0;
    border-radius: var(--crm-r-sm);
    background: var(--crm-white);
    box-shadow: var(--crm-shadow-xs);
    pointer-events: none;
    transition: transform 320ms var(--crm-ease), width 320ms var(--crm-ease), opacity 150ms;
}

.inv-filters {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.inv-filters .form-select { width: auto; max-width: 220px; }

.inv-search {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0;
    padding: 0 0.7rem;
    height: 31px;
    min-width: 250px;
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-r-sm);
    color: var(--crm-text-3);
}

.inv-search:focus-within { border-color: var(--crm-teal-600); box-shadow: 0 0 0 3px var(--crm-teal-glow); }

.inv-search input {
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 0.85rem;
    color: var(--crm-text);
    width: 100%;
}

/* ── Table ────────────────────────────────────────────────────────────────── */

.inv-card {
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-r-lg);
    overflow: hidden;
}

.inv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

.inv-table thead th {
    position: sticky;
    top: 0;
    background: var(--crm-white);
    border-bottom: 1px solid var(--crm-border);
    padding: 0.35rem 0.6rem;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}

.inv-sort {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border: 0;
    background: transparent;
    padding: 0.35rem 0.3rem;
    border-radius: var(--crm-r-sm);
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--crm-text-3);
}

.inv-sort:hover { color: var(--crm-text); background: var(--crm-bg); }
.inv-sort.is-on { color: var(--crm-navy); }
.inv-sort__icon { font-size: 0.7rem; opacity: 0.45; }
.inv-sort.is-on .inv-sort__icon { opacity: 1; }
.inv-num .inv-sort { flex-direction: row-reverse; }

.inv-table tbody td {
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--crm-border);
    vertical-align: middle;
}

.inv-table tbody tr:last-child td { border-bottom: 0; }

.inv-table tbody tr[tabindex] { cursor: pointer; transition: background var(--crm-fast); }
.inv-table tbody tr[tabindex]:hover { background: #F7FAFE; }
.inv-table tbody tr[tabindex]:focus-visible { outline: 2px solid var(--crm-teal-600); outline-offset: -2px; }
.inv-table tbody tr.is-selected { background: #F0F7FF; }
.inv-table tbody.is-loading { opacity: 0.55; transition: opacity var(--crm-fast); }

.inv-col-check { width: 44px; padding-left: 1rem !important; padding-right: 0 !important; }

.inv-cell-main { display: table-cell; }

.inv-number {
    display: block;
    white-space: nowrap;
    font-weight: 600;
    color: var(--crm-navy);
    font-variant-numeric: tabular-nums;
}

.inv-sub {
    display: flex;
    white-space: nowrap;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.1rem;
    font-size: 0.75rem;
    color: var(--crm-text-3);
}

.inv-po {
    padding: 0 0.35rem;
    border: 1px solid var(--crm-border);
    border-radius: 4px;
    font-variant-numeric: tabular-nums;
}

.inv-org a {
    color: var(--crm-text);
    text-decoration: none;
    font-weight: 500;
}

.inv-org a:hover { color: var(--crm-navy); text-decoration: underline; }

.inv-entity {
    margin-left: 0.35rem;
    font-size: 0.72rem;
    color: var(--crm-text-3);
}

.inv-date { white-space: nowrap; color: var(--crm-text-2); font-variant-numeric: tabular-nums; }

.inv-late {
    display: inline-block;
    margin-left: 0.4rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: #B4232A;
}

.inv-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.inv-num--owed { font-weight: 600; color: var(--crm-navy); }
.inv-num--clear { color: var(--crm-text-3); }
.inv-muted { color: var(--crm-text-3); }

.inv-skel-row td { padding: 0.95rem 1rem !important; }
.inv-skel-row span {
    display: block;
    height: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--crm-bg), var(--crm-surface-2), var(--crm-bg));
    background-size: 200% 100%;
    animation: inv-shimmer 1.4s ease-in-out infinite;
    animation-delay: calc(var(--i) * 80ms);
}

@keyframes inv-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .inv-skel, .inv-skel-row span { animation: none; }
    .inv-ink { transition: none; }
}

.inv-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 3rem 1rem;
    color: var(--crm-text-3);
    text-align: center;
}

.inv-empty i { font-size: 2rem; color: var(--crm-teal-600); }
.inv-empty p { margin: 0; color: var(--crm-text-2); }

.inv-more {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.85rem;
    font-size: 0.8rem;
}

/* ── Bulk bar and toast ───────────────────────────────────────────────────── */

.inv-bulk {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    z-index: 1040;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: min(560px, calc(100vw - 2rem));
    padding: 0.55rem 0.6rem 0.55rem 1.1rem;
    border-radius: 999px;
    background: var(--crm-navy);
    color: #fff;
    box-shadow: var(--crm-shadow-lift);
    transform: translateX(-50%);
    animation: inv-rise var(--crm-mid) var(--crm-ease);
}

.inv-bulk__count { font-weight: 600; }
.inv-bulk__sum { opacity: 0.7; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.inv-bulk__spacer { flex: 1; }
.inv-bulk .btn-light { border-radius: 999px; font-weight: 600; }
.inv-bulk__clear { color: rgba(255, 255, 255, 0.75); text-decoration: none; }
.inv-bulk__clear:hover { color: #fff; }

.inv-toast {
    position: fixed;
    left: 50%;
    bottom: 5.25rem;
    z-index: 1041;
    max-width: min(560px, calc(100vw - 2rem));
    padding: 0.6rem 1rem;
    border-radius: var(--crm-r);
    background: var(--crm-white);
    border: 1px solid var(--crm-border);
    box-shadow: var(--crm-shadow-lg);
    font-size: 0.85rem;
    transform: translateX(-50%);
    animation: inv-rise var(--crm-mid) var(--crm-ease);
}

@keyframes inv-rise {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .inv-bulk, .inv-toast { animation: none; }
}

.inv-setup {
    max-width: 460px;
    margin: 3rem auto;
    text-align: center;
    color: var(--crm-text-2);
}

.inv-setup i { font-size: 2.2rem; color: var(--crm-teal-600); }
.inv-setup h2 { margin: 0.5rem 0; font-size: 1.4rem; }

/* ── Phone ───────────────────────────────────────────────────────────────── */

@media (max-width: 760px) {
    .inv { padding: 1.25rem 1rem 6rem; }
    .inv-title { font-size: 1.75rem; }
    .inv-ribbon { padding: 0.75rem; }
    .inv-ribbon__quiet { margin-left: 0; width: 100%; }
    .inv-fig--lead .inv-fig__value,
    .inv-fig--late .inv-fig__value { font-size: 1.8rem; }
    .inv-filters, .inv-search { width: 100%; }
    .inv-search { min-width: 0; }
    .inv-bulk { bottom: 0.75rem; }
    .inv-bulk__sum { display: none; }
}

/* ── Drawers: shared body parts ──────────────────────────────────────────── */

html.ivdr-locked, html.ivdr-locked body { overflow: hidden; }

.ivx-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem 1rem;
}

.ivx-grid .is-wide { grid-column: 1 / -1; }
.ivx-grid .form-label { font-size: 0.8rem; font-weight: 600; color: var(--crm-text-2); margin-bottom: 0.3rem; }

.ivx-money {
    position: relative;
    display: block;
}

.ivx-money::before {
    content: "$";
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--crm-text-3);
    pointer-events: none;
}

.ivx-money input { padding-left: 1.5rem; text-align: right; font-variant-numeric: tabular-nums; }

.ivx-money--lead input {
    height: 3rem;
    font-family: 'Instrument Serif', Georgia, serif;
    font-size: 1.7rem;
    color: var(--crm-navy);
}

.ivx-money--lead::before { font-size: 1.2rem; }

.ivx-section {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 1.5rem 0 0.6rem;
}

.ivx-section h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--crm-text);
}

.ivx-linkbtn {
    border: 0;
    background: transparent;
    padding: 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--crm-teal-600);
}

.ivx-linkbtn:hover { text-decoration: underline; }
.ivx-linkbtn:disabled { color: var(--crm-text-3); text-decoration: none; }

.ivx-switch {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.86rem;
}

.ivx-switch .form-check-input { margin: 0; }

.ivx-dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.4rem 1.25rem;
    margin: 0;
    font-size: 0.86rem;
}

.ivx-dl dt { font-weight: 500; color: var(--crm-text-3); }
.ivx-dl dd { margin: 0; color: var(--crm-text); }

.ivx-error {
    margin-top: 1rem;
    padding: 0.6rem 0.8rem;
    border-radius: var(--crm-r);
    background: #FDEEEE;
    color: #8F1D23;
    font-size: 0.85rem;
}

.ivx-note {
    margin-top: 0.75rem;
    padding: 0.6rem 0.8rem;
    border-radius: var(--crm-r);
    background: var(--crm-bg);
    color: var(--crm-text-2);
    font-size: 0.83rem;
}

.ivx-foot-total {
    flex: 1;
    min-width: 0;
    font-size: 0.82rem;
    color: var(--crm-text-2);
    font-variant-numeric: tabular-nums;
}

.ivx-foot-total strong { color: var(--crm-text); }

/* Payment and credit states, beside the invoice statuses. Clearing is amber like part-paid;
   failed reads as a problem without borrowing overdue's red; disputed is violet. */
.ivx-state {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    font-size: 0.74rem;
    font-weight: 600;
    line-height: 1;
    padding: 0.32rem 0.6rem 0.32rem 0.5rem;
    border-radius: 999px;
}

.ivx-state::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.ivx-state--cleared, .ivx-state--issued, .ivx-state--applied { color: var(--crm-teal-600); background: var(--crm-teal-50); }
.ivx-state--pending, .ivx-state--requested, .ivx-state--approved { color: #8A5A00; background: #FFF6E0; }
.ivx-state--failed, .ivx-state--rejected { color: var(--crm-text-2); background: var(--crm-surface-2); }
.ivx-state--disputed { color: #5B3CC4; background: #F2EEFF; }
.ivx-state--refunded, .ivx-state--partiallyrefunded, .ivx-state--void, .ivx-state--draft { color: var(--crm-text-3); background: transparent; box-shadow: inset 0 0 0 1px var(--crm-border); }

@media (max-width: 600px) {
    .ivx-grid { grid-template-columns: 1fr; }
}

/* A short list of money rows in a drawer: label, a quiet detail, the amount. */
.ivx-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--crm-border); }

.ivx-list li {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--crm-border);
    font-size: 0.86rem;
}

.ivx-list a { font-weight: 600; color: var(--crm-navy); text-decoration: none; font-variant-numeric: tabular-nums; }
.ivx-list a:hover { text-decoration: underline; }

.ivx-list__sub {
    min-width: 0;
    font-size: 0.76rem;
    color: var(--crm-text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ivx-list__amt { font-variant-numeric: tabular-nums; font-weight: 500; }
.ivx-list__held { color: var(--crm-teal-600); }
.ivx-list__held .ivx-list__amt { font-weight: 600; }
.ivx-list li.ivx-list__none { display: block; color: var(--crm-text-3); }

/* ── GL export: one colour per kind of row, shared by the page and its chips ── */

.gl-kind {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 0.4rem;
    border-radius: 50%;
    vertical-align: middle;
    flex: none;
    background: var(--crm-text-3);
}

.gl-kind--invoice { background: var(--crm-navy); }
.gl-kind--payment { background: var(--crm-teal-600); }
.gl-kind--fee { background: #B7791F; }
.gl-kind--credit { background: #6B4FA3; }
.gl-kind--refund { background: #1D4ED8; }
.gl-kind--void { background: transparent; box-shadow: inset 0 0 0 1.5px var(--crm-text-3); }
