/* Process Monitor Terminal — terminal chrome, themes, textures.
 * Monospace-led fidelity baseline; every dimension in ch/em so the same
 * layout stretches from a laptop to a wall display via root scaling.
 * Theme switches are hard cuts (no transitions), exactly like tmux. */

:root {
  --scan-opacity: 0.5;
}

html { font-size: clamp(10px, 0.42vw + 8.2px, 22px); }

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: ui-monospace, "SF Mono", Menlo, Monaco, "Cascadia Mono",
    "DejaVu Sans Mono", Consolas, "Liberation Mono", monospace;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  line-height: 1.35;
}

/* ---------------- themes (hard cut, no transition) ---------------- */

body[data-theme="green"] {
  --bg: #050a06;
  --bg-raise: #081208;
  --fg: #3dff70;
  --fg-dim: #1f9440;
  --fg-faint: #14591f;
  --accent: #3dff70;
  --accent-2: #9dffb8;
  --warn: #e8c545;
  --err: #ff5d4d;
  --ok: #4dff88;
  --sel-bg: #1f9440;
  --sel-fg: #04140a;
  --border: #1c6b31;
  --border-focus: #3dff70;
  --status-bg: #1f9440;
  --status-fg: #04140a;
  --glow: 0 0 0.35ch rgba(61, 255, 112, 0.22);
}

body[data-theme="amber"] {
  --bg: #0c0803;
  --bg-raise: #140d05;
  --fg: #ffb000;
  --fg-dim: #a86f10;
  --fg-faint: #5c3c08;
  --accent: #ffb000;
  --accent-2: #ffd88a;
  --warn: #ffe08a;
  --err: #ff6b4a;
  --ok: #ffd24d;
  --sel-bg: #a86f10;
  --sel-fg: #140b00;
  --border: #7a5410;
  --border-focus: #ffb000;
  --status-bg: #a86f10;
  --status-fg: #140b00;
  --glow: 0 0 0.35ch rgba(255, 176, 0, 0.2);
}

body[data-theme="modern"] {
  --bg: #0f1319;
  --bg-raise: #141a22;
  --fg: #c7d3e0;
  --fg-dim: #6d7d92;
  --fg-faint: #3c4a5d;
  --accent: #56b6c2;
  --accent-2: #98c379;
  --warn: #e5c07b;
  --err: #e06c75;
  --ok: #98c379;
  --sel-bg: #2c3b52;
  --sel-fg: #e6f0fa;
  --border: #26313f;
  --border-focus: #56b6c2;
  --status-bg: #1b2430;
  --status-fg: #9fb4cc;
  --glow: none;
}

/* ---------------- frame ---------------- */

#frame {
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 0.4ch solid var(--border);
  border-top-width: 0.9ch;
  border-bottom-width: 0;
  position: relative;
}

.content {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  background: var(--bg);
}

.layout-root { height: 100%; display: flex; }
.layout-root > .pane-frame { flex: 1 1 auto; }

.split { display: flex; min-height: 0; min-width: 0; height: 100%; }
.split-h { flex-direction: row; }
.split-v { flex-direction: column; }
.split-first, .split-second { min-width: 0; min-height: 0; display: flex; }

.split-handle {
  flex: 0 0 0.5ch;
  background: var(--border);
  position: relative;
  z-index: 5;
}
.handle-h { cursor: col-resize; width: 0.5ch; }
.handle-v { cursor: row-resize; height: 0.5ch; }
.split-handle:hover, body.dragging .split-handle { background: var(--border-focus); }

/* ---------------- panes ---------------- */

.pane-frame {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  background: var(--bg);
}
.pane-frame.focused {
  border-color: var(--border-focus);
  box-shadow: inset 0 0 0 1px var(--border-focus);
}

.pane-title {
  flex: none;
  font-size: 0.78em;
  color: var(--fg-dim);
  background: var(--bg-raise);
  border-bottom: 1px solid var(--border);
  padding: 0 0.5ch;
  white-space: nowrap;
  overflow: hidden;
  cursor: default;
  user-select: none;
}
.pane-frame.focused .pane-title { color: var(--bg); background: var(--border-focus); }
.pane-frame.focused .pane-title::after { content: attr(data-hint); opacity: 0.75; margin-left: 1ch; }
.pane-frame.zoomed .pane-title::before { content: "[Z] "; }

.pane-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: 0.3ch 0.6ch;
  font-size: 0.86em;
  white-space: pre;
  text-shadow: var(--glow);
}

