/* NABIDH Middleware console - hand-written, no build step, no external requests. */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --ink: #17212b;
  --ink-2: #4a5a6a;
  --ink-3: #7b8896;
  --line: #e1e6eb;
  --line-2: #d0d7de;
  --brand: #0b6b63;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3f1;
  --side: #10222b;
  --side-ink: #b7c6cf;
  --side-hi: #ffffff;
  --ok: #167a45;   --ok-bg: #e4f5ec;
  --info: #1d62b8; --info-bg: #e5eefb;
  --warn: #9a6200; --warn-bg: #fdf0d5;
  --bad: #b3261e;  --bad-bg: #fbe7e5;
  --mute: #5b6874; --mute-bg: #eceff2;
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--sans); background: var(--bg); color: var(--ink); line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; font-weight: 650; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.1rem; } h3 { font-size: .95rem; }
p { margin: 0 0 .8em; }
code, pre, .mono { font-family: var(--mono); font-size: .86em; }
code { background: var(--mute-bg); padding: .1em .35em; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.muted { color: var(--ink-3); } .small { font-size: .85em; } .nowrap { white-space: nowrap; } .right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 10px 18px; color: var(--side-hi); font-weight: 700; letter-spacing: .01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #14a094, #0b6b63); display: grid; place-items: center; font-size: .8rem; }
.brand small { display: block; font-weight: 400; color: var(--side-ink); font-size: .72rem; letter-spacing: 0; }
.nav-h { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: #6f8794; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 6px; color: var(--side-ink); font-size: .92rem; }
.nav a:hover { background: rgba(255,255,255,.07); color: var(--side-hi); text-decoration: none; }
.nav a.on { background: rgba(20,160,148,.22); color: var(--side-hi); }
.nav svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav .count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 10px; font-size: .7rem; padding: 0 6px; }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 14px; padding: 12px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top h1 { margin: 0; font-size: 1.15rem; }
.top .spacer { flex: 1; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: .88rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; }
.content { padding: 24px 28px 60px; max-width: 1500px; }
.menu-btn { display: none; }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.card > .hd { display: flex; align-items: center; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.card > .hd h2, .card > .hd h3 { margin: 0; }
.card > .hd .spacer { flex: 1; }
.card > .bd { padding: 18px; }
.card > .bd.flush { padding: 0; }
.card.warn { border-color: #efd69a; } .card.bad { border-color: #f0b8b3; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; align-items: start; }

.stat { padding: 16px 18px; }
.stat .n { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat .l { color: var(--ink-2); font-size: .85rem; }
.stat .s { font-size: .78rem; color: var(--ink-3); margin-top: 4px; }
.stat.bad .n { color: var(--bad); } .stat.ok .n { color: var(--ok); } .stat.warn .n { color: var(--warn); } .stat.info .n { color: var(--info); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: .75rem; font-weight: 600; white-space: nowrap; line-height: 1.5; }
.badge-ok { background: var(--ok-bg); color: var(--ok); } .badge-info { background: var(--info-bg); color: var(--info); }
.badge-warn { background: var(--warn-bg); color: var(--warn); } .badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-mute { background: var(--mute-bg); color: var(--mute); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--mute); }
.dot.ok { background: #1fa35f; box-shadow: 0 0 0 3px #1fa35f33; } .dot.bad { background: var(--bad); box-shadow: 0 0 0 3px #b3261e33; } .dot.warn { background: #d99100; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); border-radius: 6px; font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.3; }
.btn:hover { background: var(--surface-2); text-decoration: none; border-color: #b8c2cc; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); } .btn-primary:hover { background: #095850; border-color: #095850; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; } .btn-danger:hover { background: #961f18; border-color: #961f18; }
.btn-ghost { border-color: transparent; background: transparent; } .btn-sm { padding: 4px 10px; font-size: .82rem; } .btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: 6px; background: #fff; font: inherit; color: var(--ink); }
textarea { font-family: var(--mono); font-size: .85rem; line-height: 1.5; resize: vertical; }
input:disabled, select:disabled { background: var(--mute-bg); }
.field { margin-bottom: 14px; } .field .hint { font-size: .8rem; color: var(--ink-3); margin-top: 3px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; color: var(--ink); font-size: .9rem; }
.check input { margin-top: 3px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; align-items: end; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; font-size: .9rem; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); background: var(--surface-2); font-weight: 650; white-space: nowrap; }
tbody tr:hover { background: #fafcfd; }
tr.row-bad td:first-child { box-shadow: inset 3px 0 0 var(--bad); } tr.row-warn td:first-child { box-shadow: inset 3px 0 0 #d99100; }
.tbl-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; font-size: .9rem; margin: 0; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; word-break: break-word; }

.alert { padding: 11px 15px; border-radius: 7px; margin-bottom: 14px; border: 1px solid; font-size: .92rem; display: flex; gap: 10px; }
.alert-ok { background: var(--ok-bg); border-color: #b9e2cb; color: #0f5b33; } .alert-bad { background: var(--bad-bg); border-color: #f0b8b3; color: #8c1d17; }
.alert-warn { background: var(--warn-bg); border-color: #efd69a; color: #6d4600; } .alert-info { background: var(--info-bg); border-color: #b9cff0; color: #154a8c; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 16px; color: var(--ink-2); border-bottom: 2px solid transparent; font-weight: 600; font-size: .92rem; white-space: nowrap; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--ink); } .tabs a.on { color: var(--brand); border-bottom-color: var(--brand); }
.tab-pane { display: none; } .tab-pane.on { display: block; }

.pager { display: flex; gap: 6px; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); font-size: .86rem; color: var(--ink-2); flex-wrap: wrap; }
.pager .pages { display: flex; gap: 4px; }
.pager a, .pager span.p { padding: 4px 10px; border: 1px solid var(--line-2); border-radius: 5px; background: #fff; color: var(--ink); }
.pager span.p.on { background: var(--brand); border-color: var(--brand); color: #fff; } .pager a:hover { text-decoration: none; background: var(--surface-2); }

.hl7 { background: #0f1b22; color: #d6e3ea; border-radius: 8px; padding: 14px 16px; overflow: auto; font-size: .82rem; line-height: 1.65; white-space: pre; margin: 0; }
.hl7 .seg { color: #6ee0d3; font-weight: 700; }
.hl7 .sep { color: #5f7a88; }
.seg-table td { padding: 5px 12px; font-size: .84rem; } .seg-table .segname { font-family: var(--mono); font-weight: 700; color: var(--brand); width: 70px; }
.seg-table .fno { font-family: var(--mono); color: var(--ink-3); width: 90px; } .seg-table .fval { font-family: var(--mono); word-break: break-all; }
.issue { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.issue:last-child { border-bottom: 0; }
.issue .ico { font-weight: 800; text-align: center; } .issue.error .ico { color: var(--bad); } .issue.warning .ico { color: #c98200; }
.issue .path { font-family: var(--mono); font-size: .78rem; color: var(--ink-3); }
.issue .fix { display: flex; gap: 6px; align-items: center; margin-top: 8px; } .issue .fix input { max-width: 340px; font-family: var(--mono); font-size: .82rem; padding: 5px 8px; }
.timeline { list-style: none; margin: 0; padding: 0; } .timeline li { padding: 10px 18px 10px 38px; position: relative; border-bottom: 1px solid var(--line); font-size: .88rem; }
.timeline li::before { content: ""; position: absolute; left: 18px; top: 16px; width: 9px; height: 9px; border-radius: 50%; background: var(--line-2); }
.timeline li.t-sent::before { background: #1fa35f; } .timeline li.t-nack::before, .timeline li.t-failed::before, .timeline li.t-validation_failed::before { background: var(--bad); }
.timeline li.t-queued::before, .timeline li.t-edited::before { background: var(--info); }
.chart { display: flex; align-items: flex-end; gap: 10px; height: 130px; padding: 4px 4px 0; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.chart .bar { width: 100%; max-width: 38px; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; background: var(--mute-bg); min-height: 2px; }
.chart .bar i { display: block; } .chart .bar .s { background: #1fa35f; } .chart .bar .b { background: var(--bad); } .chart .bar .o { background: #9db6c6; }
.chart .lab { font-size: .72rem; color: var(--ink-3); }
.secret-box { background: #0f1b22; color: #e6f2f0; border-radius: 8px; padding: 12px 14px; font-family: var(--mono); font-size: .9rem; word-break: break-all; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.secret-box button { flex: none; }
.stage-chip { display: inline-flex; align-items: center; gap: 8px; }
.stages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stage-card { border: 2px solid var(--line); border-radius: 10px; padding: 14px 16px; background: var(--surface); position: relative; }
.stage-card.current { border-color: var(--brand); background: var(--brand-soft); }
.stage-card .tag { position: absolute; top: -10px; right: 12px; background: var(--brand); color: #fff; font-size: .7rem; font-weight: 700; padding: 1px 9px; border-radius: 10px; letter-spacing: .04em; text-transform: uppercase; }
details.fold > summary { cursor: pointer; font-weight: 600; padding: 10px 0; color: var(--brand); }
dialog { border: 0; border-radius: 12px; padding: 0; max-width: 520px; width: calc(100% - 32px); box-shadow: 0 20px 60px #0006; } dialog::backdrop { background: #0a141a99; }
dialog .dh { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; } dialog .db { padding: 18px 20px; } dialog .df { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }
.guide h1 { font-size: 1.6rem; margin-top: 0; } .guide h2 { margin-top: 1.8em; padding-bottom: .3em; border-bottom: 1px solid var(--line); } .guide h3 { margin-top: 1.4em; }
.guide pre { background: #0f1b22; color: #d6e3ea; padding: 14px 16px; border-radius: 8px; overflow: auto; } .guide pre code { background: none; padding: 0; color: inherit; }
.guide table { margin: 1em 0; border: 1px solid var(--line); } .guide { max-width: 940px; }

/* ---------- guest ---------- */
.guest { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 10% -10%, #d9efec 0, transparent 60%), var(--bg); }
.guest .box { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 30px; box-shadow: 0 10px 40px #10222b14; }
.guest .brand { color: var(--ink); padding: 0 0 18px; } .guest .brand small { color: var(--ink-3); }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(2, 1fr); } .split { grid-template-columns: 1fr; } .stages { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; } .side { position: fixed; left: -270px; width: 250px; z-index: 20; transition: left .2s; } .side.open { left: 0; }
  .menu-btn { display: inline-flex; } .content { padding: 16px; } .top { padding: 10px 16px; } .g2, .g3, .g4 { grid-template-columns: 1fr; } .kv { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .side, .top, .btn, .filters, .no-print, .pager { display: none !important; } .shell { display: block; } .card { border: 0; } body { background: #fff; } .content { padding: 0; } }
