/* Clearinghouse Console — accessible, responsive, light/dark */
:root {
  /* InterSync suite palette (same tokens as every InterSync console) */
  --brand-1: #4f46e5; --brand-2: #0ea5e9; --brand-grad: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-ink: #ffffff;
  --primary-soft: #eef2ff;
  --accent: #4f46e5;
  --focus: #4f46e5;
  --side-bg: #0b1220; --side-text: #b6c2d6; --side-active: #1b2740; --side-muted: #6b7a93;
  --ok: #059669;       --ok-bg: #ecfdf5;
  --info: #2563eb;     --info-bg: #eff6ff;
  --warn: #b45309;     --warn-bg: #fffbeb;
  --bad: #dc2626;      --bad-bg: #fef2f2;
  --neutral: #475569;  --neutral-bg: #f1f5f9;
  --prod: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --sans: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b1020; --surface: #121a2c; --surface-2: #0f1626; --border: #24304a; --text: #e6ebf5; --muted: #8592ab;
    --primary: #818cf8; --primary-ink: #0b1020; --primary-soft: #1d2445; --accent: #a5b4fc; --focus: #a5b4fc;
    --side-bg: #070b15; --side-active: #16213a;
    --ok: #34d399; --ok-bg: #062a20; --info: #93c5fd; --info-bg: #0c1d3d; --warn: #fcd34d; --warn-bg: #2b1d05;
    --bad: #f87171; --bad-bg: #2d0f12; --neutral: #cbd5e1; --neutral-bg: #1e293b; --prod: #f87171;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #0b1020; --surface: #121a2c; --surface-2: #0f1626; --border: #24304a; --text: #e6ebf5; --muted: #8592ab;
  --primary: #818cf8; --primary-ink: #0b1020; --primary-soft: #1d2445; --accent: #a5b4fc; --focus: #a5b4fc;
  --side-bg: #070b15; --side-active: #16213a;
  --ok: #34d399; --ok-bg: #062a20; --info: #93c5fd; --info-bg: #0c1d3d; --warn: #fcd34d; --warn-bg: #2b1d05;
  --bad: #f87171; --bad-bg: #2d0f12; --neutral: #cbd5e1; --neutral-bg: #1e293b; --prod: #f87171;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--sans); background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
code, pre, .mono { font-family: var(--mono); font-size: .86em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -48px; background: var(--primary); color: var(--primary-ink); padding: .5rem .9rem; border-radius: 6px; z-index: 100; font-weight: 600; }
.skip-link:focus { top: 8px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- top bar ---------- */
.env-banner { background: var(--prod); color: #fff; text-align: center; font-weight: 700; padding: .35rem 1rem; font-size: .85rem; letter-spacing: .02em; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
body[data-env='production'] .topbar { border-bottom: 3px solid var(--prod); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.brand img { border-radius: 7px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; justify-content: flex-end; }
.live { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on .dot { background: #22c55e; box-shadow: 0 0 0 3px rgb(34 197 94 / 20%); }
.env-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 2px; margin: 0; background: var(--surface-2); }
.env-switch input { position: absolute; opacity: 0; pointer-events: none; }
.env-switch label { padding: .3rem .8rem; border-radius: 999px; cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--muted); }
.env-switch input:checked + label { background: var(--primary); color: var(--primary-ink); }
.env-switch input#env-production:checked + label { background: var(--prod); color: #fff; }
.env-switch input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 1px; }
.icon-btn.nav-toggle { display: none; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.sidenav { background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .6rem; position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto; }
.sidenav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sidenav a { display: block; padding: .55rem .8rem; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; }
.sidenav a:hover { background: var(--surface-2); }
.sidenav a[aria-current='page'] { background: var(--primary-soft); color: var(--text); font-weight: 700; box-shadow: inset 3px 0 0 var(--primary); }
.nav-foot { margin-top: 1.25rem; padding: 0 .8rem; font-size: .85rem; }
main { padding: 1.5rem clamp(1rem, 3vw, 2rem) 4rem; max-width: 1280px; width: 100%; }
main:focus { outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { color: var(--muted); margin: 0; }

@media (max-width: 860px) {
  .icon-btn.nav-toggle { display: inline-flex; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  #logout-btn { display: none; }
  .topbar { gap: .5rem; padding: .5rem .75rem; }
  .topbar-right { gap: .5rem; flex-wrap: nowrap; }
  .env-switch label { padding: .3rem .6rem; }
  .sidenav { position: fixed; inset: 57px auto 0 0; width: 260px; transform: translateX(-100%); transition: transform .2s ease; z-index: 30; box-shadow: var(--shadow); }
  .sidenav.open { transform: none; }
  .brand span { display: none; }
  .live-label { display: none; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.kpis { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.kpi .label { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: .15rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent; background: var(--primary); color: var(--primary-ink); cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.small { padding: .3rem .7rem; min-height: 32px; font-size: .85rem; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

label { font-weight: 600; font-size: .88rem; display: block; margin-bottom: .3rem; }
.hint { color: var(--muted); font-size: .82rem; font-weight: 400; }
input[type='text'], input[type='password'], input[type='search'], input[type='url'], input[type='number'], select, textarea {
  font: inherit; width: 100%; padding: .55rem .7rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); min-height: 40px;
}
textarea { font-family: var(--mono); font-size: .85rem; line-height: 1.45; resize: vertical; min-height: 12rem; }
input[aria-invalid='true'], textarea[aria-invalid='true'] { border-color: var(--bad); }
.field { margin-bottom: .9rem; }
.form-row { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.checkbox input { width: 18px; height: 18px; }
.filters { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); margin-bottom: 1rem; align-items: end; }

.table-wrap { position: relative; max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
caption { text-align: left; padding: .75rem 1rem; font-weight: 700; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font-family: var(--mono); font-size: .84rem; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.flash-row { animation: flash 1.6s ease; }
@keyframes flash { from { background: var(--primary-soft); } to { background: transparent; } }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; border: 1px solid transparent; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-completed, .s-active, .s-yes { color: var(--ok); background: var(--ok-bg); }
.s-accepted, .s-submitted { color: var(--info); background: var(--info-bg); }
.s-received, .s-inactive, .s-pending { color: var(--warn); background: var(--warn-bg); }
.s-rejected, .s-error, .s-no { color: var(--bad); background: var(--bad-bg); }
.s-neutral, .s-test { color: var(--neutral); background: var(--neutral-bg); }
.s-production { color: #fff; background: var(--prod); }
.tag { font-family: var(--mono); font-size: .78rem; background: var(--surface-2); border: 1px solid var(--border); padding: .05rem .4rem; border-radius: 5px; white-space: nowrap; }

.bars { display: grid; gap: .5rem; }
.bar-row { display: grid; grid-template-columns: 11rem 1fr 3rem; gap: .6rem; align-items: center; font-size: .88rem; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 999px; }
@media (max-width: 520px) { .bar-row { grid-template-columns: 7rem 1fr 2.5rem; } }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs [role='tab'] { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 3px solid transparent; padding: .55rem .9rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs [role='tab'][aria-selected='true'] { color: var(--text); border-bottom-color: var(--primary); }
pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .8rem 1rem; overflow: auto; max-height: 28rem; margin: 0; white-space: pre; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .35rem 1rem; margin: 0 0 1rem; font-size: .9rem; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.card, .callout { overflow-wrap: anywhere; }
@media (max-width: 520px) { .kv { grid-template-columns: minmax(0, 1fr); } .kv dt { margin-top: .35rem; } }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.timeline li { display: grid; grid-template-columns: 6.5rem 1fr; gap: .75rem; font-size: .88rem; padding-left: .75rem; border-left: 3px solid var(--border); }
.timeline li.warn { border-left-color: var(--warn); }
.timeline li.error { border-left-color: var(--bad); }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; }
.callout { border-left: 4px solid var(--primary); background: var(--primary-soft); padding: .75rem 1rem; border-radius: 0 8px 8px 0; margin-bottom: 1rem; }
.callout.warn { border-left-color: var(--warn); background: var(--warn-bg); }
.callout.bad { border-left-color: var(--bad); background: var(--bad-bg); }
.secret { display: flex; gap: .5rem; align-items: center; }
.secret code { flex: 1; padding: .55rem .7rem; background: var(--surface-2); border: 1px dashed var(--primary); border-radius: 8px; word-break: break-all; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.chip { font: inherit; font-size: .82rem; padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.chip:hover { border-color: var(--primary); }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.25rem; text-align: center; color: var(--muted); }
.dropzone.over { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-top: .75rem; color: var(--muted); font-size: .88rem; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { max-width: 420px; margin: 8vh auto 0; }
.login .card { padding: 1.75rem; }
.login-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); width: min(960px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 24px 64px rgb(0 0 0 / 35%); }
dialog::backdrop { background: rgb(4 16 18 / 55%); }
.dialog-inner { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem 1.2rem; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 1.1rem; }
.dialog-body { padding: 1.1rem 1.2rem 1.4rem; overflow: auto; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: .5rem; z-index: 200; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); font-size: .9rem; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .toast.ok { color: #062a2d; } }


/* ======================================================================
   InterSync suite shell — dark sidebar with the InterSync mark, white top bar,
   indigo→sky primary actions. Same look as the other InterSync consoles.
   ====================================================================== */
body { font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
.layout { grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidenav { background: var(--side-bg); color: var(--side-text); border-right: 0; top: 0; height: 100vh; padding: 16px 12px; display: flex; flex-direction: column; }
.sidenav .brand { color: #fff; padding: 4px 8px 18px; font-size: 14px; }
.sidenav .brand .brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--brand-grad); display: grid; place-items: center; flex: none; }
.sidenav .brand b { display: block; font-size: 14px; }
.sidenav .brand small { display: block; color: var(--side-muted); font-size: 11.5px; font-weight: 400; }
.sidenav .nav-label { color: var(--side-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 14px 10px 6px; }
.sidenav a { color: var(--side-text); border-radius: 8px; padding: 8px 10px; font-weight: 500; text-decoration: none; display: block; }
.sidenav a:hover { background: #ffffff0a; color: #fff; }
.sidenav a[aria-current='page'] { background: var(--side-active); color: #fff; box-shadow: inset 2px 0 0 var(--brand-2); }
.nav-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.06); font-size: 12px; color: var(--side-muted); }
.nav-foot a { color: var(--side-text); padding: 0; display: inline; }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; padding: 12px 28px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .page-title { font-size: 15px; font-weight: 650; }
#main { padding: 22px 28px 48px; max-width: 1400px; width: 100%; }
.card { border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.kpis .kpi:first-child { background: var(--brand-grad); color: #fff; border: 0; }
.kpis .kpi:first-child .label { color: #ffffffd1; }
.btn { border-radius: 8px; font-weight: 500; }
.btn:not(.secondary):not(.ghost):not(.danger) { background: var(--brand-grad); color: #fff; border-color: transparent; }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--brand-1); }
.page-head h1 { font-size: 20px; font-weight: 650; letter-spacing: -.2px; }
.login { min-height: 100vh; background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--brand-1) 22%, transparent), transparent), radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--brand-2) 22%, transparent), transparent), var(--bg); }
.isx-signin { width: 100%; justify-content: center; margin-bottom: 12px; }
.isx-or { display: flex; align-items: center; gap: 10px; margin: 6px 0 14px; font-size: 12px; color: var(--muted); }
.isx-or::before, .isx-or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
body:has(.login) .sidenav, body:has(.login) .topbar { display: none; }
body:has(.login) .layout { grid-template-columns: 1fr; }
body:has(.login) #main { padding: 0; max-width: none; }
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidenav { position: fixed; z-index: 40; left: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .sidenav.open { transform: none; box-shadow: 0 0 0 100vmax #02061773; }
  .icon-btn.nav-toggle { display: inline-flex; }
  .topbar, #main { padding-left: 16px; padding-right: 16px; }
}
