/* OMS redesign — factory portal Customers page (the merchants this factory
 * produces for). Rendered by /js/oms-rdf-customers.js into #rdfc-root, which
 * it appends to #page-merchants and marks .rd (so oms-rd.css components apply).
 * Modelled on the admin Customers / Factories list and record
 * (oms-rd-admin.css .cul-* / .ful-* / .cws-* / .fws-*).
 *
 * Everything is id-scoped (#rdfc-root, #page-merchants) so it beats the page's
 * inline <style> and oms-mobile.css (which loads after this file) without
 * !important. No remote assets.
 */

/* The old header + card list stay in the DOM (loadFactoryMerchants still
   fills #merchants-body if this module is missing) but are hidden once the
   module has taken over the page. */
#page-merchants.rdfc-on > .page-header,
#page-merchants.rdfc-on > #merchants-body { display: none; }

#rdfc-root { display: flex; flex-direction: column; gap: 16px; font-size: 14px; color: var(--ink); }
#rdfc-root .rdfc-loading { padding: 40px; text-align: center; }
#rdfc-root .rdfc-err { padding: 20px 22px; color: var(--bad); font-weight: 600; }
#rdfc-root .ph { align-items: flex-end; }
#rdfc-root .ph h1 { color: var(--ink); }
#rdfc-root .ph p { margin-top: 4px; max-width: 720px; }
#rdfc-root .btn { cursor: pointer; }
#rdfc-root .btn:disabled, #rdfc-root .iconbtn:disabled { opacity: .4; cursor: default; }
#rdfc-root .iconbtn { cursor: pointer; }
#rdfc-root a { cursor: pointer; }
#rdfc-root .muted { color: var(--muted); }

/* ── Summary strip (admin .todo-sum) ── */
#rdfc-root .rdfc-sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
#rdfc-root .rdfc-sum-k {
    appearance: none; font: inherit; color: var(--ink); text-align: left; cursor: pointer;
    display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--surface);
}
#rdfc-root .rdfc-sum-k:hover { border-color: var(--line-2); box-shadow: 0 1px 2px rgba(20,24,60,.06); }
#rdfc-root .rdfc-sum-k:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#rdfc-root .rdfc-sum-k.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
#rdfc-root .rdfc-sum-tx { display: flex; flex-direction: column; min-width: 0; flex: 1; }
#rdfc-root .rdfc-sum-tx b { font-size: 24px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
#rdfc-root .rdfc-sum-tx span { font-size: 12.5px; font-weight: 700; color: var(--muted); line-height: 1.3; }
#rdfc-root .rdfc-sum-k > i { font-style: normal; font-size: 11.5px; font-weight: 700; align-self: flex-start; max-width: 42%; text-align: right; line-height: 1.3; }

