/* ============================================================================
   CarbonActive Leitstand-Portal — "honest instrument" control-room aesthetic.
   Discipline (from the HMI house rules): NORMAL is calm/grey; colour is reserved
   for ABNORMAL. A portal full of healthy units is quiet; the stale/offline unit
   is the only thing that lights up. Type: Archivo (signage) + IBM Plex Mono (data).
   ============================================================================ */
:root {
  --bg:        #0b0e12;
  --bg-2:      #0e1218;
  --surface:   #141a22;
  --surface-2: #1a212b;
  --line:      #222b36;
  --line-2:    #2c3745;
  --fg:        #e7edf3;
  --fg-dim:    #93a1b2;
  --fg-faint:  #566473;
  --accent:    #4fd1c5;   /* teal — water & air; interaction/brand only, used sparingly */
  --accent-2:  #2f8f87;
  /* status — the ONLY saturated colours on a healthy screen */
  --online:    #4ec77d;
  --stale:     #e6ad33;
  --offline:   #e5514f;
  --radius: 14px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Archivo", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--fg);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ── command bar ───────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px;
  background: color-mix(in oklab, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 23px; width: auto; display: block; }   /* the real CarbonActive logo (white SVG, vendored) */
/* retained for any legacy markup / the login theme text fallback */
.brand-mark { color: var(--accent); display: grid; place-items: center; }
.brand-word { font-weight: 800; letter-spacing: .01em; font-size: 16px; }
.brand-word .dot-sep { color: var(--accent); }
.brand-tag {
  font-family: var(--mono); font-size: 10px; letter-spacing: .28em; color: var(--fg-faint);
  border: 1px solid var(--line-2); border-radius: 5px; padding: 3px 7px 2px; margin-left: 2px;
}
.sys { display: flex; gap: 8px; margin-left: auto; }
.sys-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 11.5px; color: var(--fg-dim);
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface);
}
.sys-pill b { color: var(--fg); font-weight: 600; }
.sys-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-faint); }
.sys-pill[data-k=online]  .dot { background: var(--online); }
.sys-pill[data-k=stale]   .dot { background: var(--stale); box-shadow: 0 0 0 0 var(--stale); animation: pulse 2.4s var(--ease) infinite; }
.sys-pill[data-k=offline] .dot { background: var(--offline); }
.sys-pill[data-k=online]:has(b:not(:empty)) { }

.user { display: flex; align-items: center; gap: 12px; position: relative; }
.user-meta { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.user-name { font-weight: 600; font-size: 13.5px; }
.user-role { font-family: var(--mono); font-size: 10px; letter-spacing: .18em; color: var(--accent); text-transform: uppercase; }
.avatar {
  width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center;
  font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--bg);
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  border: 0; cursor: pointer; transition: .18s var(--ease);
}
.avatar:hover { filter: brightness(1.08); }
.avatar[aria-expanded="true"] { box-shadow: 0 0 0 3px rgba(79,209,197,.18); }

