/* MaxRunTime PPC - standalone web UI. No external resources. */
:root {
  --navy: #0F1B2D;
  --rail: #16243A;
  --accent: #2563EB;
  --bg: #F3F5F8;
  --card: #FFFFFF;
  --border: #E2E6EC;
  --good: #16A34A;
  --warn: #D97706;
  --bad: #DC2626;
  --muted: #6B7280;
  --text: #111827;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  min-width: 0;
}
h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ell { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- frame ---------- */
.app {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}
.topbar {
  grid-column: 1 / -1;
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  min-width: 0;
}
.brand { font-weight: 600; font-size: 16px; white-space: nowrap; }
.plant-name {
  color: #CBD5E1;
  min-width: 0;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 0 1 auto;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; min-width: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  white-space: nowrap;
}
.chip-k { color: #94A3B8; }
.chip-v { font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #94A3B8; flex: none; }
.s-good .dot { background: #22C55E; }
.s-warn .dot { background: #F59E0B; }
.s-bad .dot { background: #EF4444; }
.s-info .dot { background: #60A5FA; }
.s-bad { border-color: rgba(239, 68, 68, .6); }

.rail {
  background: var(--rail);
  color: #CBD5E1;
  display: flex;
  flex-direction: column;
  padding: 10px 0;
  min-width: 0;
}
.rail a {
  color: #CBD5E1;
  text-decoration: none;
  padding: 10px 18px;
  border-left: 3px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail a:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.rail a.active { background: rgba(37, 99, 235, .22); border-left-color: var(--accent); color: #fff; font-weight: 600; }
.rail-foot {
  margin-top: auto;
  padding: 12px 18px 4px;
  font-size: 12px;
  color: #94A3B8;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  overflow-wrap: anywhere;
}
.linkbtn {
  background: none; border: 0; padding: 0; color: #93C5FD; cursor: pointer; font: inherit; text-decoration: underline;
}

.main { padding: 16px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.page { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* ---------- banners and messages ---------- */
.banner { padding: 9px 14px; border-radius: 6px; font-weight: 600; }
.banner-bad { background: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }
.banner-warn { background: #FEF3C7; color: #92400E; border: 1px solid #FCD34D; font-weight: 500; }
.msg { margin-top: 8px; font-size: 13px; padding: 7px 10px; border-radius: 6px; overflow-wrap: anywhere; }
.msg ul { margin: 4px 0 0 18px; padding: 0; }
.msg-ok { background: #DCFCE7; color: #14532D; }
.msg-bad { background: #FEE2E2; color: #991B1B; }
.msg-info { background: #EFF6FF; color: #1E3A8A; }
.help { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value {
  font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 36px;
}
.kpi-unit { font-size: 14px; color: var(--muted); margin-left: 5px; font-weight: 400; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.kv > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv > span:first-child { color: var(--muted); flex: none; }
.kv > span:last-child { font-variant-numeric: tabular-nums; text-align: right; }

.bar { position: relative; height: 8px; background: #E5E7EB; border-radius: 4px; margin: 6px 0; overflow: visible; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); border-radius: 4px; transition: width .4s; }
.bar-mark { position: absolute; top: -4px; bottom: -4px; width: 3px; margin-left: -1px; background: var(--text); border-radius: 1px; }

.word {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.word::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.word-lg { font-size: 15px; padding: 3px 12px; }
.w-good { color: var(--good); background: #DCFCE7; }
.w-warn { color: #B45309; background: #FEF3C7; }
.w-warn::before { background: var(--warn); }
.w-bad { color: var(--bad); background: #FEE2E2; }
.w-muted { color: var(--muted); background: #F3F4F6; }
.w-info { color: var(--accent); background: #DBEAFE; }

/* stale values when the PPC is not reachable */
body.stale .live { opacity: .45; filter: grayscale(1); }

/* ---------- tiles ---------- */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tile { border: 1px solid var(--border); border-radius: 6px; padding: 10px; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.tile.off { background: #FAFAFA; }
.tile-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-pct { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile-pct .u { font-size: 12px; color: var(--muted); margin-left: 3px; font-weight: 400; }
.tile-mw { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

/* ---------- forms ---------- */
.btn {
  background: #fff; color: var(--text);
  border: 1px solid #CBD5E1; border-radius: 6px;
  padding: 7px 14px; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: #1D4ED8; }
.btn-danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.active { background: #DBEAFE; border-color: var(--accent); color: #1E3A8A; font-weight: 600; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.row-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.confirm {
  margin-top: 10px; padding: 10px; border: 1px solid #FCD34D; background: #FFFBEB; border-radius: 6px;
}
.confirm .btn-row { margin-top: 8px; }

input[type=number], input[type=text], input[type=password], input[type=datetime-local], select {
  font: inherit; color: var(--text);
  border: 1px solid #CBD5E1; border-radius: 6px; padding: 6px 8px; background: #fff;
  min-width: 0; max-width: 100%;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid #93C5FD; outline-offset: 1px; }
.sp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 10px; min-width: 0; }
.sp-label { min-width: 110px; font-weight: 600; }
.inp-unit { display: inline-flex; align-items: center; gap: 6px; }
.inp-unit input { width: 130px; }
.inp-unit span { color: var(--muted); }
.sp-now { color: var(--muted); font-size: 13px; flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.fgroup { border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px 14px; margin: 0 0 12px; min-width: 0; }
.fgroup legend { font-weight: 600; padding: 0 6px; }
.fgroup .help { margin: 0 0 10px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field input[type=number], .field select { width: 100%; }
.field-hint { font-size: 11px; color: var(--muted); }
.field-err { font-size: 12px; color: var(--bad); min-height: 0; overflow-wrap: anywhere; }
.field.changed input, .field.changed select { border-color: var(--accent); background: #EFF6FF; }
.field.invalid input { border-color: var(--bad); background: #FEF2F2; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; padding: 5px 0; }
.switch input { width: 18px; height: 18px; margin: 0; }
.field.changed .switch { color: #1E3A8A; }
.save-bar { align-items: center; }

.enable-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px 16px; }
.enable-row {
  display: flex; align-items: center; gap: 8px; min-width: 0; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px;
}
.enable-row input { width: 18px; height: 18px; margin: 0; flex: none; }
.enable-row .ell { flex: 1 1 auto; }
.enable-row .word { flex: none; }
.droop-line { margin-top: 10px; }
.droop-line .word { flex: none; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; min-width: 0; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; vertical-align: middle; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: #F9FAFB; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .name-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.tbl .barcell { min-width: 160px; }
.tbl .note-cell { max-width: 360px; }
.tbl .addr-cell { padding: 3px 6px; }
.addr-in { width: 90px; text-align: right; font-variant-numeric: tabular-nums; background: #EFF6FF !important; border-color: #93C5FD !important; padding: 3px 6px !important; }
select.addr-in { width: 100px; text-align: left; }
.addr-in.fmt-scale { width: 80px; }
.addr-in.changed { background: #FEF3C7 !important; border-color: var(--warn) !important; }
.addr-in.invalid { background: #FEE2E2 !important; border-color: var(--bad) !important; }
.gm-bar {
  position: sticky; bottom: 0; z-index: 4;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  margin-top: 10px; padding: 8px 12px; border-radius: 6px;
  background: #FFFBEB; border: 1px solid #FCD34D; box-shadow: 0 -2px 8px rgba(0, 0, 0, .06);
}
.gm-bar span { font-weight: 600; flex: 1 1 140px; min-width: 0; }
.card-head .ell { flex: 1 1 200px; }
.barcell .bc { display: flex; align-items: center; gap: 8px; }
.barcell .bc .bar { flex: 1 1 80px; min-width: 60px; margin: 0; }
.barcell .bc span { font-variant-numeric: tabular-nums; min-width: 60px; text-align: right; }

/* ---------- summary ---------- */
.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 16px; }
.summary .si { min-width: 0; }
.summary .sk { color: var(--muted); font-size: 12px; }
.summary .sv { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

/* ---------- history toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.custom { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.custom label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; min-width: 0; min-height: 60px; }
.chart-box { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: #374151; margin-bottom: 6px; }
.lg { display: inline-flex; align-items: center; white-space: nowrap; }
.sw { display: inline-block; width: 20px; height: 0; border-top: 2px solid; margin-right: 6px; flex: none; }
.chart .grid { stroke: #EEF0F3; stroke-width: 1; }
.chart .grid-x { stroke: #F3F4F6; stroke-width: 1; }
.chart .axis { stroke: #CBD5E1; stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11px; font-family: "Segoe UI", system-ui, sans-serif; }
.chart .nodata { fill: var(--muted); font-size: 13px; font-family: "Segoe UI", system-ui, sans-serif; }
.chart .cursor { stroke: #64748B; stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; top: 8px; pointer-events: none; z-index: 5;
  background: var(--navy); color: #fff; font-size: 12px; padding: 7px 9px; border-radius: 6px;
  white-space: nowrap; box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}
.tip-t { font-weight: 600; margin-bottom: 3px; }
.tip-r { display: flex; align-items: center; gap: 6px; }
.tip-r .tip-l { color: #CBD5E1; flex: 1 1 auto; }
.tip-r b { font-variant-numeric: tabular-nums; margin-left: 10px; }

/* ---------- operator help ---------- */
.help-row { display: inline-flex; align-items: center; gap: 5px; min-width: 0; max-width: 100%; }
.help-row > :first-child { min-width: 0; }
.field > .help-row { display: flex; }
.enable-row .help-row { flex: 1 1 auto; }
.help-btn {
  flex: none; width: 16px; height: 16px; padding: 0; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; font: 700 11px/16px "Segoe UI", system-ui, sans-serif;
  text-align: center; cursor: pointer;
}
.help-btn:hover { background: #1D4ED8; }
.help-btn:focus-visible { outline: 2px solid #93C5FD; outline-offset: 1px; }
.help-pop {
  position: fixed; z-index: 200; max-width: min(360px, calc(100vw - 16px));
  background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 13px; line-height: 1.4; box-shadow: 0 8px 24px rgba(15, 27, 45, .18);
  overflow-wrap: anywhere; white-space: normal;
}
.help-pop-t { font-weight: 600; margin-bottom: 4px; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15, 27, 45, .55);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-box {
  background: #fff; border-radius: 8px; padding: 18px 20px; width: 380px; max-width: 100%;
  display: flex; flex-direction: column; gap: 8px; box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.modal-box input { width: 100%; }
.key-msg { margin: 0; color: var(--muted); font-size: 13px; }
.key-msg.bad-text { color: var(--bad); font-weight: 600; }

/* ---------- narrower screens ---------- */
@media (max-width: 1100px) {
  .app { grid-template-columns: 160px minmax(0, 1fr); }
  .rail a { padding: 9px 14px; }
  .rail-foot { padding: 12px 14px 4px; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 140px minmax(0, 1fr); }
  .main { padding: 12px; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .chips { margin-left: 0; }
}
@media (max-width: 640px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { flex-direction: row; flex-wrap: wrap; padding: 0; }
  .rail a { border-left: 0; border-bottom: 3px solid transparent; padding: 9px 12px; }
  .rail a.active { border-bottom-color: var(--accent); }
  .rail-foot { margin-top: 0; width: 100%; flex-direction: row; flex-wrap: wrap; gap: 4px 14px; padding: 6px 12px; }
}

/* users and change log */
.rail-user { margin-bottom: 6px; line-height: 1.5; }
.log-detail { max-width: 640px; white-space: normal; word-break: break-word; font-size: 12px; }
#log-table tr.log-bad td { color: var(--bad, #b91c1c); }
.nowrap { white-space: nowrap; }

/* availability (status tiles + dispatch table) */
.tile.down { border-color: var(--bad); background: #FEF2F2; }
.tile-avail { font-size: 12px; color: var(--bad); overflow-wrap: anywhere; line-height: 1.3; }
.tbl tr.row-down td { background: #FEF2F2; }
.tbl .avail-cell { white-space: normal; min-width: 140px; max-width: 320px; }
.tbl .avail-cell .small { overflow-wrap: anywhere; }

/* setup page */
.msg-warn { background: #FEF3C7; color: #92400E; }
#page-setup h3 { font-size: 14px; margin: 14px 0 6px; }
#st-result.stale-result { opacity: .5; }
#im-table select.im-reg { width: 340px; max-width: 60vw; text-align: left; }
#im-table .addr-in.im-unit { width: 70px; text-align: left; }
#im-file { max-width: 100%; }

/* Status page: controls and setpoints in force */
.ctl-strip { margin-bottom: 12px; }
.ctl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ctl { display: flex; flex-direction: column; gap: 5px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line, #E2E6EC); border-radius: 8px; }
.ctl-k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.ctl-sp { font-weight: 600; font-variant-numeric: tabular-nums; }
.ctl-sp .muted { font-weight: 400; }

/* ---------- config tabs and edit tables (Tray parity) ---------- */
.ctab-bar { margin-bottom: 12px; }
#page-config h3, #page-users h3 { font-size: 14px; margin: 14px 0 6px; }
.tbl .ed { padding: 3px 6px; }
.tbl .ed input[type=text], .tbl .ed input[type=number], .tbl .ed select { width: 100%; min-width: 70px; padding: 3px 6px; }
.tbl .ed input.w-name { min-width: 130px; }
.tbl .ed input.w-num { width: 90px; min-width: 70px; text-align: right; }
.tbl .ed input[type=checkbox] { width: 18px; height: 18px; }
.tbl .ed .changed, .tbl tr.row-new td { background: #FEF3C7; }
.tbl .ed .invalid { background: #FEE2E2 !important; border-color: var(--bad) !important; }
.tbl .wrap-cell { white-space: normal; min-width: 140px; max-width: 320px; overflow-wrap: anywhere; }
.bk-sec { margin-top: 10px; }
.bk-sec ul { margin: 4px 0 0 18px; padding: 0; font-size: 12px; font-family: Consolas, monospace; }
