/* ============================================================================
   Item history popup — the long-press card.

   Press and hold any item anywhere in the app and this answers the two
   questions actually asked over a counter: what did we charge for this last
   time, and who did we get it from and at what. Two rows, and a way through
   to the whole record.

   Styled here rather than in each page's own <style> block because the
   gesture is app-wide: the POS cart, the inventory table, transactions,
   supplier accounts and the returns list are four separate documents with
   four separate stylesheets, and a card that looks different on each of them
   would read as four different features. See item-history.js.

   Colours are the app's own: teal #0d9488 is the identity colour, amber
   #f59e0b the "look here" accent, and the dark theme keys off body.theme-dark
   exactly as the rest of the app does.
   ========================================================================= */

.ih-overlay {
    position: fixed;
    inset: 0;
    z-index: 2147483000;   /* above Bootstrap modals (1055) and the AI dock */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    /* A dim, not a blur: the card is a task to finish, and what is behind it
       only has to recede. */
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-pop, 200ms) var(--spring, ease-out);
}
.ih-overlay.is-open { opacity: 1; pointer-events: auto; }

.ih-card {
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 18px 48px rgba(8, 24, 22, .28);
    /* Grows out of the point that was pressed (item-history.js sets the
       origin there) and shrinks back into it on close, along the same path.
       A critically damped spring: the hold carried no momentum to
       overshoot with. The width eases too, when the chart arrives. */
    transform: scale(.94);
    transition: transform var(--dur-panel, 240ms) var(--spring, ease-out),
                max-width var(--dur-panel, 240ms) var(--spring, ease-out);
    font-size: .88rem;
    color: #0c1f1c;
}
.ih-overlay.is-open .ih-card { transform: scale(1); }

@media (prefers-reduced-motion: reduce) {
    .ih-overlay, .ih-card { transition: none; }
    .ih-overlay.is-open .ih-card, .ih-card { transform: none; }
}

