/* ==========================================================================
   Billing scene (template-parts/scene-bill.php, assets/js/scene-bill.js).
   A claims batch where one held line is rechecked, sent and paid. The markup
   renders the finished batch and the script replays it. The card keeps one
   height in every frame: rows have fixed tracks, the held-line panel is
   overlaid, and states change with opacity, colour and transform only.
   Every selector is scoped to .h-scene-bill.
   ========================================================================== */

.h-scene-bill {
    --hb-amber-bg: #F6E7CF;
    --hb-amber-ink: #8A5A12;
    --hb-amber-dot: #B7791F;
    --hb-amber-line: #EAD3AE;
    --hb-amber-tint: #FBF4E8;
    --hb-sent-bg: #E3EBF1;
    --hb-sent-ink: #33475B;
    --hb-sent-dot: #6B8499;
    /* Width, margin and the caption row come from the shared .h-scene shell in home.css. */
    position: relative;
    overflow: hidden;
    font-family: var(--font-primary);
    color: var(--ink);
}

/* ---------- Card ---------- */
.h-scene-bill .hb-card {
    container-type: inline-size;
    position: relative;
    padding: 18px clamp(12px, 3.6%, 20px) 16px;
    border: 1px solid var(--arasync-line);
    border-radius: 16px;
    background: var(--arasync-white);
    box-shadow: 0 30px 60px -32px rgba(30, 43, 58, 0.45);
}

.h-scene-bill .hb-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}
.h-scene-bill .hb-title {
    display: block;
    font: 600 1rem/1.25 var(--font-heading);
    letter-spacing: -0.01em;
    color: var(--ink);
}
.h-scene-bill .hb-batch {
    display: block;
    margin-top: 3px;
    font-size: 0.72rem;
    line-height: 1.3;
    color: var(--ink-3);
}
.h-scene-bill .hb-tag {
    flex: none;
    padding: 5px 8px;
    border-radius: 6px;
    background: var(--arasync-mist);
    font: 500 0.68rem/1 var(--font-mono);
    color: var(--teal-ink);
}

/* ---------- Table ---------- */
.h-scene-bill .hb-table {
    position: relative;
    z-index: 0;
    margin-top: 14px;
}

.h-scene-bill .hb-cols,
.h-scene-bill .hb-row {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) 54px 34px 62px 104px;
    column-gap: 10px;
    align-items: center;
}

.h-scene-bill .hb-cols {
    padding-bottom: 8px;
    font: 600 0.62rem/1 var(--font-primary);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-3);
}
.h-scene-bill .hb-c-client { grid-column: 1 / 3; }
.h-scene-bill .hb-c-units { text-align: right; }
.h-scene-bill .hb-c-payer { padding-left: 8px; }

.h-scene-bill .hb-row {
    position: relative;
    grid-template-rows: 18px 16px;
    grid-template-areas:
        "ini name code units payer status"
        "ini sub  code units payer status";
    row-gap: 2px;
    padding-block: 9px;
    border-top: 1px solid var(--arasync-line);
}

/* Row highlight sits behind the cells and bleeds slightly into the card padding. */
.h-scene-bill .hb-row::before {
    content: "";
    position: absolute;
    inset: 2px -8px;
    z-index: -1;
    border-radius: 8px;
    background: var(--hb-amber-tint);
    box-shadow: inset 0 0 0 1px transparent;
    opacity: 0;
    transition: opacity 0.35s ease, box-shadow 0.25s ease;
}
.h-scene-bill .hb-row[data-s="held"]::before { opacity: 1; }
.h-scene-bill .hb-row.is-selected::before { box-shadow: inset 0 0 0 1px var(--hb-amber-line); }
.h-scene-bill .hb-row.is-flash::before { animation: hb-flash 1.2s ease; }

@keyframes hb-flash {
    from { opacity: 1; background-color: var(--teal-soft); }
    to { opacity: 0; background-color: var(--teal-soft); }
}

