/* History belongs to the approved KPV customer and Sales family. */
.kpv-history{--history-paper:#fff;--history-soft:#faf6f5;--history-line:#ebdfe1;--history-ink:#3b2630;--history-muted:#88747b;--history-accent:#660015}
.kpv-history>section{gap:20px}.kpv-history .th{display:flex;flex:1;flex-direction:column;gap:18px;min-width:0;color:var(--history-ink);font-family:inherit}
.kpv-history-header-art .kpv-history-art{width:165px;height:108px;overflow:visible}
.kpv-history .th-cards{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px}
.kpv-history .th-card{display:flex;align-items:center;gap:14px;min-width:0;min-height:96px;padding:16px 20px;border:1px solid var(--history-line);border-radius:16px;background:var(--history-paper)}
.kpv-history .th-stat-icon{display:grid;place-items:center;flex:none;width:42px;height:42px;border:1px solid #66001512;border-radius:12px;background:var(--history-soft);color:var(--history-accent)}.th-stat-icon svg{width:21px;height:21px}
.kpv-history .th-card .l{color:var(--history-muted);font-size:12px;line-height:1.8}.kpv-history .th-card .l span{margin-left:5px;font-size:10px}.kpv-history .th-card .v{overflow-wrap:anywhere;color:var(--history-accent);font-size:25px;font-weight:600;line-height:1.5;font-variant-numeric:tabular-nums}.kpv-history .th-card .v small{margin-left:5px;color:var(--history-muted);font-size:12px;font-weight:400}.kpv-history .th-card.issue{border-color:#e4bec6;background:#fffafb}.kpv-history .th-card.issue .th-stat-icon{background:#660015;color:#ffc781}
.kpv-history .th-box{display:flex;flex:1;flex-direction:column;min-width:0;overflow:hidden;border:1px solid var(--history-line);border-radius:18px;background:var(--history-paper)}
.kpv-history .th-ledger-header{position:relative;display:flex;align-items:center;justify-content:space-between;gap:16px;min-height:62px;padding:10px 20px;border-bottom:1px solid var(--history-line)}
.kpv-history .th-ledger-title{display:flex;align-items:center;gap:10px;flex:none}.th-ledger-title .kpv-customer-search-icon{width:34px;height:34px;border-radius:10px}.th-ledger-title .kpv-customer-search-icon svg{width:19px;height:19px}.kpv-history .th-ledger-title h2{margin:0;font-size:15px;font-weight:600;color:var(--history-accent);line-height:1.6}
.kpv-history .th-loading{position:absolute;inset-inline-start:210px;top:22px;color:#b18b62}.th-loading svg{width:17px;height:17px;animation:kpv-history-spin 1s linear infinite}
.kpv-history .th-tabs{display:flex;gap:3px;min-width:0;padding:3px;border:1px solid var(--history-line);border-radius:10px;background:var(--history-soft)}
.kpv-history .th-tab{display:inline-flex;align-items:center;justify-content:center;gap:7px;min-width:0;min-height:34px;padding:5px 11px;border:0;border-radius:7px;background:transparent;color:var(--history-muted);font-size:12px;font-weight:500;line-height:1.7;cursor:pointer;transition:color .2s,background .2s}
.kpv-history .th-tab .n{min-width:21px;padding:0 5px;border:1px solid #6600150b;border-radius:5px;background:#66001505;color:var(--history-muted);font-size:10px;line-height:18px;font-variant-numeric:tabular-nums}.kpv-history .th-tab.on{background:#660015;color:#fff}.kpv-history .th-tab.on .n{border-color:#ffffff14;background:#ffffff15;color:#fff}.kpv-history .th-tab:disabled{cursor:wait}
.kpv-history .th-filter{padding:16px 20px 12px;border-bottom:1px solid var(--history-line)}
.kpv-history .th-filter-grid{display:grid;grid-template-columns:1.35fr repeat(4,minmax(0,1fr));gap:12px 16px;min-width:0}
.kpv-history .th-filter-grid>div{min-width:0}.kpv-history .th-filter label{display:block;margin-bottom:6px;color:var(--history-ink);font-size:12px;font-weight:500;line-height:20px}
.kpv-history .th-in{display:block;width:100%;min-width:0;height:46px;padding:0 12px;border:1px solid var(--history-line);border-radius:10px;background:var(--history-paper);color:var(--history-ink);font-family:inherit;font-size:13px;box-shadow:none;transition:border-color .2s,box-shadow .2s}.kpv-history .th-in:focus{border-color:#b78596;outline:none;box-shadow:0 0 0 3px #6600150a}.kpv-history .th-in:disabled{background:var(--history-soft);color:var(--history-muted);opacity:.8;cursor:default}.kpv-history select.th-in{appearance:base-select}.kpv-history .th-in::placeholder{color:#b099a2;font-size:12px}
.kpv-history .th-search-control{position:relative}.th-search-control>svg{position:absolute;top:15px;left:12px;width:16px;height:16px;color:#a47c89;pointer-events:none}.kpv-history .th-search-control .th-in{padding-left:36px}
.kpv-history .th-filter-options{display:flex;align-items:center;flex-wrap:wrap;gap:8px 22px;margin-top:12px;padding-top:10px;border-top:1px solid #66001509}
.kpv-history .th-check{display:inline-flex!important;align-items:center;gap:8px;min-height:28px;margin:0!important;font-size:12px!important;font-weight:400!important;color:var(--history-muted)!important;cursor:pointer}.th-check input{width:16px;height:16px;flex:none;border:1px solid #cdb5be;border-radius:4px;accent-color:#660015;color:#660015}.th-check:has(input:checked){color:var(--history-accent)!important}
.kpv-history .th-reset{display:inline-flex;align-items:center;gap:6px;min-height:28px;margin-inline-start:auto;padding:3px 0;color:var(--history-muted);font-size:12px;line-height:20px;cursor:pointer}.th-reset svg{width:14px;height:14px}.kpv-history .th-reset:hover{color:var(--history-accent)}
.kpv-history .th-results{display:flex;flex:1;flex-direction:column;min-width:0}.kpv-history .th-table-scroll{overflow-x:auto;flex:1;min-width:0}.kpv-history .th-table{width:100%;min-width:1180px;border-collapse:collapse;font-size:13px}.kpv-history .th-table>thead th{padding:13px 14px;border-bottom:1px solid var(--history-line);background:var(--history-soft);color:var(--history-muted);font-size:11px;font-weight:500;line-height:1.7;text-align:left;white-space:nowrap}.kpv-history .th-table>thead th:first-child{width:46px;padding-inline:14px 4px}
.kpv-history .th-table>tbody>tr.row>td{padding:15px 14px;border-bottom:1px solid var(--history-line);vertical-align:middle;white-space:nowrap;font-size:12px;line-height:1.8}.kpv-history .th-table>tbody>tr.row>td:first-child{padding-inline:14px 4px}.kpv-history .th-table>tbody>tr.row{cursor:pointer;transition:background .18s}.kpv-history .th-table>tbody>tr.row:hover{background:var(--history-soft)}.kpv-history .th-table>tbody:has(.is-open)>tr.row{background:var(--history-soft)}
.kpv-history .num{text-align:right!important;font-variant-numeric:tabular-nums}.kpv-history .font-mono{font-size:11px;letter-spacing:-.15px}.kpv-history .th-reference{font-weight:600;color:var(--history-ink)}
.kpv-history .th-row-toggle{display:grid;place-items:center;width:28px;height:28px;border:1px solid var(--history-line);border-radius:8px;color:var(--history-muted);background:var(--history-paper)}.th-row-toggle svg{width:13px;height:13px;transition:rotate .2s}.th-row-toggle svg:not(.is-open){rotate:-90deg}
.kpv-history .th-pill{display:inline-flex;align-items:center;gap:5px;max-width:100%;padding:3px 8px;border:1px solid transparent;border-radius:6px;font-size:10px;font-weight:500;line-height:1.7}.kpv-history .th-kind-pill{border-color:#66001514;background:#66001507;color:#7e3547}.kpv-history .th-kind-pill--easy_gold{border-color:#b2875638;background:#fff6e7;color:#92632e}.kpv-history .th-kind-pill--counter_buy{border-color:#98766c24;background:#faf4f0;color:#8b5a4e}
.kpv-history .th-status--ok{border-color:#25936525;background:#edf9f3;color:#237651}.kpv-history .th-status--waiting{border-color:#bd8e3828;background:#fff8e8;color:#9a6a21}.kpv-history .th-status--issue{border-color:#bb41562b;background:#fceff1;color:#a13248}.kpv-history .th-status--cancelled{border-color:#806b7820;background:#f4f0f2;color:#88747b}
.kpv-history .th-detail{padding:18px 20px;border-bottom:1px solid var(--history-line);background:var(--history-soft)}.kpv-history .th-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(270px,1fr));gap:14px}.kpv-history .th-sec{padding:15px 16px;border:1px solid var(--history-line);border-radius:12px;background:var(--history-paper)}.kpv-history .th-sec h4{display:flex;align-items:center;gap:7px;margin:0 0 12px;color:var(--history-accent);font-size:13px;font-weight:600;line-height:1.7}.kpv-history .th-sec h4:before{content:'';width:3px;height:13px;border-radius:3px;background:#c39b65}
.kpv-history .th-kv{display:grid;grid-template-columns:115px minmax(0,1fr);gap:7px 12px;font-size:12px;line-height:1.8}.th-kv dt{color:var(--history-muted)}.th-kv dd{min-width:0;overflow-wrap:anywhere}.kpv-history .th-mini{width:100%;border-collapse:collapse;font-size:12px;line-height:1.8}.kpv-history .th-mini th{padding:7px 8px;border-bottom:1px solid var(--history-line);color:var(--history-muted);font-size:11px;font-weight:500;text-align:left;white-space:nowrap}.kpv-history .th-mini td{padding:8px;border-bottom:1px solid #6600150a;vertical-align:top}.kpv-history .th-link{color:var(--history-accent);font-weight:500;text-decoration:none}.kpv-history .th-link:hover{text-decoration:underline}.kpv-history .th-open{display:inline-flex;align-items:center;min-height:30px;padding:4px 10px;border:1px solid var(--history-line);border-radius:8px;background:var(--history-paper);color:var(--history-accent);font-size:11px;font-weight:500;text-decoration:none}.kpv-history .th-muted{color:var(--history-muted)}
.kpv-history .th-pagination{padding:12px 20px;border-top:1px solid var(--history-line)}.kpv-history .th-pagination:empty{display:none}
.kpv-history .th-empty{display:flex;flex:1;flex-direction:column;align-items:center;justify-content:center;min-height:370px;padding:28px 20px 32px;text-align:center}.kpv-history .th-empty-art{width:min(100%,420px);height:auto;margin-bottom:14px}.kpv-history .th-empty h3{margin:0 0 10px;color:var(--history-accent);font-size:20px;font-weight:600;line-height:1.6}.kpv-history .th-empty p{max-width:390px;margin:0;color:var(--history-muted);font-size:14px;line-height:1.9;text-wrap:balance}
.kpv-history :is(button,a,input,select):focus-visible{outline:2px solid #b98053;outline-offset:3px}
.fi-main-ctn:has(.kpv-history){min-height:100vh;min-height:100svh}.fi-main:has(>.kpv-history),.kpv-history,.kpv-history>section,.kpv-history>section>div:has(>.grid),.kpv-history>section>div>.grid{display:flex;flex:1 0 auto;flex-direction:column;min-width:0}
.kpv-history-header,.kpv-history .th-cards,.kpv-history .th-ledger-header,.kpv-history .th-filter{flex-shrink:0}
/* Layered receipt and clock story, scoped so native SVG placements survive reduced motion. */
.kpv-history-sheet-back{animation:kpv-history-sheet-back 7s cubic-bezier(.22,.75,.25,1) infinite}.kpv-history-sheet-front{animation:kpv-history-sheet-front 7s cubic-bezier(.22,.75,.25,1) infinite}.kpv-history-clock{animation:kpv-history-clock 7s ease-in-out infinite}.kpv-history-clock-hand{transform-origin:175px 100px;animation:kpv-history-hand 7s ease-in-out infinite}.kpv-history-receipt-line{stroke-dasharray:50;animation:kpv-history-receipt-line 7s ease-in-out infinite}.kpv-history-header-spark{transform-box:fill-box;transform-origin:center;animation:kpv-history-spark 7s ease-in-out infinite}
@keyframes kpv-history-sheet-back{0%,100%{translate:7px -7px}32%,82%{translate:0 0}}@keyframes kpv-history-sheet-front{0%,100%{translate:-8px 5px}28%,82%{translate:0 0}}@keyframes kpv-history-clock{0%,100%{translate:7px 4px}40%,82%{translate:0 0}}@keyframes kpv-history-hand{0%,18%{rotate:0deg}60%,85%{rotate:180deg}100%{rotate:360deg}}@keyframes kpv-history-receipt-line{0%,25%,100%{stroke-dashoffset:50;opacity:.2}45%,80%{stroke-dashoffset:0;opacity:1}}@keyframes kpv-history-spark{0%,45%,85%,100%{opacity:0;scale:.4}60%{opacity:1;scale:1.2}72%{opacity:.5;scale:.8}}@keyframes kpv-history-spin{to{rotate:360deg}}
.th-art-timeline{animation:kpv-history-line-entry 6s ease-in-out infinite}.th-art-receipt{animation:kpv-history-line-entry 6s .3s ease-in-out infinite}.th-art-flow,.th-art-edge{stroke-dasharray:1;animation:kpv-history-draw 6s ease-in-out infinite}.th-art-row{animation:kpv-history-row 6s ease-in-out infinite}.th-art-clock-hand{transform-origin:377px 66px;animation:kpv-history-hand 6s ease-in-out infinite}.th-art-spark{animation:kpv-history-spark 6s ease-in-out infinite}
@keyframes kpv-history-line-entry{0%,100%{opacity:.35;translate:0 8px}25%,82%{opacity:1;translate:0 0}}@keyframes kpv-history-draw{0%,12%{stroke-dashoffset:1;opacity:.3}42%,82%{stroke-dashoffset:0;opacity:1}100%{stroke-dashoffset:0;opacity:.2}}@keyframes kpv-history-row{0%,28%,87%,100%{opacity:0;translate:0 0}38%,48%{opacity:1;translate:0 0}65%,76%{opacity:1;translate:0 48px}}
html.dark .kpv-history{--history-paper:#261e25;--history-soft:#30242c;--history-line:#4d3440;--history-ink:#f6e9ed;--history-muted:#bba7af;--history-accent:#ffc781}.dark .kpv-history .th-card.issue{background:#35202b;border-color:#79404e}.dark .kpv-history .th-kind-pill{background:#ffc7810c;border-color:#ffc78120;color:#dbc0a5}.dark .kpv-history .th-status--ok{background:#183b2c;color:#9cd6b6}.dark .kpv-history .th-status--waiting{background:#42341f;color:#e8c588}.dark .kpv-history .th-status--issue{background:#482832;color:#f2adbd}.dark .kpv-history .th-status--cancelled{background:#3a3037;color:#c6b5bd}.dark .th-empty-art{filter:brightness(1.6) saturate(.8)}
@media(max-width:1200px){.kpv-history .th-filter-grid{grid-template-columns:repeat(3,minmax(0,1fr))}.kpv-history .th-ledger-header{align-items:flex-start;flex-direction:column;gap:12px;padding:14px 18px}.kpv-history .th-tabs{width:100%}.kpv-history .th-tab{flex:1}.kpv-history .th-loading{top:22px;inset-inline-start:auto;inset-inline-end:20px}}
@media(max-width:767px){.kpv-history-header-art .kpv-history-art{width:112px;height:80px}.kpv-history .th-cards{gap:10px}.kpv-history .th-card{padding:12px;min-height:84px;gap:9px}.kpv-history .th-stat-icon{width:32px;height:32px;border-radius:10px}.th-stat-icon svg{width:17px;height:17px}.kpv-history .th-card .v{font-size:20px}.kpv-history .th-filter-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.kpv-history .th-search-field{grid-column:1/-1}.kpv-history .th-filter{padding:14px 16px 10px}.kpv-history .th-filter-options{gap:8px 16px}.kpv-history .th-tabs{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px}.kpv-history .th-tab{justify-content:space-between;padding:6px 10px}.kpv-history .th-empty-art{width:min(100%,300px)}.kpv-history .th-empty h3{font-size:18px}.kpv-history .th-empty p{font-size:13px}.kpv-history .th-empty{min-height:320px}.kpv-history .th-pagination{padding:12px 16px}}
@media(max-width:520px){.kpv-history .th-cards{grid-template-columns:repeat(2,minmax(0,1fr))}.kpv-history .th-card:first-child{grid-column:1/-1;min-height:76px}.kpv-history .th-card{align-items:flex-start;gap:10px}.kpv-history .th-card .l{font-size:11px}.kpv-history .th-card .v small{font-size:10px}.kpv-history .th-check{font-size:11px!important}.kpv-history .th-reset{font-size:11px}.kpv-history .th-ledger-title h2{font-size:14px}}
@media(prefers-reduced-motion:reduce){.kpv-history *, .kpv-history-header *{animation:none!important;transition:none!important}.kpv-history-art *,.th-empty-art *{translate:none;rotate:none;scale:none;opacity:1}.kpv-history-receipt-line,.th-art-flow,.th-art-edge{stroke-dashoffset:0}.kpv-history-header-spark,.th-art-spark,.th-art-row{display:none}}
@media print{.kpv-history *, .kpv-history-header *{animation:none!important}.th-filter{display:none}.kpv-history-art *,.th-empty-art *{translate:none;rotate:none;scale:none;opacity:1}.kpv-history-receipt-line,.th-art-flow,.th-art-edge{stroke-dashoffset:0}}

/* Reuse the actual customer header tokens and let long history lists grow. */
.kpv-history{--customer-paper:var(--history-paper);--customer-soft:var(--history-soft);--customer-line:var(--history-line);--customer-ink:var(--history-ink);--customer-muted:var(--history-muted)}
.kpv-history select.th-in{display:inline-flex;align-items:center;justify-content:space-between;gap:10px}
.kpv-history .th-box,.kpv-history .th-results,.kpv-history .th-table-scroll{flex:1 0 auto}

/* Natural-height rows keep only horizontal scrolling during their entrance. */
.kpv-history .th-table-scroll{overflow-y:hidden}

/* Same calendar/bill cells as Sales, including second-line time. */
.kpv-history{--sales-ink:var(--history-ink);--sales-muted:var(--history-muted);--sales-accent:var(--history-accent)}
.kpv-history .th-table>tbody>tr.row>td:is(.th-date-cell,.th-bill-cell){padding:0}
.kpv-history .kpv-sale-date-cell{min-width:160px}
.kpv-history .kpv-sale-bill-cell{min-width:185px}

.kpv-history .th-kind-cell{display:flex;flex-direction:column;align-items:flex-start;gap:5px}
.kpv-history .th-channel-chip{display:inline-flex;align-items:center;gap:5px;min-height:20px;padding:1px 6px;border:1px solid var(--history-line);border-radius:5px;background:var(--history-soft);color:var(--history-muted);font-size:10px;font-weight:500;line-height:16px;white-space:nowrap}
.kpv-history .th-channel-chip svg{width:12px;height:12px;flex:none;color:var(--history-accent);stroke-width:1.6}

/* Summary cards open the same filtered ledger in a focused, native dialog. */
.kpv-history button.th-card{text-align:start;cursor:pointer;transition:border-color .2s,box-shadow .2s,background .2s}
.kpv-history button.th-card:hover{border-color:#b77e90;box-shadow:0 4px 18px #6600150a}
.th-stat-copy{display:block;flex:1;min-width:0}.th-stat-copy>.l,.th-stat-copy>.v{display:block}
.kpv-history .th-stat-chevron{width:16px;height:16px;flex:none;color:var(--history-muted);transition:translate .2s}.kpv-history button.th-card:hover .th-stat-chevron{translate:3px 0}
.kpv-history .th-summary-modal .fi-modal-window{border:1px solid var(--history-line);border-radius:20px;background:var(--history-paper);color:var(--history-ink);box-shadow:0 24px 90px #26000b33}
.kpv-history .th-summary-modal .fi-modal-header{border-bottom:1px solid var(--history-line);background:var(--history-paper)}
.kpv-history .th-summary-modal .fi-modal-heading{color:var(--history-accent);font-weight:600}
.kpv-history .th-summary-modal .fi-modal-content{gap:18px;padding:20px 24px 24px}
.th-summary-total{display:flex;align-items:center;gap:12px;padding:15px 18px;border:1px solid var(--history-line);border-radius:12px;background:var(--history-soft)}
.th-summary-total>div{flex:1}.th-summary-total .th-muted{font-size:11px}.th-summary-total strong{display:block;font-size:25px;line-height:1.5;font-weight:600;color:var(--history-accent);font-variant-numeric:tabular-nums}.th-summary-total small{font-size:12px;font-weight:400;color:var(--history-muted)}
.th-summary-count{font-size:12px;color:var(--history-muted);white-space:nowrap}
.th-summary-scroll{max-height:48vh;overflow:auto;border:1px solid var(--history-line);border-radius:12px;transition:opacity .2s}.th-summary-pending{opacity:.5;pointer-events:none}
.th-summary-table{width:100%;min-width:870px;border-collapse:collapse;font-size:12px;line-height:1.8}
.th-summary-table th{position:sticky;top:0;z-index:1;padding:11px 12px;background:var(--history-soft);border-bottom:1px solid var(--history-line);color:var(--history-muted);font-size:11px;font-weight:500;text-align:start;white-space:nowrap}
.th-summary-table td{padding:10px 12px;border-bottom:1px solid var(--history-line);white-space:nowrap;vertical-align:middle}
.th-summary-table tbody tr:last-child td{border-bottom:0}.th-summary-table tbody tr:hover{background:var(--history-soft)}
.kpv-history .th-summary-table .kpv-sale-date-cell,.kpv-history .th-summary-table .kpv-sale-bill-cell{padding:0;min-width:140px}
.th-summary-bill{display:block}.th-summary-kind{display:block;margin:3px 0 0 50px;font-size:10px;color:var(--history-muted)}
.th-summary-open{display:inline-flex;align-items:center;gap:7px;min-height:34px;padding:5px 10px;border:1px solid var(--history-line);border-radius:8px;color:var(--history-accent);background:var(--history-paper);font-size:11px}.th-summary-open:hover{border-color:#b77e90;background:var(--history-soft)}.th-summary-open svg{width:14px;height:14px}
.th-summary-table .th-summary-empty{height:200px;white-space:normal;text-align:center}.th-summary-empty svg{width:32px;height:32px;margin:0 auto 12px;color:var(--history-accent)}.th-summary-empty strong,.th-summary-empty span{display:block}.th-summary-empty span{margin-top:6px;color:var(--history-muted)}
@media(max-width:767px){.kpv-history .th-summary-modal .fi-modal-content{padding:14px;gap:12px}.th-summary-total{padding:12px;gap:9px;flex-wrap:wrap}.th-summary-total strong{font-size:22px}.th-summary-count{font-size:11px}.th-summary-scroll{max-height:50vh}}
/* Teleport out of the page's motion transform so the popup is viewport anchored. */
.kpv-history-popup .th-summary-modal{min-height:100dvh;grid-template-rows:1fr auto 1fr}
.kpv-history-popup .fi-modal-window{max-height:calc(100dvh - 32px)}
.kpv-history-popup .fi-modal-content{min-height:0;overflow-y:auto}
