/* --fs: size factor for boxes, icons and charts, set by the header switch
   (Standard 0.85, Large 1, Extra Large 1.2).
   --ts: text factor, set by the same switch (Standard 0.9, Large 1, Extra Large 1.2).
   Type scale: every font size in the application is one of the --t-* steps below,
   so headings, labels, values and tables keep the same proportions at every size.
   Sizes in the comments are at Large; Standard is 10 % smaller (tables 11.7 px). */
:root {
  --fs: 1;
  --ts: 1;
  --t-xs: calc(12px * var(--ts));    /* captions, axis notes, small labels */
  --t-sm: calc(13px * var(--ts));    /* tables, navigation, form fields, secondary text */
  --t-md: calc(14px * var(--ts));    /* body text, card subtitles */
  --t-lg: calc(15px * var(--ts));    /* card titles */
  --t-xl: calc(16px * var(--ts));    /* brand, small figures on cards */
  --t-h1: calc(20px * var(--ts));    /* page titles */
  --t-stat: calc(22px * var(--ts));  /* figures in summary tiles */
  --t-kpi: calc(26px * var(--ts));   /* headline KPI figures */
  --side-w: calc(170px * var(--fs));
  --top-h: calc(56px * var(--fs));
  --top-bg: #18213a;
  --side-bg: #1e2a40;
  --side-text: #e8edf6;
  --side-muted: #aab4c6;
  --accent: #2f6fed;
  --page: #f3f5f9;
  --card: #ffffff;
  --border: #e3e7ee;
  --border-strong: #d4dae4;
  --text: #1f2633;
  --muted: #6b7486;
  --faint: #9aa3b2;
  --th-bg: #f1f3f7;
  --row-alt: #f7f8fb;
  --shadow: 0 1px 3px rgba(20, 30, 55, .06), 0 1px 2px rgba(20, 30, 55, .04);
  --green: #1fa83a;
  --green-bg: #dcf7df;
  --orange: #f29d12;
  --orange-bg: #fdecd2;
  --red: #e5484d;
  --red-bg: #fde0e0;
  --grey: #8a93a3;
  --grey-bg: #e9ecf1;
  --blue: #3478f6;
  --crit: #b4232a;
  --chart-line: #3d63d9;
  --chart-bar: #2dc23a;
}
:root[data-theme="dark"] {
  --page: #0f1522;
  --card: #172033;
  --border: #263149;
  --border-strong: #2f3b55;
  --text: #e6ebf3;
  --muted: #9aa5b8;
  --faint: #6f7a8f;
  --th-bg: #1d2840;
  --row-alt: #1a2438;
  --shadow: 0 1px 3px rgba(0, 0, 0, .3);
  --green-bg: #173d22;
  --orange-bg: #43311a;
  --red-bg: #4a1f24;
  --grey-bg: #2a3348;
}

* { box-sizing: border-box; }
html { height: 100%; }
body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--t-md); line-height: 1.4; color: var(--text); background: var(--page);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  display: grid; grid-template-columns: var(--side-w) 1fr; grid-template-rows: var(--top-h) 1fr;
  grid-template-areas: "top top" "side main";
}
body.collapsed { grid-template-columns: 64px 1fr; }
a { color: var(--blue); text-decoration: none; }
button { font: inherit; cursor: pointer; }
svg { display: block; }

/* ---------------- top bar ---------------- */
.topbar {
  grid-area: top; background: var(--top-bg); color: #fff; display: flex; align-items: center;
  gap: 12px; padding: 0 14px 0 12px; position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 7px; flex: none; margin-right: 4px; }