.h-scene-bill .hb-ini {
    grid-area: ini;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font: 600 0.72rem/1 var(--font-heading);
}
.h-scene-bill .hb-ini[data-tone="teal"] { background: var(--teal-soft); color: var(--teal-ink); }
.h-scene-bill .hb-ini[data-tone="slate"] { background: var(--hb-sent-bg); color: var(--hb-sent-ink); }
.h-scene-bill .hb-ini[data-tone="sage"] { background: #E3EEDF; color: #3E5A39; }
.h-scene-bill .hb-ini[data-tone="sky"] { background: #DCEDF1; color: #23596A; }

.h-scene-bill .hb-name {
    grid-area: name;
    overflow: hidden;
    font: 600 0.84rem/18px var(--font-heading);
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--ink);
}

.h-scene-bill .hb-sub {
    grid-area: sub;
    display: grid;
    min-width: 0;
}
.h-scene-bill .hb-sub small {
    grid-area: 1 / 1;
    overflow: hidden;
    font-size: 0.7rem;
    line-height: 16px;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--ink-3);
    transition: opacity 0.3s ease;
}
.h-scene-bill .hb-meta { display: none; }
.h-scene-bill .hb-note { font-weight: 600; color: var(--hb-amber-ink); opacity: 0; }
.h-scene-bill .hb-row[data-s="held"] .hb-prog,
.h-scene-bill .hb-row[data-s="held"] .hb-meta { opacity: 0; }
.h-scene-bill .hb-row[data-s="held"] .hb-note { opacity: 1; }

.h-scene-bill .hb-code {
    grid-area: code;
    justify-self: start;
    padding: 4px 6px;
    border-radius: 5px;
    background: var(--arasync-mist);
    font: 500 0.7rem/1 var(--font-mono);
    color: var(--teal-ink);
}
.h-scene-bill .hb-units {
    grid-area: units;
    font-size: 0.82rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    color: var(--ink);
}
.h-scene-bill .hb-payer {
    grid-area: payer;
    overflow: hidden;
    padding-left: 8px;
    font-size: 0.8rem;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--ink-2);
}

/* ---------- Status pills: ready, held, sent, paid ---------- */
.h-scene-bill .hb-status {
    grid-area: status;
    justify-self: start;
    display: flex;
}
.h-scene-bill .hb-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 22px;
    padding: 0 8px 0 7px;
    border-radius: 999px;
    background: var(--teal-soft);
    font: normal 600 0.68rem/1 var(--font-primary);
    white-space: nowrap;
    color: var(--teal-ink);
    transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}
.h-scene-bill .hb-pill::before {
    content: "";
    flex: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--arasync-primary);
}
.h-scene-bill .hb-row[data-s="ready"] .hb-pill {
    background: var(--arasync-gray-50);
    box-shadow: inset 0 0 0 1px var(--arasync-line);
    color: var(--ink-2);
}
.h-scene-bill .hb-row[data-s="held"] .hb-pill { background: var(--hb-amber-bg); color: var(--hb-amber-ink); }
.h-scene-bill .hb-row[data-s="held"] .hb-pill::before { background: var(--hb-amber-dot); }
.h-scene-bill .hb-row[data-s="sent"] .hb-pill { background: var(--hb-sent-bg); color: var(--hb-sent-ink); }
.h-scene-bill .hb-row[data-s="sent"] .hb-pill::before { background: var(--hb-sent-dot); }

/* ---------- Held-line panel, overlaid above the held row ---------- */
.h-scene-bill .hb-pop {
    position: absolute;
    right: 0;
    bottom: calc(100% - 2px);
    z-index: 3;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "label label"
        "text  btn";
    align-items: end;
    gap: 6px 14px;
    width: min(380px, 100%);
    padding: 12px 14px;
    border: 1px solid var(--hb-amber-line);
    border-left: 3px solid var(--hb-amber-dot);
    border-radius: 12px;
    background: var(--arasync-white);
    box-shadow: 0 18px 36px -18px rgba(30, 43, 58, 0.45);
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
}
.h-scene-bill .hb-pop::after {
    content: "";
    position: absolute;
    right: 74px;
    bottom: -6px;
    width: 10px;
    height: 10px;
    border-right: 1px solid var(--hb-amber-line);
    border-bottom: 1px solid var(--hb-amber-line);
    background: var(--arasync-white);
    transform: rotate(45deg);
}
.h-scene-bill .hb-pop.is-open {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition-delay: 0s;
}
.h-scene-bill .hb-pop-label {
    grid-area: label;
    font: 600 0.62rem/1 var(--font-primary);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--hb-amber-ink);
}
.h-scene-bill .hb-pop-text {
    grid-area: text;
    margin: 0;
    font-size: 0.76rem;
    line-height: 1.4;
    color: var(--ink);
}
.h-scene-bill .hb-recheck {
    grid-area: btn;
    justify-self: start;
    padding: 7px 12px;
    border-radius: 8px;
    background: var(--arasync-primary);
    font: 600 0.72rem/1 var(--font-primary);
    color: #fff;
    transition: transform 0.15s ease, filter 0.15s ease;
}
.h-scene-bill .hb-recheck.is-pressed { transform: scale(0.94); filter: brightness(1.15); }

