/* ---------------------------------------------------------------------------
   Engemann Middleware -- 1980s terminal look:
   monochrome, monospace, no rounded corners, hard shadows.
   --------------------------------------------------------------------------- */
:root {
  --bg: #eae8e3;          /* yellowed paper / plastic case */
  --panel: #ffffff;
  --ink: #000000;
  --border: #000000;
  --text: #000000;
  --muted: #5a5a5a;
  --accent: #000000;
  --accent-soft: #d5d5d5;
  --green: #2b2b2b;
  --amber: #6b6b6b;
  --red: #000000;
  --teal: #8a8a8a;
  --radius: 0;
  --ui: Arial, "Helvetica Neue", Helvetica, sans-serif;
  --heavy: "Arial Black", "Arial Bold", Arial, Helvetica, sans-serif;
  --mono: "Courier New", "DejaVu Sans Mono", Consolas, monospace;
  --shadow: 2px 2px 0 var(--ink);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--ui);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  /* subtle scanlines */
  background-image: repeating-linear-gradient(
    to bottom, rgba(0,0,0,.035) 0 1px, transparent 1px 3px);
}

/* ---------- Header ---------- */
header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  height: 54px;
  background: var(--ink);
  color: #fff;
  border-bottom: 1px solid #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--heavy);
  font-weight: 900; font-size: 15px; white-space: nowrap;
}
nav { display: flex; gap: 0; flex: 1; }
nav a {
  color: #cfcfcf;
  text-decoration: none;
  padding: 6px 14px;
  border: 1px solid transparent;
  font-size: 12px;
  white-space: nowrap;
}
nav a:hover { color: #fff; border-color: #fff; }
nav a.active { background: #fff; color: #000; font-weight: 700; }
.header-actions { display: flex; gap: 8px; }

.pill {
  background: #fff; color: #000;
  border: 1px solid #000;
  border-radius: 0;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
}

/* ---------- Status bar ---------- */
.statusbar {
  display: flex; flex-wrap: wrap; gap: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--ink);
  padding: 0 16px;
  font-size: 12px;
}
.sb-item {
  display: flex; align-items: baseline; gap: 8px;
  padding: 7px 18px 7px 0;
  margin-right: 18px;
  border-right: 1px solid var(--ink);
}
.sb-item:last-child { border-right: none; }
.sb-k { color: var(--muted); }
.sb-k::after { content: ":"; }
.sb-v { font-weight: 700; }
.sb-v.err { background: var(--ink); color: #fff; padding: 0 6px; }
.dot {
  display: inline-block; width: 9px; height: 9px;
  border-radius: 50%; margin-right: 7px;
  border: 1px solid rgba(0,0,0,.35);
  vertical-align: baseline;
}
.dot-ok  { background: #1eb955; }
.dot-err { background: #e02b2b; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--ink);
  background: var(--panel);
  color: var(--text);
  padding: 5px 12px;
  border-radius: 0;
  cursor: pointer;
  font-family: var(--ui);
  font-size: 12px;
  box-shadow: 1px 1px 0 var(--ink);
}
.btn:hover { background: var(--ink); color: #fff; }
.btn:active { transform: translate(1px, 1px); box-shadow: none; }
.btn:disabled { opacity: .45; cursor: wait; box-shadow: none; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--panel); color: var(--ink); }
.btn-danger { border-style: dashed; }
.btn-ghost { background: transparent; border-color: #fff; color: #fff; box-shadow: none; }
.btn-ghost:hover { background: #fff; color: #000; }
header .btn { background: #000; border-color: #fff; color: #fff; box-shadow: none; }
header .btn:hover { background: #fff; color: #000; }

/* ---------- Layout ---------- */
/* The wide order/buffer tables use the whole window; a cap would only add
   horizontal scrolling on screens that have the room. */
main { max-width: 100%; margin: 0 auto; padding: 22px 16px; }
/* Reading-width content (login, forms, single panels) keeps a sane measure. */
main > .panel, main > .hint, main > p { max-width: 1100px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap { display: flex; justify-content: center; padding: 9vh 20px 0; }
.login-card {
  background: var(--panel); border: 1px solid var(--ink);
  border-radius: 0; padding: 28px 30px; width: 380px;
  box-shadow: var(--shadow);
}
.login-card h2 { margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 12px; margin-bottom: 20px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.login-card input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--ink);
  border-radius: 0; font-size: 14px; font-family: var(--ui); background: var(--panel);
}
.login-card input:focus { outline: none; background: var(--accent-soft); }
.login-card .btn-primary { width: 100%; margin-top: 18px; padding: 10px; font-size: 13px; }
.login-error { color: var(--red); font-size: 12px; margin-top: 12px; min-height: 18px; }

h2 { margin: 0 0 14px; font-size: 18px; font-family: var(--heavy); font-weight: 900; }
h3 { margin: 22px 0 10px; font-size: 14px; font-family: var(--heavy); font-weight: 900; }

.panel {
  background: var(--panel);
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

/* ---------- Tables ---------- */
.tablewrap {
  overflow-x: auto; width: 100%; background: var(--panel);
  border: 1px solid var(--ink); border-radius: 0;
  box-shadow: var(--shadow);
}
/* Scroll only when the columns genuinely do not fit. */
.tablewrap > table { min-width: 100%; width: max-content; }
table { border-collapse: collapse; width: 100%; font-size: 12px; line-height: 1.25; }
th, td { text-align: left; padding: 4px 9px; border-bottom: 1px solid var(--ink); white-space: nowrap; }
th {
  font-size: 11px; font-weight: 700;
  color: #fff; background: var(--ink); position: sticky; top: 0;
  border-bottom: 1px solid var(--ink);
}
tr:last-child td { border-bottom: none; }

th.grp {
  text-align: left; font-family: var(--heavy); font-weight: 900;
  border-right: 1px solid #fff; border-left: 1px solid #fff;
}
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--ink); color: #fff; }
tbody tr.clickable:hover a, tbody tr.clickable:hover .muted { color: #fff; }
td.wrap { white-space: normal; }

/* ---------- Pivot grouping ---------- */
/* Document row: the fold-out handle sits on the document number. */
.grouptoggle { cursor: pointer; user-select: none; white-space: nowrap; }
.grouptoggle:hover { background: var(--ink); color: #fff; }
.grouptoggle:hover .muted { color: #fff; }
.caret { display: inline-block; width: 10px; font-size: 9px; }
tr.grouprow > td { font-weight: 500; }
/* Folded-out line rows step back so the document rows stay the structure. */
tr.linerow > td { background: #fafafa; }
tr.linerow > td.sub { color: var(--muted); padding-left: 22px; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid var(--ink);
  border-radius: 0;
  font-size: 11px;
  font-weight: 700;
  background: var(--panel);
  color: var(--ink);
}
.badge.OPEN        { background: #ffffff; }
.badge.PENDING     { background: #e6e6e6; }
.badge.TRANSMITTED { background: #cccccc; }
.badge.CONFIRMED   { background: #ffffff; font-weight: 700; }
.badge.PARTIAL     { background: #d9d9d9; border-style: dashed; }
.badge.MISMATCH    { background: var(--ink); color: #fff; }
.badge.COMPLETED   { background: var(--ink); color: #fff; }
.badge.ARCHIVED    { background: #f0f0f0; color: var(--muted); border-style: dotted; }
.badge.MATCH       { background: #ffffff; font-weight: 700; }
.badge.SENT        { background: #ffffff; font-weight: 700; }
.badge.FAILED      { background: var(--ink); color: #fff; }
.badge.test        { background: #ffffff; border-style: dashed; }
.badge.BUFFERED    { background: #f0f0f0; border-style: dashed; }
.badge.READY       { background: #ffffff; font-weight: 700; }

/* Buffer: running timers and the note above the table */
.timer  { font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
/* Transferred rows are done: kept visible, but stepped back visually */
tr.done td { opacity: .62; }
tr.done .dot-ok { opacity: 1; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }

/* Check column: holds the full list of issues, so it gets room and a
   smaller type size instead of pushing the order columns off screen. */
/* Buffer bookkeeping columns: kept a step smaller than the order data */
.buf-col   { font-size: 10px; }
.resp-col  { font-size: 10px; }
/* Fulfilment column: the "information missing ..." wording needs to wrap */
.status-col { white-space: normal; min-width: 150px; max-width: 210px; line-height: 1.25; }
/* What exactly deviates -- kept very small, it is detail not a headline */
.deviation  { font-size: 9px; color: var(--ink); }

/* Confirmation boxes from the Engemann response: ticked = confirmed,
   empty = nothing back yet, empty with a red frame = the response differs. */
.chk {
  margin: 0 0 0 6px; vertical-align: -1px;
  width: 11px; height: 11px; accent-color: #1eb955; cursor: default;
}
.chk-bad { accent-color: #d02a2a; outline: 1px solid #d02a2a; }
.check-col { min-width: 300px; max-width: 420px; line-height: 1.3; }
.hint  { color: var(--muted); font-size: 12px; margin: -8px 0 16px; max-width: 70ch; }

.ok    { color: var(--ink); }
.bad   { color: var(--ink); font-weight: 700; }
.warn  { color: var(--muted); }
.err   { color: var(--ink); font-weight: 700; }
.muted { color: var(--muted); }

/* ---------- Filter bar ---------- */
.filterbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filterbar input[type=text], .filterbar input[type=password], .filterbar select {
  padding: 6px 10px; border: 1px solid var(--ink); border-radius: 0;
  background: var(--panel); font-size: 13px; font-family: var(--ui);
}
.filterbar input:focus, .filterbar select:focus { outline: none; background: var(--accent-soft); }
.filterbar label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 5px; }

/* ---------- Detail view ---------- */
.detail-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.detail-head h2 { margin: 0; }
.detail-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 20px; }
.kv div .k { color: var(--muted); font-size: 12px; }
.kv div .v { font-weight: 700; }

pre.json {
  background: var(--ink); color: #e8e8e8;
  padding: 14px; border-radius: 0; border: 1px solid var(--ink);
  overflow-x: auto; font-size: 12.5px; line-height: 1.5;
  max-height: 480px; overflow-y: auto;
}
details summary { cursor: pointer; color: var(--accent); margin: 8px 0; font-size: 12px; }

/* ---------- Timeline / events ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--ink); }
.timeline li:last-child { border-bottom: none; }
.timeline .ts { color: var(--muted); font-size: 12px; min-width: 150px; }
.timeline .ev { font-weight: 700; min-width: 220px; }
.timeline .det { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--panel); color: var(--ink);
  padding: 12px 18px; border: 1px solid var(--ink); border-radius: 0;
  box-shadow: var(--shadow);
  max-width: 440px; z-index: 100;
  white-space: pre-line;
  font-size: 13px;
}
.toast.err { background: var(--ink); color: #fff; }

.pagination { display: flex; gap: 8px; align-items: center; margin-top: 14px; color: var(--muted); font-size: 12px; }

a { color: var(--ink); }
a:hover { background: var(--ink); color: #fff; }