.pane-footer {
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--bg-raise);
  font-size: 0.74em;
  color: var(--fg-dim);
  overflow: hidden;
  white-space: pre;
}

/* ---------------- htop ---------------- */

.htop { display: flex; flex-direction: column; white-space: normal; }
.h-header { color: var(--fg); white-space: nowrap; overflow: hidden; }
.h-header b { color: var(--accent-2); }
.h-gap { display: inline-block; width: 3ch; }
.h-meters { margin: 0.2em 0; }
.h-meter { white-space: pre; overflow: hidden; }
.m-label { color: var(--fg-dim); }
.m-val { color: var(--accent-2); }
.h-memval { color: var(--fg-dim); margin-left: 1ch; }

.bar { letter-spacing: 0; }
.bar-low { color: var(--accent); }
.bar-mid { color: var(--warn); }
.bar-hi { color: var(--err); }

.h-cols { color: var(--fg-dim); border-bottom: 1px solid var(--border); white-space: pre; }
.h-rows { flex: 1 1 auto; overflow: hidden; margin-top: 1px; }
.h-row { white-space: pre; overflow: hidden; cursor: pointer; }
.h-row:hover { background: var(--bg-raise); }
.h-row.sel { background: var(--sel-bg); color: var(--sel-fg); }
.h-row.sel .h-cmd { color: var(--sel-fg); }
.h-row .h-cells { color: inherit; }
.h-cmd { color: var(--accent-2); }
.h-row.kthread .h-cmd { color: var(--fg-dim); }
.h-row.svc .h-cmd { color: var(--warn); }
.h-row.sel.svc .h-cmd { color: inherit; }
.h-more { color: var(--fg-faint); }
.h-note { min-height: 1.3em; color: var(--err); white-space: pre; }
.h-note:not(.visible) { visibility: hidden; }

.h-foot { display: flex; gap: 0.6ch; margin: 0 -0.6ch -0.3ch; padding: 0 0.4ch; }
.fkey { white-space: nowrap; }
.fkey b { color: var(--bg); background: var(--fg-dim); padding: 0 0.4ch; }
.fkey:hover b { background: var(--accent); }
.h-foot .fkey:first-child { margin-left: -0.4ch; }

/* ---------------- logs ---------------- */