/* ---------- Footer: batch status and the send button ---------- */
.h-scene-bill .hb-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--arasync-line);
}
.h-scene-bill .hb-foot-text {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 2.6em;
    margin: 0;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--ink);
}
.h-scene-bill .hb-foot-text > span {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.h-scene-bill .hb-foot-ic {
    position: relative;
    display: grid;
    place-items: center;
    flex: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--teal-soft);
    color: var(--teal-ink);
    transition: background-color 0.3s ease, color 0.3s ease;
}
.h-scene-bill .hb-foot-ic svg { width: 12px; height: 12px; stroke-width: 3; }
.h-scene-bill .hb-foot-ic::after {
    content: "";
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0;
}
.h-scene-bill .hb-foot-text[data-v="held"] .hb-foot-ic { background: var(--hb-amber-bg); color: var(--hb-amber-dot); }
.h-scene-bill .hb-foot-text[data-v="ready"] .hb-foot-ic { background: var(--arasync-mist); color: var(--arasync-primary); }
.h-scene-bill .hb-foot-text[data-v="wait"] .hb-foot-ic,
.h-scene-bill .hb-foot-text[data-v="ack"] .hb-foot-ic { background: var(--hb-sent-bg); color: var(--hb-sent-ink); }
.h-scene-bill .hb-foot-text[data-v="held"] .hb-foot-ic svg,
.h-scene-bill .hb-foot-text[data-v="ready"] .hb-foot-ic svg,
.h-scene-bill .hb-foot-text[data-v="wait"] .hb-foot-ic svg { opacity: 0; }
.h-scene-bill .hb-foot-text[data-v="held"] .hb-foot-ic::after,
.h-scene-bill .hb-foot-text[data-v="ready"] .hb-foot-ic::after,
.h-scene-bill .hb-foot-text[data-v="wait"] .hb-foot-ic::after { opacity: 1; }

.h-scene-bill .hb-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: none;
    min-width: 116px;
    height: 34px;
    padding: 0 14px;
    border-radius: 999px;
    background: var(--arasync-primary);
    font: 600 0.78rem/1 var(--font-primary);
    white-space: nowrap;
    color: #fff;
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.15s ease, filter 0.15s ease;
}
.h-scene-bill .hb-send svg { width: 14px; height: 14px; stroke-width: 2.6; }
.h-scene-bill .hb-send:not([data-v="done"]) svg { display: none; }
.h-scene-bill .hb-send[data-v="wait"] { background: var(--hb-sent-bg); color: var(--hb-sent-ink); }
.h-scene-bill .hb-send[data-v="done"] { background: var(--teal-soft); color: var(--teal-ink); }
.h-scene-bill .hb-send.is-pressed { transform: scale(0.95); filter: brightness(1.12); }

/* ---------- Narrow cards: code, units and payer move under the name ---------- */
@container (max-width: 479px) {
    .h-scene-bill .hb-cols,
    .h-scene-bill .hb-row {
        grid-template-columns: 28px minmax(0, 1fr) auto;
        column-gap: 8px;
    }
    .h-scene-bill .hb-row {
        grid-template-rows: 22px 16px;
        grid-template-areas:
            "ini name status"
            "ini sub  sub";
        padding-block: 8px;
    }
    .h-scene-bill .hb-c-code,
    .h-scene-bill .hb-c-units,
    .h-scene-bill .hb-c-payer,
    .h-scene-bill .hb-code,
    .h-scene-bill .hb-units,
    .h-scene-bill .hb-payer,
    .h-scene-bill .hb-prog { display: none; }
    .h-scene-bill .hb-meta { display: block; }
    .h-scene-bill .hb-c-status,
    .h-scene-bill .hb-status { justify-self: end; }
    .h-scene-bill .hb-pop { width: 100%; }
    .h-scene-bill .hb-pop::after { right: 20px; }
}

@container (max-width: 339px) {
    .h-scene-bill .hb-pop {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "label"
            "text"
            "btn";
        gap: 8px;
        padding: 11px 12px;
    }
}

@container (max-width: 279px) {
    .h-scene-bill .hb-foot {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .h-scene-bill *,
    .h-scene-bill *::before,
    .h-scene-bill *::after { animation: none !important; transition: none !important; }
}
