/* IPME UI kit — interim local implementation of the IPME-UI-001 Rev B CONTRACT
   (tokens §3, shell §2, list §5, blade §6, modal/toast §7, z-index §8).
   Version 0.9.0-jpm. Replace with ipme-corp/ipme-ui v1 when it is published;
   pages use only the documented UI.* API and --ui-* tokens. */

@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('fonts/inter-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url('fonts/inter-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url('fonts/inter-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url('fonts/inter-latin-700-normal.woff2') format('woff2'); }

:root {
  --ui-primary: #1a3a6e; --ui-primary-hover: #1e4a88; --ui-primary-tint: rgba(26,58,110,.11);
  --ui-danger: #cf1b28; --ui-danger-hover: #a8151f;
  --ui-success: #1a7f4e; --ui-warning: #b45309; --ui-info: #0d9488;
  --ui-bg: #f0f2f5; --ui-surface: #ffffff;
  --ui-nav-bg: #e8eef8; --ui-subnav-bg: #f4f7fc;
  --ui-border: #e2e5e9; --ui-border-strong: #cdd0d6;
  --ui-text: #1e2433; --ui-muted: #5c636e; --ui-hint: #8a8f98;
  --ui-row-hover: #f5f8fb; --ui-row-selected: #e3ecf7;
  --ui-brand: #d2232a; --ui-brand-dark: #a91b21;   /* JPM (§3a) — brand zone only */
  --ui-topbar-h: 56px; --ui-nav-h: 40px; --ui-subnav-h: 0px; --ui-chrome-h: 96px;
  --ui-radius: 6px; --ui-radius-card: 10px;
  --ui-shadow-card: 0 1px 3px rgba(0,0,0,.05); --ui-shadow-blade: -8px 0 24px rgba(0,0,0,.14); --ui-shadow-modal: 0 12px 40px rgba(0,0,0,.22);
  --ui-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --ui-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* status pills */
  --ui-s-draft-bg: #eef0f3; --ui-s-draft-tx: #4b5563;
  --ui-s-sent-bg: #e0ebfb; --ui-s-sent-tx: #1e4a88;
  --ui-s-accepted-bg: #dcf3e7; --ui-s-accepted-tx: #1a7f4e;
  --ui-s-invoiced-bg: #dcf3e7; --ui-s-invoiced-tx: #1a7f4e;
  --ui-s-issued-bg: #e0ebfb; --ui-s-issued-tx: #1e4a88;
  --ui-s-declined-bg: #f3e8e8; --ui-s-declined-tx: #7f1d1d;
  --ui-s-expired-bg: #fdf0dc; --ui-s-expired-tx: #92400e;
  --ui-s-overdue-bg: #fde4e4; --ui-s-overdue-tx: #a8151f;
  --ui-s-void-bg: #eceef1; --ui-s-void-tx: #6b7280;
  --ui-s-active-bg: #dcf3e7; --ui-s-active-tx: #1a7f4e;
  --ui-s-inactive-bg: #eceef1; --ui-s-inactive-tx: #6b7280;
  --ui-s-warn-bg: #fdf0dc; --ui-s-warn-tx: #92400e;
  --ui-s-ok-bg: #dcf3e7; --ui-s-ok-tx: #1a7f4e;
  --ui-s-error-bg: #fde4e4; --ui-s-error-tx: #a8151f;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--ui-font); font-size: 13px; line-height: 1.45; color: var(--ui-text); background: var(--ui-bg); -webkit-font-smoothing: antialiased; }
body.ui-app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
h1, h2, h3 { margin: 0; font-weight: 600; color: var(--ui-text); }
h1 { font-size: 18px; } h2 { font-size: 15px; } h3 { font-size: 13px; }
a { color: var(--ui-primary); text-decoration: none; } a:hover { text-decoration: underline; }
.mono, code { font-family: var(--ui-mono); font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--ui-muted); } .hint { color: var(--ui-hint); font-size: 12px; }
.err-text { color: var(--ui-danger); }
.hidden { display: none !important; }

/* ── Shell (§2) ── */
.ui-topbar { flex: 0 0 var(--ui-topbar-h); height: var(--ui-topbar-h); background: var(--ui-surface); border-bottom: 1px solid var(--ui-border); display: flex; align-items: center; gap: 12px; padding: 0 16px; position: relative; z-index: 200; }
.ui-topbar::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--ui-brand); }
.ui-topbar .ui-logo { height: 32px; width: auto; display: block; }
.ui-topbar .ui-divider { width: 1px; height: 28px; background: var(--ui-border); }
.ui-topbar .ui-appname { font-size: 13px; color: var(--ui-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-topbar .ui-appname b { color: var(--ui-text); font-weight: 600; }
.ui-topbar .ui-appname .ui-dot { color: var(--ui-brand); font-weight: 700; padding: 0 2px; }
.ui-topbar .ui-spacer { flex: 1; }
.ui-topbar .ui-user { font-size: 13px; color: var(--ui-text); white-space: nowrap; }
.ui-nav, .ui-subnav { display: flex; align-items: stretch; gap: 2px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; position: relative; z-index: 200; }
.ui-nav { flex: 0 0 var(--ui-nav-h); height: var(--ui-nav-h); background: var(--ui-nav-bg); border-bottom: 1px solid var(--ui-border); }
.ui-subnav { flex: 0 0 34px; height: 34px; background: var(--ui-subnav-bg); border-bottom: 1px solid var(--ui-border); }
.ui-nav a, .ui-subnav a { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; color: var(--ui-text); font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent; text-decoration: none; }
.ui-nav a { font-size: 13px; } .ui-subnav a { font-size: 12px; }
.ui-nav a:hover, .ui-subnav a:hover { background: var(--ui-primary-tint); text-decoration: none; }
.ui-nav a.active, .ui-subnav a.active { color: var(--ui-primary); font-weight: 600; border-bottom-color: var(--ui-primary); background: var(--ui-primary-tint); }
.ui-nav .ui-nav-right { margin-left: auto; display: flex; gap: 2px; }
.ui-nav svg { width: 15px; height: 15px; flex: 0 0 auto; }

/* ── Page body ── */
.ui-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ui-page { flex: 1; min-height: 0; overflow: auto; padding: 16px 20px 32px; }
.ui-toolbar { flex: 0 0 auto; min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--ui-surface); border-bottom: 1px solid var(--ui-border); flex-wrap: wrap; }
.ui-toolbar h1 { font-size: 18px; font-weight: 600; white-space: nowrap; }
.ui-toolbar .ui-count { font-size: 13px; font-weight: 400; color: var(--ui-muted); margin-left: 4px; }
.ui-toolbar .ui-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ui-toolbar .ui-actions { margin-left: auto; display: flex; gap: 8px; }
.ui-search { width: 240px; }

/* ── Controls ── */
.btn { font: inherit; font-size: 13px; font-weight: 600; border-radius: var(--ui-radius); border: 1px solid var(--ui-border-strong); background: var(--ui-surface); color: var(--ui-text); padding: 6px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; line-height: 18px; }
.btn:hover { background: var(--ui-row-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--ui-primary); border-color: var(--ui-primary); color: #fff; }
.btn.primary:hover { background: var(--ui-primary-hover); }
.btn.danger { background: var(--ui-danger); border-color: var(--ui-danger); color: #fff; }
.btn.danger:hover { background: var(--ui-danger-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ui-primary); }
.btn.ghost:hover { background: var(--ui-primary-tint); }
.btn.sm { font-size: 12px; padding: 3px 8px; }
.btn.brand { background: var(--ui-brand); border-color: var(--ui-brand); color: #fff; } /* sign-in page only (§3a.4) */
.btn.brand:hover { background: var(--ui-brand-dark); }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=search], input[type=password], select, textarea {
  font: inherit; font-size: 13px; color: var(--ui-text); background: var(--ui-surface); border: 1px solid var(--ui-border-strong); border-radius: var(--ui-radius); padding: 6px 8px; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--ui-primary-tint); outline-offset: 0; border-color: var(--ui-primary); }
input[readonly], textarea[readonly] { background: var(--ui-bg); }
textarea { resize: vertical; min-height: 64px; width: 100%; }
label.ui-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.ui-seg { display: inline-flex; border: 1px solid var(--ui-border-strong); border-radius: var(--ui-radius); overflow: hidden; }
.ui-seg button { font: inherit; font-size: 12px; font-weight: 500; border: 0; background: var(--ui-surface); padding: 5px 10px; cursor: pointer; color: var(--ui-text); }
.ui-seg button + button { border-left: 1px solid var(--ui-border-strong); }
.ui-seg button.on { background: var(--ui-primary-tint); color: var(--ui-primary); font-weight: 600; }

.pill { display: inline-block; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; border-radius: 10px; padding: 1px 8px; white-space: nowrap; background: var(--ui-s-draft-bg); color: var(--ui-s-draft-tx); }
.pill.s-sent { background: var(--ui-s-sent-bg); color: var(--ui-s-sent-tx); }
.pill.s-accepted, .pill.s-invoiced { background: var(--ui-s-accepted-bg); color: var(--ui-s-accepted-tx); }
.pill.s-issued { background: var(--ui-s-issued-bg); color: var(--ui-s-issued-tx); }
.pill.s-declined { background: var(--ui-s-declined-bg); color: var(--ui-s-declined-tx); }
.pill.s-expired { background: var(--ui-s-expired-bg); color: var(--ui-s-expired-tx); }
.pill.s-overdue { background: var(--ui-s-overdue-bg); color: var(--ui-s-overdue-tx); }
.pill.s-void, .pill.s-inactive { background: var(--ui-s-void-bg); color: var(--ui-s-void-tx); }
.pill.s-active, .pill.s-ok { background: var(--ui-s-ok-bg); color: var(--ui-s-ok-tx); }
.pill.s-warn { background: var(--ui-s-warn-bg); color: var(--ui-s-warn-tx); }
.pill.s-error { background: var(--ui-s-error-bg); color: var(--ui-s-error-tx); }
.pill.s-cap { background: var(--ui-primary-tint); color: var(--ui-primary); text-transform: none; letter-spacing: 0; font-size: 11px; }

/* ── List (§5) ── */
.ui-listwrap { flex: 1; min-height: 0; overflow: auto; background: var(--ui-surface); }
table.ui-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.ui-table th { position: sticky; top: 0; z-index: 5; background: var(--ui-surface); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ui-muted); text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--ui-border-strong); white-space: nowrap; user-select: none; }
table.ui-table th.sortable { cursor: pointer; }
table.ui-table th .ui-sort { color: var(--ui-primary); padding-left: 3px; }
table.ui-table td { padding: 7px 10px; border-bottom: 1px solid var(--ui-border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 360px; vertical-align: middle; }
table.ui-table tbody tr { cursor: default; }
table.ui-table tbody tr:hover td { background: var(--ui-row-hover); }
table.ui-table tbody tr.selected td { background: var(--ui-row-selected); }
table.ui-table tr.ui-group td { background: var(--ui-subnav-bg); font-weight: 600; cursor: pointer; }
table.ui-table td.num, table.ui-table th.num { text-align: right; }
.ui-empty { padding: 40px 20px; text-align: center; color: var(--ui-muted); }
table.ui-plain { width: 100%; border-collapse: collapse; font-size: 13px; }
table.ui-plain th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ui-muted); text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--ui-border-strong); white-space: nowrap; }
table.ui-plain td { padding: 6px 8px; border-bottom: 1px solid var(--ui-border); vertical-align: top; }
table.ui-plain tfoot td { border-bottom: 0; font-weight: 600; }