/* ── Segmented views, toolbar, table, footer (admin .ord-*) ── */
#rdfc-root .rdfc-segrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
#rdfc-root .seg.rdfc-seg { flex-wrap: wrap; max-width: 100%; }
#rdfc-root .seg.rdfc-seg a { cursor: pointer; user-select: none; white-space: nowrap; color: var(--ink-2); }
#rdfc-root .seg.rdfc-seg a.on { color: var(--ink); }
#rdfc-root .seg.rdfc-seg a .c { font-weight: 700; }
#rdfc-root .rdfc-listcard { overflow: visible; }
#rdfc-root .rdfc-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }
#rdfc-root .rdfc-toolbar .input { height: 36px; font-size: 13.5px; }
#rdfc-root .rdfc-toolbar .rdfc-search { width: auto; min-width: 220px; flex: 1 1 220px; max-width: 360px; }
#rdfc-root .rdfc-toolbar .rdfc-select { width: auto; min-width: 150px; flex: 0 0 auto; padding: 0 10px; font-size: 13px; }
#rdfc-root .rdfc-toolbar .rdfc-count { margin-left: auto; font-size: 12.5px; font-weight: 700; }
#rdfc-root .rdfc-toolbar .rdfc-note { font-size: 12.5px; line-height: 1.45; }
#rdfc-root .rdfc-scroll { overflow-x: auto; }
#rdfc-root .tbl.rdfc-tbl, #rdfc-root .tbl.rdfc-mini { width: 100%; border-collapse: collapse; font-size: 13.5px; }
#rdfc-root .tbl th {
    background: var(--sunk); color: var(--muted); padding: 10px 14px; font-size: 11px; letter-spacing: .07em;
    text-transform: uppercase; font-weight: 700; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: left;
}
#rdfc-root .tbl th.num { text-align: right; }
#rdfc-root .tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 13.5px; white-space: nowrap; }
#rdfc-root .tbl tr:last-child td { border-bottom: 0; }
#rdfc-root .tbl tr:hover { background: none; }
#rdfc-root .tbl tr.rdfc-row { cursor: pointer; }
#rdfc-root .tbl tr.rdfc-row:hover td { background: rgba(61,78,232,.035); }
#rdfc-root .tbl tr.rdfc-closed td { opacity: .7; }
#rdfc-root .tbl td.rdfc-wrap { white-space: normal; min-width: 140px; max-width: 320px; line-height: 1.4; }
#rdfc-root .tbl td.rdfc-empty { text-align: center; color: var(--muted); padding: 34px 16px; white-space: normal; }
#rdfc-root .tbl .pill, #rdfc-root .tbl .chip, #rdfc-root .tbl .health { height: 22px; font-size: 11.5px; }
#rdfc-root .rdfc-sub { font-size: 12px; margin-top: 2px; font-weight: 600; }
#rdfc-root .rdfc-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
#rdfc-root .rdfc-name-td { min-width: 220px; white-space: normal; }
#rdfc-root .rdfc-nm { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
#rdfc-root .rdfc-nm b { font-weight: 800; }
#rdfc-root .rdfc-nm .mono { font-size: 11.5px; margin-top: 1px; }
#rdfc-root .rdfc-theirs { white-space: normal; max-width: 280px; line-height: 1.4; font-size: 12.5px; }
#rdfc-root .rdfc-chev { color: var(--muted); width: 40px; }
#rdfc-root .rdfc-chev svg { width: 16px; height: 16px; display: block; }
#rdfc-root .rdfc-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; }
#rdfc-root .rdfc-link { font-weight: 800; color: var(--ink); }
#rdfc-root tr.rdfc-row:hover .rdfc-link { color: var(--accent); }
#rdfc-root .rdfc-late { display: inline-block; padding: 1px 6px; border-radius: 6px; background: var(--bad-soft); color: var(--bad); font-size: 10.5px; font-weight: 800; letter-spacing: .03em; vertical-align: 1px; font-family: inherit; }
#rdfc-root .urgent { vertical-align: 1px; }
#rdfc-root .rdfc-warn-t { color: var(--warn); font-weight: 800; }

/* Avatar tile (initials on a colour derived from the platform id) */
#rdfc-root .rdfc-tile { display: inline-grid; place-items: center; flex: none; color: #fff; font-weight: 800; letter-spacing: .02em; line-height: 1; }

/* Health chips (.rd .health has ok/off/warn; add bad) */
#rdfc-root .health { white-space: nowrap; }
#rdfc-root .health.rdfc-h-ok { background: var(--ok-soft); color: var(--ok); }
#rdfc-root .health.rdfc-h-off { background: #EEF0F5; color: var(--muted); }
#rdfc-root .health.rdfc-h-warn { background: var(--warn-soft); color: var(--warn); }
#rdfc-root .health.rdfc-h-bad { background: var(--bad-soft); color: var(--bad); }
#rdfc-root .health.rdfc-h-acc { background: var(--accent-soft); color: #2A37B8; }

/* ── Record header (admin .ow-head / .cws-*) ── */
#rdfc-root .rdfc-head { padding: 16px 22px 14px; display: flex; flex-direction: column; gap: 10px; position: relative; z-index: 5; }
#rdfc-root .rdfc-head-r1, #rdfc-root .rdfc-head-r2 { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; }
#rdfc-root .rdfc-head-r1 { align-items: flex-start; }
#rdfc-root .rdfc-id { min-width: 0; flex: 1; }
#rdfc-root .rdfc-id .crumb { margin-bottom: 8px; }
#rdfc-root .rdfc-id .crumb a { color: var(--accent); }
#rdfc-root .rdfc-idrow { gap: 14px; align-items: center; min-width: 0; }
#rdfc-root .ws-head { gap: 10px; }
#rdfc-root .ws-head h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; color: var(--ink); }
#rdfc-root .rdfc-chips { gap: 6px; flex-wrap: wrap; }
#rdfc-root .rdfc-chips .chip, #rdfc-root .rdfc-chips .health { height: 22px; font-size: 11.5px; }
#rdfc-root .rdfc-hsub { margin: 4px 0 0; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
#rdfc-root .rdfc-hsub .mono { font-size: 12px; }
#rdfc-root .rdfc-ext { width: 12px; height: 12px; vertical-align: -1px; }
#rdfc-root .rdfc-pos { font-size: 12.5px; font-weight: 700; min-width: 42px; text-align: center; }
#rdfc-root .rdfc-acts { position: relative; flex-wrap: wrap; justify-content: flex-end; }
#rdfc-root .rdfc-acts .btn svg { width: 14px; height: 14px; }
#rdfc-root .rdfc-acts .menu { top: 42px; }
#rdfc-root .menu[hidden] { display: none; }

