/* Пульт котельной: светлая эмаль щита, графит, латунь для действий. Одна яркая деталь — огонёк
   вердикта; остальное — спокойные плоские панели без теней. */
:root {
  --enamel: #edefea;
  --panel: #f7f8f5;
  --ink: #1f2522;
  --muted: #69716c;
  --rule: #d8dcd5;
  --brass: #94661c;
  --ok: #2f7a4e;
  --warn: #b27b12;
  --bad: #b9442a;
  --drawer-h: 42vh;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --enamel: #161a18;
    --panel: #1d2220;
    --ink: #e3e7e1;
    --muted: #8f978f;
    --rule: #2d3430;
    --brass: #d3a24f;
    --ok: #5dbb86;
    --warn: #e2ad48;
    --bad: #e7795c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--enamel);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
body.drawer-open { padding-bottom: var(--drawer-h); }
h1, h2 { margin: 0; line-height: 1.2; }
a { color: inherit; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; border-radius: 4px; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }

/* --- кнопки --- */
.btn {
  font: inherit; font-size: 14px; color: var(--ink); cursor: pointer;
  background: transparent; border: 1px solid var(--rule); border-radius: 8px;
  padding: 5px 12px; line-height: 1.3; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { border-color: var(--brass); color: var(--brass); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--brass); color: var(--panel); border-color: var(--brass); }
.btn-quiet { border-color: transparent; color: var(--muted); }
.btn-quiet:hover:not(:disabled) { color: var(--ink); border-color: var(--rule); }
.btn-small { font-size: 13px; padding: 2px 9px; border-radius: 6px; }
.btn.armed, .btn.armed:hover { background: var(--bad); border-color: var(--bad); color: #fff; }

/* --- шапка --- */
.top {
  display: flex; align-items: center; gap: 16px;
  max-width: 1180px; margin: 0 auto; padding: 14px 20px 0;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .01em; }
.updated { color: var(--muted); font-size: 13px; margin-left: auto; }
.top form { margin: 0; }

.overview { max-width: 1180px; margin: 0 auto; padding: 12px 20px 40px; }

/* --- вердикт: единственная яркая деталь --- */
.verdict {
  display: flex; gap: 20px; align-items: flex-start;
  padding: 26px 28px; border-radius: 16px;
  background: color-mix(in srgb, var(--ok) 9%, var(--panel));
}
.verdict-warn { background: color-mix(in srgb, var(--warn) 12%, var(--panel)); }
.verdict-bad { background: color-mix(in srgb, var(--bad) 13%, var(--panel)); }
.verdict h1 { font-size: 34px; font-weight: 750; letter-spacing: -.015em; }
.verdict-text { min-width: 0; }
.verdict-note { margin: 8px 0 0; color: var(--muted); }
.pilot {
  flex: none; width: 22px; height: 22px; margin-top: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--ok) 18%, transparent),
              0 0 22px 4px color-mix(in srgb, var(--ok) 45%, transparent);
}
.pilot-warn { background: var(--warn); --glow: var(--warn); animation: flicker 2.4s ease-in-out infinite; }
.pilot-bad { background: var(--bad); --glow: var(--bad); animation: flicker 1.1s ease-in-out infinite; }
.pilot-warn, .pilot-bad {
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--glow) 20%, transparent),
              0 0 24px 6px color-mix(in srgb, var(--glow) 50%, transparent);
}
@keyframes flicker { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .pilot { animation: none !important; } }
.issues { margin: 12px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.issues li { padding-left: 18px; position: relative; }
.issues li::before {
  content: ""; position: absolute; left: 2px; top: .62em; width: 7px; height: 7px; border-radius: 50%;
}
.issue-bad::before { background: var(--bad); }
.issue-warn::before { background: var(--warn); }
.busy { margin: 12px 0 0; font-weight: 600; color: var(--warn); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* --- машина --- */
.machine {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 28px;
  margin: 26px 4px 0;
}
.gauge { min-width: 0; }
.gauge-head { display: flex; align-items: baseline; justify-content: space-between; }
.gauge-label { color: var(--muted); font-size: 14px; }
.gauge-percent { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.gauge-bar { display: block; width: 100%; height: 6px; margin: 6px 0 6px; }
.gauge-bar .track { fill: var(--rule); }
.gauge-bar .fill { fill: var(--ok); }
.gauge-bar .mark { stroke: var(--panel); stroke-width: .8; }
.gauge-warn .fill { fill: var(--warn); } .gauge-warn .gauge-percent { color: var(--warn); }
.gauge-bad .fill { fill: var(--bad); } .gauge-bad .gauge-percent { color: var(--bad); }
.gauge-foot { display: grid; gap: 4px; }
.gauge-value { color: var(--muted); font-size: 13px; }
.spark { display: block; width: 100%; height: 26px; }
.spark polyline { fill: none; stroke: var(--muted); stroke-width: 1.3; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.gauge-warn .spark polyline { stroke: var(--warn); }
.gauge-bad .spark polyline { stroke: var(--bad); }
.machine-note { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 13px; }

/* --- кто ест ресурсы --- */
.procs { margin: 24px 4px 0; }
.procs-summary {
  display: flex; align-items: baseline; gap: 4px 14px; flex-wrap: wrap;
  cursor: pointer; list-style: none; padding: 4px 0;
}
.procs-summary::-webkit-details-marker { display: none; }
.procs-summary::before {
  content: "▸"; color: var(--muted); font-size: 13px; width: 10px; transition: transform .15s;
}
.procs[open] > .procs-summary::before { transform: rotate(90deg); }
.procs-summary:hover h2 { color: var(--brass); }
.procs h2 { font-size: 17px; }
.procs-lead { color: var(--muted); font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.procs-lead b { color: var(--ink); font-weight: 600; }
.procs-body { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; min-width: 0; }
.procs-head { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.segmented .btn[aria-pressed="true"] { border-color: var(--brass); color: var(--brass); font-weight: 600; }
.procs-span { color: var(--muted); font-size: 13px; }
.procs-custom { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; font-size: 14px; }
.procs-custom[hidden] { display: none; }
.procs-custom label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.procs-custom input {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--enamel);
  border: 1px solid var(--rule); border-radius: 8px; padding: 3px 8px;
}
.procs-hint { color: var(--muted); font-size: 13px; }
.procs-empty { margin: 0; color: var(--muted); font-size: 14px; }
.procs-foot { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.procs-foot .machine-note { margin: 0; }

/* Таблица процессов — как в htop: одна на всё, отличается только сортировка. */
.table-scroll { overflow-x: auto; min-width: 0; }
.ptable { width: 100%; border-collapse: collapse; font-size: 14px; }
.ptable th {
  text-align: left; font-weight: 400; color: var(--muted); font-size: 13px;
  padding: 4px 8px; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
.ptable td { padding: 4px 8px; border-bottom: 1px solid var(--rule); vertical-align: middle; white-space: nowrap; }
.ptable th:first-child, .ptable td:first-child { padding-left: 0; }
.ptable .num { text-align: right; font-variant-numeric: tabular-nums; }
.ptable th.sorted, .ptable th.sorted .th-sort { color: var(--brass); font-weight: 600; }
.ptable td.cmd { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; }
.ptable .muted, .ptable td.muted { color: var(--muted); }
.ptable td.muted { font-size: 13px; }
.ptable .col-graph { width: 110px; }
.ptable .col-graph .spark { width: 110px; height: 22px; }
.ptable .col-actions { text-align: right; }
.ptable .col-actions .btn + .btn { margin-left: 4px; }
.th-sort {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer;
  text-decoration: underline dotted; text-underline-offset: 3px;
}
.th-sort::after { content: " ↓"; visibility: hidden; }
.sorted .th-sort::after { visibility: visible; }
.ptable tr.signalled td { opacity: .45; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- плитки проектов --- */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 28px; }
.tile {
  background: var(--panel); border-radius: 14px; padding: 18px 20px 16px;
  display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.tile-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tile-head h2 { font-size: 19px; font-weight: 700; }
.tile-link { color: var(--muted); font-size: 13px; margin-left: auto; overflow-wrap: anywhere; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot-ok { background: var(--ok); } .dot-warn { background: var(--warn); } .dot-bad { background: var(--bad); }
.tile-head .dot { width: 11px; height: 11px; }
.tile-error { margin: 0; color: var(--bad); }
.version { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.pr { color: var(--muted); margin-right: 2px; }
.facts { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 14px; }
.facts div { display: contents; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.services { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.service {
  display: grid; grid-template-columns: auto minmax(70px, max-content) 1fr auto; align-items: center;
  gap: 4px 10px; padding: 7px 0; border-bottom: 1px solid var(--rule);
}
.service-name { font-weight: 600; }
.service-state { color: var(--muted); font-size: 13px; min-width: 0; }
.service-actions { display: flex; gap: 6px; justify-content: flex-end; }
.tile-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 4px; }

/* --- последние действия --- */
.jobs { margin-top: 32px; }
.jobs h2 { font-size: 17px; margin-bottom: 8px; }
.job-list { list-style: none; margin: 0; padding: 0; }
.job {
  display: grid; grid-template-columns: 110px 1fr auto auto; gap: 12px; align-items: center;
  padding: 6px 0; border-bottom: 1px solid var(--rule); font-size: 14px;
}
.job-when { color: var(--muted); }

/* --- нижняя панель: логи и вывод задач --- */
.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--drawer-h); z-index: 10;
  display: flex; flex-direction: column;
  background: var(--panel); border-top: 1px solid var(--rule);
  box-shadow: 0 -10px 30px -18px rgba(0, 0, 0, .35);
}
.drawer[hidden] { display: none; }
.drawer-grip { height: 10px; cursor: ns-resize; flex: none; position: relative; touch-action: none; }
.drawer-grip::after {
  content: ""; position: absolute; left: 50%; top: 3px; width: 44px; height: 4px; margin-left: -22px;
  border-radius: 2px; background: var(--rule);
}
.drawer-head {
  display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap;
  padding: 0 20px 10px; border-bottom: 1px solid var(--rule);
}
.drawer-title { font-size: 16px; font-weight: 700; }
.drawer-state { font-size: 14px; }
.filters { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; flex: 1; }
.filters[hidden] { display: none; }
.filters select, .filters input[type="search"] {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--enamel);
  border: 1px solid var(--rule); border-radius: 8px; padding: 4px 8px;
}
.filters input[type="search"] { width: 220px; max-width: 100%; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.drawer-body {
  flex: 1; margin: 0; overflow: auto; padding: 12px 20px;
  font: 12.5px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--ink);
  white-space: pre;
}
.drawer-body.wrap { white-space: pre-wrap; word-break: break-word; }
.drawer-body .l-bad { color: var(--bad); }
.drawer-body .l-warn { color: var(--warn); }
.drawer-body mark { background: color-mix(in srgb, var(--brass) 35%, transparent); color: inherit; border-radius: 2px; }
.drawer-foot { padding: 6px 20px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--rule); }

/* --- вход --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-form { width: min(340px, 100%); display: grid; gap: 14px; }
.login-form h1 { font-size: 24px; margin-bottom: 6px; }
.login-form label { display: grid; gap: 5px; color: var(--muted); font-size: 14px; }
.login-form input {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--panel);
  border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px;
}
.login-form .btn { padding: 10px; font-size: 15px; }
.login-error { margin: 0; color: var(--bad); }

/* --- узкие экраны --- */
@media (max-width: 900px) {
  .machine { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiles { grid-template-columns: minmax(0, 1fr); }
  .ptable .col-user { display: none; }
}
@media (max-width: 560px) {
  .top, .overview { padding-left: 16px; padding-right: 16px; }
  .verdict { padding: 20px 18px; gap: 14px; }
  .verdict h1 { font-size: 26px; }
  .pilot { width: 18px; height: 18px; margin-top: 5px; }
  .machine { gap: 14px 18px; }
  .service { grid-template-columns: auto 1fr; }
  .service-state { grid-column: 2; }
  .service-actions { grid-column: 1 / -1; justify-content: flex-start; padding-left: 19px; }
  /* На телефоне — только главное: имя, цифры, кнопки; полная команда — во всплывающей подсказке. */
  .ptable .col-where, .ptable .col-graph { display: none; }
  .ptable td.cmd .muted { display: none; }
  .ptable td.cmd { min-width: 110px; }  /* имя не сжимается до трёх букв; лишнее — прокруткой */
  .job { grid-template-columns: 1fr auto; }
  .job-when { grid-column: 1 / -1; font-size: 12px; }
  .drawer-head { padding: 0 16px 10px; }
  .drawer-body { padding: 10px 16px; }
  body { --drawer-h: 60vh; }
}