.menu {
  position: absolute; top: calc(100% + 10px); right: 0; z-index: 20; min-width: 248px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; padding: 6px;
  box-shadow: 0 24px 50px -22px rgba(0,0,0,.85); animation: rise .16s var(--ease) both;
}
.menu[hidden] { display: none; }
.menu-i {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 10px 11px; border-radius: 8px; border: 0; background: none; cursor: pointer;
  color: var(--fg-dim); font-family: var(--sans); font-size: 13.5px; text-decoration: none; transition: .14s var(--ease);
}
.menu-i:hover { background: var(--surface-2); color: var(--fg); }
.menu-i svg { color: var(--fg-faint); flex: none; }
.menu-i:hover svg { color: var(--accent); }
.menu-i.danger:hover { color: var(--offline); }
.menu-i.danger:hover svg { color: var(--offline); }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }
/* launcher (role-gated apps/tools) — two-line items (name + muted sub), app-grid feel à la the HMI UI */
.menu-label { padding: 7px 11px 3px; font-family: var(--mono); font-size: 10px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--fg-faint); }
.tools[hidden], .menu-label[hidden] { display: none; }
.menu-i.tool { align-items: flex-start; gap: 11px; padding: 8px 11px; }
.menu-i.tool svg { margin-top: 2px; }
.tool-txt { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.tool-name { color: var(--fg); font-size: 13.5px; font-weight: 600; }
.tool-sub { color: var(--fg-faint); font-size: 11px; }
.menu-i.tool:hover .tool-sub { color: var(--fg-dim); }

/* ── layout ────────────────────────────────────────────────────── */
main { max-width: 1200px; margin: 0 auto; padding: 46px 28px 40px; }

.hero { margin-bottom: 30px; }
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .32em; text-transform: uppercase; color: var(--fg-faint); margin: 0 0 14px; }
.greeting { font-size: clamp(30px, 5vw, 46px); font-weight: 800; letter-spacing: -.02em; margin: 0 0 8px; }
.greeting .u { color: var(--accent); }
.sub { color: var(--fg-dim); font-size: 15px; margin: 0 0 26px; max-width: 60ch; }
.sub b { color: var(--fg); font-weight: 600; }

.controls { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.search { display: flex; align-items: center; gap: 9px; padding: 0 13px; height: 42px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; color: var(--fg-faint); min-width: 300px; flex: 1 1 300px; max-width: 420px; transition: .18s var(--ease); }
.search:focus-within { border-color: var(--accent-2); color: var(--accent); box-shadow: 0 0 0 3px rgba(79,209,197,.08); }
.search input { background: none; border: 0; outline: 0; color: var(--fg); font-family: var(--sans); font-size: 14px; width: 100%; }
.search input::placeholder { color: var(--fg-faint); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-family: var(--mono); font-size: 12px; letter-spacing: .06em;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--fg-dim); cursor: pointer; transition: .16s var(--ease);
}
.chip:hover { color: var(--fg); border-color: var(--fg-faint); }
.chip[aria-selected="true"] { color: var(--bg); background: var(--fg); border-color: var(--fg); font-weight: 600; }
.chip .n { opacity: .55; margin-left: 5px; }

/* ── the HMI grid ──────────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }

.card {
  position: relative; overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 20px 16px; display: flex; flex-direction: column; gap: 14px;
  transition: border-color .16s var(--ease);
}
/* Calm hover: the border brightens, nothing moves or lifts (muscle-memory — the target stays put). */
.card:hover { border-color: var(--line-2); }
/* left accent bar = status. NORMAL is calm (thin, muted); abnormal is loud. */
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--fg-faint); opacity: .5; }
.card.s-online::before  { background: var(--online); opacity: .55; }
.card.s-stale::before   { background: var(--stale); opacity: 1; }
.card.s-offline::before { background: var(--offline); opacity: 1; }
/* offline/stale units desaturate the whole card so healthy ones recede */
.card.s-offline { filter: saturate(.5) brightness(.92); }
.card.s-offline .unit { color: var(--fg-dim); }