/* ── Blade (§6) ── */
.ui-blade { position: fixed; right: 0; top: var(--ui-chrome-h); bottom: 0; width: min(720px, 92vw); background: var(--ui-surface); box-shadow: var(--ui-shadow-blade); z-index: 300; display: flex; flex-direction: column; border-left: 1px solid var(--ui-border); }
.ui-blade.size-S { width: min(480px, 92vw); } .ui-blade.size-M { width: min(720px, 92vw); } .ui-blade.size-L { width: min(960px, 92vw); } .ui-blade.size-XL { width: min(1280px, 92vw); }
.ui-blade-head { flex: 0 0 auto; display: flex; align-items: flex-start; gap: 12px; padding: 14px 20px 10px; border-bottom: 1px solid var(--ui-border); }
.ui-blade-head .ui-blade-titles { flex: 1; min-width: 0; }
.ui-blade-head .ui-blade-title { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-blade-head .ui-blade-sub { font-size: 12px; color: var(--ui-muted); margin-top: 3px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ui-blade-head .ui-blade-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.ui-blade-close { width: 30px; height: 30px; border: 0; background: transparent; font-size: 20px; line-height: 30px; cursor: pointer; color: var(--ui-muted); border-radius: var(--ui-radius); flex: 0 0 30px; }
.ui-blade-close:hover { background: var(--ui-row-hover); color: var(--ui-text); }
.ui-blade-tabs { flex: 0 0 auto; display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--ui-border); background: var(--ui-surface); }
.ui-blade-tabs button { font: inherit; font-size: 13px; font-weight: 500; border: 0; background: transparent; padding: 9px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--ui-muted); }
.ui-blade-tabs button.active { color: var(--ui-primary); border-bottom-color: var(--ui-primary); font-weight: 600; }
.ui-blade-body { flex: 1; min-height: 0; overflow: auto; padding: 16px 20px; }
.ui-blade-foot { flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 8px; padding: 10px 20px; border-top: 1px solid var(--ui-border); background: var(--ui-subnav-bg); }
.ui-section { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ui-muted); margin: 18px 0 8px; }
.ui-section:first-child { margin-top: 0; }
.ui-grid { display: grid; grid-template-columns: 1fr; gap: 10px 16px; }
.ui-blade.size-M .ui-grid, .ui-blade.size-L .ui-grid, .ui-blade.size-XL .ui-grid, .ui-page .ui-grid { grid-template-columns: 1fr 1fr; }
.ui-grid .span2 { grid-column: 1 / -1; }
.ui-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ui-field > span.lbl { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ui-muted); }
.ui-field > .val { font-size: 13px; min-height: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.ui-field input, .ui-field select, .ui-field textarea { width: 100%; }
.ui-field input[type=checkbox], label.ui-check input[type=checkbox] { width: auto; margin: 0; }
.ui-field label.ui-check { margin-top: 18px; }
.ui-kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.ui-kv dt { color: var(--ui-muted); } .ui-kv dd { margin: 0; }
.ui-totals { margin-left: auto; width: 300px; font-size: 13px; }
.ui-totals div { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; }
.ui-totals div.total { border-top: 1px solid var(--ui-text); font-weight: 700; font-size: 15px; margin-top: 4px; padding-top: 6px; }

/* ── Cards / metrics ── */
.ui-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.ui-card { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: var(--ui-radius-card); box-shadow: var(--ui-shadow-card); padding: 14px 16px; }
.ui-card.link { cursor: pointer; } .ui-card.link:hover { border-color: var(--ui-primary); }
.ui-metric-v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ui-metric-l { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--ui-muted); font-weight: 600; }
.ui-metric-s { font-size: 12px; color: var(--ui-muted); margin-top: 2px; }
.ui-panel { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: var(--ui-radius-card); box-shadow: var(--ui-shadow-card); padding: 16px 18px; margin-bottom: 16px; max-width: 980px; }
.ui-callout { border-left: 3px solid var(--ui-info); background: #effaf8; padding: 10px 12px; border-radius: 0 var(--ui-radius) var(--ui-radius) 0; margin: 8px 0; }
.ui-callout.warn { border-left-color: var(--ui-warning); background: #fdf6ec; }
.ui-callout.err { border-left-color: var(--ui-danger); background: #fdf0f0; }

/* ── Modal (§7) ── */
.ui-modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.38); z-index: 400; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; overflow: auto; }
.ui-modal { background: var(--ui-surface); border-radius: var(--ui-radius-card); box-shadow: var(--ui-shadow-modal); width: 480px; max-width: 100%; display: flex; flex-direction: column; max-height: 84vh; }
.ui-modal.wide { width: 640px; } .ui-modal.xwide { width: 860px; }
.ui-modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--ui-border); }
.ui-modal-head h2 { flex: 1; font-size: 15px; }
.ui-modal-body { padding: 16px 18px; overflow: auto; flex: 1; min-height: 0; }
.ui-modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--ui-border); }
.ui-modal .ui-grid { grid-template-columns: 1fr 1fr; }