.brand-mark svg { width: calc(28px * var(--fs)); height: calc(28px * var(--fs)); }
.brand-name { font-size: var(--t-xl); letter-spacing: .2px; white-space: nowrap; }
.brand-name b { font-weight: 700; margin-left: 2px; color: #8fb2ff; }
body.collapsed .brand-name { display: none; }
body.collapsed .brand { width: 32px; }
.icon-btn { background: none; border: 0; color: #fff; padding: 6px; border-radius: 6px; display: inline-flex; position: relative; }
.icon-btn:hover { background: rgba(255,255,255,.08); }
.icon-btn svg { width: calc(22px * var(--fs)); height: calc(22px * var(--fs)); stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
.icon-btn.dark { color: var(--text); }
.icon-btn.dark:hover { background: var(--grey-bg); }
.global-search { flex: 1; max-width: 1060px; }
.global-search input {
  width: 100%; height: calc(30px * var(--fs)); border-radius: 6px; border: 0; background: #2a3550; color: #fff;
  padding: 0 10px; font-size: var(--t-md); outline: none;
}
.global-search input::placeholder { color: #9aa6bd; }
.global-search input:focus { background: #33405e; }
.topbar .user { display: flex; align-items: center; gap: 7px; margin-left: 6px; }
.avatar svg { width: calc(36px * var(--fs)); height: calc(36px * var(--fs)); border-radius: 50%; }
.user-text { display: flex; flex-direction: column; line-height: 1.15; }
.user-text b { font-weight: 500; font-size: var(--t-md); }
.user-text small { font-size: var(--t-sm); color: #d6dceb; }
.chev { width: 16px; height: 16px; stroke: #fff; fill: none; stroke-width: 2; }
/* The badge sets display:grid, which beats the browser's own [hidden] rule; without this
   the bell kept showing "0" after every alarm was acknowledged. */
[hidden] { display: none !important; }
.bell-count {
  position: absolute; top: 0; right: -2px; background: var(--red); color: #fff; font-size: var(--t-xs); font-weight: 700;
  min-width: 15px; height: 15px; border-radius: 8px; display: grid; place-items: center; padding: 0 3px;
}
.cfg-dup { margin: 8px 12px; }
.cfg-dup-in { border: 2px solid #c27a00; background: var(--card); border-radius: 10px; padding: 12px 14px; }
.cfg-dup-in b { font-size: var(--t-md); color: #a76200; }
.note.warn { border-left: 0; color: inherit; background: rgba(194,122,0,.12); border-radius: 8px; padding: 8px 12px; margin: 8px 12px; }
.cfg-dup-in p { margin: 6px 0; }
.cfg-dup-in .acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.cfg-dup-in label { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; font-size: var(--t-sm); }
.cfg-chk { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-sm); color: var(--muted); white-space: nowrap; }
#vDiscBox { margin: 0 10px 10px; }
.health-box { position: fixed; top: calc(64px * var(--fs)); right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.health-card { pointer-events: auto; border-radius: 10px; padding: 10px 12px 10px 14px; font-size: var(--t-sm); line-height: 1.4; box-shadow: 0 6px 20px rgba(0,0,0,.18); display: flex; gap: 10px; align-items: flex-start; }
.health-card b { display: block; font-size: var(--t-md); }
.health-card small { display: block; opacity: .9; }
.health-card.down { background: #8f1d24; color: #fff; }
.health-card.up { background: #146c34; color: #fff; }
.health-card .hc-dot { flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: #fff; }
.health-card.down .hc-dot { animation: hcBlink 1s steps(2, start) infinite; }
.health-card button { margin-left: auto; background: none; border: 0; color: inherit; font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; min-width: 28px; min-height: 28px; }
@keyframes hcBlink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .health-card.down .hc-dot { animation: none; } }
.db-badge { font-size: var(--t-md); background: #7a1d22; color: #ffd9db; padding: 3px 8px; border-radius: 10px; white-space: nowrap; }
.link-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50; background: #b4232a; color: #fff; text-align: center;
  padding: 5px; font-size: var(--t-lg); font-weight: 600;
}
body.offline .content { filter: grayscale(.6); opacity: .75; }

/* ---------------- sidebar ---------------- */
.sidebar {
  grid-area: side; background: var(--side-bg); color: var(--side-text); padding: 18px 0 16px;
  display: flex; flex-direction: column; position: sticky; top: var(--top-h); height: calc(100vh - var(--top-h)); overflow-y: auto;
}
.side-title { font-size: var(--t-md); color: var(--side-text); padding: 6px 11px 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 14px; padding: 0 6px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 8px; color: var(--side-text); font-size: var(--t-sm); padding: 7px 7px;
  border-radius: 4px; line-height: 1.2; padding: 10px 10px;
}
.sidebar nav a svg { width: calc(20px * var(--fs)); height: calc(20px * var(--fs)); fill: currentColor; flex: none; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.side-shift { margin-top: 26px; border-top: 1px solid #3a4862; padding: 14px 11px 0; font-size: var(--t-sm); }
.ss-label { color: var(--side-text); margin-bottom: 14px; }
.ss-name { color: #4d8dff; margin-bottom: 6px; padding-left: 5px; }
.ss-window { margin-bottom: 18px; padding-left: 5px; }
.ss-remaining { margin-bottom: 8px; padding-left: 5px; }
.ss-bar { height: 10px; width: 74%; margin-left: 5px; background: #33415d; border-radius: 1px; overflow: hidden; }
.ss-bar span { display: block; height: 100%; background: #2f74ff; width: 0; }
.ss-donut { width: calc(76px * var(--fs)); height: calc(76px * var(--fs)); margin: 16px 0 0 22px; }
.ss-donut .track { fill: none; stroke: #33415d; stroke-width: 6; }
.ss-donut .fill { fill: none; stroke: #2f74ff; stroke-width: 6; stroke-linecap: round; stroke-dasharray: 150.8; stroke-dashoffset: 150.8; transition: stroke-dashoffset .6s; }
.ss-donut text { fill: #fff; font-size: var(--t-sm); font-weight: 700; }
body.collapsed .sidebar nav a span, body.collapsed .side-shift, body.collapsed .side-title { display: none; }
body.collapsed .sidebar nav a { justify-content: center; }

/* ---------------- content ---------------- */
.content { grid-area: main; padding: 18px 14px 24px 14px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 0 4px 14px; flex-wrap: wrap; }
.page-head h1 { font-size: var(--t-h1); margin: 6px 0 6px; font-weight: 700; }
.page-head .sub { font-size: var(--t-md); color: var(--text); }
.head-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field {
  height: calc(38px * var(--fs)); border: 1px solid var(--border-strong); background: var(--card); color: var(--text);
  border-radius: 3px; padding: 0 10px; font-size: var(--t-md); outline: none;
}
.field:focus { border-color: var(--accent); }
.card { background: var(--card); border-radius: 6px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 10px 6px; }
.card-head b { font-size: var(--t-lg); font-weight: 600; }
.card-head .muted { font-size: var(--t-md); color: var(--text); }
.card-head a { font-size: var(--t-md); }
.chip-live { font-size: var(--t-md); background: var(--orange-bg); color: #9a5a00; padding: 3px 10px; border-radius: 10px; }
.chip-live button { border: 0; background: none; color: var(--blue); padding: 0 0 0 6px; font-size: var(--t-md); }

/* KPI tiles (dashboard) */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 28px; margin: 0 22px 18px; }
.kpi { display: flex; align-items: center; gap: 16px; padding: 18px 18px 20px; min-height: 150px; border: 0; }
.kpi .ico { width: calc(72px * var(--fs)); height: calc(72px * var(--fs)); flex: none; }
.kpi .body { flex: 1; text-align: center; }
.kpi .t { margin-bottom: 10px !important; font-size: var(--t-lg); margin-bottom: 14px; }
.kpi .v { font-size: var(--t-kpi); font-weight: 700; letter-spacing: .2px; }
.kpi .d { font-size: var(--t-sm); margin-top: 14px; }
.up-good { color: var(--green); } .down-bad { color: var(--red); } .flat { color: var(--muted); }

/* tables */
.tbl-wrap { overflow: auto; margin: 0 6px 8px; border: 1px solid var(--border); border-radius: 2px; }
table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
th {
  background: var(--th-bg); font-weight: 700; padding: 6px 8px; text-align: center; position: sticky; top: 0; z-index: 1;
  border-right: 1px solid var(--border); white-space: nowrap; user-select: none; cursor: pointer;
}
th:last-child { border-right: 0; }
th .sort { color: var(--faint); font-size: var(--t-xs); margin-left: 3px; }
td { padding: 8px 8px; text-align: center; border-top: 1px solid var(--border); }
tbody tr:nth-child(even) { background: var(--row-alt); }
td.left, th.left { text-align: left; }
.empty td { color: var(--muted); padding: 18px; }
.sev { font-weight: 500; white-space: nowrap; }
.sev::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-right: 5px; vertical-align: 1px; }
.sev-critical { color: var(--crit); font-weight: 700; } .sev-high { color: var(--red); } .sev-medium { color: var(--orange); } .sev-low { color: var(--blue); }
.st-active {
  display: inline-block; border: 1.5px solid #f2a3a5; color: var(--red); background: var(--card); border-radius: 5px;
  padding: 4px 10px; min-width: 104px; font-size: var(--t-sm); font-weight: 600;
}
/* Action buttons: each keeps one meaning; it never turns into another action. */
.acts { display: inline-flex; gap: 6px; flex-wrap: nowrap; }
.act {
  border: 1.5px solid var(--border-strong); background: var(--card); color: var(--text); border-radius: 5px;
  padding: 4px 10px; min-width: calc(104px * var(--fs)); font-size: var(--t-sm); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.act:disabled { opacity: .5; cursor: default; }
.head-right { display: inline-flex; align-items: center; gap: 12px; }
.btn-outline.sm:disabled { opacity: .5; cursor: default; }
.st-ack {
  display: inline-block; border: 1px solid var(--border-strong); color: var(--text); border-radius: 5px;
  padding: 4px 10px; min-width: 104px; font-size: var(--t-sm); font-weight: 600; background: var(--card);
}

/* status pills */
.pill { display: inline-flex; align-items: center; gap: 8px; font-size: var(--t-sm); font-weight: 600; padding: 4px 9px; border-radius: 12px; white-space: nowrap; }
.pill::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.running { background: var(--green-bg); color: #13852b; }
.pill.idle { background: var(--orange-bg); color: #e08900; }
.pill.stopped { background: var(--red-bg); color: var(--red); }
.pill.comm { background: var(--grey-bg); color: var(--grey); }
.pill.other { background: var(--grey-bg); color: var(--muted); }
:root[data-theme="dark"] .pill.running { color: #4cd469; }
.pill.solid { background: #19c22b; color: #fff; padding: 3px 24px; }
.pill.solid::after { display: none; }
.pill.solid.idle { background: var(--orange); } .pill.solid.stopped { background: var(--red); } .pill.solid.comm, .pill.solid.other { background: var(--grey); }

/* machines page */
.summary { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 0 0 18px; }
.sum { display: flex; align-items: center; gap: 16px; padding: 16px 18px; min-height: 100px; border: 0; }
.sum .sq { width: calc(44px * var(--fs)); height: calc(44px * var(--fs)); border-radius: 7px; display: grid; place-items: center; flex: none; }
.sum .sq svg { width: calc(22px * var(--fs)); height: calc(22px * var(--fs)); }
.sum .t { font-size: var(--t-sm); }
.sum .v { font-size: var(--t-stat); font-weight: 700; margin: 3px 0; }
.sum .s { font-size: var(--t-sm); }
.toolbar { display: flex; gap: 10px; align-items: center; }
.search-box { position: relative; display: flex; align-items: center; gap: 8px; }
.search-box svg { width: 17px; height: 17px; stroke: var(--muted); fill: none; stroke-width: 2; }
.search-box .field { width: 300px; height: calc(36px * var(--fs)); font-size: var(--t-sm); }
.filter-ico svg { width: 17px; height: 17px; stroke: var(--muted); fill: none; stroke-width: 2; }
.toolbar select.field { width: 216px; height: calc(36px * var(--fs)); font-size: var(--t-sm); }
.view-toggle { display: inline-flex; border: 1px solid var(--accent); border-radius: 4px; overflow: hidden; }
.view-toggle button { width: 48px; height: calc(36px * var(--fs)); border: 0; background: var(--card); color: var(--text); display: grid; place-items: center; }
.view-toggle button.on { background: var(--accent); color: #fff; }
.view-toggle svg { width: 18px; height: 18px; fill: currentColor; }
.mgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-bottom: 14px; }
.mcard { border-top: 3px solid var(--grey); border-radius: 5px; padding: 10px 10px 0; display: flex; flex-direction: column; }
.mcard.running { border-top-color: var(--green); } .mcard.idle { border-top-color: var(--orange); } .mcard.stopped { border-top-color: var(--red); }
.mcard.nocomm { opacity: .6; }
.mtop { display: flex; align-items: center; gap: 12px; padding: 0 6px 8px; }
.mtop .bi svg { width: calc(34px * var(--fs)); height: calc(34px * var(--fs)); fill: var(--muted); }
.mtop .nm { flex: 1; min-width: 0; }
.mtop .nm b { font-size: var(--t-lg); display: block; }
.mtop .nm small { font-size: var(--t-sm); color: var(--faint); }
.mstats { display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 0 2px 4px; }
.mstats div { display: flex; flex-direction: column; gap: 9px; }
.mstats div:nth-child(2) { text-align: center; } .mstats div:nth-child(3) { text-align: right; }
.mstats span { font-size: var(--t-xs); font-weight: 700; color: var(--muted); }
.mstats b { font-size: var(--t-xl); }
.mbar { height: 6px; background: var(--grey-bg); border-radius: 2px; margin: 2px 2px 10px; overflow: hidden; }
.mbar span { display: block; height: 100%; background: var(--grey); }
.mcard.running .mbar span { background: var(--green); } .mcard.idle .mbar span { background: var(--orange); } .mcard.stopped .mbar span { background: var(--red); }
.mfoot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding: 9px 14px 9px 22px; color: var(--text); font-size: var(--t-sm); font-weight: 600; }
.mfoot svg { width: 18px; height: 18px; stroke: var(--text); fill: none; stroke-width: 2; }
.mfoot:hover { color: var(--accent); }
.mlist td b { font-weight: 600; }

/* details page */
.crumb { font-size: var(--t-sm); color: var(--muted); font-weight: 600; margin: 0 0 8px 8px; }
.dhead { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 30px; margin: 0 6px 12px 14px; }
.dhead h1 { font-size: var(--t-h1); margin: 0; font-weight: 700; }
.dhead small { font-size: var(--t-sm); color: var(--muted); display: block; margin-top: 3px; }
.dhead .lu { font-size: var(--t-sm); text-align: left; line-height: 1.7; }
.dhead .lu b { font-weight: 600; }
.btn-outline { border: 1px solid var(--accent); color: var(--accent); background: var(--card); border-radius: 3px; height: calc(36px * var(--fs)); padding: 0 36px; font-size: var(--t-sm); font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.btn-outline svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2.4; }
.dgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.dgrid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-items: stretch; }
/* v1.9.1: symmetric 2 x 2 bottom row on Machine Details (Current Status | Downtime by reason,
   Active Alarms | Recent Downtimes); every card fills its cell, lists page instead of scrolling. */
.dgrid2 > .card { display: flex; flex-direction: column; }
.dgrid2 .pie-card .pie-wrap { flex: 1; }
.list-card .tbl-wrap { flex: 1; display: flex; flex-direction: column; }
.list-card .tbl-wrap > table { flex: 0 0 auto; }
.list-card .tbl-wrap > .pager { margin-top: auto; }
.list-card table { font-size: var(--t-sm); }
.list-card td { padding: 5px 6px; }
.list-card th { padding: 4px 6px; }
tbody tr.pad, tbody tr.pad td { border-color: transparent; background: transparent !important; }
tbody tr.pad:hover, tbody tr.pad:hover td { background: transparent !important; }
.pager.compact { position: static; padding: 6px 8px; font-size: var(--t-xs); }
.pager.compact .btn-outline.sm { height: calc(26px * var(--fs)); padding: 0 10px; }
.pie-legend .pager.compact { padding: 6px 0 0; border-top: 0; display: flex; }
.info { display: grid; grid-template-columns: 1fr minmax(180px, 34%); padding: 10px 8px 12px; }
.info h3, .cs h3 { font-size: var(--t-sm); margin: 0 0 8px 2px; font-weight: 700; }
.irow { display: grid; grid-template-columns: 24px calc(140px * var(--fs)) 1fr; align-items: center; gap: 8px; font-size: var(--t-sm); padding: 4.5px 0; }
.irow svg { width: 18px; height: 18px; fill: var(--text); }
.info .img { display: grid; place-items: center; }
.info .img img, .info .img svg { width: 100%; max-width: 240px; max-height: 210px; }
.kstrip { display: grid; grid-template-columns: repeat(5, 1fr); padding: 12px 6px; }
.kstrip > div { display: flex; align-items: center; gap: 8px; padding: 0 6px; border-right: 1px solid var(--border); }
.kstrip > div:last-child { border-right: 0; }
.kstrip .kc { width: calc(34px * var(--fs)); height: calc(34px * var(--fs)); border-radius: 7px; display: grid; place-items: center; flex: none; }
.kstrip .kc svg { width: 20px; height: 20px; }
.kstrip .kt { font-size: var(--t-xs); font-weight: 600; text-align: center; }
.kstrip .kv { font-size: var(--t-lg); font-weight: 700; text-align: center; margin: 3px 0; }
.kstrip .kd { font-size: var(--t-xs); text-align: center; color: var(--muted); }
.kstrip .kd.up-good { color: var(--green); } .kstrip .kd.down-bad { color: var(--red); }
.charts2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.chart-card .card-head { padding: 6px 8px 0; }
.chart-card .card-head b { font-size: var(--t-xs); }
.chart-tools { display: flex; gap: 6px; align-items: center; }
.chart-tools select { height: calc(26px * var(--fs)); font-size: var(--t-xs); padding: 0 4px; border-radius: 3px; border: 1px solid var(--border-strong); background: var(--grey-bg); color: var(--text); }
.chart-tools button { border: 0; background: none; padding: 2px; color: var(--text); }
.chart-tools button svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }
.chart { height: calc(210px * var(--fs)); }
.chart.big { height: 132px; }
.cs { padding: 10px 8px; }
.csrow { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; font-size: var(--t-sm); padding: 4.5px 0; }
.csrow svg { width: 17px; height: 17px; }
.csrow .val { text-align: right; min-width: 70px; }
.csrow .val .pill.solid { padding: 2px 22px; font-size: var(--t-xs); }
.pie-card { padding: 8px 10px; }
.pie-card h3 { font-size: var(--t-md); text-align: center; font-weight: 500; margin: 2px 0 0; }
.pie-wrap { display: grid; grid-template-columns: 1fr minmax(170px, 45%); align-items: center; min-height: 260px; }
.pie-legend { font-size: var(--t-xs); display: flex; flex-direction: column; gap: 8px; }
.pie-legend div { display: grid; grid-template-columns: 14px 1fr auto; gap: 6px; align-items: center; }
.pie-legend i { width: 12px; height: 12px; border-radius: 1px; display: block; }
.na { color: var(--faint); }
.bad-q { color: var(--orange); }

/* generic */
.grid-gap { display: flex; flex-direction: column; gap: 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 6px 10px 10px; }
.filters label { font-size: var(--t-md); color: var(--muted); display: flex; gap: 6px; align-items: center; }
.btn { height: 30px; padding: 0 14px; border-radius: 3px; border: 1px solid var(--accent); background: var(--accent); color: #fff; font-size: var(--t-md); font-weight: 600; }
.note { padding: 18px; color: var(--muted); font-size: var(--t-md); line-height: 1.55; }
.tag { font-size: var(--t-sm); padding: 2px 7px; border-radius: 9px; }
.tag.ok { background: var(--green-bg); color: #13852b; } .tag.bad { background: var(--red-bg); color: var(--red); } .tag.warn { background: var(--orange-bg); color: #9a5a00; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: var(--t-sm); }

.modal { position: fixed; inset: 0; background: rgba(10, 15, 30, .55); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--card); border-radius: 8px; width: min(1100px, 100%); padding: 10px 14px 14px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-chart { height: 60vh; }
.toast { position: fixed; bottom: 18px; right: 18px; background: #222b3d; color: #fff; padding: 10px 14px; border-radius: 6px; z-index: 70; font-size: var(--t-md); max-width: 360px; }

@media (max-width: 1200px) {
  .mgrid { grid-template-columns: repeat(3, 1fr); }
  .kpis { gap: 12px; margin: 0 0 14px; }
  .dgrid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .kpis, .summary { grid-template-columns: repeat(2, 1fr); }
  .mgrid { grid-template-columns: repeat(2, 1fr); }
  .charts2 { grid-template-columns: 1fr; }
  .kstrip { grid-template-columns: repeat(3, 1fr); row-gap: 12px; }
  .search-box .field { width: 180px; }
  .toolbar select.field { width: 130px; }
}
@media (max-width: 640px) {
  body { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .sidebar { position: fixed; left: 0; top: var(--top-h); z-index: 30; width: 200px; transform: translateX(-100%); transition: transform .2s; }
  body.menu-open .sidebar { transform: none; }
  body.collapsed { grid-template-columns: 1fr; }
  .brand { width: auto; }
  .user-text, .chev { display: none; }
  .content { padding: 14px 16px; }
  .kpis, .summary, .mgrid { grid-template-columns: 1fr; }
  .dhead { grid-template-columns: 1fr auto; gap: 10px; }
  .info { grid-template-columns: 1fr; }
  .toolbar { flex-wrap: wrap; }
  .search-box .field { width: 100%; }
}
:root[data-theme="dark"] .tag.warn { color: #f5b85a; }
:root[data-theme="dark"] .tag.ok { color: #4cd469; }
:root[data-theme="dark"] .chip-live { color: #f5b85a; }

/* ---------------- auth ---------------- */
.topbar .user { position: relative; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.topbar .user:hover { background: rgba(255,255,255,.06); }
.user-menu { position: absolute; right: 0; top: calc(50px * var(--fs)); background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(10,15,30,.18); min-width: 200px; z-index: 40; padding: 6px 0; cursor: default; }
.user-menu[hidden] { display: none; }
.um-head { padding: 8px 14px 10px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.um-head small { color: var(--muted); font-size: var(--t-md); }
.user-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 9px 14px; font-size: var(--t-sm); }
.user-menu button:hover { background: var(--grey-bg); }
.auth { position: fixed; inset: 0; z-index: 80; background: linear-gradient(160deg, #18213a 0%, #1e2a40 60%, #25365a 100%); display: grid; place-items: center; padding: 16px; }
.auth[hidden] { display: none; }
.auth-card { background: var(--card); color: var(--text); width: min(380px, 100%); border-radius: 10px; padding: 26px 28px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.auth-brand { display: flex; align-items: center; gap: 9px; font-size: var(--t-h1); margin-bottom: 18px; }
.auth-brand svg { width: 30px; height: 30px; }
.auth-brand b { color: var(--accent); margin-left: 2px; }
.auth h2 { font-size: var(--t-h1); margin: 0 0 14px; }
.auth label { display: flex; flex-direction: column; gap: 5px; font-size: var(--t-md); color: var(--muted); margin-bottom: 12px; }
.auth input { height: 36px; border: 1px solid var(--border-strong); border-radius: 4px; padding: 0 10px; font-size: var(--t-md); background: var(--card); color: var(--text); outline: none; }
.auth input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,111,237,.15); }
.auth .btn { width: 100%; height: 38px; margin-top: 4px; font-size: var(--t-md); }
.auth .btn:disabled { opacity: .6; cursor: wait; }
.btn-link { background: none; border: 0; color: var(--blue); font-size: var(--t-sm); padding: 10px 0 0; width: 100%; }
.auth-foot { font-size: var(--t-md); color: var(--muted); margin: 10px 0 0; line-height: 1.5; }
.auth-msg[hidden] { display: none; }
.auth-msg { display: block; font-size: var(--t-sm); padding: 8px 10px; border-radius: 4px; margin-bottom: 12px; background: var(--red-bg); color: var(--red); line-height: 1.4; }
.auth-msg.m-info { background: var(--orange-bg); color: #9a5a00; }
.auth-msg.m-ok { background: var(--green-bg); color: #13852b; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)) auto; gap: 10px; align-items: end; padding: 4px 10px 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: var(--t-md); color: var(--muted); }
.form-grid .chk { flex-direction: row; align-items: center; gap: 6px; height: 32px; }
.btn.ghost { background: var(--card); color: var(--accent); }
.btn.sm, .btn-outline.sm { height: 24px; padding: 0 9px; font-size: var(--t-sm); }
.act { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.secret { margin: 0 10px 12px; padding: 10px 12px; border-radius: 6px; background: var(--orange-bg); color: var(--text); font-size: var(--t-lg); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.secret code { font-family: Consolas, "Courier New", monospace; font-size: var(--t-h1); font-weight: 700; letter-spacing: 1px; background: var(--card); padding: 3px 8px; border-radius: 4px; }
.sidebar nav a[hidden] { display: none; }
@media (max-width: 900px) { .form-grid { grid-template-columns: 1fr 1fr; } }

/* text size switch in the header */
.fs-switch { display: inline-flex; border: 1px solid #3a4862; border-radius: 6px; overflow: hidden; flex: none; }
.fs-switch button { background: none; border: 0; color: #c9d2e3; padding: 0 9px; height: calc(30px * var(--fs)); font-weight: 600; line-height: 1; }
.fs-switch button[data-fs="0.85"] { font-size: 12px; } .fs-switch button[data-fs="1"] { font-size: 15px; } .fs-switch button[data-fs="1.2"] { font-size: 18px; }
.fs-switch button.on { background: var(--accent); color: #fff; }
@media (max-width: 640px) { .fs-switch { display: none; } }

.kstrip .kv { white-space: nowrap; }
.kstrip .kd { line-height: 1.3; }
@media (max-width: 1500px) {
  .dgrid { grid-template-columns: 1fr; }
}
/* Without the downtime-by-reason card: Current Status | Active Alarms, Recent Downtimes across. */
.dgrid2.no-pie #dDtCard { grid-column: 1 / -1; }
@media (max-width: 900px) { .dgrid2, .dgrid2.no-pie { grid-template-columns: 1fr; } .dgrid2.no-pie #dDtCard { grid-column: auto; } }
@media (max-width: 640px) {
  .topbar { gap: 6px; padding: 0 8px; }
  .brand-name { display: none; }
  .global-search { min-width: 0; }
  .topbar .user { margin-left: 0; padding: 4px 2px; }
}
.dgrid > *, .dgrid2 > *, .info > * { min-width: 0; }
.irow > span { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 640px) { .irow { grid-template-columns: 22px 120px 1fr; } }
.charts2 > *, .kstrip > * { min-width: 0; }
@media (max-width: 640px) { .kstrip { grid-template-columns: repeat(2, 1fr); } .kstrip > div { border-right: 0; } }

/* v1.3.0 energy */
.energy-card { display: grid; grid-template-columns: minmax(230px, 300px) 1fr; }
.energy-card[hidden] { display: none; }
.en-stats { display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 14px 18px; border-right: 1px solid var(--border); }
.en-stat .t { font-size: var(--t-sm); color: var(--muted); font-weight: 600; }
.en-stat .v { font-size: var(--t-stat); font-weight: 700; white-space: nowrap; }
.en-stat .s { font-size: var(--t-xs); color: var(--muted); }
.en-chart { min-width: 0; }
.mstats.en { border-top: 1px dashed var(--border); padding-top: 6px; margin-top: 4px; }
.mstats.en b { font-size: var(--t-md); white-space: nowrap; }
.summary.six { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 1100px) { .summary.six { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) {
  .energy-card { grid-template-columns: 1fr; }
  .en-stats { border-right: 0; border-bottom: 1px solid var(--border); flex-direction: row; flex-wrap: wrap; }
  .summary.six { grid-template-columns: repeat(2, 1fr); }
  .acts { flex-wrap: wrap; }
}
.head-right .btn-outline.sm { white-space: nowrap; }
@media (max-width: 640px) { .card-head:has(.head-right) { flex-wrap: wrap; gap: 6px; } .head-right { flex-wrap: wrap; } }

/* v1.3.1 alarm condition indicators (bell and machines) */
.bell-count { animation: oee-pulse 1.2s ease-in-out infinite; }
.bell-count.ack { background: var(--orange); animation: none; }
@keyframes oee-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.aflag {
  display: flex; align-items: center; gap: 7px; margin: 0 6px 8px; padding: 5px 9px; border-radius: 5px;
  font-size: var(--t-sm); font-weight: 700; text-decoration: none; line-height: 1.25;
}
.aflag svg { width: calc(18px * var(--fs)); height: calc(18px * var(--fs)); flex: none; fill: currentColor; stroke: var(--card); stroke-width: 2.2; }
.aflag span { min-width: 0; }
.aflag.un { background: var(--red); color: #fff; animation: oee-pulse 1.2s ease-in-out infinite; }
.aflag.un svg { stroke: var(--red); }
.aflag.ack { background: var(--orange-bg); color: #8a5300; border: 1px solid var(--orange); }
:root[data-theme="dark"] .aflag.ack { background: rgba(242, 157, 18, .18); color: #ffc46b; }
.aflag.sm { display: inline-flex; margin: 0; padding: 2px 8px; font-size: var(--t-sm); white-space: nowrap; }
.aflag.inl { display: inline-flex; margin: 0 0 0 10px; vertical-align: middle; }
@media (prefers-reduced-motion: reduce) { .bell-count, .aflag.un { animation: none; } }

/* v1.3.2 machine-level alarm state */
.st-cause {
  display: inline-block; border: 1.5px solid var(--orange); color: #8a5300; background: var(--orange-bg); border-radius: 5px;
  padding: 4px 10px; font-size: var(--t-sm); font-weight: 600; white-space: nowrap;
}
:root[data-theme="dark"] .st-cause { background: rgba(242, 157, 18, .18); color: #ffc46b; }
.mstate { padding: 0 10px 6px; font-size: var(--t-sm); color: var(--muted); }
.mstate:empty { display: none; }
#aMach table { margin-bottom: 4px; }
.tbl-wrap.held { outline: 2px dashed var(--orange); outline-offset: -2px; }
.st-ack.gone { opacity: .55; font-style: italic; }
.st-pair { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

/* Proportional alarm columns: short columns shrink to their content, Message takes the rest. */
th.fit, td.fit { width: 1%; white-space: nowrap; }
th.msg, td.msg { width: auto; min-width: calc(140px * var(--fs)); text-align: left; }
td.msg .tag { white-space: nowrap; display: inline-block; margin-left: 4px; }
/* KPI tiles: a 1fr track cannot shrink below its content, which pushed the 4th tile past the
   right edge at about 1000 px. minmax(0, 1fr) lets the tiles share the width evenly. */
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi .body { min-width: 0; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .kpis { grid-template-columns: minmax(0, 1fr); } }

/* v1.4.0 grouped alarm list: one row per alarm, machine and reset cells span the group */
table.grouped td.grp { vertical-align: middle; background: var(--card); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
table.grouped td.grp:first-child { border-left: 0; }
table.grouped tr.grp-first td { border-top: 2px solid var(--border-strong); }
table.grouped tbody tr:nth-child(even) { background: transparent; }
.grp-state { margin-top: 6px; font-size: var(--t-xs); }
.grp-state .st-pair { justify-content: flex-start; }
.grp-state > span, .grp-state .st-pair > span { white-space: normal; padding: 2px 7px; font-size: var(--t-xs); }
table.grouped td.grp:first-child { width: calc(150px * var(--fs)); min-width: calc(120px * var(--fs)); }
table.grouped .act { min-width: 0; }
table.grouped td.wrap { white-space: normal; }
table.grouped td.wrap > span { white-space: normal; max-width: calc(150px * var(--fs)); }
table.grouped .msg-sub { margin-top: 3px; font-size: var(--t-xs); }
table.grouped .act-reset { line-height: 1.2; padding-top: 5px; padding-bottom: 5px; }
table.grouped td, table.grouped th { padding-left: 5px; padding-right: 5px; }

/* v1.4.0 machine image: fixed frame (the size the drawn placeholder had, 240 x 210); any image is
   scaled to fit inside it without stretching; no image or a broken file leaves the frame empty. */
.info .img-frame { position: relative; width: 100%; max-width: 240px; aspect-ratio: 240 / 210; overflow: hidden; }
.info .img-frame img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; object-fit: contain; display: block; }

/* v1.4.1 alarm analytics */
.dgrid-an { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
.dgrid-an > * { min-width: 0; }
.filters .quick { display: inline-flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 1100px) { .dgrid-an { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- v1.5.0 operator actions, lock */

:root { --purple: #6b4fd8; --purple-bg: #ece8fd; }
:root[data-theme="dark"] { --purple-bg: #2c2550; }
/* operator signed in, on cards */
.mop { display: flex; align-items: center; gap: 6px; margin: -2px 0 8px; font-size: var(--t-sm); color: var(--text); font-weight: 600; }
.mop svg { width: calc(17px * var(--fs)); height: calc(17px * var(--fs)); fill: var(--accent); flex: none; }
.mop.none { color: var(--muted); font-weight: 400; }
.mop.none svg { fill: var(--faint); }
/* maintenance lock marker */
.lockflag { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; padding: 6px 10px; border-radius: 6px; background: var(--purple-bg); color: var(--purple); border: 1px solid var(--purple); font-size: var(--t-sm); font-weight: 600; }
.lockflag svg { width: calc(17px * var(--fs)); height: calc(17px * var(--fs)); fill: currentColor; color: currentColor; flex: none; }
.lockflag.inl { display: inline-flex; margin: 0 0 0 10px; vertical-align: middle; }
:root[data-theme="dark"] .lockflag { color: #b9a8ff; }
.tag.lock { background: var(--purple-bg); color: var(--purple); }
/* operator action bar on Machine Details */
.opbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; margin-bottom: 14px; border-left: 0; outline: 2px solid var(--accent); outline-offset: -2px; }
.sb-info { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 280px; }
.sb-info svg { width: calc(30px * var(--fs)); height: calc(30px * var(--fs)); fill: var(--accent); flex: none; color: var(--accent); }
.sb-info b { display: block; }
.sb-info small { display: block; color: var(--muted); font-size: var(--t-sm); }
.sb-acts { display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; }
.act-lock { min-height: 56px; padding: 8px 18px; border: 1px solid var(--purple); color: var(--purple); background: var(--card); border-radius: 6px; font-weight: 600; cursor: pointer; font-size: var(--t-md); }
.act-lock:hover { background: var(--purple-bg); }
.act-lock.armed { background: var(--purple); color: #fff; }
/* unlock form */
.unlock { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.unlock .field { width: 170px; }
/* lock screen (whole operator screen) */
.lockscreen { position: fixed; inset: 0; z-index: 80; background: rgba(28, 20, 66, .92); display: grid; place-items: center; padding: 16px; overflow: auto; }
.lockscreen[hidden] { display: none; }
.ls-card { background: var(--card); color: var(--text); border-radius: 10px; padding: 26px 30px; width: min(620px, 100%); text-align: center; border-top: 6px solid var(--purple); }
.ls-card > svg { width: 64px; height: 64px; fill: var(--purple); color: var(--purple); }
.ls-card h2 { margin: 6px 0 14px; font-size: var(--t-kpi); }
.ls-m { display: grid; gap: 10px; justify-items: center; padding: 12px 0; border-top: 1px solid var(--border); }
.ls-m > b { font-size: var(--t-stat); }
.ls-m span { color: var(--muted); }
.ls-m span b { color: var(--purple); font-size: var(--t-h1); }
.ls-card p { font-size: var(--t-sm); }
/* shift-end prompt */
.sp-card { width: min(520px, 100%); padding: 20px 22px; }
.sp-card h2 { margin: 0 0 8px; }
.sp-acts { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
/* analytics tabs */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin: -4px 0 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 16px; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; font-weight: 600; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.ls-card > svg { display: block; margin: 0 auto; }
/* User Management: machines assigned to an operator (v1.5.1) */
.u-ms { grid-column: 1 / -1; border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px 10px; display: grid; gap: 8px; min-width: 0; }
.u-ms[hidden] { display: none; }
.u-ms legend { color: var(--muted); font-size: var(--t-sm); padding: 0 4px; }
.u-ms-tools { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.u-ms-tools .btn-link { width: auto; padding: 0; font-size: var(--t-sm); cursor: pointer; }
.u-ms-line > b { display: block; font-size: var(--t-sm); color: var(--muted); margin-bottom: 2px; }
.u-ms-boxes { display: flex; flex-wrap: wrap; gap: 0 18px; }
.u-ms .chk { color: var(--text); }
.u-ms small { font-size: var(--t-sm); }
@media (max-width: 640px) { .unlock .field { width: 100%; } }
/* User form on a phone: one column; inputs shrink to the column (they pushed the page sideways) */
.form-grid label > .field { min-width: 0; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

/* v1.5.2 pager: 20 records a page, Previous and Next shown only when a list holds more than 20 records */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px 14px; flex-wrap: wrap; padding: 8px 10px; border-top: 1px solid var(--border); background: var(--card); position: sticky; bottom: 0; left: 0; z-index: 2; font-size: var(--t-sm); }
.pager .pg-info { color: var(--muted); }
.pager .pg-acts { display: inline-flex; align-items: center; gap: 12px; }
.pager .pg-num { font-weight: 600; white-space: nowrap; }
.pager .btn-outline.sm { height: calc(30px * var(--fs)); padding: 0 16px; }

/* ---------------- v1.6.0 Configuration page ---------------- */
.cfg-rev { font-size: var(--t-sm); color: var(--muted); }
.cfg-rev b { color: var(--text); }
.cfg-bar { position: sticky; bottom: 0; z-index: 30; margin: 14px -4px 0; padding: 10px 14px; background: var(--card); border: 2px solid var(--orange); border-radius: 8px; box-shadow: 0 -4px 14px rgba(20, 30, 55, .12); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: var(--t-md); }
.cfg-bar[hidden] { display: none; }
.cfg-bar .field { flex: 1; min-width: 180px; }
.cfg-bar .btn { height: calc(34px * var(--fs)); }
.cfg-check { margin-bottom: 14px; border-left: 5px solid var(--green); }
.cfg-check.bad { border-left-color: var(--red); }
.cfg-check ul { margin: 0 0 10px; padding: 0 14px 0 34px; font-size: var(--t-sm); line-height: 1.5; }
.cfg-check .errs li { color: var(--red); }
.cfg-check .warns li { color: #9a5a00; }
:root[data-theme="dark"] .cfg-check .warns li { color: #f0b860; }
.btn-link.sm { width: auto; padding: 0; font-size: var(--t-sm); }
.field.sm { height: calc(28px * var(--fs)); font-size: var(--t-sm); padding: 0 6px; width: 100%; min-width: 0; }
.cfg-srv { margin-bottom: 14px; padding: 6px 4px 8px; }
.cfg-srv-row { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; padding: 6px 10px; font-size: var(--t-sm); }
.cfg-srv-row label { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.cfg-job { flex: 1; min-width: 240px; }
.cfg-opts { padding: 0 10px 6px; font-size: var(--t-sm); color: var(--muted); }
.cfg-opts summary { cursor: pointer; }
.cfg-opts label { display: inline-flex; gap: 6px; align-items: center; margin: 6px 14px 0 0; }
.cfg-opts .field { width: 110px; }
.cfg-split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 14px; align-items: start; }
.cfg-split.mach { grid-template-columns: minmax(200px, 260px) minmax(0, 1fr); }
.cfg-split > * { min-width: 0; }
#mEd { display: grid; gap: 14px; }
.cfg-search .field { width: min(320px, 50vw); }
.cfg-tree { max-height: calc(70vh); overflow: auto; border-top: 1px solid var(--border); font-size: var(--t-sm); }
.trow { display: grid; grid-template-columns: 18px 18px minmax(120px, 1fr) minmax(70px, auto) minmax(60px, 140px) auto; gap: 6px; align-items: center; padding: 3px 8px; border-bottom: 1px solid var(--border); cursor: pointer; }
.trow:hover { background: var(--row-alt); }
.trow.sel { background: rgba(47, 111, 237, .12); }
.trow.gone .tn { text-decoration: line-through; color: var(--muted); }
.trow svg { width: 16px; height: 16px; }
.tx { display: grid; place-items: center; color: var(--muted); }
.tx svg { transition: transform .15s; }
.tx.open svg { transform: rotate(90deg); }
.tn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tt { color: var(--muted); font-size: var(--t-xs); white-space: nowrap; }
.tv { font-family: Consolas, "Courier New", monospace; font-size: var(--t-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
.tu { display: inline-flex; gap: 4px; }
.tu .tag { font-size: var(--t-xs); }
.tacts { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px 8px; border-bottom: 1px solid var(--border); background: var(--row-alt); }
.cfg-hint { padding: 6px 10px; font-size: var(--t-sm); }
.cfg-side .kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; padding: 4px 12px 12px; font-size: var(--t-sm); word-break: break-word; }
.cfg-side .kv > span:nth-child(odd) { color: var(--muted); }
.cfg-assign { display: grid; gap: 8px; padding: 10px 12px 14px; border-top: 1px solid var(--border); }
.cfg-prop { margin-bottom: 14px; border: 2px solid var(--accent); }
.cfg-ptbl td, .cfg-etbl td { padding: 5px 6px; vertical-align: top; }
.cfg-ptbl td.left .field { min-width: 110px; }
.cfg-ptbl details summary { cursor: pointer; color: var(--accent); white-space: nowrap; }
.cfg-mlist { display: grid; gap: 2px; text-align: left; margin-top: 4px; font-size: var(--t-xs); min-width: 300px; }
.cfg-mlist > div { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border-bottom: 1px dotted var(--border); }
.cfg-notes { font-size: var(--t-sm); color: #9a5a00; min-width: 200px; }
:root[data-theme="dark"] .cfg-notes { color: #f0b860; }
.cfg-mlist-card .cfg-ml { max-height: 70vh; overflow: auto; border-top: 1px solid var(--border); }
.cfg-mi { padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; display: grid; gap: 1px; }
.cfg-mi small { color: var(--muted); font-size: var(--t-xs); }
.cfg-mi .tag { justify-self: start; font-size: var(--t-xs); }
.cfg-mi:hover { background: var(--row-alt); }
.cfg-mi.sel { background: rgba(47, 111, 237, .12); border-left: 4px solid var(--accent); }
.cfg-form { grid-template-columns: repeat(4, minmax(140px, 1fr)); }
.cfg-grp { border-top: 1px solid var(--border); }
.cfg-gh { padding: 8px 12px 2px; font-weight: 700; color: var(--muted); font-size: var(--t-sm); text-transform: uppercase; letter-spacing: .4px; }
.cfg-role { display: grid; grid-template-columns: minmax(150px, 230px) minmax(0, 1fr); gap: 10px; align-items: start; padding: 5px 12px; }
.cfg-role .rl { font-size: var(--t-sm); padding-top: 4px; }
.cfg-role .rl small { display: block; color: var(--muted); font-size: var(--t-xs); }
.cfg-role.off { opacity: .55; }
.tagcell { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 6px; align-items: center; }
.tagcell small { grid-column: 1 / -1; font-size: var(--t-xs); word-break: break-all; }
.cfg-picker { position: absolute; z-index: 90; width: min(560px, calc(100vw - 16px)); box-shadow: 0 10px 34px rgba(20, 30, 55, .3); border: 1px solid var(--border-strong); }
.cfg-picker .field { flex: 1; min-width: 0; }
.cfg-picker .chk { font-size: var(--t-sm); }
.cfg-pk-list { max-height: 50vh; overflow: auto; border-top: 1px solid var(--border); }
.pk-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: var(--t-sm); word-break: break-all; }
.pk-row:hover { background: var(--row-alt); }
.pk-row.sel { background: rgba(47, 111, 237, .14); }
.cfg-feats { display: grid; gap: 8px; padding: 6px 14px 4px; font-size: var(--t-md); }
.cfg-feats .chk { display: flex; gap: 8px; align-items: center; }
.cfg-file { position: relative; overflow: hidden; cursor: pointer; }
.cfg-file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.cfg-banner { margin-bottom: 14px; padding: 14px 18px; border-left: 5px solid var(--accent); font-size: var(--t-md); }
@media (max-width: 1100px) {
  .cfg-split, .cfg-split.mach { grid-template-columns: minmax(0, 1fr); }
  .cfg-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .cfg-form { grid-template-columns: minmax(0, 1fr); }
  .cfg-role { grid-template-columns: minmax(0, 1fr); }
  .trow { grid-template-columns: 18px 18px minmax(0, 1fr) auto; }
  .trow .tv, .trow .tu { display: none; }
  .cfg-bar .acts { flex-wrap: wrap; }
}

/* ---------------- v1.6.0 extended OEE ---------------- */
.oee-card { margin: 8px 0 14px; }
.oee-big { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; padding: 4px 6px 10px; }
.oee-big .ob { padding: 8px 12px; border-right: 1px solid var(--border); }
.oee-big .ob:last-child { border-right: 0; }
.oee-big .obt { font-size: var(--t-sm); font-weight: 600; color: var(--muted); }
.oee-big .obv { font-size: var(--t-stat); font-weight: 700; margin: 2px 0; }
.oee-big .obs { font-size: var(--t-xs); color: var(--muted); }
.oee-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; padding: 0 10px 10px; }
.oee-grid .ot { border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; display: grid; gap: 1px; background: var(--row-alt); }
.oee-grid .ot span { font-size: var(--t-xs); color: var(--muted); }
.oee-grid .ot b { font-size: var(--t-xl); }
.oee-grid .ot small { font-size: var(--t-xs); color: var(--muted); }
.oee-loss { border-top: 1px solid var(--border); margin: 0 6px 6px; }
.perf-strip { margin: -8px 0 22px; padding: 8px 12px 10px; }
.perf-strip[hidden] { display: none; }
.ps-head { font-weight: 600; font-size: var(--t-sm); margin-bottom: 6px; }
.ps-head small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.ps-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 6px; }
.ps-row > div { display: grid; padding: 4px 8px; border-left: 3px solid var(--accent); }
.ps-row span { font-size: var(--t-xs); color: var(--muted); }
.ps-row b { font-size: var(--t-xl); }
.ps-row small { font-size: var(--t-xs); color: var(--muted); }
@media (max-width: 640px) { .oee-big .ob { border-right: 0; border-bottom: 1px solid var(--border); } }

.cfg-assign .btn { justify-self: start; }
.cfg-etbl select.field.sm { width: auto; min-width: 7.5em; }
.cfg-etbl td.left > .field { min-width: 170px; }
.cfg-etbl .tagcell { min-width: 280px; }
#mEd { grid-template-columns: minmax(0, 1fr); }
#mEd > * { min-width: 0; }
.oee-card .card-head { flex-wrap: wrap; gap: 4px 12px; }
.oee-card .card-head .muted { font-size: var(--t-sm); }

/* v1.9.0: alarm times (acknowledged / reset at the SCADA / HMI) */
td small.muted { font-size: var(--t-xs); }

/* v1.9.0: hourly OEE table, one cell per clock hour, coloured by band */
.hmap { border-collapse: separate; border-spacing: 2px; width: max-content; min-width: 100%; }
.hmap th, .hmap td { padding: 6px 8px; font-size: var(--t-sm); }
.hmap th.hm-h { text-align: center; font-weight: 600; color: var(--muted); white-space: nowrap; }
.hmap td.hm { text-align: center; border-radius: 4px; min-width: calc(54px * var(--fs)); font-variant-numeric: tabular-nums; background: var(--row-alt); }
.hmap tbody tr:nth-child(even) { background: transparent; }
.hmap td.left { position: sticky; left: 0; background: var(--card); white-space: nowrap; z-index: 1; }
.hmap tr.hm-row { cursor: pointer; }
.hmap tr.hm-row:hover td.left, .hmap tr.hm-row.on td.left { color: var(--accent); }
.hmap tr.hm-row.on td.left { box-shadow: inset 3px 0 0 var(--accent); }
.hm-good { background: #d7f2de !important; color: #11602a; }
.hm-mid { background: #fdebc8 !important; color: #7a4a00; }
.hm-low { background: #fbd5d6 !important; color: #8f1d22; }
:root[data-theme="dark"] .hm-good { background: rgba(46, 158, 91, .28) !important; color: #9fe3b6; }
:root[data-theme="dark"] .hm-mid { background: rgba(240, 160, 32, .25) !important; color: #ffd08a; }
:root[data-theme="dark"] .hm-low { background: rgba(214, 69, 69, .28) !important; color: #ffb3b5; }
.hmap td.hm-live { font-style: italic; outline: 1.5px dashed var(--border-strong); outline-offset: -2px; }
.hmap th.hm-live { color: var(--accent); }
.hm-legend { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-xs); color: var(--muted); flex-wrap: wrap; }
.hm-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-left: 8px; }
.hm-legend i.hm-good { background: #2e9e5b !important; } .hm-legend i.hm-mid { background: #f0a020 !important; } .hm-legend i.hm-low { background: #d64545 !important; }
.field.hsel { height: calc(30px * var(--fs)); padding: 0 8px; font-size: var(--t-sm); width: auto; }

/* v1.9.1: Shifts (from the PLC) card on Configuration > Shifts and Reasons */
.sh-now, .sh-off { margin: 4px 12px 12px; font-size: var(--t-md); }
.sh-off { padding: 10px 14px; border-radius: 8px; background: var(--warn-bg, rgba(242, 157, 18, .12)); border: 1px solid rgba(242, 157, 18, .45); }
.sh-now .tag { margin-left: 8px; }

/* v1.9.1 type polish: headings a touch tighter, labels calmer, figures crisp */
h1, h2, h3, .page-head h1, .dhead h1 { letter-spacing: -0.01em; line-height: 1.25; }
.kpi .v, .sum .v, .mstats b, .kstrip .kv { letter-spacing: -0.01em; line-height: 1.15; font-variant-numeric: tabular-nums; }
td.num, td.r, .num { font-variant-numeric: tabular-nums; }
.card-head b, .info h3, .cs h3 { letter-spacing: 0; }
th { font-weight: 600; }

/* v1.9.1 TV / kiosk mode: header and sidebar hidden, the open screen fills the display */
.icon-btn#tvBtn svg { fill: none; }
body.kiosk { grid-template-columns: 1fr; grid-template-rows: 1fr; grid-template-areas: "main"; }
body.kiosk .topbar, body.kiosk .sidebar { display: none; }
body.kiosk .content { padding: 14px 18px 18px; }
body.kiosk .health-box { top: 58px; }
body.kiosk.kiosk-idle, body.kiosk.kiosk-idle * { cursor: none !important; }
.kiosk-bar { position: fixed; top: 10px; right: 14px; z-index: 65; display: none; align-items: center; gap: 10px;
  background: rgba(24, 33, 58, .92); color: #fff; border-radius: 8px; padding: 6px 8px 6px 12px; font-size: var(--t-sm);
  box-shadow: 0 6px 20px rgba(0,0,0,.25); transition: opacity .25s; }
body.kiosk .kiosk-bar { display: flex; }
body.kiosk.kiosk-idle .kiosk-bar { opacity: 0; pointer-events: none; }
.kiosk-bar .kb-clock { font-variant-numeric: tabular-nums; color: #d6dceb; }
.kiosk-bar button { background: var(--accent); color: #fff; border: 0; border-radius: 5px; padding: 5px 12px; font-size: var(--t-sm); font-weight: 600; }

/* Settings: every column the same width, so the Connections table and every tag table line up */
table.eqcols { table-layout: fixed; width: 100%; }
table.eqcols th, table.eqcols td { width: 20%; text-align: left; padding-left: 12px; padding-right: 12px; vertical-align: middle; }
table.eqcols td { overflow-wrap: break-word; }
