/* RIM application layer on top of the Nocturne design system.
   nocturne.css stays the untouched system source of truth; everything
   app-specific (page shell, flash banner, status text, table geometry,
   popovers) lives here and is built only from Nocturne tokens. */

/* ── shell ─────────────────────────────────────────────────────────── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--color-bg);
    /* header rule: the Nocturne fade, painted from the divider token */
    background-image: linear-gradient(to right,
        transparent, var(--color-divider) 48px,
        var(--color-divider) calc(100% - 48px), transparent);
    background-repeat: no-repeat;
    background-position: bottom;
    background-size: 100% 1px;
}

.nav { padding: 14px 24px; gap: 20px; }
.nav-user { font-size: 12px; color: color-mix(in srgb, var(--color-text) 55%, transparent); }
.nav .btn { font-size: 12px; padding: 4px 10px; }
.nav form { margin: 0; }

/* Nocturne is left-aligned and asymmetric: whitespace goes on the right. */
.page {
    padding: 24px;
    max-width: 1560px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: var(--space-6);
    flex-wrap: wrap;
}
.page-head h1 { margin-bottom: 0; }
.page-actions { display: flex; gap: var(--space-2); align-items: flex-end; }

h1 { margin-bottom: 0; }
h4 { margin: 26px 0 8px; }
.subline {
    font-size: 12.5px;
    color: color-mix(in srgb, var(--color-text) 55%, transparent);
    margin: var(--space-2) 0 var(--space-4);
}
.subline a { color: var(--color-accent-300); }
.prose {
    font-size: 12.5px;
    color: color-mix(in srgb, var(--color-text) 55%, transparent);
    max-width: 78ch;
    text-wrap: pretty;
    margin: var(--space-3) 0 var(--space-6);
}
.prose strong, .prose em { color: var(--color-text); }
.prose a { color: var(--color-accent-300); }

/* ── flash / warning banner (replaces pico's <mark> at block scale) ── */
.flash {
    background: var(--color-accent-900);
    border: 1px solid var(--color-accent-700);
    border-radius: var(--radius-md);
    padding: 9px 14px;
    font-size: 13px;
    color: var(--color-accent-100);
    margin: var(--space-3) 0;
    max-width: 1100px;
}
.flash a { color: var(--color-accent-200); }