/* Tabs */
#rdfc-root .wtabs.rdfc-tabs { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; gap: 2px; }
#rdfc-root .wtabs.rdfc-tabs::-webkit-scrollbar { display: none; }
#rdfc-root .wtabs.rdfc-tabs .wtab { white-space: nowrap; flex: 0 0 auto; padding: 11px 14px; }
#rdfc-root .rdfc-pane { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ── Overview ── */
#rdfc-root .kpis.rdfc-kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
#rdfc-root .rdfc-kpis .kpi b { font-size: 24px; }
#rdfc-root .rdfc-kpis .kpi i { font-size: 11.5px; font-weight: 600; }
#rdfc-root .rdfc-kpis .kpi.rdfc-bad { border-color: #F3C2C7; background: #FFF7F8; }
#rdfc-root .rdfc-kpis .kpi.rdfc-bad b { color: var(--bad); }
#rdfc-root .rdfc-g3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
#rdfc-root .rdfc-g2 { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; align-items: start; }
#rdfc-root .ch h3 { color: var(--ink); }
#rdfc-root .ch h3 .muted { font-weight: 700; font-size: 12.5px; }
#rdfc-root .rdfc-lnk { font-size: 13px; font-weight: 700; color: var(--accent); }
#rdfc-root .li { padding: 11px 16px; }
#rdfc-root .li .pill, #rdfc-root .li .chip { flex: none; }
#rdfc-root .li .s { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rdfc-root .rdfc-click { cursor: pointer; }
#rdfc-root .rdfc-click:hover { background: var(--sunk); }
#rdfc-root .rdfc-more { justify-content: center; font-weight: 700; }
#rdfc-root .kvl.rdfc-kvl > div > span:last-child { min-width: 0; overflow-wrap: anywhere; }
#rdfc-root .kvl .health { height: 22px; font-size: 11.5px; }
#rdfc-root .tbl.rdfc-mini td { padding: 9px 16px; }
#rdfc-root .tbl.rdfc-mini th { padding: 8px 16px; }
#rdfc-root .rdfc-chipwrap { display: flex; flex-wrap: wrap; gap: 6px; }
#rdfc-root button.chip.rdfc-cchip { cursor: pointer; font-family: inherit; }
#rdfc-root button.chip.rdfc-cchip:hover { border-color: var(--accent); color: var(--accent); }
#rdfc-root .rdfc-subs .chip { margin: 1px 0; }

/* ── Products grid (admin .cws-prod) ── */
#rdfc-root .rdfc-prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
#rdfc-root a.rdfc-prod { display: flex; flex-direction: column; gap: 5px; color: var(--ink); cursor: pointer; min-width: 0; }
#rdfc-root .rdfc-prod-img { width: 100%; aspect-ratio: 1 / 1; overflow: hidden; background: #F1F2F7; }
#rdfc-root .rdfc-prod-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
#rdfc-root .rdfc-noimg { font-size: 11px; color: #B4B8CC; font-weight: 700; }
#rdfc-root .rdfc-prod-code { font-size: 12.5px; font-weight: 800; overflow-wrap: anywhere; }
#rdfc-root a.rdfc-prod:hover .rdfc-prod-code { color: var(--accent); }
#rdfc-root .rdfc-prod-desc { font-size: 12.5px; color: var(--ink-2); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#rdfc-root .rdfc-prod-chips { gap: 6px; flex-wrap: wrap; }
#rdfc-root .rdfc-prod-chips .chip { height: 20px; font-size: 11px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
#rdfc-root .rdfc-span { grid-column: 1 / -1; margin: 0; }

@media (max-width: 1200px) {
    #rdfc-root .kpis.rdfc-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    #rdfc-root .rdfc-g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    #rdfc-root .ph { flex-direction: column; align-items: flex-start; }
    #rdfc-root .kpis.rdfc-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #rdfc-root .rdfc-g3, #rdfc-root .rdfc-g2 { grid-template-columns: minmax(0, 1fr); }
    #rdfc-root .rdfc-head { padding: 12px 14px; }
    #rdfc-root .rdfc-head-r1, #rdfc-root .rdfc-head-r2 { flex-wrap: wrap; }
    #rdfc-root .rdfc-acts { justify-content: flex-start; }
    #rdfc-root .rdfc-toolbar .rdfc-search { max-width: none; min-width: 0; }
    #rdfc-root .rdfc-sum-k > i { display: none; }
    #rdfc-root .rdfc-prod-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
