/* /var/www/mcp/lib/style.css
   Shared baseline styles for internal tools. */

:root {
    --bg:        #f5f6f8;
    --surface:   #ffffff;
    --border:    #e1e4e8;
    --text:      #1a1d21;
    --text-mute: #6b7280;
    --primary:   #2563eb;
    --primary-h: #1d4ed8;
    --danger:    #dc2626;
    --warn:      #d97706;
    --ok:        #16a34a;
    --radius:    8px;
    --shadow:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
    background: var(--primary);
    color: white;
    border: 0;
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}
button:hover { background: var(--primary-h); }
button.ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
button.ghost:hover { background: #f3f4f6; }
button.danger { background: var(--danger); }

input[type=email],
input[type=password],
input[type=text],
select,
textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: white;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
    border-color: var(--primary);
}

label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-mute);
    margin-bottom: 12px;
}
label input, label select, label textarea {
    margin-top: 4px;
}

.error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
    padding: 10px 12px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}

/* ── Login page ──────────────────────────────────────────────── */

body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--surface);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 380px;
}
.login-card .logo {
    display: block;
    height: 40px;
    margin: 0 auto 24px;
}
.login-card h1 {
    margin: 0 0 4px;
    font-size: 22px;
}
.login-card .subtitle {
    margin: 0 0 24px;
    color: var(--text-mute);
}
.login-card button {
    width: 100%;
    margin-top: 8px;
}
.login-card .hint {
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-mute);
    text-align: center;
}

/* ── App layout ──────────────────────────────────────────────── */

.app {
    max-width: min(2200px, 100%);   /* fill the screen instead of a narrow column */
    margin: 0 auto;
    padding: 22px 30px;
}

