:root {
  --back: #e8e8e8;
  --header: #1976d2;
  --pane: #ffffff;
  --ink: #282828;
  --muted: #505050;
  --a: rgb(176, 16, 16);
  --b: rgb(232, 118, 12);
  --c: rgb(16, 110, 52);
  --psi: #4169e1;
  --vw: #ff00ff;
  --tk: #00ffff;
  --vt: #d2c4a8;
  --rh: #90ee90;
  --font: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--back);
  color: var(--ink);
  font-family: var(--font);
}
body { display: flex; flex-direction: column; overflow: hidden; }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 8px 12px;
  background: var(--header);
  border-bottom: 1px solid #1565c0;
}
.brand { display: flex; align-items: center; }
.brand img {
  display: block;
  height: 40px;
  width: auto;
  background: #fff;
  border-radius: 8px;
  padding: 4px 8px;
}
nav { display: flex; flex-wrap: wrap; gap: 6px; }
nav a {
  color: #fff;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.18);
}
nav a.active { background: #fff; color: #1565c0; }
.auth-bar { margin-left: auto; display: flex; align-items: center; gap: 10px; color: #fff; font-size: 13px; }
.auth-bar a.auth-users { color: #fff; font-weight: 600; }
.auth-bar button {
  font: 13px var(--font);
  padding: 5px 10px;
  border: 0;
  border-radius: 6px;
  background: #fff;
  color: #1565c0;
  font-weight: 600;
  cursor: pointer;
}
.login {
  max-width: 360px;
  margin: 48px auto;
  padding: 20px;
  background: #fff;
  border: 1px solid #c8c8c8;
}
.login h2 { margin: 0 0 8px; font-size: 20px; }
.login p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.login label { display: block; margin: 10px 0 4px; font-size: 13px; font-weight: 600; }
.login input {
  width: 100%;
  font: 15px var(--font);
  padding: 8px;
}
.login button {
  margin-top: 16px;
  width: 100%;
  font: 15px var(--font);
  font-weight: 700;
  padding: 8px;
  border: 0;
  border-radius: 6px;
  background: var(--header);
  color: #fff;
  cursor: pointer;
}
.login .err { color: var(--a); min-height: 1.2em; }

#view {
  flex: 1;
  min-height: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  flex: 1;
  min-height: 0;
  width: 100%;
}
.grid-alarms {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  flex: 1;
  min-height: 0;
  width: 100%;
}
.pane {
  background: var(--pane);
  border: 1px solid #c8c8c8;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pane h2 {
  margin: 0;
  padding: 6px 10px 0;
  font-size: 18px;
  text-align: center;
}
.status { margin: 0; padding: 0 10px 4px; font-size: 12px; color: var(--muted); text-align: center; }
.inspect-hint { margin: 0; padding: 0 10px 4px; font-size: 11px; color: var(--muted); text-align: center; }
.chart-host { flex: 1; min-height: 0; position: relative; }
.chart-host canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 12px; padding: 4px 10px 8px; font-size: 12px; }
.chk { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; user-select: none; }
.chk input { margin: 0; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.hist {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  align-items: center;
  padding: 6px 10px 10px;
}
.hist button, .hist input {
  font: 13px var(--font);
  padding: 4px 8px;
}
.hist .live-on { background: #b4e6b4; color: #005000; font-weight: 700; }

.pane-alarms { min-height: 0; }
.grid-alarms-mini {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: stretch;
  gap: 0 8px;
}
.alarm-col {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.alarm-list { flex: 1; min-height: 0; overflow: auto; padding: 4px 8px 8px; }
.alarm {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 8px;
  padding: 6px 4px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}
.alarm:hover { background: #f6f6f6; }
.alarm-static { cursor: default; }
.alarm-static:hover { background: transparent; }
.chart-host canvas.no-inspect { cursor: default; }
.alarm .code { font-weight: 700; white-space: nowrap; }
.alarm .desc { font-weight: 400; }
.g-A { color: var(--a); }
.g-B { color: var(--b); }
.g-C { color: var(--c); }

.detail {
  margin: 8px;
  padding: 10px;
  background: #f3f3f3;
  border: 1px solid #ddd;
}
.detail h3 { margin: 0 0 6px; }
.detail h4 { margin: 12px 0 4px; font-size: 13px; }
.detail p { margin: 4px 0; }
.detail ol, .detail ul { margin: 4px 0 0; padding-left: 22px; }
.detail .io { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.detail .pdf-source { margin-top: 14px; padding-top: 7px; }
.detail .help-note { margin: 0 0 10px; font-size: 12px; color: var(--muted); max-width: 52rem; }
.muted { color: var(--muted); }
.detail a { color: #1565c0; }

.one {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.one > .pane { flex: 1; min-height: 0; }

@media (min-width: 801px) {
  .one > .pane h2 {
    font-size: 32px;
    padding: 10px 10px 2px;
  }
  .one .legend { font-size: 16px; gap: 10px 16px; padding: 8px 10px 10px; }
  .one .swatch { width: 14px; height: 14px; }
}

@media (max-width: 800px) {
  html, body { height: auto; min-height: 100%; }
  body { overflow: auto; }
  #view { display: block; flex: none; }
  .one, .one > .pane { flex: none; height: auto; min-height: 0; }
  .grid-2, .grid-alarms, .grid-alarms-mini {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    height: auto;
    flex: none;
  }
  .pane { min-height: 0; }
  .chart-host {
    flex: none;
    width: 100%;
    height: auto;
    min-height: 0;
    aspect-ratio: 2 / 1;
  }
  .brand img { height: 32px; }
}