/* ── sync sentinel: Shopify out of sync — must be impossible to miss ── */
.sync-alert {
    background: color-mix(in srgb, #b3261e 24%, var(--color-bg, #111));
    border-bottom: 1px solid color-mix(in srgb, #b3261e 55%, transparent);
    color: #ffd9d6;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
}
.sync-alert a { color: #fff; text-decoration: underline; }
/* RIM-2 foreign incoming: fix-it-now, so it outshouts the sync banner */
.sync-alert-loud {
    background: color-mix(in srgb, #b3261e 45%, var(--color-bg, #111));
    padding: 16px 24px;
    font-size: 16px;
    line-height: 1.5;
}

/* ── status values: text, not tags ─────────────────────────────────── */
.status {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: color-mix(in srgb, var(--color-text) 65%, transparent);
    white-space: nowrap;
}
.status-good { color: var(--color-accent-300); }
.status-dead { color: var(--color-neutral-400); }

/* ── numbers ───────────────────────────────────────────────────────── */
.num, .table td, .table th { font-variant-numeric: tabular-nums; }
.right { text-align: right; }

/* ── buttons ───────────────────────────────────────────────────────── */
.btn-xs { font-size: 11px; padding: 2px 8px; border-radius: var(--radius-sm); }
.btn-chosen {
    color: var(--color-accent);
    border-color: var(--color-accent);
    background: color-mix(in srgb, var(--color-accent) 16%, transparent);
}
.inline-form { display: inline; margin: 0; }
.row-form { display: flex; gap: var(--space-2); align-items: center; margin: 0; }

/* ── fields ────────────────────────────────────────────────────────── */
.field { margin: 0; }
.field-row {
    display: flex;
    gap: var(--space-3);
    align-items: flex-end;
    flex-wrap: wrap;
    margin: 0;
}
.check {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    cursor: pointer;
}
.check input { accent-color: var(--color-accent); width: 15px; height: 15px; margin: 0; }
.check-caption {
    font-size: 12px;
    color: color-mix(in srgb, var(--color-text) 70%, transparent);
    margin-bottom: 5px;
}
.input-xs { min-height: 28px; padding: 3px 7px; font-size: 13px; }

/* ── bulk-selection bar ────────────────────────────────────────────── */
/* Pinned to the bottom of the viewport so it stays reachable on a long PO;
   JS unhides it once a line is checked. */
.bulk-bar {
    position: sticky;
    bottom: var(--space-4);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin: var(--space-4) 0;
    padding: 9px 14px;
    width: fit-content;
    max-width: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-accent-700);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}
/* the class's display:flex would otherwise beat the UA [hidden] rule */
.bulk-bar[hidden] { display: none; }
.bulk-bar .check { margin: 0; }
.bulk-count { font-size: 13px; white-space: nowrap; }
.bulk-count strong { color: var(--color-accent-300); }
.bulk-sep {
    width: 1px;
    align-self: stretch;
    background: var(--color-divider);
}

/* ── tags / chips ──────────────────────────────────────────────────── */
.tag + .tag { margin-left: var(--space-1); }
.chip-x { color: inherit; text-decoration: none; margin-left: 6px; opacity: .7; }

/* ── tables ────────────────────────────────────────────────────────── */
.table { table-layout: fixed; }
.table td { vertical-align: top; }
.table th { white-space: nowrap; }
.table-auto { table-layout: auto; }
.table td small,
.table td .muted {
    color: color-mix(in srgb, var(--color-text) 55%, transparent);
}
.table tbody tr.row-inactive { opacity: .55; }

/* Variant rows inside a rowspan group: fainter rule, shorter fade.
   The group's final row keeps the standard 8% / 48px rule. */
.table tbody tr.vrow:not(.group-end) {
    background: linear-gradient(to right,
        transparent, color-mix(in srgb, var(--color-text) 4%, transparent) 24px,
        color-mix(in srgb, var(--color-text) 4%, transparent) calc(100% - 24px),
        transparent) no-repeat bottom / 100% 1px;
}
.table tbody tr.vrow:not(.group-end):hover {
    background:
        linear-gradient(color-mix(in srgb, var(--color-text) 4%, transparent),
                        color-mix(in srgb, var(--color-text) 4%, transparent)) no-repeat 0 0 / 100% 100%,
        linear-gradient(to right,
            transparent, color-mix(in srgb, var(--color-text) 4%, transparent) 24px,
            color-mix(in srgb, var(--color-text) 4%, transparent) calc(100% - 24px),
            transparent) no-repeat bottom / 100% 1px;
}
.table td.group-cell { padding: 14px var(--space-2); }
.table tr.vrow td { padding: 6px var(--space-2); font-size: 13.5px; }
/* product images: always a square, cropped from the centre (Shopify
   photos come in any aspect ratio) */
.thumb, .thumb-sm { aspect-ratio: 1; object-fit: cover; object-position: center; }
.thumb { border-radius: var(--radius-md); width: 100%; height: auto; }
.thumb-sm { border-radius: var(--radius-md); width: 96px; height: auto; }
/* one-text-line thumb beside a PO / shipment line's title */
.line-product { display: flex; align-items: flex-start; gap: var(--space-2); min-width: 0; }
.line-thumb {
    flex: none;
    width: 22px;
    height: 22px;
    object-fit: cover;
    object-position: center;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--color-text) 8%, transparent);
}
.stack { display: flex; flex-direction: column; gap: var(--space-1); align-items: flex-start; }
.stack-h { display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; }

/* ── details as a secondary button + popover panel ─────────────────── */
details > summary.as-btn {
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-family: var(--font-heading);
    font-weight: var(--font-heading-weight);
    font-size: 14px;
    line-height: 1.2;
    color: var(--color-text);
    background: transparent;
    border: 1px solid var(--color-divider);
    padding: var(--space-2) calc(var(--space-3) * 1.2);
    border-radius: var(--radius-md);
}
details > summary.as-btn::-webkit-details-marker { display: none; }
details > summary.as-btn:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
details > summary.as-btn::before { content: "▸"; font-size: 10px; opacity: .8; }
details[open] > summary.as-btn::before { content: "▾"; }
details > summary.as-btn.btn-xs { font-size: 11px; padding: 2px 8px; }

.panel {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-top: var(--space-3);
    box-shadow: var(--shadow-sm);
}

/* Inline editors hang off the cell as a small floating popover. */
.popover-host { position: relative; }
.popover {
    position: absolute;
    right: 0;
    z-index: 30;
    width: 250px;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 12px;
    margin-top: var(--space-2);
    text-align: left;
    white-space: normal;
}
.popover-narrow { width: 190px; }
.popover form { margin: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.popover-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ── cards grid (dashboard) ────────────────────────────────────────── */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(224px, 1fr));
    gap: 12px;
    max-width: 1180px;
    margin-top: var(--space-6);
}
.card-title { font-size: 15px; font-weight: 400; }
.card-title strong { font-size: 22px; font-weight: var(--font-heading-weight); }
.card-title a { text-decoration: none; }