/* ── Toast (§7) ── */
.ui-toasts { position: fixed; right: 16px; bottom: 16px; z-index: 500; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.ui-toast { background: #1e2433; color: #fff; border-radius: var(--ui-radius); padding: 10px 12px; box-shadow: var(--ui-shadow-modal); display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.ui-toast.ok { background: #14532d; } .ui-toast.error { background: var(--ui-danger); }
.ui-toast .x { margin-left: auto; cursor: pointer; opacity: .8; border: 0; background: transparent; color: inherit; font-size: 16px; line-height: 16px; }

/* ── Sign-in & public pages ── */
body.ui-plainpage { min-height: 100dvh; display: flex; flex-direction: column; }
.ui-stripe { height: 3px; background: var(--ui-brand); }
.ui-signin { margin: 10vh auto 0; width: 380px; max-width: calc(100% - 32px); background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: var(--ui-radius-card); box-shadow: var(--ui-shadow-card); padding: 28px 28px 24px; }
.ui-signin .ui-logo { height: 44px; display: block; margin: 0 auto 10px; }
.ui-signin h1 { text-align: center; font-size: 18px; margin-bottom: 4px; }
.ui-signin .btn { width: 100%; justify-content: center; padding: 10px 12px; }

/* ── Responsive (§2, §6) ── */
@media (max-width: 900px) { .ui-blade { width: 100vw !important; } .ui-blade .ui-grid { grid-template-columns: 1fr !important; } .ui-search { width: 160px; } }
@media (max-width: 700px) { body.ui-app { height: auto; min-height: 100dvh; overflow: auto; } .ui-listwrap { overflow: visible; } .ui-topbar .ui-user { display: none; } }
@media (pointer: coarse) { table.ui-table td { padding: 10px; } }