.logs { padding: 0.2ch 0; }
.log-view { height: 100%; overflow-y: auto; overflow-x: hidden; white-space: pre-wrap; word-break: break-word; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.log-line { padding: 0 0.5ch; }
.log-stamp { color: var(--fg-faint); }
.log-src { color: var(--fg-dim); }
.lv-debug { color: var(--fg-faint); }
.lv-info { color: var(--fg); }
.lv-ok { color: var(--ok); }
.lv-warn { color: var(--warn); }
.lv-error { color: var(--err); }
.lv-error .log-src, .lv-warn .log-src { color: inherit; }

/* ---------------- shell ---------------- */

.shell { white-space: normal; cursor: text; }
.sh-out-wrap { height: 100%; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; outline: none; white-space: pre-wrap; }
.sh-user { color: var(--ok); }
.sh-path { color: var(--accent); }
.sh-dim, .sh-dollar { color: var(--fg-dim); }
.sh-out { padding-left: 1ch; }
.sh-out.ok { color: var(--ok); }
.sh-out.err { color: var(--err); }
.sh-out.warn { color: var(--warn); }
.sh-out.dim { color: var(--fg-dim); }
.sh-typed { color: var(--fg); }
.sh-cursor {
  display: inline-block; width: 0.62em; height: 1.05em;
  background: var(--fg); vertical-align: text-bottom;
  animation: blink 1.06s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sh-cursor { animation: none; } }

.sh-input {
  position: absolute; opacity: 0; width: 1px; height: 1px;
  left: -9999px; pointer-events: none;
}

/* ---------------- net ---------------- */

.pane-body[data-pane="net"] { font-size: 0.74em; line-height: 1.26; }

.net-sec {
  color: var(--bg); background: var(--fg-dim); display: inline-block;
  padding: 0 0.6ch; margin: 0.1em 0 0.2em; font-size: 0.92em;
}
.net-ifname { color: var(--accent-2); white-space: pre; }
.net-desc { color: var(--fg-dim); }
.net-cum { color: var(--fg-faint); float: right; }
.net-row { white-space: pre; }
.net-dir { color: var(--fg-dim); display: inline-block; width: 3ch; }
.net-spark { color: var(--accent); letter-spacing: 0.05ch; }
.net-cur { color: var(--fg); }
.net-ping { white-space: pre; }
.net-pname { display: inline-block; width: 11ch; color: var(--fg); }
.net-ping.hot .net-pname, .net-ping.hot .net-ms, .net-ping.hot .net-spark { color: var(--err); }
.net-ping.hot .net-loss { color: var(--err); }
.net-ms { color: var(--fg); display: inline-block; width: 10ch; }
.net-loss { color: var(--fg-dim); }

/* ---------------- services ---------------- */

.services { white-space: pre; overflow-x: hidden; }
.svc-head { color: var(--fg-faint); border-bottom: 1px solid var(--border); }
.svc-row { cursor: pointer; }
.svc-row:hover { background: var(--bg-raise); }
.svc-row.sel { background: var(--sel-bg); color: var(--sel-fg); }
.svc-row.sel .svc-addr, .svc-row.sel .svc-checks, .svc-row.sel .svc-since, .svc-row.sel .svc-rs { color: inherit; }
.st-running .svc-dot { color: var(--ok); }
.st-running .svc-state { color: var(--ok); }
.st-degraded .svc-dot, .st-degraded .svc-state { color: var(--err); }
.st-starting .svc-dot, .st-starting .svc-state,
.st-stopping .svc-dot, .st-stopping .svc-state { color: var(--warn); }
.st-down .svc-dot, .st-down .svc-state { color: var(--err); }
.svc-dot { display: inline-block; width: 2ch; }
.svc-name { color: var(--fg); }
.svc-state { display: inline-block; width: 11ch; }
.svc-checks, .svc-since, .svc-rs { color: var(--fg-dim); }
.svc-addr { color: var(--fg-faint); }
.svc-row.pulse { animation: pulse 0.75s steps(2) 3; }
@keyframes pulse { 50% { filter: brightness(1.9); } }
.svc-hint { border-top: 1px solid var(--border); color: var(--fg-dim); white-space: pre; }
.svc-hint b { color: var(--fg); background: var(--bg-raise); padding: 0 0.4ch; }

/* ---------------- disk ---------------- */

.disk-head { color: var(--fg-faint); border-bottom: 1px solid var(--border); white-space: pre; overflow: hidden; }
.disk-row { white-space: pre; overflow: hidden; }
.disk-dev { color: var(--fg); }
.disk-size, .disk-used, .disk-pct { color: var(--fg-dim); }
.disk-mnt { color: var(--accent-2); }
.disk-io { color: var(--fg-faint); }
.disk-row.hot .disk-pct { color: var(--err); }
.disk-warn { color: var(--warn); white-space: normal; }

/* ---------------- sys ---------------- */

.sys-clock {
  font-size: 3.2em; line-height: 1.05; color: var(--accent);
  text-shadow: var(--glow); letter-spacing: 0.06em;
}
.sys-date { color: var(--fg-dim); margin-bottom: 0.4em; }
.sys-host { color: var(--fg); }
.sys-sess { color: var(--fg-faint); }
.sys-line { color: var(--fg); margin-top: 0.25em; white-space: pre; overflow: hidden; }
.sys-line b { color: var(--accent-2); }
.sys-loadhist { color: var(--fg-dim); letter-spacing: 0.05ch; }
.heat { display: inline-block; width: 1.4ch; text-align: center; }
.heat-0 { color: var(--fg-faint); }
.heat-1 { color: var(--fg-dim); }
.heat-2 { color: var(--accent); }
.heat-3 { color: var(--warn); }
.heat-4 { color: var(--err); }
.sys-alerts.hot { color: var(--err); }
.sys-alerts.calm { color: var(--ok); }
.sys-notes { margin-top: 0.5em; border-top: 1px solid var(--border); padding-top: 0.3em; }
.sys-note { color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sys-note.dim { color: var(--fg-faint); }

/* ---------------- status bar ---------------- */

.statusbar {
  flex: none;
  display: flex;
  justify-content: space-between;
  background: var(--status-bg);
  color: var(--status-fg);
  font-size: 0.82em;
  padding: 0 0.2ch;
  user-select: none;
  white-space: pre;
  overflow: hidden;
  position: relative;
}
.sb-left, .sb-right { display: flex; }
.sb-sess { background: var(--bg); color: var(--accent); padding: 0 0.6ch; }
.sb-sess.prefix { background: var(--err); color: #fff; }
.sb-win { padding: 0 0.7ch; cursor: pointer; }
.sb-win.on { background: var(--bg); color: var(--accent); }
.sb-win:hover:not(.on) { background: rgba(0, 0, 0, 0.18); }
.sb-right > span { padding: 0 0.6ch; }
.sb-clock { background: var(--bg); color: var(--accent); }
.sb-paused { color: var(--status-fg); cursor: pointer; }
.sb-paused.on { background: var(--err); color: #fff; }
.sb-theme, .sb-help { cursor: pointer; }
.sb-help { background: var(--bg); color: var(--accent); }
.sb-message {
  position: absolute; bottom: 100%; left: 0;
  background: var(--err); color: #fff; padding: 0.1em 1ch;
  white-space: pre;
}

/* ---------------- overlays ---------------- */

#overlays { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.ovl {
  pointer-events: auto;
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--bg-raise); color: var(--fg);
  border: 2px solid var(--border-focus);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.55);
  padding: 1.2em 1.6em; font-size: 0.9em; max-width: 92vw; max-height: 90vh; overflow: auto;
}
.ovl-title { color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 0.35em; margin-bottom: 0.5em; }
.ovl-foot { margin-top: 0.8em; color: var(--fg-dim); }
.dim { color: var(--fg-dim); }

.help-cols { display: flex; gap: 2.2em; }
.help-cols > div { min-width: 24ch; }
.help-h { color: var(--accent); margin: 0.3em 0 0.2em; }
.help-cols b { color: var(--accent-2); background: var(--bg); padding: 0 0.3ch; }

.pick-row { padding: 0.15em 0.5em; cursor: pointer; }
.pick-row:hover { background: var(--sel-bg); color: var(--sel-fg); }
.pick-row.on { background: var(--sel-bg); color: var(--sel-fg); }

.detach { text-align: center; font-size: 1.1em; cursor: pointer; }

.bigclock { text-align: center; }
#bigclock { font-size: 5em; color: var(--accent); letter-spacing: 0.04em; }

.pane-number {
  position: absolute; z-index: 30;
  background: var(--err); color: #fff;
  font-size: 1.6em; font-weight: bold;
  padding: 0 0.5ch; margin: 0.2em;
  pointer-events: none;
}

/* ---------------- scanlines & vignette ---------------- */

body::after {
  content: "";
  position: fixed; inset: 0; z-index: 60; pointer-events: none;
  background: repeating-linear-gradient(0deg,
    rgba(0, 0, 0, 0.16) 0px, rgba(0, 0, 0, 0.16) 1px,
    transparent 1px, transparent 3px);
  opacity: var(--scan-opacity);
}
body[data-theme="modern"]::after { opacity: 0.3; }
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 59; pointer-events: none;
  background: radial-gradient(ellipse at center,
    transparent 58%, rgba(0, 0, 0, 0.32) 100%);
}