/* ── dialogs ───────────────────────────────────────────────────────── */
.dialog-backdrop { z-index: 50; }
.progress {
    height: 3px;
    border-radius: 2px;
    background: var(--color-neutral-800);
    overflow: hidden;
}
.progress > span {
    display: block;
    height: 100%;
    width: 35%;
    background: var(--color-accent);
    animation: rim-progress 1.4s ease-in-out infinite;
}
@keyframes rim-progress {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(340%); }
}
.dialog-note {
    font-size: 11.5px;
    color: color-mix(in srgb, var(--color-text) 55%, transparent);
}

/* ── misc ──────────────────────────────────────────────────────────── */
.auth-card { max-width: 360px; margin: 72px auto; }
.scroll-x { overflow-x: auto; }
ul.plain { list-style: none; padding: 0; margin: 0; }

/* The system's .nav-brand pushes everything after it to the right; RIM's
   links follow the brand and only the user block is right-aligned. */
.nav-brand { margin-right: 0; }
.nav-brand a { color: inherit; text-decoration: none; }
.nav-user { margin-left: auto; }

/* 20px gutter between every column (products list). Applied as symmetric
   cell padding and pulled back by the table's own negative margin so the
   grid still starts flush left — rowspan groups make :first-child
   unreliable for edge trimming. */
.table-gutter td, .table-gutter th { padding-left: 10px; padding-right: 10px; }
.table-gutter { margin-inline: -10px; width: calc(100% + 20px); }

/* Button labels never wrap mid-phrase in a narrow table column. */
.btn, details > summary.as-btn { white-space: nowrap; }

/* Wide tables keep their designed column widths and scroll inside
   .scroll-x rather than squeezing the last column out of view. */
.table-wide { min-width: 1720px; }
.table-lines { min-width: 1080px; }

/* The forecast review table is wider than the standard content column. */
.page-wide { max-width: none; }

