/* Billing analysis (views/analysis.js). Kit tokens only. Prefix an-. */

/* Amounts: leakage reads destructive, overbilling reads warning */
.an-amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.an-amt.leakage { color: var(--destructive); }
.an-amt.overbilling { color: var(--warning); }

/* Header: period select, export menu */
.an-period { width: auto; min-width: 180px; }
.an-export { position: relative; }
.an-export > summary { list-style: none; }
.an-export > summary::-webkit-details-marker { display: none; }
.an-export > summary svg.lucide:last-child { width: 14px; height: 14px; color: var(--muted-foreground); }
.an-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 40; width: 240px; padding: 4px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--popover); box-shadow: var(--shadow-filter-popover); }

/* Tabs row */
.an-tabs { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.an-subtabs { margin-bottom: 12px; }
.an-h2 { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.an-h2 .count, .an-h3 .count { font-size: 12px; font-weight: 500; color: var(--muted-foreground); }
.an-h2.an-sec { margin: 0 0 12px; }
.an-h3 { display: flex; align-items: center; gap: 8px; margin: 20px 0 8px; font-size: 14px; line-height: 20px; font-weight: 600; }
/* Scoped (V4): this used to leak into the dashboard widget grid and offset every widget after the first. */
:not(.hm-grid) > section + section, :not(.hm-grid) > .an-card + section, :not(.hm-grid) > section + .an-card { margin-top: 32px; }

/* Tables */
.an-table .cell-main, .an-table .cell-sub { display: block; }
.an-cust { max-width: 170px; }
.an-reason { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-chev { width: 16px; height: 16px; color: var(--muted-foreground); }
.an-span { color: var(--muted-foreground); }
.an-nr { display: flex; align-items: center; gap: 12px; min-width: 0; }
.an-nr .t-meta { min-width: 0; }
.an-table tfoot td { font-weight: 600; border-top: 1px solid var(--border); background: var(--muted); }
.an-table tfoot .cell-sub { font-weight: 400; }
.an-flags { display: flex; flex-wrap: wrap; gap: 4px; }
.an-exlinks { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.an-table .btn.sm svg.lucide { width: 14px; height: 14px; }

/* Unbilled ageing */
.an-ageing { margin-top: 16px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); }
.an-ageing-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.an-ageing-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.an-age { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: var(--radius-lg); background: var(--muted); }
.an-age-v { font-size: 20px; line-height: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.an-age.zero .an-age-v { color: var(--muted-foreground); }

/* Reconciliation tiles */
.an-recon-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.an-recon-head b { font-variant-numeric: tabular-nums; color: var(--foreground); }
.an-recon-nr { margin-bottom: 12px; }
.an-pairs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 12px; }
.an-pair { display: flex; flex-direction: column; gap: 8px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); min-width: 0; text-align: left; }
.an-pair.click { cursor: pointer; transition: background var(--motion-quick), border-color var(--motion-quick); }
.an-pair.click:hover { background: var(--accent); }
.an-pair.click:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.an-pair.off { background: var(--muted); opacity: .6; }
.an-pair-head { display: flex; align-items: center; gap: 8px; }
.an-pair-st { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.an-pair-src { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--border); }
.an-src-line { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12px; line-height: 16px; }
.an-src-dot { width: 8px; height: 8px; border-radius: var(--radius-full); flex: none; background: var(--primary); }
.an-src-dot.r { background: var(--muted-foreground); }

/* Pair compare (from the v3 Compare sources view) */
.an-cmp-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.an-cmp-head { display: grid; grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr); gap: 8px; align-items: stretch; margin-bottom: 12px; }
.an-cmp-vs { display: grid; place-items: center; color: var(--muted-foreground); }
.an-cmp-sum { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--muted); min-width: 0; }
.an-cmp-sum-head { display: flex; align-items: center; gap: 12px; }
.an-cmp-logo { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius-lg); background: var(--background); box-shadow: var(--shadow-2xs); color: var(--primary); flex: none; }
.an-cmp-logo.r { color: var(--muted-foreground); }
.an-cmp-rows { margin: 12px 0 0; display: flex; flex-direction: column; }
.an-cmp-rows > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 14px; border-bottom: 1px solid var(--border); }
.an-cmp-rows > div:last-child { border-bottom: 0; }
.an-cmp-rows dt { color: var(--muted-foreground); }
.an-cmp-rows dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 500; }
.an-cmp-rows .an-total dd { font-weight: 600; }
.an-cmp-totals { display: flex; flex-wrap: wrap; gap: 8px 32px; padding: 12px 16px; margin-bottom: 16px; border-radius: var(--radius-lg); background: var(--background-brand); }
.an-cmp-totals > span { display: flex; flex-direction: column; gap: 2px; }
.an-cmp-totals b { font-variant-numeric: tabular-nums; }
.an-cmp-cols, .an-cmp-row { display: grid; grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr) 380px; gap: 8px; align-items: center; }
.an-cmp-cols { padding: 0 4px 6px; font-size: 12px; font-weight: 500; color: var(--muted-foreground); }
.an-cmp-list { display: flex; flex-direction: column; gap: 6px; }
.an-cmp-row { padding: 4px; border-radius: var(--radius-lg); }
.an-cmp-row:hover { background: var(--muted); }
.an-cmp-cell { min-width: 0; }
.an-cmp-rec { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); min-width: 0; }
.an-cmp-rec.none { border-style: dashed; }
.an-cmp-rec .cell-main, .an-cmp-rec .cell-sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-cmp-amt { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.an-cmp-none { display: flex; align-items: center; min-height: 48px; padding: 6px 12px; border: 1px dashed var(--border); border-radius: var(--radius-lg); color: var(--muted-foreground); font-size: 14px; }
.an-cmp-mid { display: grid; place-items: center; }
.an-cmp-ind { width: 24px; height: 24px; display: grid; place-items: center; border-radius: var(--radius-full); }
.an-cmp-ind svg.lucide { width: 14px; height: 14px; }
.an-cmp-ind.success { background: var(--success-foreground); color: var(--success); }
.an-cmp-ind.destructive { background: var(--destructive-foreground); color: var(--destructive); }
.an-cmp-ind.info { background: var(--information-foreground); color: var(--information); }
.an-cmp-act { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.an-cmp-st { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; margin-right: auto; }
.an-cmp-act .btn svg.lucide { width: 14px; height: 14px; }

/* Find a match, Create exception dialogs */
.an-mt, .an-nx { display: flex; flex-direction: column; gap: 12px; }
.an-mt-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius-lg); background: var(--muted); }
.an-mt-list { display: flex; flex-direction: column; gap: 8px; }
.an-mt-cand { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); cursor: pointer; }
.an-mt-cand:hover { background: var(--accent); }
.an-mt-cand.on { border-color: var(--border-brand); background: var(--background-brand); }
.an-mt-cand input { margin-top: 4px; accent-color: var(--primary); }
.an-mt-why { margin-top: 4px; font-size: 14px; line-height: 20px; }
.an-nx-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.an-nx-reason { height: auto; min-height: 72px; padding-top: 8px; resize: vertical; }
#anx-err { color: var(--destructive); min-height: 16px; }