.ih-head {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px 10px;
    border-bottom: 1px solid #e6f1ee;
}
.ih-title { flex: 1; min-width: 0; }
.ih-name {
    font-weight: 800;
    font-size: .98rem;
    line-height: 1.25;
    word-break: break-word;
}
.ih-sub {
    margin-top: 2px;
    font-size: .72rem;
    color: #6b8f88;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.ih-close {
    flex: none;
    width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 0; border-radius: 8px;
    background: transparent; color: #6b8f88;
    cursor: pointer;
}
.ih-close:hover { background: #eef6f4; color: #0c1f1c; }

.ih-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--o-line, #e6f1ee);
}
.ih-actions:empty, .ih-body:empty, .ih-foot:empty { display: none; }
.ih-action {
    flex: 1 1 max-content;
    min-height: 44px;
    padding: 6px 10px;
    border: 1px solid var(--o-line, #d2e6e0);
    border-radius: 8px;
    background: var(--o-tigris-soft, #eff8f6);
    color: var(--o-tigris-strong, #0f6d61);
    font-weight: 700;
    cursor: pointer;
}
body.theme-dark .ih-action {
    background: var(--o-tigris-soft, #1b302c);
    color: var(--o-tigris-strong, #a4e1d8);
    border-color: var(--o-line, #345650);
}
.ih-action.is-destructive {
    background: var(--o-danger-soft, #fdf0ef);
    color: var(--o-danger, #9f2929);
    border-color: var(--o-danger-line, #f2cfcd);
}
body.theme-dark .ih-action.is-destructive {
    background: var(--o-danger-soft, #392522);
    color: var(--o-danger, #ffbbb5);
    border-color: var(--o-danger-line, #66433f);
}

/* Pressed means pressed, the moment the finger lands. */
.ih-close, .ih-more, .ih-panel-head {
    transition: scale var(--dur-pop, 200ms) var(--spring, ease-out);
}
:is(.ih-close, .ih-more, .ih-panel-head):active:not(:disabled) {
    scale: .97;
    transition-duration: var(--dur-press, 100ms);
}

.ih-body { padding: 12px 16px 4px; }

/* One row per question. The label is the question, the figure is the answer,
   and everything else is the detail that makes the answer trustworthy. */
.ih-row {
    display: flex;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid #e6f1ee;
    border-radius: 12px;
    margin-bottom: 10px;
    background: #f8fcfb;
}
.ih-row-icon {
    flex: none;
    width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 9px;
    background: rgba(13, 148, 136, .12);
    color: #0d9488;
}
.ih-row.ih-supply .ih-row-icon { background: rgba(245, 158, 11, .14); color: #b45309; }
.ih-row-main { flex: 1; min-width: 0; }
.ih-row-label {
    font-size: .66rem; font-weight: 800; text-transform: uppercase;
    letter-spacing: .05em; color: #6b8f88;
}
.ih-row-price {
    font-weight: 900; font-size: 1.05rem; line-height: 1.2;
    /* 'en-US' numerals everywhere money is shown, same as the rest of the
       app: these are read against printed labels and receipts. */
    font-variant-numeric: tabular-nums;
}
.ih-row-price .ih-cur { font-size: .66em; font-weight: 700; color: #6b8f88; margin-inline-start: 3px; }
.ih-row-meta { margin-top: 3px; font-size: .74rem; color: #55736e; line-height: 1.45; }
.ih-row-meta .ih-dot { opacity: .45; margin: 0 5px; }
.ih-row-when { margin-top: 2px; font-size: .72rem; color: #8aa8a2; }
.ih-row-empty { font-size: .8rem; color: #9ab3ae; font-style: italic; }
.ih-badge {
    display: inline-block; margin-inline-start: 6px;
    padding: 1px 6px; border-radius: 999px;
    font-size: .62rem; font-weight: 800; text-transform: uppercase;
    background: rgba(245, 158, 11, .18); color: #b45309;
}

.ih-foot {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 16px 14px;
}
.ih-more {
    flex: 1;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    background: linear-gradient(135deg, #0d9488, #0f766e);
    color: #fff; border: 0; border-radius: 10px;
    padding: 9px 14px; font-size: .84rem; font-weight: 800;
    cursor: pointer;
}
.ih-more:hover { background: linear-gradient(135deg, #0b7a70, #0d5f58); }
.ih-more:disabled { opacity: .5; cursor: not-allowed; }

.ih-state { padding: 22px 16px; text-align: center; color: #6b8f88; font-size: .84rem; }
.ih-state.is-err { color: #b91c1c; }

/* ── Sales by month, to the right of the two rows ───────────────────────── */
/* The card widens only when it has the chart to show; the two rows keep
   their own width on the left and the chart takes the right. Below 760px the
   chart drops under the rows instead of squeezing both. */
.ih-card.has-trend { max-width: 860px; }
.ih-split { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 760px) {
    .ih-split { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); align-items: start; }
}
.ih-trend {
    padding: 10px 12px 10px;
    border: 1px solid #e6f1ee;
    border-radius: 12px;
    margin-bottom: 10px;
    background: #f8fcfb;
}
.ih-trend-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ih-trend-range { font-size: .68rem; color: #8aa8a2; }
.ih-trend-stats { display: flex; gap: 18px; margin-top: 4px; }
.ih-stat b {
    display: block; font-weight: 900; font-size: 1.05rem; line-height: 1.2;
    font-variant-numeric: tabular-nums;
}
.ih-stat span { font-size: .7rem; color: #6b8f88; }
.ih-trend-empty { margin-top: 10px; }

.ih-bars {
    position: relative;
    display: flex; align-items: stretch; gap: 2px;
    height: 150px; margin-top: 10px;
}
.ih-bar-col {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; align-items: center;
    border-radius: 6px; outline: none; cursor: default;
}
.ih-bar-col:hover, .ih-bar-col:focus-visible { background: rgba(13, 148, 136, .06); }
.ih-bar-val {
    height: 16px; font-size: .7rem; font-weight: 800; color: #0c1f1c;
    font-variant-numeric: tabular-nums;
}
/* The baseline is the track's bottom edge; bars grow up from it with only
   their top corners rounded, so every bar reads against the same floor. */
.ih-bar-track {
    flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center;
    border-bottom: 1px solid #cde4df;
}
.ih-bar {
    display: block; width: 62%; max-width: 30px;
    background: #0d9488; border-radius: 4px 4px 0 0;
    transition: height 260ms cubic-bezier(.2, .9, .3, 1);
}
/* The month still running is a part-month: lighter, so it is not read as
   a fall against the full months beside it. */
.ih-bar-col.is-current .ih-bar { background: #5eead4; }
.ih-bar-m { margin-top: 4px; font-size: .68rem; font-weight: 700; color: #55736e; }
.ih-bar-tx { font-size: .68rem; color: #8aa8a2; font-variant-numeric: tabular-nums; }
.ih-tip {
    position: absolute; top: calc(100% + 6px); transform: translateX(-50%);
    z-index: 2; pointer-events: none;
    min-width: 130px; padding: 7px 9px;
    background: #0c1f1c; color: #e2efed; border-radius: 8px;
    box-shadow: 0 6px 18px rgba(8, 24, 22, .28);
    font-size: .72rem; line-height: 1.45; white-space: nowrap;
}
.ih-tip[hidden] { display: none; }
.ih-tip-title { font-weight: 800; }
.ih-trend-key {
    display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px;
    font-size: .68rem; color: #8aa8a2;
}
.ih-trend-key span { display: inline-flex; align-items: center; gap: 5px; }
.ih-key-bar { display: inline-block; width: 9px; height: 9px; border-radius: 2px; background: #0d9488; }
@media (prefers-reduced-motion: reduce) { .ih-bar { transition: none; } }

/* ── Alternatives: under "Last supplied" ───────────────────────────────── */
/* A row-shaped button, so it sits in the column as a third answer rather
   than as a control bolted on; the list opens beneath it in place. */
.ih-alt { margin-bottom: 10px; }
.ih-alt-btn {
    display: flex; align-items: center; gap: 10px;
    width: 100%; text-align: start;
    padding: 9px 12px;
    border: 1px dashed #b9dcd5; border-radius: 12px;
    background: transparent; color: inherit; font: inherit;
    cursor: pointer;
    transition: scale var(--dur-pop, 200ms) var(--spring, ease-out), background 120ms ease;
}
.ih-alt-btn:hover:not(:disabled) { background: #eef6f4; border-style: solid; }
.ih-alt-btn:active:not(:disabled) { scale: .98; transition-duration: var(--dur-press, 100ms); }
.ih-alt-btn:disabled { cursor: default; opacity: .7; }
.ih-alt-btn .ih-row-icon { background: rgba(99, 102, 241, .12); color: #4f46e5; }
.ih-alt-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ih-alt-title { font-weight: 800; font-size: .84rem; }
.ih-alt-count {
    display: inline-block; min-width: 18px; padding: 0 6px; margin-inline-start: 4px;
    border-radius: 999px; background: #0d9488; color: #fff;
    font-size: .68rem; line-height: 18px; text-align: center;
}
.ih-alt-sci { font-size: .72rem; color: #6b8f88; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ih-alt-chevron { flex: none; color: #6b8f88; transition: transform 180ms ease; }
.ih-alt-btn[aria-expanded="true"] .ih-alt-chevron { transform: rotate(180deg); }
.ih-alt-menu {
    margin-top: 6px;
    border: 1px solid #e6f1ee; border-radius: 12px;
    background: #f8fcfb;
    padding: 8px 10px;
}
.ih-alt-menu[hidden] { display: none; }
.ih-alt-menu .ih-state { padding: 12px 8px; }
.ih-alt-head { font-size: .7rem; color: #6b8f88; margin-bottom: 6px; }
.ih-alt-head b { color: #0c1f1c; }
.ih-alt-list {
    list-style: none; margin: 0; padding: 0;
    max-height: 260px; overflow-y: auto;
}
.ih-alt-item { padding: 7px 2px; border-top: 1px solid #e6f1ee; }
.ih-alt-item:first-child { border-top: 0; }
.ih-alt-item.is-out { opacity: .6; }
.ih-alt-line { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.ih-alt-name { font-weight: 700; font-size: .82rem; min-width: 0; word-break: break-word; }
.ih-alt-price { flex: none; font-weight: 900; font-variant-numeric: tabular-nums; }
.ih-alt-price .ih-cur { font-size: .66em; font-weight: 700; color: #6b8f88; margin-inline-start: 3px; }
.ih-alt-none { font-size: .72rem; font-weight: 600; color: #9ab3ae; font-style: italic; }
.ih-alt-meta {
    display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 2px;
    font-size: .72rem; color: #55736e; font-variant-numeric: tabular-nums;
}
.ih-alt-k { color: #8aa8a2; }
.ih-alt-empty { padding: 4px 2px; }
.ih-badge-muted { background: rgba(100, 116, 139, .16); color: #475569; }
.ih-badge-danger { background: rgba(220, 38, 38, .14); color: #b91c1c; }

/* The hold itself, so it reads as doing something before the card arrives
   rather than as the app having frozen. The ring draws in step with the
   hold and lands as the card opens (HOLD_MS, 500 ms); it waits out the
   first 120 ms, so an ordinary tap on a row shows nothing at all. Lifting
   the finger takes it straight away. */
.ih-pressing {
    box-shadow: inset 0 0 0 2px rgba(13, 148, 136, .45);
    transition: box-shadow 380ms linear 120ms;
    -webkit-user-select: none;
    user-select: none;
}
[data-item-barcode], [data-item-actions] { -webkit-touch-callout: none; }
@media (prefers-reduced-motion: reduce) {
    .ih-pressing { transition: none; }
}

/* ── Dark theme ─────────────────────────────────────────────────────────── */
body.theme-dark .ih-card { background: #13201d; color: #e2efed; }
body.theme-dark .ih-head { border-bottom-color: rgba(45, 212, 191, .18); }
body.theme-dark .ih-sub,
body.theme-dark .ih-row-label { color: #9db8b2; }
body.theme-dark .ih-close { color: #9db8b2; }
body.theme-dark .ih-close:hover { background: rgba(45, 212, 191, .12); color: #e2efed; }
body.theme-dark .ih-row { background: #0f1c1a; border-color: rgba(45, 212, 191, .18); }
body.theme-dark .ih-row-icon { background: rgba(45, 212, 191, .16); color: #2dd4bf; }
body.theme-dark .ih-row.ih-supply .ih-row-icon { background: rgba(251, 191, 36, .16); color: #fbbf24; }
body.theme-dark .ih-row-meta { color: #9db8b2; }
body.theme-dark .ih-row-when { color: #7d9a94; }
body.theme-dark .ih-row-price .ih-cur { color: #9db8b2; }
body.theme-dark .ih-badge { background: rgba(251, 191, 36, .18); color: #fbbf24; }
body.theme-dark .ih-state { color: #9db8b2; }
body.theme-dark .ih-trend { background: #0f1c1a; border-color: rgba(45, 212, 191, .18); }
body.theme-dark .ih-trend-range,
body.theme-dark .ih-bar-tx,
body.theme-dark .ih-trend-key { color: #7d9a94; }
body.theme-dark .ih-stat span,
body.theme-dark .ih-bar-m { color: #9db8b2; }
body.theme-dark .ih-bar-val { color: #e2efed; }
body.theme-dark .ih-bar-track { border-bottom-color: rgba(45, 212, 191, .22); }
body.theme-dark .ih-bar,
body.theme-dark .ih-key-bar { background: #2dd4bf; }
body.theme-dark .ih-bar-col.is-current .ih-bar { background: #115e59; }
body.theme-dark .ih-bar-col:hover,
body.theme-dark .ih-bar-col:focus-visible { background: rgba(45, 212, 191, .08); }
body.theme-dark .ih-tip { background: #e2efed; color: #0c1f1c; }

body.theme-dark .ih-alt-btn { border-color: rgba(45, 212, 191, .3); }
body.theme-dark .ih-alt-btn:hover:not(:disabled) { background: rgba(45, 212, 191, .1); }
body.theme-dark .ih-alt-btn .ih-row-icon { background: rgba(129, 140, 248, .18); color: #a5b4fc; }
body.theme-dark .ih-alt-count { background: #2dd4bf; color: #0c1f1c; }
body.theme-dark .ih-alt-sci,
body.theme-dark .ih-alt-chevron,
body.theme-dark .ih-alt-head,
body.theme-dark .ih-alt-price .ih-cur { color: #9db8b2; }
body.theme-dark .ih-alt-head b { color: #e2efed; }
body.theme-dark .ih-alt-menu { background: #0f1c1a; border-color: rgba(45, 212, 191, .18); }
body.theme-dark .ih-alt-item { border-top-color: rgba(45, 212, 191, .14); }
body.theme-dark .ih-alt-meta { color: #9db8b2; }
body.theme-dark .ih-alt-k,
body.theme-dark .ih-alt-none { color: #7d9a94; }
body.theme-dark .ih-badge-muted { background: rgba(148, 163, 184, .18); color: #cbd5e1; }
body.theme-dark .ih-badge-danger { background: rgba(248, 113, 113, .18); color: #fca5a5; }

/* ── The inventory row's history panel ──────────────────────────────────── */
/* Where "More" lands: the item's own row in the inventory table, with the
   whole record under it. Lazy-loaded, because rendering this for every row
   of every page would be forty joins per product for a panel almost nobody
   opens. */
.ih-panel { margin-top: 14px; }
.ih-panel-head {
    display: flex; align-items: center; gap: 8px;
    width: 100%;
    background: transparent;
    border: 1px solid #cde4df; border-radius: 10px;
    padding: 8px 12px;
    font-size: .8rem; font-weight: 800; color: #0f766e;
    cursor: pointer;
}
.ih-panel-head:hover { background: #eef6f4; }
.ih-panel-head .ih-panel-chevron { transition: transform 180ms ease; margin-inline-start: auto; }
.ih-panel-head[aria-expanded="true"] .ih-panel-chevron { transform: rotate(180deg); }
.ih-panel-body { padding-top: 10px; }
.ih-panel-body[hidden] { display: none; }
.ih-hist-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .ih-hist-grid { grid-template-columns: 1fr; } }
.ih-hist-col h6 {
    font-size: .7rem; font-weight: 800; text-transform: uppercase;
    letter-spacing: .05em; color: #6b8f88; margin-bottom: 6px;
}
.ih-hist-note { font-size: .7rem; color: #9ab3ae; margin-top: 6px; }
/* The row is highlighted when "More" lands on it, so someone arriving from
   another tab can see which of fifty rows was the one they pressed. */
.ih-target-row > td { animation: ihTargetFlash 2.4s ease; }
@keyframes ihTargetFlash {
    0%, 60% { background-color: rgba(245, 158, 11, .22); }
    100%    { background-color: transparent; }
}
@media (prefers-reduced-motion: reduce) {
    .ih-target-row > td { animation: none; background-color: rgba(245, 158, 11, .14); }
}
body.theme-dark .ih-panel-head { border-color: rgba(45, 212, 191, .22); color: #2dd4bf; }
body.theme-dark .ih-panel-head:hover { background: rgba(45, 212, 191, .1); }
body.theme-dark .ih-hist-col h6 { color: #9db8b2; }
/* The cheapest delivery, net of supplier discount (see invHistoryMarkup). */
.ih-cheapest > td {
    background-color: rgba(16, 185, 129, .14) !important;
    font-weight: 700;
}
.ih-cheapest > td:first-child { box-shadow: inset 3px 0 0 #10b981; }
[dir="rtl"] .ih-cheapest > td:first-child { box-shadow: inset -3px 0 0 #10b981; }
body.theme-dark .ih-cheapest > td { background-color: rgba(45, 212, 191, .16) !important; }