/* ── products view: sortable headers, count badges ─────────────────── */
.th-sort { color: inherit; text-decoration: none; white-space: nowrap; }
.th-sort:hover { color: var(--color-accent); }
.th-sort.active { color: var(--color-accent); }
.sort-arrow { font-size: 9px; margin-left: 3px; opacity: .55; }
.th-sort.active .sort-arrow { opacity: 1; }
.badge {
    display: inline-block;
    font-size: 10.5px;
    line-height: 1.4;
    padding: 0 6px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: .03em;
    font-weight: 600;
}
.badge-amber { color: #f2c46d; background: color-mix(in srgb, #f2c46d 16%, transparent); }
.badge-red { color: #f08a8a; background: color-mix(in srgb, #f08a8a 16%, transparent); }
.count-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-bottom: var(--space-1); }
.count-overdue > a { color: #f2c46d; }
.gap-large { color: #f08a8a; font-weight: 600; }

/* ── floating timeline panel (rim.js data-panel) ───────────────────── */
.dialog-panel { width: min(680px, 100%); max-height: 82vh; overflow: auto; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); }
.timeline { display: flex; flex-direction: column; gap: var(--space-3); }
.tl-event { border-left: 2px solid var(--color-divider); padding-left: var(--space-3); }
.tl-count { border-left-color: var(--color-accent); }
.tl-receipt { border-left-color: var(--color-accent-2-500); }
.tl-request { border-left-color: #f2c46d; }
.tl-head { font-size: 13.5px; }
.tl-at { font-variant-numeric: tabular-nums; opacity: .6; margin-right: var(--space-2); }
.tl-rows { font-size: 12.5px; margin-top: 4px; border-collapse: collapse; }
.tl-rows td { padding: 1px var(--space-3) 1px 0; vertical-align: top; }

/* ── bundle count-request panel (rim.js data-panel) ────────────────── */
.badge-green { color: #7fd1a0; background: color-mix(in srgb, #7fd1a0 16%, transparent); }
.request-rows { width: 100%; border-collapse: collapse; margin: var(--space-3) 0; font-size: 13px; }
.request-rows td { padding: var(--space-2) var(--space-2) var(--space-2) 0; vertical-align: top; border-top: 1px solid var(--color-divider); }
.request-rows tr:first-child td { border-top: 0; }
.req-thumb { width: 40px; }
.thumb-xs { width: 40px; height: 40px; object-fit: cover; border-radius: var(--radius-sm); }
.req-status { white-space: nowrap; }
.req-status .badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.req-action { text-align: right; white-space: nowrap; }

/* ── Tom Select pickers (draft PO add-product, /shipments search) ──── */
.ts-wrapper { margin-bottom: 0; }
.ts-control {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-divider);
    border-radius: var(--radius-md);
    padding: 6px 10px;
    min-height: 36px;
    font-size: 14px;
}
/* tom-select forces #fff in these states (higher specificity) — keep the bar dark */
.ts-wrapper .ts-control,
.ts-wrapper.full .ts-control,
.ts-wrapper.single.input-active .ts-control { background: var(--color-surface); color: var(--color-text); }
.ts-control input { color: var(--color-text); }
.ts-control input::placeholder { color: color-mix(in srgb, var(--color-text) 50%, transparent); }
.ts-wrapper.focus .ts-control { border-color: var(--color-accent); }
.ts-dropdown {
    background: var(--color-surface);
    border: 1px solid var(--color-divider);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    color: var(--color-text);
    z-index: 100;
}
.ts-dropdown .active { background: color-mix(in srgb, var(--color-accent) 16%, transparent); color: inherit; }
.ts-dropdown .optgroup-header {
    background: transparent;
    color: color-mix(in srgb, var(--color-text) 60%, transparent);
    font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
}
/* the select's .input class lands on the wrapper too — one box, not two */
.ts-wrapper.input { padding: 0; border: 0; background: transparent; box-shadow: none; height: auto; min-height: 0; }

/* ── product config grid (T-55) ── */
.flash-error { background: color-mix(in srgb, #f08a8a 14%, transparent); border-color: #f08a8a; color: #f6c0c0; }
.config-scroll { overflow-x: auto; margin-top: var(--space-4); }
.config-table td { vertical-align: middle; padding: 3px 6px; }
.config-table td .input { width: auto; max-width: none; }
.config-table td.config-n { width: 32px; font-size: 11.5px; }
.config-catalog { display: flex; align-items: center; gap: var(--space-2); min-width: 220px; font-size: 12.5px; }
.config-actions { white-space: nowrap; }
.config-text { white-space: pre-line; font-size: 12.5px; }
/* "◌" + vowel mark (Arabic/Hebrew allowed_characters): Chrome draws the pair as tofu when a
   webfont leads the stack, so these cells (and the input inside, font: inherit) use the system font (RIM-36) */
.config-script { font-family: system-ui, sans-serif; }
.config-nothumb { display: inline-block; background: color-mix(in srgb, var(--color-text) 10%, transparent); }
.config-description { max-width: 820px; }
.config-add { max-width: 420px; margin-top: var(--space-4); }

/* ── product type-ahead (T-90, product-suggest.js) ─────────────────── */
.suggest-host { position: relative; }
.suggest-list {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 40;
    width: max(100%, 440px);
    max-height: min(60vh, 520px);
    overflow-y: auto;
    margin: var(--space-1) 0 0;
    padding: var(--space-2) 0;
    list-style: none;
    background: var(--color-surface);
    border: 1px solid var(--color-divider);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}
.suggest-list[hidden] { display: none; }
.suggest-head {
    padding: var(--space-3) var(--space-4) var(--space-1);
    font-size: 11px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: color-mix(in srgb, var(--color-text) 55%, transparent);
}
.suggest-option { padding: var(--space-2) var(--space-4); cursor: pointer; }
.suggest-option[aria-selected="true"] { background: color-mix(in srgb, var(--color-accent) 18%, transparent); }
.suggest-row { display: flex; align-items: center; gap: var(--space-4); min-width: 0; }
.suggest-thumb {
    flex: none;
    width: 36px;
    height: 36px;
    aspect-ratio: 1;
    object-fit: cover;
    object-position: center;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--color-text) 8%, transparent);
}
.suggest-text { display: flex; flex-direction: column; min-width: 0; }
.suggest-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest-meta { font-size: 12px; color: color-mix(in srgb, var(--color-text) 55%, transparent); }
/* the same rows inside TomSelect pickers (T-91): compact in the control */
.suggest-row-sm { gap: var(--space-2); }
.suggest-row-sm .suggest-thumb { width: 22px; height: 22px; }
.suggest-row-sm .suggest-meta { display: none; }
.ts-dropdown .option.suggest-row { padding: var(--space-2) var(--space-4); }
.ts-dropdown-content:has(.suggest-row) { max-height: min(50vh, 360px); }

/* ── shipment details box (shipment_detail.html) ───────────────────── */
/* View mode shows each value as a box the size of its input; Edit swaps
   the boxes for the inputs in place (rim.js [data-edit-box]). */
.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-3);
}
.field-value {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 36px;
    padding: 6px 10px;
    font-size: 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--color-text) 5%, transparent);
    min-width: 0;
}
/* same head height with or without the Edit button: no jump on toggle */
.edit-box > .panel-head { align-items: center; min-height: 32px; }
.field-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.edit-box:not(.is-editing) .edit-only,
.edit-box.is-editing .view-only { display: none; }

/* ── PO list status filter: a select-looking summary over a checkbox popover (T-108) ── */
.status-filter-summary {
    list-style: none;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.status-filter-summary::-webkit-details-marker { display: none; }
.status-filter-summary::after { content: " ▾"; opacity: .7; }
.status-filter-group { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.status-filter-group legend { font-size: 12px; opacity: .75; margin-bottom: var(--space-1); }

/* ── PO type tabs + custom POs (RIM-26) ───────────────────────────── */
.po-tabs { margin-top: var(--space-4); }
.po-tabs a.seg-opt { color: var(--color-text); text-decoration: none; }
.po-tabs a.seg-opt[aria-current="page"] { color: var(--color-accent); box-shadow: inset 0 0 0 1px var(--color-accent); }
.po-tabs a.seg-opt:not([aria-current]):hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
.custom-order { margin-top: var(--space-6); }
.custom-order-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); }
.custom-order-head h3 { margin: 0; font-size: 16px; }
.custom-order.is-removed { opacity: .55; }
.custom-props { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.custom-props li { overflow-wrap: anywhere; }
.custom-export { position: absolute; left: -9999px; width: 1px; height: 1px; }