/* ---------------- connect screen ---------------- */

.connect {
  padding: 1.2em; color: var(--fg); font-size: 0.95em; white-space: pre-wrap;
}

/* ---------------- small-viewport note ---------------- */

.smallnote {
  display: none; position: fixed; inset: auto 0 0 0; z-index: 50;
  justify-content: center;
}
.smallnote.show { display: flex; }
.smallnote-box {
  background: var(--bg-raise); color: var(--fg);
  border: 2px solid var(--warn); border-bottom: 0;
  padding: 1em 1.4em; max-width: 46ch; font-size: 0.9em;
}
.smallnote-title { color: var(--warn); margin-bottom: 0.4em; }
.smallnote p { color: var(--fg-dim); margin: 0.3em 0; }
.smallnote-actions { margin-top: 0.6em; display: flex; align-items: center; gap: 1ch; }
.smallnote button {
  font: inherit; background: var(--warn); color: #140b00;
  border: 0; padding: 0.2em 1em; cursor: pointer;
}

body.attached-small .layout-root { display: block; overflow-y: auto; height: 100%; }
body.attached-small .layout-root .split { display: block; height: auto; }
body.attached-small .layout-root .split-first { height: auto !important; flex: none !important; }
body.attached-small .layout-root .split-handle { display: none; }
body.attached-small .pane-frame { border-left: 0; border-right: 0; max-height: 46vh; }
body.attached-small .pane-body { overflow-y: auto; }

@media (max-width: 959px) {
  .sb-host, .sb-date { display: none; }
}

/* selection & focus */
::selection { background: var(--sel-bg); color: var(--sel-fg); }
body.dragging { cursor: inherit; user-select: none; }
