/* PicoFarm process screen: dark control-room theme. Status colours are fixed (good / warning /
   serious / critical) and always paired with a text label; the trend line uses one blue. */
:root {
  --bg: #141413; --surface: #1a1a19; --panel: #20201f; --line: #3a3a37; --pipe: #5d5c57;
  --text: #f0efec; --text2: #c3c2b7; --muted: #8f8e86;
  --water: #1f4a72; --water-top: #3987e5; --flow: #3987e5; --series: #3987e5;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
.bar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { letter-spacing: 0.12em; color: var(--text2); font-size: 13px; }
.brand b { color: var(--text); }
.grow { flex: 1; }
.clock { font-variant-numeric: tabular-nums; color: var(--text2); }
select, input { font: inherit; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
input[type=number] { width: 90px; }
.btn { font: inherit; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--text2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn.go { background: var(--good); border-color: var(--good); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #141413; font-weight: 700; }
.btn:disabled { opacity: 0.4; cursor: default; }
.estop { font: inherit; font-weight: 800; letter-spacing: 0.08em; background: var(--crit); color: #fff; border: 2px solid #ff8f8f; border-radius: 8px; padding: 8px 18px; cursor: pointer; }
.estop:disabled { opacity: 0.45; }
.estop.latched { animation: blink 1s steps(2, start) infinite; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; border: 1px solid var(--line); color: var(--text2); }
.pill.ok::before, .pill.bad::before, .pill.stale::before { content: "●"; margin-right: 6px; }
.pill.ok::before { color: var(--good); }
.pill.stale::before { color: var(--warn); }
.pill.bad { border-color: var(--crit); }
.pill.bad::before { color: var(--crit); }
.login { max-width: 360px; margin: 60px auto; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.err { color: var(--serious); }

/* annunciator */
.annunciator { display: flex; gap: 10px; align-items: stretch; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.tiles { flex: 1; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 6px; }
.tile { border: 1px solid var(--line); border-radius: 4px; padding: 6px 4px; text-align: center; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; color: var(--muted); background: var(--bg); line-height: 1.2; min-height: 36px; display: flex; align-items: center; justify-content: center; }
.tile.warn { background: var(--warn); color: #141413; border-color: var(--warn); }
.tile.crit { background: var(--crit); color: #fff; border-color: #ff8f8f; }
.tile.unack { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { background: var(--bg); color: var(--text); } }
.ann-btns { display: flex; flex-direction: column; gap: 6px; }

/* layout */
.layout { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(320px, 1fr); gap: 12px; padding: 12px 14px; }
.mimic-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
#mimic { width: 100%; height: auto; display: block; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 8px; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.panel h3 { margin: 0; font-size: 13px; letter-spacing: 0.08em; color: var(--text2); text-transform: uppercase; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.panel-head h3 { flex: 1; }
.seg { display: flex; gap: 2px; }
.seg button { font: inherit; font-size: 12px; background: transparent; color: var(--muted); border: 1px solid transparent; border-radius: 5px; padding: 2px 8px; cursor: pointer; }
.seg button.on { color: var(--text); border-color: var(--line); background: var(--panel); }

/* loop faceplates */
.loops { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.loop { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.loop:hover, .loop:focus-visible { border-color: var(--text2); outline: none; }
.loop .top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.loop .tagname { font-size: 11px; color: var(--muted); letter-spacing: 0.06em; }
.loop .name { font-size: 12px; color: var(--text2); letter-spacing: 0.06em; }
.loop .pv { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.loop .pv small { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.loop .sp { font-size: 12px; color: var(--text2); font-variant-numeric: tabular-nums; }
.loop .bar-outer { height: 6px; background: var(--bg); border-radius: 3px; margin-top: 6px; position: relative; overflow: hidden; }
.loop .bar-band { position: absolute; top: 0; bottom: 0; background: #2e3d2e; }
.loop .bar-pv { position: absolute; top: -2px; bottom: -2px; width: 3px; background: var(--text); border-radius: 2px; }
.mode { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 4px; border: 1px solid var(--line); color: var(--text2); }
.mode.auto { border-color: var(--good); color: var(--text); }
.mode.auto::before { content: "● "; color: var(--good); }
.loop.alarm { border-color: var(--warn); }
.hold { grid-column: 1 / -1; font-size: 12px; color: var(--text2); padding: 6px 10px; border: 1px dashed var(--line); border-radius: 8px; }

/* trends */
.trend { margin: 6px 0 10px; }
.trend .th { display: flex; justify-content: space-between; font-size: 12px; color: var(--text2); }
.trend .th b { color: var(--text); font-variant-numeric: tabular-nums; }
.trend .plot { position: relative; height: 110px; background: var(--bg); border-radius: 4px; }
.trend .plot svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.trend .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend .dot { fill: var(--series); }
.trend .band { fill: rgba(12, 163, 12, 0.12); }
.trend .grid { stroke: var(--line); stroke-width: 1; }
.trend .axis { fill: var(--muted); font-size: 10px; }
.trend .hair { stroke: var(--text2); stroke-width: 1; }
.trend .hit { fill: transparent; }
.tip { position: fixed; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 12px; z-index: 20; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.4); }
#trend-table table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
#trend-table th, #trend-table td { text-align: right; padding: 2px 6px; border-bottom: 1px solid var(--line); }
#trend-table th:first-child, #trend-table td:first-child { text-align: left; }

/* events */
.events { list-style: none; margin: 6px 0 0; padding: 0; max-height: 240px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.events li { display: flex; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); font-size: 12px; }
.events time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.events .lv { font-weight: 700; font-size: 10px; padding: 1px 5px; border-radius: 3px; align-self: flex-start; }
.events .lv.warn { background: var(--warn); color: #141413; }
.events .lv.crit { background: var(--crit); color: #fff; }

/* SVG mimic */
#mimic text { fill: var(--text); }
#mimic .c { text-anchor: middle; }
#mimic .r { text-anchor: end; }
#mimic .lbl { font-size: 13px; fill: var(--text2); letter-spacing: 0.04em; }
#mimic .tag { font-size: 12px; fill: var(--muted); letter-spacing: 0.05em; }
#mimic .state { font-size: 13px; font-weight: 700; letter-spacing: 0.05em; }
#mimic .small { font-size: 12px; fill: var(--text2); }
#mimic .dim { fill: var(--muted); }
#mimic .big { font-size: 44px; font-weight: 650; }
#mimic .pv { font-size: 22px; font-weight: 650; }
#mimic .unit { font-size: 12px; fill: var(--text2); }
#mimic .itag { font-size: 12px; fill: var(--text2); font-weight: 600; }
#mimic .vessel { fill: var(--panel); stroke: var(--pipe); stroke-width: 2; }
#mimic .vessel-wall { fill: none; stroke: #8a8983; stroke-width: 3; }
#mimic .chem { fill: #2a3540; }
#mimic .water { fill: var(--water); }
#mimic .water-top { stroke: var(--water-top); stroke-width: 2; }
#mimic .spline { stroke: var(--text2); stroke-width: 1; stroke-dasharray: 6 5; opacity: 0.7; }
#mimic .pipe { fill: none; stroke: var(--pipe); stroke-width: 6; stroke-linejoin: round; }
#mimic .flow { fill: none; stroke: var(--flow); stroke-width: 3; stroke-dasharray: 10 9; stroke-linejoin: round; opacity: 0; }
#mimic .flow.on { opacity: 1; animation: flow 0.9s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -19; } }
#mimic .arrowhead { fill: var(--flow); }
#mimic .signal { stroke: var(--text2); stroke-width: 1.2; stroke-dasharray: 3 4; }
#mimic .inst circle { fill: var(--panel); stroke: var(--text2); stroke-width: 1.5; }
#mimic .inst line { stroke: var(--text2); stroke-width: 1; }
#mimic .inst.alarm circle { stroke: var(--warn); stroke-width: 3; }
#mimic .probe { stroke: #b9b8b0; stroke-width: 4; stroke-linecap: round; }
#mimic .bulb { fill: #b9b8b0; }
#mimic .pump { cursor: pointer; outline: none; }
#mimic .pump circle { fill: var(--panel); stroke: var(--text2); stroke-width: 2; }
#mimic .pump path { fill: var(--text2); }
#mimic .pump.run circle { fill: var(--good); stroke: #8be08b; }
#mimic .pump.run path { fill: #fff; }
#mimic .pump.ni circle { stroke-dasharray: 4 4; opacity: 0.5; }
#mimic .pump.ni path { opacity: 0.4; }
#mimic .pump:hover circle, #mimic .pump:focus-visible circle { stroke: var(--text); stroke-width: 3; }
#mimic .float line { stroke: var(--text2); stroke-width: 2; }
#mimic .float circle { fill: var(--panel); stroke: var(--text2); stroke-width: 2; }
#mimic .float.active circle { fill: var(--warn); stroke: var(--warn); }
#mimic .float.crit circle { fill: var(--crit); stroke: var(--crit); }
#mimic .float.ni { opacity: 0.35; }
#mimic .s-good { fill: #5fd35f; }
#mimic .s-warn { fill: var(--warn); }
#mimic .s-crit { fill: #ff6b6b; }
#mimic .s-off { fill: var(--muted); }
#mimic .floor { stroke: var(--pipe); stroke-width: 2; }
#mimic .hatch { stroke: var(--line); stroke-width: 2; }
#mimic .inst-small path { fill: var(--panel); stroke: var(--text2); stroke-width: 1.5; }
#mimic .inst-small path.wet { fill: var(--crit); stroke: var(--crit); }
#mimic .stale { font-size: 14px; font-weight: 700; fill: var(--warn); }
#mimic .estop-box { fill: rgba(208, 59, 59, 0.92); stroke: #ff8f8f; stroke-width: 2; }
#mimic .estop-big { font-size: 22px; font-weight: 800; letter-spacing: 0.06em; fill: #fff; }
#mimic .estop-sub { font-size: 12px; fill: #fff; }
#mimic .bad { fill: var(--serious) !important; }

/* faceplate dialog */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(420px, 94vw); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.face { padding: 14px 16px; }
.face header { display: flex; justify-content: space-between; align-items: center; }
.face h3 { margin: 0; font-size: 15px; letter-spacing: 0.04em; }
.face .x { background: none; border: 0; color: var(--text2); font-size: 18px; cursor: pointer; }
.face .kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 10px 0; font-size: 13px; }
.face .kv span:nth-child(odd) { color: var(--muted); }
.face .row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.face label { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 6px 0; }
.face .msg { min-height: 1.2em; font-size: 13px; color: var(--text2); }
.face .msg.bad { color: var(--serious); }

@media (prefers-reduced-motion: reduce) {
  #mimic .flow.on { animation: none; stroke-dasharray: none; }
  .tile.unack { animation: none; outline: 2px solid var(--text); }
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
}
@media (max-width: 560px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* on a phone only the active alarms take space */
  .tile:not(.warn):not(.crit) { display: none; }
  .tiles.quiet::before { content: "No active alarms"; grid-column: 1 / -1; color: var(--text2); font-size: 13px; padding: 6px 2px; }
  .loops { grid-template-columns: 1fr; }
  .annunciator { flex-direction: column; }
  .ann-btns { flex-direction: row; }
}

/* Workstation: the whole process screen in one viewport, no scrolling. Everything below the bar and
   the annunciator shares the remaining height; the mimic scales to fit and the trends are drawn to
   the exact size of their cells. Narrower or shorter screens keep the scrolling layout above. */
@media (min-width: 1100px) and (min-height: 520px) {
  html, body { height: 100%; overflow: hidden; }
  body { display: flex; flex-direction: column; }
  .bar { flex: none; padding: 6px 14px; }
  #hmi { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .annunciator { flex: none; padding: 7px 14px; gap: 8px; }
  .tiles { grid-template-columns: repeat(17, minmax(0, 1fr)); gap: 5px; }
  .tile { font-size: 10px; min-height: 34px; padding: 2px 3px; letter-spacing: 0.02em; }
  .ann-btns { flex-direction: row; align-items: stretch; }
  .layout { flex: 1; min-height: 0; grid-template-columns: minmax(0, 1fr) clamp(330px, 25vw, 600px); padding: 10px 14px; gap: 10px; }
  .mimic-wrap { min-height: 0; display: flex; padding: 4px; }
  #mimic { flex: 1; width: 100%; height: 100%; min-height: 0; }
  .hint { display: none; }
  .side { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 10px; }
  .loops { gap: 8px; }
  .loop { padding: 6px 10px; }
  .loop .pv { font-size: 22px; line-height: 1.15; }
  .hold { padding: 4px 10px; }
  .panel { padding: 8px 10px; }
  .trends-panel { display: flex; flex-direction: column; min-height: 0; }
  #trends { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 6px 10px; }
  #trends[hidden] { display: none !important; }
  #trend-table { flex: 1; min-height: 0; overflow: auto; }
  .trend { display: flex; flex-direction: column; min-height: 0; margin: 0; }
  .trend .plot { flex: 1; height: auto; min-height: 40px; }
  .events-panel { display: flex; flex-direction: column; max-height: 19vh; min-height: 0; }
  .events { flex: 1; min-height: 0; max-height: none; }
}
@media (min-width: 1100px) and (min-height: 520px) and (max-height: 780px) {
  .loop .name { display: none; }
  .events-panel { max-height: 16vh; }
}
@media (min-width: 1100px) and (min-height: 520px) and (max-height: 660px) {
  .loop .sp { display: none; }
  .loop .pv { font-size: 20px; }
  .tile { min-height: 30px; }
  .layout { padding: 8px 14px; gap: 8px; }
  .side { gap: 8px; }
}