/* Open month: status and stages only */
.an-open { display: flex; flex-direction: column; gap: 16px; }
.an-open-card { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 16px 20px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); }
.an-open-card .t-title { display: flex; align-items: center; gap: 8px; }
.an-open-ic, .an-blocked-ic { width: 40px; height: 40px; display: grid; place-items: center; flex: none; border-radius: var(--radius-lg); background: var(--muted-brand); color: var(--primary); }
.an-open-facts { display: flex; gap: 32px; margin-top: 8px; }
.an-open-facts > span { display: flex; flex-direction: column; gap: 2px; }
.an-open-stages { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.an-open-stage { display: inline-flex; align-items: center; gap: 8px; }
.an-open-stage b { font-variant-numeric: tabular-nums; }

/* One contract: not ready */
.an-blocked { display: flex; align-items: center; gap: 16px; padding: 16px 20px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); }
.an-blocked .row { gap: 12px; margin-bottom: 4px; }
.an-blocked .btn svg.lucide { width: 16px; height: 16px; }
.an-note { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; padding: 8px 12px; border-radius: var(--radius-lg); background: var(--muted); font-size: 14px; color: var(--muted-foreground); }
.an-note svg.lucide { width: 16px; height: 16px; }

/* Lineage strip */
.an-lin { margin-bottom: 32px; }
.an-lin-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.an-chip-src { display: flex; align-items: flex-start; gap: 12px; min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--card); text-align: left; font: inherit; color: inherit; }
.an-chip-src.click { cursor: pointer; transition: background var(--motion-quick), border-color var(--motion-quick); }
.an-chip-src.click:hover { background: var(--accent); border-color: var(--border-brand); }
.an-chip-ic { width: 32px; height: 32px; display: grid; place-items: center; flex: none; border-radius: var(--radius-md); background: var(--muted); color: var(--primary); }
.an-chip-ic svg.lucide { width: 16px; height: 16px; }
.an-chip-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.an-chip-t { font-size: 14px; line-height: 20px; font-weight: 500; }
.an-chip-n { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 12px; line-height: 16px; overflow-wrap: normal; word-break: normal; }