.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.badge { font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: .16em; padding: 4px 8px 3px; border-radius: 6px; border: 1px solid var(--line-2); color: var(--fg-dim); }
.badge.p-FBAW { color: #6cc6e0; border-color: #274a56; background: #0e1b20; }
.badge.p-BnL  { color: #86d08a; border-color: #294d2c; background: #0f1c11; }
.badge.p-IGC  { color: #cbb26a; border-color: #4a4327; background: #1a170e; }

.status { display: inline-flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-dim); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-faint); position: relative; }
.s-online  .status { color: var(--online); }
.s-online  .status .dot { background: var(--online); }
.s-stale   .status { color: var(--stale); }
.s-stale   .status .dot { background: var(--stale); animation: pulse 2.2s var(--ease) infinite; }
.s-offline .status { color: var(--offline); }
.s-offline .status .dot { background: var(--offline); }

.unit { font-size: 19px; font-weight: 700; letter-spacing: -.01em; margin: 0; line-height: 1.2; }
.loc { font-family: var(--mono); font-size: 11.5px; color: var(--fg-faint); margin-top: -8px; letter-spacing: .02em; }

.kpis { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.kpi { display: flex; flex-direction: column; gap: 3px; padding: 7px 11px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; min-width: 78px; }
.kpi .k { font-family: var(--mono); font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-faint); }
/* The number is the dominant element of the tile. tabular-nums = every digit is one fixed width, so
   columns of KPIs align and the value does NOT reflow as its magnitude changes (no flicker/flap). */
.kpi .v {
  font-family: var(--mono); font-size: 20px; font-weight: 600; color: var(--fg);
  line-height: 1.05; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
  display: flex; align-items: baseline; gap: 3px;
}
/* unit de-emphasized + clearly separated from the figure (smaller, dim, never competes with the number) */
.kpi .v .un { font-size: 10.5px; color: var(--fg-faint); font-weight: 400; letter-spacing: .02em; }
.kpi.blind .v { color: var(--fg-faint); }  /* honest: –– never a fake number */
/* Per-KPI severity (ubridge-derived) — colour by exception only; normal/null stays calm grey. */
.kpi.sev-warn  { border-color: var(--stale); }
.kpi.sev-warn  .v { color: var(--stale); }
.kpi.sev-alarm { border-color: var(--offline); background: color-mix(in oklab, var(--offline) 9%, var(--bg)); }
.kpi.sev-alarm .v { color: var(--offline); }
/* honest empty state — the backend sends no KPI tiles until the site publishes */
.kpi-none { font-family: var(--mono); font-size: 11px; color: var(--fg-faint); letter-spacing: .04em; padding: 7px 2px; }

.card-f { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 4px; }
.role { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--fg-dim); }
.role svg { color: var(--fg-faint); }
.role.r-admin, .role.r-engineer { color: var(--accent); }
.role.r-admin svg, .role.r-engineer svg { color: var(--accent); }

.launch {
  display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
  font-size: 13px; font-weight: 600; color: var(--bg); background: var(--fg);
  padding: 9px 15px; border-radius: 9px; transition: .16s var(--ease); border: 1px solid var(--fg);
}
.launch:hover { background: var(--accent); border-color: var(--accent); gap: 10px; }
.launch svg { transition: transform .16s var(--ease); }
.launch:hover svg { transform: translateX(2px); }
.s-offline .launch { background: transparent; color: var(--fg-dim); border-color: var(--line-2); }
.s-offline .launch:hover { color: var(--fg); border-color: var(--fg-faint); background: var(--surface-2); }

.meta { font-family: var(--mono); font-size: 10px; color: var(--fg-faint); letter-spacing: .04em; border-top: 1px dashed var(--line); padding-top: 10px; display: flex; justify-content: space-between; gap: 10px; }
.meta .last { color: var(--fg-dim); }
.s-stale .meta .last, .s-offline .meta .last { color: var(--stale); }
.s-offline .meta .last { color: var(--offline); }

/* ── empty + withheld ──────────────────────────────────────────── */
.empty { text-align: center; padding: 64px 20px; color: var(--fg-dim); }
.empty-t { font-size: 17px; font-weight: 600; margin: 0 0 4px; color: var(--fg); }
.empty-s { font-size: 13.5px; margin: 0; }
.withheld { text-align: center; color: var(--fg-faint); font-family: var(--mono); font-size: 12px; margin: 30px 0 0; letter-spacing: .02em; }
.withheld a { color: var(--accent); text-decoration: none; border-bottom: 1px dotted var(--accent-2); }

/* ── footer ────────────────────────────────────────────────────── */
.foot { max-width: 1200px; margin: 20px auto 40px; padding: 20px 28px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; color: var(--fg-faint); font-size: 12px; }
.mono { font-family: var(--mono); }
.foot-honest { color: var(--fg-faint); }

/* ── motion ────────────────────────────────────────────────────── */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--stale) 60%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 12px 18px; padding: 12px 18px; }
  .sys { order: 3; width: 100%; margin-left: 0; }
  main { padding: 30px 18px; }
  .grid { grid-template-columns: 1fr; }
}