/* Header — copied verbatim from PO Receipt's server/po-dashboard.html
   inline <style>, so the two pages feel like one app. White background +
   bottom border + centered alignment + 48px logo. h1 = page name (24px),
   meta-line = "Rolan Australia · <date>", nav on the right. */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: #fff;
    border-bottom: 1px solid #e1e4e8;
    margin-bottom: 24px;
}
.app-header .brand {
    display: flex;
    align-items: center;
    gap: 16px;
}
.app-header .brand .logo {
    height: 48px;
}
.app-header h1 { margin: 0; font-size: 24px; }
.app-header .meta { color: #6b7280; font-size: 13px; }
.app-header nav {
    display: flex;
    align-items: center;
    gap: 8px;
}
.app-header nav a {
    padding: 6px 12px;
    border-radius: 6px;
    color: #1a1d21;
    font-size: 13px;
    text-decoration: none;
}
.app-header nav a:hover { background: #f3f4f6; text-decoration: none; }
.app-header nav .meta { padding: 6px 8px; }

/* ── Stat cards ──────────────────────────────────────────────── */

.stats {
    display: none;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border-top: 3px solid var(--primary);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stat-card.late      { border-top-color: var(--danger); }
.stat-card.partial   { border-top-color: var(--warn); }
.stat-card.attention { border-top-color: #7c3aed; }
.stat-card.ok        { border-top-color: var(--ok); }
.stat-card .label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-mute);
    font-weight: 600;
}
.stat-card .value {
    font-size: 28px;
    font-weight: 700;
    margin-top: 4px;
}

/* ── Tabs (clean, professional — minimal colour) ─────────────── */
/* Note: explicit overrides on every state because the base `button`
   rule sets a blue background that would otherwise leak through. */

.tabs {
    display: flex;
    gap: 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
.tab,
.tab:hover,
.tab:focus,
.tab:focus-visible,
.tab:active,
.tab.active {
    background: transparent;
    background-color: transparent;
    box-shadow: none;
}
.tab {
    padding: 12px 0;
    cursor: pointer;
    border: 0;
    color: var(--text-mute);
    font-weight: 500;
    font-size: 14px;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: color .12s, border-color .12s;
    outline: none;
}
.tab:hover {
    color: var(--text);
}
.tab:focus-visible {
    outline: 2px solid var(--border);
    outline-offset: 2px;
    border-radius: 2px;
}
.tab.active {
    color: var(--text);
    border-bottom-color: var(--text);   /* black underline */
    font-weight: 600;
}
.tab .count {
    background: #f3f4f6;
    color: var(--text-mute);
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}
.tab.active .count {
    background: #1a1d21;
    color: #ffffff;
}

/* Urgent tabs — Needs Attention + Late Orders both pinned red so the
   agent's "do something now" queues stand out from the neutral All
   Purchase Orders / Unprocessed / Closed. Stays red whether active or
   inactive; active state adds the underline + bold from the standard
   .tab.active rule. Count badge gets a stronger red fill when active. */
.tab[data-tab="attention"],
.tab[data-tab="late"] {
    color: #dc2626;
    font-weight: 600;
}
.tab[data-tab="attention"]:hover,
.tab[data-tab="late"]:hover {
    color: #991b1b;
}
.tab[data-tab="attention"].active,
.tab[data-tab="late"].active {
    color: #dc2626;
    border-bottom-color: #dc2626;
}
.tab[data-tab="attention"] .count,
.tab[data-tab="late"] .count {
    background: #fee2e2;
    color: #991b1b;
}
.tab[data-tab="attention"].active .count,
.tab[data-tab="late"].active .count {
    background: #dc2626;
    color: #ffffff;
}

/* Happy-path tab — Awaiting Delivery sits between the urgent reds and
   the neutral greys. Green signals "no action needed, everything's on
   track" so the eye skips past it when scanning for problems. */
.tab[data-tab="awaiting_delivery"] {
    color: #16a34a;
    font-weight: 600;
}
.tab[data-tab="awaiting_delivery"]:hover {
    color: #15803d;
}
.tab[data-tab="awaiting_delivery"].active {
    color: #16a34a;
    border-bottom-color: #16a34a;
}
.tab[data-tab="awaiting_delivery"] .count {
    background: #d1fae5;
    color: #166534;
}
.tab[data-tab="awaiting_delivery"].active .count {
    background: #16a34a;
    color: #ffffff;
}

/* ── Toolbar — matches PO Receipt's search bar ───────────────── */

.toolbar {
    background: var(--surface);
    padding: 16px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    display: flex;
    gap: 16px;
    align-items: center;
}
.toolbar input[type=search] {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: white;
}
.toolbar input[type=search]::placeholder {
    color: #9ca3af;
}
.toolbar .row-summary {
    color: var(--text-mute);
    font-size: 13px;
    white-space: nowrap;
}

/* ── Table ───────────────────────────────────────────────────── */

.table {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    width: 100%;
}
.table table {
    width: 100%;
    border-collapse: collapse;
}
.table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-mute);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}
.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
/* Rows aren't directly clickable any more — the toggle in the Actions column is.
   Keep the hover tint for visual consistency / scanability. */
.table tr.po-row:hover { background: #fafbfc; }
.table tr.po-row.expanded { background: #f9fafb; }
.table th.col-actions, .table td.col-actions { text-align: center; width: 64px; }

/* iOS-style toggle for expanding the per-row detail panel.
   Off (default) = grey track. On (expanded) = blue track + thumb slid right. */
.row-toggle {
    appearance: none;
    -webkit-appearance: none;
    background: #d1d5db;
    border: 0;
    border-radius: 12px;
    width: 38px;
    height: 22px;
    position: relative;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s ease;
}
.row-toggle:hover { background: #9ca3af; }
.row-toggle.on { background: #2563eb; }
.row-toggle.on:hover { background: #1d4ed8; }
.row-toggle:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.row-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s ease;
}
.row-toggle.on .row-toggle-thumb { transform: translateX(16px); }
/* Unread supplier reply: warm background tint + thicker left border so the row
   visually pops from a scrolling table. iPhone-inbox metaphor — bold + tinted = unread. */
.table tr.po-row.unread { background: #fff7ed; }
.table tr.po-row.unread:hover { background: #fff1e1; }
.table tr.po-row.unread td:first-child { border-left: 3px solid #ef4444; padding-left: 13px; }
.table tr.po-row.unread strong { font-weight: 700; }
/* ⚠️ Ken alert: row's last message is an auto-fired Ken alert email.
   Stronger red tint than .unread so alert rows pop out of a sea of
   warm-tinted unread rows. Wins specificity over .unread when both apply. */
.table tr.po-row.alert,
.table tr.po-row.unread.alert { background: #fee2e2; }
.table tr.po-row.alert:hover,
.table tr.po-row.unread.alert:hover { background: #fecaca; }
.table tr.po-row.alert td:first-child,
.table tr.po-row.unread.alert td:first-child { border-left: 4px solid #dc2626; padding-left: 12px; }
.table tr.po-row.alert strong { font-weight: 700; color: #991b1b; }
.table tr:last-child td { border-bottom: 0; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    /* Always one line — "On track" / "Due today" must not wrap when the
       column gets narrow. */
    white-space: nowrap;
}
.badge.late         { background: #fee2e2; color: #991b1b; }
.badge.due-today    { background: #fef3c7; color: #92400e; }
.badge.on-track     { background: #d1fae5; color: #065f46; }
/* Back Ordered — past expected_date but every owing item has a future
   supplier_eta. Distinct from Late so the dashboard doesn't surface
   backordered POs as fires. Soft amber/blue so it reads "we know about
   this, supplier has rebooked" not "you should panic". 2026-05-07. */
.badge.back-ordered { background: #ede9fe; color: #5b21b6; }
.badge.unknown      { background: #e5e7eb; color: var(--text-mute); }
.badge.partial      { background: #fef3c7; color: #92400e; }

/* Responsible badge — who currently owns chasing the PO. Driven by
   PO-level handed_to_ken (cascade triggers keep this in sync with item
   level). Clint = automated chase scope; Ken = human queue. 2026-05-07. */
.badge.responsible-clint { background: #dbeafe; color: #1e40af; }
.badge.responsible-ken   { background: #fce7f3; color: #9d174d; }
.badge.pending   { background: #dbeafe; color: #1e40af; }

/* Last-message preview cell — replaces the old Notes badge in the list.
   Two lines: meta (direction arrow + timestamp), then the snippet text
   truncated to one ellipsised line. Hover shows the full snippet via the
   browser-native title attribute. */
.last-msg {
    max-width: 460px;
    font-size: 12px;
    line-height: 1.35;
    color: var(--text);
}
.last-msg-meta {
    color: var(--text-mute);
    font-size: 11px;
    margin-bottom: 2px;
    white-space: nowrap;
}
.last-msg-arrow {
    display: inline-block;
    width: 14px;
    text-align: center;
    font-weight: 700;
}
.last-msg.inbound  .last-msg-arrow { color: #2563eb; }   /* blue ← supplier said */
.last-msg.outbound .last-msg-arrow { color: #6b7280; }   /* grey → we sent */
.last-msg.internal .last-msg-arrow { color: #d97706; font-size: 11px; }   /* orange 📝 internal note */
.last-msg-body {
    /* One-line truncate. The tooltip / detail panel show the full content. */
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text);
}
.last-msg.no-body .last-msg-arrow { vertical-align: baseline; }

/* Customer vs Supplier tag on the last-message cell (SWO list) */
.msg-party {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .02em;
    padding: 1px 6px;
    border-radius: 999px;
    vertical-align: 1px;
}
.msg-party.customer { background: #eff6ff; color: #1e40af; }   /* blue  — customer */
.msg-party.supplier { background: #fff7ed; color: #9a3412; }   /* amber — supplier */

/* Notes hover tooltip — wraps the count badge and reveals the full notes
   content (with timestamps + author) on hover. Anchored to the right edge
   so the rightmost column doesn't push the tooltip off-screen. */
.notes-cell {
    position: relative;
    display: inline-block;
    cursor: help;
}
.notes-tooltip {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 50;
    width: 360px;
    max-height: 360px;
    overflow-y: auto;
    padding: 10px 12px;
    background: #1f2937;
    color: #f9fafb;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    font-size: 12px;
    line-height: 1.4;
    text-align: left;
    white-space: normal;
    cursor: text;
}
/* Invisible hit-area bridge so the 6px visual gap between the badge and the
   tooltip doesn't break hover when the cursor moves down into the popover. */
.notes-tooltip::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: -6px;
    height: 6px;
}
.notes-cell:hover .notes-tooltip,
.notes-cell:focus-within .notes-tooltip { display: block; }
.notes-tooltip .note-item {
    padding: 6px 0;
    border-bottom: 1px solid #374151;
}
.notes-tooltip .note-item:last-child { border-bottom: 0; }
.notes-tooltip .note-meta {
    font-size: 11px;
    color: #9ca3af;
    margin-bottom: 2px;
    font-weight: 500;
}
.notes-tooltip .note-body {
    color: #f3f4f6;
    word-wrap: break-word;
}

/* Reply-status pill — one-glance "where is this conversation". Same shape as
   .badge so the column reads consistently next to On-time. */
.reply-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}
/* Reply column is only relevant on the "Needs Attention" tab — every row
   there is by definition awaiting an agent. Hidden everywhere else to keep
   the All Orders / Late Orders views uncluttered. body[data-tab] is set by
   app.js whenever the active tab changes. */
.col-reply { display: none; }
body[data-tab="attention"] .col-reply { display: table-cell; }

.reply-badge.supplier-replied { background: #fee2e2; color: #991b1b; font-weight: 600; }
.reply-badge.waiting-agent    { background: #ede9fe; color: #5b21b6; }
.reply-badge.waiting-supplier { background: #fef3c7; color: #92400e; }
.reply-badge.waiting-customer { background: #dbeafe; color: #1e40af; }
.reply-badge.resolved         { background: #d1fae5; color: #065f46; }
.reply-badge.pending-send     { background: #f3f4f6; color: var(--text-mute); }
.reply-badge.unknown          { background: #f3f4f6; color: var(--text-mute); }

/* Pulsing red dot for new reply — matches the iOS notification dot vibe */
.unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
    animation: unread-pulse 1.6s ease-out infinite;
}
@keyframes unread-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(239, 68, 68, 0.5); }
    70%  { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);   }
    100% { box-shadow: 0 0 0 0   rgba(239, 68, 68, 0);   }
}

/* Human-agent handover banner inside detail panel.
   Full-width — spans both grid columns so it sits like a divider between the
   meta card and the items / activity two-column layout below. Without this,
   the banner would claim cell 1, Items would land in cell 2, and Activity
   would drop to a second row alone. */
.ken-banner {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: #faf5ff;
    border: 1px solid #d8b4fe;
    border-left: 4px solid #7c3aed;
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 14px;
}
.ken-banner strong { display: block; color: #5b21b6; margin-bottom: 2px; }
.ken-banner .meta { color: #6b21a8; font-size: 12px; }
.release-ken-btn {
    background: #7c3aed;
    color: #fff;
    border: 0;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.release-ken-btn:hover:not(:disabled) { background: #6d28d9; }
.release-ken-btn:disabled { opacity: 0.5; cursor: not-allowed; background: #9ca3af; }

/* Locked state — any item has supplier_eta > expected_date + 2 days. */
.ken-banner-locked { background: #fef2f2; border-color: #fecaca; border-left-color: #dc2626; }
.ken-banner-locked strong { color: #991b1b; }
.ken-banner-locked .meta { color: #b91c1c; }
.ken-banner-overdue {
    display: block;
    margin-top: 6px;
    color: #991b1b !important;
    font-weight: 600;
    font-size: 12px;
}

/* Resend issue report — sits in the compose-tabs row, right-aligned. */
.compose-tabs { display: flex; align-items: center; gap: 8px; }
.resend-issue-btn {
    margin-left: auto;
    background: #fff;
    color: #b91c1c;
    border: 1px solid #fecaca;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s, color .15s;
}
.resend-issue-btn:hover:not(:disabled) { background: #fee2e2; }
.resend-issue-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Inline supplier-email entry — shown immediately when po_orders.supplier_email
   is empty, OR toggled in via the "Edit" link beside the To: address when an
   email is already saved. */
.compose-need-email { padding: 10px 0; }
.compose-need-email input.compose-input { font-size: 14px; }

/* Standard-reply template dropdown — sits inline in the compose-tabs row
   (next to Reply / Internal note). Auto-width, compact. The placeholder
   option ("Choose a template…") does the labelling. */
.compose-template-select {
    margin-left: 8px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    font-size: 12px;
    color: var(--text-mute);
    cursor: pointer;
    max-width: 240px;
}
.compose-template-select:focus { outline: 2px solid var(--text); outline-offset: 1px; }
.compose-template-select.hidden { display: none; }
.compose-need-email.hidden,
.compose-reply-body.hidden { display: none; }

/* "Edit" link beside the To: address. Subtle — reads as secondary action. */
.edit-email-link {
    margin-left: 6px;
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
}
.edit-email-link:hover { text-decoration: underline; }

/* Cancel button on the email-edit form — paired with the primary Save email button. */
.compose-cancel {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}
.compose-cancel:hover { background: #f3f4f6; }

/* ── Detail panel ────────────────────────────────────────────── */

tr.detail-row > td {
    padding: 0;
    background: #f9fafb;
}
.detail-content {
    padding: 20px 24px;
    display: grid;
    align-items: start;
    /* 2026-05-12 (v3): two-column side-by-side at >=1280px viewport,
       stacked single-column below that. Forcing 2fr/3fr with a
       440px-min-items kept overflowing on narrow windows — the
       activity panel ended up overlapping the items column's qty
       cell. Stacking eliminates the overlap entirely and keeps each
       section at its natural full width when there isn't room for
       a 2-up layout. */
    grid-template-columns: 1fr;
    gap: 16px;
}
@media (min-width: 1280px) {
    .detail-content {
        grid-template-columns: minmax(440px, 2fr) 3fr;   /* items left, activity right */
    }
}
.detail-content h3,
.so-detail-grid h3 {
    margin: 0 0 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: .5px;
}
.detail-section {
    background: var(--surface);
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    /* min-width: 0 lets the grid track shrink below the content's intrinsic
       size — without it, an unbreakable long string in a message body
       (data URI, long URL, base64 image dropped through HTML strip)
       forces the track wider than its fr allotment and pushes the whole
       grid beyond the viewport. PO67836 trigger 2026-04-29. */
    min-width: 0;
    overflow: hidden;
}
.detail-section.full { grid-column: 1 / -1; }

/* When a PO row expands, smooth-scroll it to the top with a small visual
   gap so it doesn't sit flush against the viewport edge. Used by the
   onRowClick handler's tr.scrollIntoView({ block: 'start' }). */
tr.po-row.expanded {
    scroll-margin-top: 16px;
}

.po-meta {
    grid-column: 1 / -1;
    background: var(--surface);
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

/* PO timeline — full-width strip showing key date events */
.po-timeline {
    grid-column: 1 / -1;
    background: var(--surface);
    padding: 14px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.po-timeline h3 {
    margin: 0 0 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: .5px;
}
.po-timeline-events {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.po-timeline-event {
    display: grid;
    grid-template-columns: 14px 1fr auto;
    gap: 10px;
    align-items: baseline;
    padding: 4px 0;
    font-size: 13px;
}
.po-timeline-event .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text);
    margin-top: 6px;
    justify-self: center;
}
.po-timeline-event .label {
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.po-timeline-event .label .extra {
    color: var(--text-mute);
    font-size: 12px;
    margin-left: 6px;
}
.po-timeline-event .label .detail {
    color: var(--text-mute);
    font-size: 12px;
    font-style: italic;
}
.po-timeline-event .when {
    color: var(--text-mute);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
/* Future events — dimmed */
.po-timeline-event.future .dot {
    background: white;
    border: 2px solid var(--border);
    width: 6px;
    height: 6px;
}
.po-timeline-event.future .label,
.po-timeline-event.future .when { color: var(--text-mute); }
/* Overdue — red dot */
.po-timeline-event.overdue .dot { background: var(--danger); }
.po-timeline-event.overdue .when { color: var(--danger); font-weight: 500; }
/* Chase events — orange dot */
.po-timeline-event.chase .dot { background: var(--warn); }
.po-meta .field { font-size: 13px; }
.po-meta .field .label { color: var(--text-mute); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.po-meta .field .value { font-weight: 500; margin-top: 2px; }
.po-meta .ns-link { font-size: 12px; }

/* Attachment links inside chat bubbles — clickable, opens in new tab */
.msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.msg-att-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: white;
    font-size: 12px;
    color: var(--text);
    text-decoration: none;
    max-width: 240px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.msg-att-link:hover { background: #f3f4f6; }
.msg-att-icon { font-size: 13px; }

/* Pulsing "checking..." pill — shown while attachments-list.php is in flight */
.msg-att-loading {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    background: white;
    font-size: 11px;
    color: var(--text-mute);
    font-style: italic;
}
.msg-att-loading .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-mute);
    animation: msg-att-pulse 1.2s ease-in-out infinite;
}
@keyframes msg-att-pulse {
    0%, 100% { opacity: 0.3; }
    50%      { opacity: 1;   }
}
/* When the slot has nothing in it (no attachments + not loading) collapse it */
.msg-attachments:empty { display: none; }

/* System messages in the chat (e.g. "Handed to Ken") — centered, distinct from bubbles */
.msg-system {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 0;
    padding: 4px 0;
    font-size: 12px;
    color: var(--text-mute);
}
.msg-system::before,
.msg-system::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}
.msg-system-body {
    background: #fef3c7;
    border: 1px solid #fde68a;
    color: #92400e;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 500;
}
.msg-system-time { color: var(--text-mute); font-variant-numeric: tabular-nums; }

/* Compose pinned to bottom of the activity section — chat-style input */
.detail-section.activity { display: flex; flex-direction: column; }
.detail-section.activity .timeline { flex: 1; }
.compose {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.compose-tabs {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}
.compose-tab {
    background: transparent;
    border: none;
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-mute);
    cursor: pointer;
    transition: background-color .15s, color .15s;
}
.compose-tab:hover:not(.active):not(:disabled) {
    background: #f3f4f6;
    color: var(--text);
}
.compose-tab.active {
    color: white;
    background: #2563eb;
}
.compose-tab:disabled { color: var(--border); cursor: not-allowed; }
.compose-body.hidden { display: none; }
.compose-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    box-sizing: border-box;
}
.compose-input:focus { outline: none; border-color: var(--text); }
.compose-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
}
.compose-meta {
    flex: 1;
    font-size: 11px;
    color: var(--text-mute);
}
.compose-meta strong { color: var(--text); font-weight: 500; }
.compose-status {
    font-size: 12px;
    color: var(--text-mute);
}
.compose-status.success { color: var(--ok); }
.compose-status.error   { color: var(--danger); }
.compose-send {
    background: var(--text);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
}
.compose-send:hover  { opacity: .9; }
.compose-send:disabled { opacity: .5; cursor: not-allowed; }
.compose-send.danger { background: var(--danger); }
.compose-send.compose-send-secondary {
    background: transparent;
    color: var(--text-mute);
    border: 1px solid var(--border);
}
.compose-send.compose-send-secondary:hover { color: var(--text); border-color: var(--text-mute); opacity: 1; }

/* Pinned note (sticky-note) — surfaced as the LOWER HALF of the same
   visual row as the PO. The pinned-note-row TD is transparent so the
   PO row's tint flows down into it as one continuous block; the yellow
   lives only on the inset chip. Left-edge red/alert rail extends down
   into the pinned-note-row via state-class mirroring in JS. */
.pinned-note-row > td {
    padding: 0 14px 6px;
    background: transparent;
    border-top: 0;
    border-bottom: 1px solid var(--border);
}
/* Kill the bottom border of the PO row when a pinned-note-row sits
   under it — and also kill the PO row's bottom padding so the red
   rail on the first cell runs unbroken into the pinned-note-row's
   first cell. Without this, the PO row's padding-bottom area shows
   the bar but the cell ends in the visual gap. */
.table tr.po-row:has(+ .pinned-note-row) > td { border-bottom: 0; padding-bottom: 4px; }

.pinned-note-row .pinned-note {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}
.pinned-note-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fff9c4;
    border: 1px solid #f59f00;
    border-radius: 4px;
    padding: 3px 10px;
    font: inherit;
    color: inherit;
    cursor: pointer;
    text-align: left;
    max-width: 70%;
    overflow: hidden;
}
.pinned-note-chip:hover { background: #fff3a3; }
.pinned-note-chip .pinned-note-text {
    font-weight: 500;
    white-space: normal;
    overflow-wrap: anywhere;
}
.pinned-note-chip-clear {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-mute);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    line-height: 1;
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}
.pinned-note-chip-clear:hover { color: var(--danger); border-color: var(--danger); }
.pinned-note-meta { color: var(--text-mute); font-size: 12px; }

/* Match the PO row's background tint so the chip sits on the same
   coloured field instead of breaking it. */
.table tr.pinned-note-row.unread > td { background: #fff7ed; }
.table tr.pinned-note-row.unread:hover > td { background: #fff1e1; }
.table tr.pinned-note-row.alert > td,
.table tr.pinned-note-row.unread.alert > td { background: #fee2e2; }
.table tr.pinned-note-row.alert:hover > td,
.table tr.pinned-note-row.unread.alert:hover > td { background: #fecaca; }

/* Left-edge bar — same widths/colours as .po-row state, applied to the
   pinned-note-row's only TD so the bar continues straight down. */
.table tr.pinned-note-row.unread > td { border-left: 3px solid #ef4444; padding-left: 13px; }
.table tr.pinned-note-row.alert > td,
.table tr.pinned-note-row.unread.alert > td { border-left: 4px solid #dc2626; padding-left: 12px; }
.pinned-note {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 13px;
    color: #5b4500;
    line-height: 1.4;
}
.pinned-note-icon { font-size: 14px; flex-shrink: 0; }
.pinned-note-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}
.pinned-note-meta {
    color: #856404;
    font-size: 12px;
    font-weight: 400;
    white-space: nowrap;
    flex-shrink: 0;
}
/* Inline pinned-note strip inside the expanded detail panel. Spans both
   grid columns so it sits as its own row between the supplier meta header
   and the Items / Activity two-column layout — Alex's preferred spot
   (2026-05-13). Edit/Clear actions on the right; click Edit → prompt(). */
.pinned-note-inline {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: #fff9c4;
    border: 1px solid #f59f00;
    border-radius: 6px;
    font-size: 13px;
    color: #5b4500;
}
.pinned-note-inline .pinned-note-text {
    flex: 1;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pinned-note-inline.pinned-note-inline-empty {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-mute);
}
.pinned-note-meta-empty {
    flex: 1;
    font-size: 12px;
    color: var(--text-mute);
}
.pinned-note-actions {
    display: inline-flex;
    gap: 6px;
    flex-shrink: 0;
}
.pinned-note-btn {
    border: 1px solid #f59f00;
    background: #fffdf3;
    color: #5b4500;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}
.pinned-note-btn:hover { background: #fff3a3; }
.pinned-note-btn-danger { color: var(--danger); border-color: var(--danger); }
.pinned-note-btn-danger:hover { background: #fee2e2; }
.pinned-note-btn-primary {
    background: var(--accent, #2563eb);
    border-color: var(--accent, #2563eb);
    color: white;
}
.pinned-note-btn-primary:hover { opacity: .9; background: var(--accent, #2563eb); }

/* Attachment picker on the supplier-reply compose box (2026-05-13).
   Hidden native file input wrapped by a clickable label, plus a flex-row
   of attachment chips that the user can remove individually with ×. */
.compose-attachments {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}
.attachment-chips {
    display: contents;          /* chips flow as siblings of .attachment-add */
}
.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px 4px 8px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #f3f4f6;
    font-size: 12px;
    color: var(--text);
    max-width: 280px;
}
.attachment-chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}
.attachment-chip-size {
    color: var(--text-mute);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}
.attachment-chip-remove {
    border: 0;
    background: transparent;
    color: var(--text-mute);
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    font-size: 16px;
}
.attachment-chip-remove:hover { color: var(--danger); }
.attachment-add {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px dashed var(--border);
    border-radius: 14px;
    color: var(--text-mute);
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}
.attachment-add:hover { color: var(--text); border-color: var(--text-mute); }
.attachment-add[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.attachment-input { display: none; }   /* native input hidden, label clicks fire it */

/* Item rows in detail panel */
.item-line {
    display: grid;
    /* 2026-05-12 (v4): pinned qty column to 90px fixed instead of `auto`.
       `auto` was getting compressed below content size when the parent
       grid had min-width:0, producing the "1.0" / "0.0" truncation. A
       fixed 90px guarantees enough room for "1.00 left" / "0.00/1.00"
       at any viewport width. */
    grid-template-columns: 1fr 90px;
    gap: 8px;
    /* 2026-05-12: bumped vertical padding 12→18 and divider darkened
       #d1d5db→#9ca3af + thickened 1px→2px. With customer-allocation
       accordions hanging under each item, the previous separator was
       getting visually buried — items + their accordions were bleeding
       into the next item. The thicker mid-grey line + extra breathing
       room makes each item read as its own block at a glance. */
    padding: 18px 0;
    border-bottom: 2px solid #9ca3af;
    font-size: 13px;
}
.item-line:last-child { border-bottom: 0; }
/* 2026-05-12 (v4): truncate SKU + description with ellipsis when they
   exceed the column width, so every item row is the same height. The
   full string is still available via the title tooltip on .desc.
   min-width: 0 on .item-main is required for the ellipsis to engage
   inside a grid track — without it the cell would expand to fit content
   and push the qty column off-screen. */
.item-line .item-main { min-width: 0; }
.item-line .sku,
.item-line .desc {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.item-line .sku { font-weight: 500; }
.item-line .desc { color: var(--text-mute); font-size: 12px; margin-top: 2px; }
/* Cancel-from-PO card + customer-allocations accordion span both grid
   columns so they read as their own row underneath the SKU/qty pair
   (matching how a customer alloc-row sits in the page rhythm). Without
   this they were nested inside the left .item-main column and ended up
   visually narrower than the alloc-row card on items with allocations. */
.item-line .item-cancel-wrap,
.item-line .alloc-accordion {
    grid-column: 1 / -1;
}

/* 2026-08-06 (Alex): make each PO-manager item read as one self-contained
   card, with its customer allocation(s) nested as an indented, accented
   sub-panel underneath — the old flat divider layout made it hard to tell
   which customer line belonged to which SKU. Scoped to .detail-content so
   the SO manager (which shares .item-line) is untouched. */
.detail-content .item-line {
    padding: 14px 16px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-bottom: 1px solid var(--border);   /* override base 2px grey divider */
    border-radius: 10px;
    background: #f6f8fc;   /* light tint so each item box stands out from the page */
}
.detail-content .item-line:last-child { margin-bottom: 0; }
.detail-content .item-line.item-received {
    background: transparent;
    border-style: dashed;
}
.detail-content .item-line .alloc-accordion {
    margin-top: 12px;
    margin-left: 6px;
    padding: 6px 12px 8px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-left: 3px solid #818cf8;   /* indigo accent ties allocs to their item */
    border-radius: 8px;
}
.detail-content .item-line .alloc-accordion > .alloc-summary {
    font-weight: 600;
    color: var(--text);
    padding: 2px 0 6px;
}
.detail-content .item-line .alloc-list { gap: 6px; }
.item-line .qty {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--text-mute);
    font-size: 12px;
    /* 2026-05-12: prevent the "1.00 left / 0.00/1.00" pair from
       wrapping into the activity column at narrower widths.
       min-width guarantees the column never gets squeezed below
       what "0.00/00.00" needs even when the SKU/desc on the left
       is very long. */
    white-space: nowrap;
    min-width: 80px;
}
.item-line .status-line { margin-top: 4px; }
.item-line .item-comment { color: var(--text-mute); font-size: 11px; margin-top: 2px; }

/* Per-item release controls (Items Needs Attention tab only). 2026-05-07. */
.item-release { margin-top: 6px; font-size: 12px; }
.item-release-blocked {
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
}
.item-release-info {
    color: #6b7280;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
}
.item-release-btn {
    background: #7c3aed;
    color: #fff;
    border: 0;
    padding: 5px 12px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 12px;
    cursor: pointer;
    margin-top: 6px;
}
.item-release-btn:hover:not(:disabled) { background: #6d28d9; }
.item-release-btn:disabled { opacity: 0.5; cursor: not-allowed; background: #9ca3af; }

/* Items list section subheaders — splits Unreceipted vs Received groups
   so the post-receipt report-problem flow has a clear home. Big and
   colour-coded because warehouse + agents glance at the panel and need to
   tell the two groups apart at a flick of the eyes. */
.item-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 20px 0 10px;
    padding: 10px 14px;
    background: #fef2f2;
    border-left: 4px solid #dc2626;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 700;
    color: #991b1b;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.item-section-header:first-child { margin-top: 0; }
.item-section-header .meta {
    background: #dc2626;
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 999px;
    letter-spacing: 0.3px;
    line-height: 1.4;
}
.item-section-header-received {
    background: #f0fdf4;
    border-left-color: #16a34a;
    color: #166534;
}
.item-section-header-received .meta { background: #16a34a; }

/* Collapsible Received section — defaults closed (no open attr in markup),
   click the summary to expand. Hides the native triangle marker so we can
   use our own chevron that rotates 90deg when open. */
details.item-section-collapsible {
    margin: 0;
}
details.item-section-collapsible > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
}
details.item-section-collapsible > summary::-webkit-details-marker {
    display: none;
}
details.item-section-collapsible > summary::after {
    content: '\25B6';   /* ▶ right-pointing triangle */
    margin-left: auto;
    font-size: 11px;
    transition: transform 0.15s ease;
    color: #16a34a;
}
details.item-section-collapsible[open] > summary::after {
    transform: rotate(90deg);
}

/* Received items have a slightly de-emphasised body — they're for
   reference / problem-reporting, not active chase work. */
.item-line.item-received .sku { font-weight: 500; color: var(--text); }
.item-line.item-received .desc { opacity: 0.9; }

/* Report-problem inline form */
.report-issue-btn {
    margin-top: 6px;
    padding: 4px 10px;
    border: 1px solid #fca5a5;
    background: #fff;
    color: #b91c1c;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
}
.report-issue-btn:hover { background: #fef2f2; }
.report-issue-form { margin-top: 8px; }
.report-issue-form.hidden { display: none; }
.report-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
}
.report-form .report-reason {
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
}
.report-form .report-comment { font-size: 13px; }
.report-photo-row { display: flex; flex-direction: column; gap: 6px; }
.report-photo-row.hidden { display: none; }
.report-photo-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.report-photo-preview {
    max-width: 240px;
    max-height: 240px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    object-fit: contain;
}
.report-photo-preview.hidden { display: none; }
.report-actions { display: flex; gap: 8px; align-items: center; }

/* QR-for-phone — opens a modal with a QR code pointing at the PO Receipt
   mobile page for this PO. Mirrors the PO Receipt dashboard's QR styling
   so the two pages share visual language. */
.qr-btn {
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}
.qr-btn:hover { background-color: #f9fafb; }
.qr-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.qr-overlay.visible { display: flex; }
.qr-modal {
    background: #fff;
    border-radius: 12px;
    padding: 32px;
    text-align: center;
    max-width: 360px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.qr-modal h3 { font-size: 16px; font-weight: 600; margin: 0 0 4px; }
.qr-modal p  { font-size: 12px; color: #6b7280; margin: 0 0 16px; }
.qr-modal canvas { margin: 0 auto 16px; display: block; }
.qr-modal .qr-url {
    font-size: 11px;
    color: #9ca3af;
    word-break: break-all;
    margin-bottom: 16px;
}
.qr-close-btn {
    background: #1a1a1a;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 24px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}
.qr-close-btn:hover { background: #333; }

/* Activity timeline — merged Gmail thread + internal notes, chat-style */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 340px;      /* compact window (was 85vh) so the reply box sits close, not a screen away */
    overflow-y: auto;
    padding-right: 4px;
}
.msg {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: white;
    font-size: 13px;
}
.msg-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
    align-items: baseline;
}
.msg-sender {
    font-weight: 600;
    color: var(--text);
}
.msg-org {
    color: var(--text-mute);
    font-size: 12px;
    margin-left: 4px;
    font-weight: 400;
}
.msg-time {
    color: var(--text-mute);
    font-size: 11px;
    white-space: nowrap;
}
.msg-recipients {
    color: var(--text-mute);
    font-size: 11px;
    margin-bottom: 4px;
    line-height: 1.5;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.msg-rec-label {
    font-weight: 600;
    margin-right: 4px;
    color: var(--text-mute);
}
.msg-subject {
    color: var(--text-mute);
    font-size: 11px;
    margin-bottom: 6px;
}
.msg-body {
    color: var(--text);
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    /* overflow-wrap: anywhere is the strict modern equivalent of word-wrap:
       break-word — breaks even arbitrary character runs (data URIs,
       base64-encoded content, long URLs) so a rogue string in a supplier
       email can't push the column wider than its allotted width. */
    overflow-wrap: anywhere;
    word-break: break-word;
    /* Belt-and-braces: if anything still tries to overflow horizontally,
       clip it inside the bubble rather than letting it leak into the
       table layout. */
    overflow: hidden;
    /* HTML tables in supplier emails are flattened to tab-separated text by
       po.php's htmlToText. tab-size 4 gives readable column gaps without the
       16+ char default. */
    tab-size: 4;
    -moz-tab-size: 4;
}
.msg-tag {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: 6px;
    vertical-align: 1px;
}

/* Sender-type styling — each sender gets a clear coloured left accent bar plus
   a tinted card, so Supplier (green) / Rolan-us (blue) / Customer (purple) read
   apart at a glance. Shared across every PO Manager tab. (Alex 2026-09-13) */
.msg.supplier {
    background: #ecfdf5;              /* green tint */
    border-color: #a7f3d0;
    border-left: 4px solid #10b981;  /* green accent */
}
.msg.supplier .msg-tag {
    background: #a7f3d0;
    color: #065f46;
}
.msg.rolan {
    background: #eff6ff;              /* blue tint */
    border-color: #bfdbfe;
    border-left: 4px solid #3b82f6;  /* blue accent */
}
.msg.rolan .msg-tag {
    background: #bfdbfe;
    color: #1e3a8a;
}
.msg.bot {
    background: #fffbeb;              /* amber tint */
    border-color: #fde68a;
    border-left: 4px solid #f59e0b;  /* amber accent */
}
.msg.bot .msg-tag {
    background: #fde68a;
    color: #78350f;
}
.msg.note {
    background: #fafafa;              /* grey */
    border-color: #e5e7eb;
    border-left: 4px solid #9ca3af;  /* grey accent */
}
.msg.note .msg-tag {
    background: #1a1d21;
    color: white;
}
/* Customer message — purple card + accent, clearly distinct from Rolan blue. */
.msg.customer {
    background: #faf5ff;              /* purple tint */
    border-color: #e9d5ff;
    border-left: 4px solid #a855f7;  /* purple accent */
}
.msg.customer .msg-tag {
    background: #e9d5ff;
    color: #6b21a8;
}

.timeline-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-mute);
    font-size: 13px;
}
.timeline-truncated {
    text-align: center;
    color: var(--text-mute);
    font-size: 11px;
    padding: 4px 0;
    font-style: italic;
}

/* Loading spinner inside detail panel */
.detail-loading {
    padding: 40px;
    text-align: center;
    color: var(--text-mute);
    grid-column: 1 / -1;
}

/* ── Empty / loading ─────────────────────────────────────────── */

.empty {
    padding: 40px;
    text-align: center;
    color: var(--text-mute);
}
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ──────────────────────────────────────────────────────────────────
   Customer allocations accordion (per-item) — added 2026-05-07
   ─────────────────────────────────────────────────────────────────
   Each line item on a PO can be allocated to multiple sales orders.
   The accordion lives inside .item-line and lets Clint/Ken drill into
   each customer's order to message them about ETA / cancel / refund.
   Channel-aware: Magento → Gmail send; eBay/Amazon → marketplace MCP.
*/
/* Customer Orders — full-width section under the items + activity grid.
   Each PO line item with allocations gets a sub-group, headed by SKU +
   description + count, then the alloc-rows below at full panel width.
   Click any row to open that customer's tab in the Activity panel. */
.alloc-section {
    margin-top: 4px;
}
.alloc-groups {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.alloc-group {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
}
.alloc-group-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 8px 12px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    flex-wrap: wrap;
}
.alloc-group-sku {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 600;
    color: var(--text);
}
.alloc-group-count {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-mute);
    white-space: nowrap;
}

/* Old per-item accordion styles — left here in case any caller still
   renders one, but the helper that emitted them now no-ops. */
.alloc-accordion {
    margin-top: 8px;
    border-top: 1px dashed var(--border);
    padding-top: 8px;
}
.alloc-accordion > .alloc-summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-mute);
    list-style: none;
    user-select: none;
    padding: 4px 0;
}
.alloc-accordion > .alloc-summary::-webkit-details-marker { display: none; }
.alloc-accordion > .alloc-summary::marker { content: ''; }
.alloc-accordion .alloc-summary-label strong { color: var(--text); }

/* Inside the full-width Customer Orders section: rows render as flat
   list items (no card-in-card double border). Inside legacy per-item
   accordions (kept for compatibility) the cardstyle below still applies. */
.alloc-list {
    display: flex;
    flex-direction: column;
}
.alloc-group .alloc-list {
    /* Flat list — no internal borders between rows; group's outer border
       provides the container. Horizontal divider between rows. */
}
.alloc-group .alloc-row {
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: var(--surface);
}
.alloc-group .alloc-row:last-child {
    border-bottom: none;
}
.alloc-row {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fafbfc;
    overflow: hidden;
}
.alloc-row-summary {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 10px 14px;
    font-size: 14px;
}
.alloc-row-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.alloc-so {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;   /* never wrap the order number onto two lines */
    flex-shrink: 0;        /* keep it whole; the customer name truncates instead */
}
/* 2026-08-07 (Alex): per-allocation action row — quick NetSuite deep links +
   a "message customer" affordance under each customer allocation. */
.alloc-row-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 0 14px 10px;
}
.alloc-action-btn,
.alloc-action-link {
    font-size: 12px;
    line-height: 1.5;
    padding: 3px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}
.alloc-action-btn.alloc-msg {
    border-color: #c7d2fe;
    background: #eef2ff;
    color: #3730a3;
    font-weight: 500;
}
.alloc-action-btn:hover,
.alloc-action-link:hover { background: #f3f4f6; }
.alloc-action-btn.alloc-msg:hover { background: #e0e7ff; }

/* 2026-08-07 (Alex): removed the white .po-meta detail card (its info dupes the
   list row). PO number in the list is now the NetSuite deep-link; Show QR lives
   in a slim borderless bar. */
.po-num-link {
    color: #2563eb;
    text-decoration: none;
    font-weight: 600;
}
.po-num-link:hover { text-decoration: underline; }
.po-actions-bar {
    grid-column: 1 / -1;
    margin: 0 0 12px;
    padding: 0;
    display: flex;
    gap: 10px;
    align-items: center;
}
/* Manual "Mark as processed" button (po-actions-bar) — 2026-08-19 (Alex). */
.mark-processed-btn {
    padding: 6px 14px;
    background: #16a34a;
    color: #fff;
    border: 0;
    border-radius: 6px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}
.mark-processed-btn:hover:not(:disabled) { background: #15803d; }
.mark-processed-btn:disabled { opacity: .6; cursor: not-allowed; }
/* "no ref" placeholder when customer_order_number hasn't synced yet — muted
   italic so it's clear there's no order reference rather than implying an
   actual ID. */
.alloc-so-pending,
.so-detail-meta-pending {
    font-family: inherit;
    font-style: italic;
    font-weight: 500;
    color: var(--text-mute);
}
.alloc-customer {
    color: var(--text);
    font-weight: 500;
    white-space: normal;
    overflow-wrap: anywhere;
}
.alloc-row-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text-mute);
    flex-shrink: 0;
}
.alloc-row-meta .alloc-qty,
.alloc-row-meta .alloc-total { white-space: nowrap; }
.alloc-row-meta .alloc-total { font-weight: 500; color: var(--text); }
.alloc-status {
    text-transform: capitalize;
    font-size: 11px;
    padding: 1px 8px;
    border-radius: 999px;
    background: #e5e7eb;
    color: var(--text-mute);
}
.alloc-status.status-closed         { background: #e0f2fe; color: #075985; }
.alloc-status.status-pendingfulfillment,
.alloc-status.status-pending-fulfillment { background: #fef3c7; color: #92400e; }
/* "→" arrow hint that clicking opens the SO in the Activity panel. */
.alloc-open {
    color: var(--text-mute);
    font-size: 13px;
    width: 14px;
    text-align: center;
    transition: transform .15s, color .15s;
}
.alloc-row-summary:hover .alloc-open {
    color: var(--primary);
    transform: translateX(2px);
}

/* Item-level cancel button — sits inside the item card, above the
   allocations accordion. For orphan PO qty (no customer waiting).
   Red at rest so the destructive action is unmistakable. */
.item-cancel-btn {
    background: var(--danger);
    border: 1px solid var(--danger);
    color: white;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, opacity .15s;
}
/* 2026-05-12 (v2): box the item-level Cancel-from-PO control so it
   matches the alloc-row card shape. Orphan qty (no customer alloc)
   reads as its own block — explanatory label on the left, red Cancel
   button on the right — same rhythm as "Allocated to N customer · K
   units · × Cancel from PO and SO". Visual consistency makes "Cancel
   from PO" + "Cancel from PO and SO" land in the same vertical column
   regardless of whether an item has allocations.

   2026-05-12 (v5): swapped neutral grey → soft amber for the no-SO
   state. The amber palette flags "orphan qty, decision needed" without
   reading as an error — keeps it distinct from the calm grey of
   customer-allocated alloc-rows so the eye picks out which lines are
   awaiting a Cancel/Reorder decision at a glance. */
.item-cancel-wrap {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 8px;
}
.item-cancel-wrap .item-cancel-label {
    flex: 1;
    min-width: 0;
}
.item-cancel-wrap .item-cancel-label strong {
    color: #78350f;                   /* match label color so the qty number stays in the amber palette */
    font-weight: 700;
}
.item-cancel-btn:hover:not(:disabled) {
    background: #b91c1c;
    border-color: #b91c1c;
}
.item-cancel-btn:disabled {
    opacity: .55;
    cursor: not-allowed;
}
.item-line.item-line-cancel-fired {
    opacity: .65;
}

/* Cancel-allocation button — small red pill on the right edge of each
   alloc-row. Red at rest so the destructive action is unmistakable. */
.alloc-cancel-btn {
    background: var(--danger);
    border: 1px solid var(--danger);
    color: white;
    border-radius: 6px;
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, opacity .15s;
    margin-left: 8px;
    white-space: nowrap;
}
.alloc-cancel-btn:hover:not(:disabled) {
    background: #b91c1c;
    border-color: #b91c1c;
}
.alloc-cancel-btn:disabled {
    opacity: .55;
    cursor: not-allowed;
}

/* Cancelled state — show on the row itself so user can see at a glance
   which allocations have been actioned. Strike-through + muted color. */
.alloc-row.alloc-row-cancelled {
    opacity: .55;
}
.alloc-row.alloc-row-cancelled .alloc-so,
.alloc-row.alloc-row-cancelled .alloc-customer,
.alloc-row.alloc-row-cancelled .alloc-qty {
    text-decoration: line-through;
    color: var(--text-mute);
}

/* ──────────────────────────────────────────────────────────────────
   Activity tab strip — segmented-control pill, refreshed 2026-05-07
   ─────────────────────────────────────────────────────────────────
   The Activity panel hosts Supplier (always present) plus a tab per
   opened SO. Tabs sit inside a soft gray rail; the active one rises
   above with a white card + subtle shadow. SO tabs have × to close
   (Supplier permanent). Strip is horizontally scrollable when many
   tabs are open.
*/
.activity-tabs {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 14px;
    padding: 4px;
    border-radius: 10px;
    background: #eef0f3;
    min-height: 36px;   /* fit the tallest (active) tab; overflow-x:auto below
                           was collapsing this flex row and clipping the tabs,
                           worst on short 1-supplier bars (Alex, 2026-09-19) */
    overflow-x: auto;
    scrollbar-width: thin;
    max-width: 100%;
}
.activity-tab {
    background: transparent;
    border: none;
    border-radius: 7px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-mute);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    transition: background-color .15s, color .15s, box-shadow .15s, transform .15s;
}
.activity-tab:hover:not(.active) {
    color: var(--text);
    background: rgba(255,255,255,.5);
}
.activity-tab.active {
    color: #1d4ed8;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,.08), inset 0 0 0 1.5px #2563eb;   /* blue ring = clearly the tab you're on */
    font-weight: 700;
}
.activity-tab-label {
    line-height: 1.2;
}
/* Channel-coloured dot leading each SO tab — quick visual marker for
   whether the customer comes from website / eBay / Amazon. */
.activity-tab-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-mute);
    flex-shrink: 0;
}
.activity-tab-dot.channel-website { background: #2563eb; }
.activity-tab-dot.channel-ebay    { background: #dc2626; }
.activity-tab-dot.channel-amazon  { background: #d97706; }
.activity-tab-dot.channel-other   { background: #6b7280; }
/* Type dots: every tab carries one so supplier vs customer always reads —
   green = supplier, purple = customer (matches the message-bubble colours). */
.activity-tab-dot.dot-supplier { background: #059669; }
.activity-tab-dot.dot-customer { background: #7c3aed; }
/* Divider between the supplier group and the customer group. Hidden when it's
   the last child (i.e. no customer tabs have been opened after it). */
.activity-tab-sep {
    width: 1px;
    align-self: stretch;
    min-height: 20px;
    background: #d1d5db;
    margin: 0 4px;
    flex: 0 0 auto;
}
.activity-tab-sep:last-child { display: none; }
.activity-tab-close {
    color: var(--text-mute);
    font-size: 16px;
    line-height: 1;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color .15s, color .15s;
    margin-left: -4px; /* tighten gap to label */
}
.activity-tab-close:hover {
    background: var(--danger);
    color: white;
}
.activity-tab.active .activity-tab-close {
    color: var(--text-mute);
}
.activity-panes { position: relative; }
.activity-pane.hidden { display: none; }
.activity-pane[data-pane^="so:"] {
    padding-top: 4px;
}

/* "3 × " qty prefix on the SKU line — at-a-glance count of how many units
   are still owing on this item. Subtle but visible (mute color, slight
   weight) so it doesn't dominate the SKU itself. */
.sku-qty {
    color: var(--text-mute);
    font-weight: 600;
    margin-right: 2px;
}

/* Rolan Part ID shown next to the SKU on each item line. Subtle muted
   monospace so it reads as a secondary identifier rather than competing
   with the supplier SKU. */
.sku-rpi {
    color: var(--text-mute);
    font-weight: 400;
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    margin-left: 4px;
}

/* Channel chips — colour-coded by marketplace. */
.channel-chip {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 1px 7px;
    border-radius: 999px;
    background: #e5e7eb;
    color: var(--text-mute);
    line-height: 1.5;
}
.channel-chip.channel-website { background: #dbeafe; color: #1e3a8a; }
.channel-chip.channel-ebay    { background: #fee2e2; color: #b91c1c; }
.channel-chip.channel-amazon  { background: #fef3c7; color: #92400e; }

/* Customer detail card (inside an expanded alloc-row). */
.so-detail-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.so-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}
.so-detail-customer {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
}
.so-detail-meta {
    font-size: 12px;
    color: var(--text-mute);
    margin-top: 2px;
}
.so-detail-ns {
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}
.so-detail-email {
    margin-top: 2px;
    font-size: 12px;
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.so-detail-email-missing {
    color: var(--danger);
    font-family: inherit;
    font-style: italic;
}

/* Allocation method tag — only renders for non-default methods (oos /
   delivery_issue / manual). Lets ops see at a glance why a particular SO
   was allocated this way. */
.alloc-method {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 1px 6px;
    border-radius: 999px;
    background: #e5e7eb;
    color: var(--text-mute);
    line-height: 1.5;
}
.alloc-method.method-oos             { background: #fee2e2; color: #b91c1c; }
.alloc-method.method-delivery_issue  { background: #fef3c7; color: #92400e; }
.alloc-method.method-manual          { background: #ede9fe; color: #5b21b6; }

/* Customer activity uses the SAME .timeline as the Supplier thread — this is
   only a transparent wrapper (no box / scroll of its own), so the inner
   .timeline (340px, scrolls, .msg cards) renders identically to the supplier
   side. */
.so-mini-thread { display: block; }
.so-thread-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-mute);
    font-size: 13px;
}

/* Customer message bubbles — outbound (we sent) and internal note variants.
   Inbound bubbles will land here once we add gmail-thread reading; they'll
   pick up .so-bubble-in (left-aligned, light gray) — placeholder for now. */
.so-bubble {
    max-width: 92%;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.so-bubble-meta {
    font-size: 11px;
    color: var(--text-mute);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.so-bubble-body { color: var(--text); }
.so-bubble-out {
    align-self: flex-end;
    background: #dbeafe;
    border: 1px solid #bfdbfe;
}
.so-bubble-out .so-bubble-meta { color: #1e3a8a; }
.so-bubble-note {
    align-self: stretch;
    background: #fef3c7;
    border: 1px dashed #fcd34d;
}
.so-bubble-note .so-bubble-meta { color: #92400e; }
.so-bubble-in {
    align-self: flex-start;
    background: white;
    border: 1px solid var(--border);
}

/* SO compose now uses the shared .compose / .compose-* classes (so the
   layout, textarea sizing, To: meta line, and Send button match the supplier
   compose exactly). The .so-compose modifier just adds the small tweaks below.
   Stub blocks for unsupported channels (eBay/Amazon) keep their own look. */
.so-compose .compose-tabs { margin-bottom: 10px; }
.so-compose-stub {
    border: 1px dashed var(--border);
    background: #fafbfc;
    border-radius: 6px;
    padding: 14px;
    font-size: 13px;
    color: var(--text-mute);
    line-height: 1.6;
}
.so-compose-stub strong { color: var(--text); }

/* ─────────────────────────────────────────────────────────────────────────
   SO Manager — Stage 3 polish (added 2026-06-04)
   ETD past-date highlight + inline detail placeholder row.
   ─────────────────────────────────────────────────────────────────────── */
.etd-late {
    color: #b91c1c;
    font-weight: 600;
}

/* Detail row appears beneath an expanded SO row when the user clicks the
   Open toggle. Two-column layout: items left, activity right (mirrors
   PO Manager's expand panel, customer-side). */
tr.so-detail-row > .so-detail-cell {
    background: #f9fafb;
    padding: 14px 18px;
    border-top: 1px solid #e5e7eb;
}
.so-detail-placeholder {
    color: var(--text-mute);
    font-size: 13px;
    line-height: 1.5;
}
.so-detail-placeholder strong { color: var(--text); }
.so-detail-loading { display: flex; justify-content: center; padding: 24px; }
.so-detail-error {
    color: #b91c1c; background: #fef2f2;
    padding: 12px; border-radius: 6px; font-size: 13px;
}

.so-detail-grid {
    display: grid;
    grid-template-columns: minmax(360px, 1fr) minmax(360px, 1fr);
    gap: 18px;
}

/* Items column reuses PO Manager's `.item-section-header`, `.item-line`,
   `.alloc-row`, `.item-cancel-wrap` classes verbatim — see lib/style.css
   around line 1236. No SO-specific overrides; the alloc-row palette is the
   same calm grey PO Manager uses for customer rows. Yellow palette is
   reserved for `.item-cancel-wrap` (orphan / unsourced warning).

   One layout fix: PO Manager wraps alloc-rows in `.alloc-accordion` which
   the .item-line grid spans full-width via `grid-column: 1 / -1`. SO
   Manager renders alloc-rows directly under .item-main + .qty without an
   accordion wrapper, so we explicitly span them full-width here. */
.so-items .item-line > .alloc-row {
    grid-column: 1 / -1;
}

/* Expanded SO row — small scroll gap so smooth scrollIntoView() doesn't
   land the row flush against the table header. Mirrors tr.po-row.expanded
   in PO Manager. */
tr.so-row.expanded {
    scroll-margin-top: 16px;
    background: #f9fafb;
}

/* `.item-cancel-wrap.in-stock` — green variant of the orphan-warning box,
   used by SO Manager when NS has already committed on-hand stock against
   the line. Same shape as the amber default, recoloured to the on-track
   palette (green-50 / green-500 / green-900). Alex 2026-06-04. */
.item-cancel-wrap.in-stock {
    border-color: #10b981;            /* green-500 */
    background: #ecfdf5;              /* green-50 */
    color: #065f46;                   /* green-900 */
}
.item-cancel-wrap.in-stock .item-cancel-label strong { color: #065f46; }

/* ── Activity column ── */
/* Outer container is `.detail-section` (PO Manager's white card). This rule
   only adds SO-Manager-specific layout — flex column + max height so the
   reply form pins to the bottom and the stream scrolls. */
.so-activity {
    display: flex; flex-direction: column;
    max-height: 580px;
}
.so-activity-error {
    background: #fef2f2; color: #b91c1c;
    padding: 8px 10px; border-radius: 4px;
    font-size: 12px; margin-bottom: 10px;
}
.so-activity-stream {
    flex: 1;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 10px;
    padding-right: 4px;
    margin-bottom: 12px;
}
.so-activity-empty {
    color: var(--text-mute);
    font-size: 12px;
    font-style: italic;
    padding: 12px 0;
}
.so-msg {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.45;
}
.so-msg-note { background: #fffbeb; border-color: #fde68a; }
.so-msg-email { background: #fff; }
.so-msg-head {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 4px;
    font-size: 12px;
}
.chip-internal {
    background: #fef3c7; color: #78350f;
    padding: 1px 6px; border-radius: 3px;
    font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
}
.so-msg-subject { font-size: 12px; margin-bottom: 4px; }
.so-msg-body { white-space: pre-wrap; word-wrap: break-word; }

/* ── Reply form ── */
.so-reply-form {
    border-top: 1px solid #e5e7eb;
    padding-top: 12px;
}
.so-reply-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.so-reply-tab {
    background: #f3f4f6; border: 0; border-radius: 4px;
    padding: 6px 12px; cursor: pointer;
    font-size: 12px; color: var(--text-mute);
}
.so-reply-tab.active {
    background: var(--text, #111827); color: #fff;
}
.so-reply-body {
    width: 100%; box-sizing: border-box;
    padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px;
    font-family: inherit; font-size: 13px;
    resize: vertical;
}
.so-reply-actions {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 8px;
}
.so-reply-hint { font-size: 12px; }
.so-reply-send {
    background: #2563eb; color: #fff; border: 0; border-radius: 4px;
    padding: 6px 14px; cursor: pointer;
    font-weight: 600; font-size: 13px;
}
.so-reply-send:hover { background: #1d4ed8; }
.so-reply-send:disabled {
    background: #9ca3af; cursor: not-allowed;
}

@media (max-width: 1100px) {
    .so-detail-grid { grid-template-columns: 1fr; }
}


/* ── Per-user unread (the blue dot) ─────────────────────────────────────────
   A supplier has answered and THIS person has not opened the PO since. Server-
   decided (api/pos.php), inbound-only, per viewer. Distinct from
   .po-row.unread above, which is the shared "supplier replied since we sent"
   state that tints the row: this table already uses colour for .alert (failed
   send), so the per-user signal is weight + a blue dot, never a background.
   Mirrors the Out of Stock Items tab so the two screens read the same. */
.table tr.po-row.mine-unread td { font-weight: 600; }
.table tr.po-row.mine-unread td .meta { font-weight: 400; }
.mine-unread-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #2563eb;
    margin-right: 7px;
    vertical-align: middle;
}
/* "Anne has read it" — shown only when somebody ELSE opened the PO after the
   reply and you have not. Unread and already-handled are different situations
   and the dot alone cannot tell them apart. */
.seen-by { font-weight: 400; font-size: 11px; color: #6b7280; margin-top: 2px; }

/* The blue "N new" pill beside a tab's total. ID selectors because
   /lib/style.css styles .count on the active tab (and the red/green tab
   variants) and would otherwise win against a bare class. Blue, matching the
   row dot, so the badge and the thing it counts are visibly one signal. Hidden
   entirely at zero via the [hidden] attribute (app.js toggles it). */
/* ── Tabs: KPI tiles (big number on top, label beneath) ─────────────────── */
.tabs {
    gap: 10px;
    align-items: stretch;
    border-bottom: none;
    flex-wrap: wrap;
    row-gap: 10px;
}
.tabs .tab {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 3px;
    white-space: nowrap;
    padding: 9px 16px;
    min-width: 116px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f7f8fa;
    margin-bottom: 0;
    color: var(--text);
    text-decoration: none;
}
.tabs .tab:hover { background: #f0f2f4; }
.tabs .tab.active {
    background: #fff;
    border-color: #1a1d21;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .08);
}
/* number row */
.tabs .tab-kpi {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 20px;
    font-weight: 800;
    line-height: 1.15;
    color: var(--text);
}
/* the id-count span is now a plain big number, not a pill */
.tabs .tab-kpi .count {
    background: none !important;
    color: inherit !important;
    padding: 0 !important;
    min-width: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    font-size: inherit !important;
    font-weight: inherit !important;
}
/* urgent = red number, happy-path = green number */
.tabs .tab.qred .tab-kpi { color: #e5342b; }   /* urgent queues: red number */
.tabs .tab[data-tab="awaiting_delivery"] .tab-kpi { color: #16a34a; }
/* blue "N new" pill riding the number */
.tabs .tab-kpi .po-unread-pill {
    font-size: 10px;
    font-weight: 800;
    color: #fff;
    background: #2563eb;
    border-radius: 8px;
    padding: 1px 6px;
    line-height: 1.5;
}
.tabs .tab-kpi .po-unread-pill[hidden] { display: none; }
/* label under the number */
.tabs .tab-lbl {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: .03em;
}
.tabs .tab.active .tab-lbl { color: var(--text); }

/* ── Detail panel: equal-height columns + comfortable Activity height ─────────
   The two detail columns (Items on the left, Activity/compose on the right)
   share one grid row. Previously `.detail-content` used align-items:start, so
   the shorter Activity card ended early with a grey gap and the compose area
   felt cramped. Stretch the columns to equal height, give each a min-height
   floor, and let the Activity panes flex-fill so the message thread takes the
   slack and the compose box pins to the bottom (less scrolling). Applies to
   EVERY PO Manager tab via the shared .detail-content. (Alex 2026-09-13) */
.detail-content { align-items: stretch; }

@media (min-width: 1280px) {
    /* Floor so short content isn't cramped, and a one-screen ceiling so a long
       thread / long item list scrolls INSIDE its own card instead of growing
       the whole page. Both columns share the cap so they stay matched. */
    .detail-content > .detail-section:not(.full) {
        min-height: 560px;
        max-height: 100vh;
    }
    /* Items column scrolls its own content past the cap. The Activity column
       keeps the base overflow:hidden and lets its inner thread
       (.so-mini-thread / .enq-thread, flex:1) do the scrolling so the compose
       stays pinned at the bottom. */
    .detail-content > .detail-section:not(.full):not(.activity) { overflow-y: auto; }
}

/* ── Step blocks (SKU hub: Step 1 / 2 / 3) ───────────────────────────────────
   One consistent, left-aligned heading style with a chevron toggle that rotates
   when open, and a prominent green tick badge when the step is done. The block
   auto-collapses only when done (the JS sets `open` only while not done); the
   chevron still lets the user open/close any of them by hand. (Alex 2026-09-13) */
.step-details { margin-top: 16px; }
.step-details > .step-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}
.step-details > .step-summary::-webkit-details-marker { display: none; }
.step-chev {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 6px;
    background: #e2e8f0; color: #334155;
    font-size: 13px; font-weight: 700; line-height: 1;
    transition: transform .15s ease, background .15s ease;
    flex: 0 0 auto;
}
.step-details > .step-summary:hover .step-chev { background: #cbd5e1; }
.step-details[open] > .step-summary .step-chev { transform: rotate(90deg); }
.step-title {
    font-size: 10.5px;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-mute);
    font-weight: 700;
}
.step-tick {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border-radius: 50%;
    background: #16a34a; color: #fff;
    font-size: 12px; font-weight: 700; line-height: 1;
    flex: 0 0 auto;
}
.step-tail { font-size: 12px; }
.step-body { margin-top: 10px; }

/* Activity column fills its card so compose sits at the bottom. */
.detail-section.activity > .activity-panes {
    flex: 1 1 auto; min-height: 0;
    display: flex; flex-direction: column;
}
.detail-section.activity > .activity-panes > .activity-pane:not(.hidden) {
    flex: 1 1 auto; min-height: 0;
    display: flex; flex-direction: column;
}
/* Customer (SO) pane: content sits at the TOP of the card (thread then compose),
   with any spare space at the bottom. The thread takes its natural height but can
   shrink + scroll internally when long (flex:0 1 auto + min-height:0). */
.activity-pane > .so-detail-card {
    flex: 1 1 auto; min-height: 0;
    display: flex; flex-direction: column;
}
.activity-pane > .so-detail-card > .so-mini-thread {
    flex: 0 1 auto; min-height: 0; overflow-y: auto;
    display: flex; flex-direction: column;
}
/* Supplier (enquiry) pane thread behaves the same way. */
.activity-pane > .enq-thread {
    flex: 0 1 auto; min-height: 0; overflow-y: auto;
    display: flex; flex-direction: column;
}
/* Let the thread use the FULL height of the tall activity card instead of the
   fixed 340px window the compact layout used. The scroll now lives on the
   .so-mini-thread / .enq-thread wrapper (or on .timeline directly for the PO
   detail), so the messages fill top-to-bottom. */
.detail-section.activity .timeline { max-height: none; }
.activity-pane .so-mini-thread > .timeline,
.activity-pane .enq-thread > .timeline {
    max-height: none;
    overflow: visible;      /* the wrapper scrolls, not the timeline */
    flex: 0 0 auto;
    /* Top-aligned: messages start at the top of the pane (no white gap above),
       compose sits directly under them, any spare space falls at the bottom. */
    margin-top: 0;
}