/* Waterfall card */
.an-card { padding: 20px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); }
.an-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.an-wf { display: flex; flex-direction: column; }
.an-wf-cols, .an-wf-row { display: grid; grid-template-columns: minmax(220px, 360px) minmax(0, 1fr) 96px 96px; gap: 16px; align-items: center; }
.an-wf-cols { padding: 0 0 8px; font-size: 12px; font-weight: 500; color: var(--muted-foreground); border-bottom: 1px solid var(--border); }
.an-wf-cols .num, .an-wf-val, .an-wf-delta { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.an-wf-row { padding: 8px 0; border-bottom: 1px solid var(--border); }
.an-wf-label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.an-wf-name { font-size: 14px; line-height: 20px; }
.an-wf-row.tot .an-wf-name, .an-wf-row.tot .an-wf-val { font-weight: 600; }
.an-wf-row.adj .an-wf-name { padding-left: 16px; color: var(--muted-foreground); }
.an-wf-row.adj.zero { opacity: .6; }
.an-wf-why { font-size: 12px; line-height: 16px; color: var(--muted-foreground); }
.an-wf-row.adj .an-wf-why { padding-left: 16px; }
.an-wf-cite { padding-left: 16px; }
.an-wf-delta { font-size: 12px; color: var(--muted-foreground); }
.an-wf-track { display: flex; height: 16px; border-radius: var(--radius-xs); background: var(--muted); }
.an-wf-bar { flex: none; height: 16px; border-radius: var(--radius-xs); background: var(--primary); }
.an-wf-bar.sow { background: var(--muted-brand); border: 1px solid var(--border-brand); }
.an-wf-bar.dec { background: var(--muted-foreground); opacity: .55; }
.an-wf-bar.inc { background: var(--success); }
.an-wf-bar.billed { background: var(--information); }
.an-wf-bar.gap { background: var(--destructive); }
.an-wf-bar.over { background: var(--warning); }
.an-wf-row.gap { border-bottom: 0; margin-top: 4px; padding: 10px 12px; border-radius: var(--radius-lg); grid-template-columns: minmax(208px, 348px) minmax(0, 1fr) 96px 84px; }
.an-wf-row.gap.bad { background: var(--destructive-foreground); }
.an-wf-row.gap.over { background: var(--warning-foreground); }
.an-wf-row.gap.ok { background: var(--success-foreground); }
.an-wf-row.gap .an-wf-name, .an-wf-row.gap .an-wf-val { font-weight: 600; }
.an-wf-row.gap.bad .an-wf-name, .an-wf-row.gap.bad .an-wf-val { color: var(--destructive); }
.an-wf-row.gap .an-wf-track { background: transparent; }
.an-wf-rev { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 4px; padding: 4px 8px; border-radius: var(--radius-md); background: var(--background-brand); font-size: 12px; line-height: 16px; align-self: flex-start; }
.an-wf-rev svg.lucide { width: 12px; height: 12px; color: var(--primary); }

/* CSV viewer in the side panel */
.an-csv { display: flex; flex-direction: column; gap: 12px; }
.an-csv-wrap { max-height: calc(100vh - 200px); overflow: auto; }

/* Period-end run: the v3 4B full-screen overlay */
@keyframes an-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.an-pe-scrim { position: fixed; inset: 0; z-index: 90; display: flex; justify-content: center; align-items: flex-start; overflow-y: auto; padding: 32px 16px; background: color-mix(in srgb, var(--foreground) 45%, transparent); animation: an-in var(--motion-standard) var(--ease-enter); }
.an-pe-scrim[hidden] { display: none; }
body.an-pe-lock { overflow: hidden; }
.an-pe { position: relative; width: min(1120px, 100%); display: flex; flex-direction: column; align-items: center; gap: 24px; padding: 32px 40px; border-radius: var(--radius-xl); background: var(--background); box-shadow: var(--shadow-lg); }
.an-pe-x { position: absolute; top: 16px; right: 16px; }
.an-pe-head { text-align: center; }
.an-pe-head .rx-head-sub { display: inline-flex; align-items: center; gap: 8px; margin-top: 4px; }
.an-pe-steps { display: flex; align-items: center; gap: 12px; margin: 0; padding: 0; list-style: none; width: 100%; max-width: 940px; }
.an-pe-steps li { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; color: var(--muted-foreground); white-space: nowrap; }
.an-pe-steps li + li::before { content: ''; flex: 0 0 16px; height: 2px; background: var(--border); }
.an-pe-steps li.done + li::before, .an-pe-steps li.done::before { background: var(--primary); }
.an-pe-steps li.on { color: var(--foreground); font-weight: 500; }
.an-pe-steps li.done { color: var(--foreground); }
.an-pe-n { display: grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: var(--radius-full); background: var(--muted); font-size: 12px; font-weight: 600; }
.an-pe-steps li.done .an-pe-n { background: var(--primary); color: var(--primary-foreground); }
.an-pe-steps li.on .an-pe-n { background: var(--muted-brand); }
.an-pe-n svg.lucide { width: 12px; height: 12px; }
.an-pe-n .rx-spin { width: 14px; height: 14px; }
.an-pe-tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; width: 100%; }
.an-pe-tile { display: flex; flex-direction: column; gap: 4px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--card); opacity: .55; transition: opacity var(--motion-standard), border-color var(--motion-standard), box-shadow var(--motion-standard), background var(--motion-standard); }
.an-pe-tile.active { opacity: 1; border-color: var(--border-brand); box-shadow: 0 0 0 4px var(--muted-brand); }
.an-pe-tile.done { opacity: 1; border-color: var(--border-brand); background: var(--background-brand); }
.an-pe-tile .row { min-height: 36px; }
.an-pe-tn { font-weight: 600; font-size: 14px; line-height: 20px; }
.an-pe-ok { color: var(--success); }
.an-pe-now { width: 100%; max-width: 720px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; min-height: 120px; }
.an-pe-bar { width: 100%; border-radius: var(--radius-full); overflow: hidden; margin-top: 8px; }
.an-pe-run { display: flex; align-items: baseline; gap: 8px; margin-top: 8px; font-size: 14px; }
.an-pe-run .an-amt { font-size: 16px; }
.an-pe-res { width: 100%; display: flex; flex-direction: column; gap: 16px; padding: 20px 24px; border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-md); animation: an-in var(--motion-standard) var(--ease-enter); }
.an-pe-list { display: flex; flex-direction: column; }
.an-pe-row { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 8px; border: 0; border-bottom: 1px solid var(--border); background: transparent; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.an-pe-row:last-child { border-bottom: 0; }
.an-pe-row:hover { background: var(--accent); }
.an-pe-btns { gap: 8px; }
.an-pe-done { display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin-bottom: 24px; border: 1px solid var(--border-brand); border-radius: var(--radius-xl); background: var(--background-brand); }
.an-pe-done-ic { color: var(--success); display: grid; place-items: center; }

@media (max-width: 1100px) {
  .an-pairs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .an-cmp-cols, .an-cmp-row { grid-template-columns: minmax(0, 1fr) 32px minmax(0, 1fr); }
  .an-cmp-act { grid-column: 1 / -1; }
  .an-pe-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .an-pe-steps li { white-space: normal; }
  .an-ageing-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .an-pairs, .an-cmp-head { grid-template-columns: minmax(0, 1fr); }
  .an-cmp-vs { display: none; }
  .an-wf-cols, .an-wf-row, .an-wf-row.gap { grid-template-columns: minmax(0, 1fr) 72px; }
  .an-wf-track, .an-wf-delta, .an-wf-cols span:nth-child(2), .an-wf-cols span:nth-child(4) { display: none; }
}

.an-table tfoot .an-amt { font-weight: 600; }
