/* Пульт — тёмная тема по умолчанию, светлая по настройке телефона */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --surface-3: #2e2e2b;
  --border: rgba(255, 255, 255, 0.10);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --accent-wash: rgba(57, 135, 229, 0.14);
  --track: rgba(57, 135, 229, 0.20);
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-wash: rgba(208, 59, 59, 0.16);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --page: #f3f3f0;
    --surface: #fcfcfb;
    --surface-2: #f0efec;
    --surface-3: #e6e5e0;
    --border: rgba(11, 11, 11, 0.10);
    --text: #0b0b0b;
    --text-2: #52514e;
    --muted: #6f6d68;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --accent: #2a78d6;
    --accent-wash: rgba(42, 120, 214, 0.10);
    --track: #cde2fb;
    --critical-wash: rgba(208, 59, 59, 0.10);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.4 var(--font);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 600px; margin: 0 auto;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 8px; flex: none; }
.brand h1 { font-size: 18px; line-height: 1.1; }
.brand .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 5px 11px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-2);
  font-size: 13px; font-weight: 500;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.on .dot { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.pill.wait .dot { background: var(--warning); animation: blink 1.2s infinite; }
.pill.down .dot { background: var(--serious); animation: blink 1.2s infinite; }
.pill.err .dot { background: var(--critical); }
@keyframes blink { 50% { opacity: 0.35; } }

main { max-width: 600px; margin: 0 auto; padding: 4px 16px 24px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
main > * { min-width: 0; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  font-weight: 600; cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.danger { background: var(--critical); border-color: transparent; color: #fff; }
.btn.danger-soft { background: var(--critical-wash); color: var(--text); border-color: color-mix(in srgb, var(--critical) 35%, transparent); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.big { min-height: 56px; font-size: 17px; border-radius: 14px; width: 100%; }
.btn svg { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- питание ---------- */
.power { display: grid; gap: 12px; }
.power .state { display: flex; align-items: center; gap: 12px; }
.power .glyph {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted);
}
.power .glyph svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; }
.power .glyph.on { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.power .glyph.wait { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.power .glyph.down { background: color-mix(in srgb, var(--serious) 18%, transparent); color: var(--serious); }
.power .title { font-size: 20px; font-weight: 600; line-height: 1.2; }
.power .note { color: var(--text-2); font-size: 14px; }
.power .row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.power .row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.power .row3 .btn { padding: 8px 6px; flex-direction: column; gap: 4px; font-size: 13px; min-height: 64px; }
.countdown { font-size: 44px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; }
.progress { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.progress.err { background: var(--critical-wash); }
.spinner { width: 16px; height: 16px; margin-top: 2px; flex: none; border-radius: 50%; border: 2px solid var(--muted); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.plugline { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--text-2); font-size: 14px; }

/* ---------- плитки ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tiles[hidden] { display: none; }
.tile {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; min-width: 0; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.tile.sel { border-color: color-mix(in srgb, var(--accent) 70%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent); }
.tile .lab { font-size: 13px; color: var(--text-2); display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.tile .val { font-size: 26px; font-weight: 600; line-height: 1.15; white-space: nowrap; }
.tile .val small { font-size: 15px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.tile .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .spark { display: block; width: 100%; height: 30px; margin-top: 6px; }
.tile .cores { display: grid; grid-auto-flow: column; gap: 3px; margin-top: 6px; }
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* шкала: заливка = степень, дорожка = светлая ступень того же цвета */
.meter { height: 6px; border-radius: 99px; background: var(--track); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); min-width: 2px; }
.meter.warn { background: color-mix(in srgb, var(--warning) 22%, transparent); }
.meter.warn > span { background: var(--warning); }
.meter.crit { background: color-mix(in srgb, var(--critical) 22%, transparent); }
.meter.crit > span { background: var(--critical); }
.meter.thin { height: 4px; }

/* ---------- график ---------- */
.seg { display: flex; gap: 4px; padding: 3px; border-radius: 11px; background: var(--surface-2); overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 0 auto; border: 0; border-radius: 8px; padding: 7px 10px; min-height: 34px;
  background: transparent; color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.chart { position: relative; margin-top: 10px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart svg { display: block; width: 100%; height: 180px; overflow: visible; }
.chart .empty { height: 180px; display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.tip {
  position: fixed; z-index: 20; pointer-events: none;
  padding: 6px 9px; border-radius: 8px;
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  font-size: 13px; box-shadow: var(--shadow); white-space: nowrap;
}
.tip b { font-weight: 600; }

/* ---------- действия ---------- */
.acts { display: grid; gap: 14px; }
.acts h3 { font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 99px; padding: 8px 14px; min-height: 38px; cursor: pointer; font-size: 14px;
}
.chip.cur { border-color: color-mix(in srgb, var(--good) 60%, transparent); }
.chip:active { transform: scale(0.97); }
.shot { display: block; width: 100%; margin-top: 10px; border-radius: 10px; border: 1px solid var(--border); cursor: zoom-in; background: var(--surface-2); }

/* ---------- процессы ---------- */
.proc-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.small-seg { flex: 0 0 auto; }
.small-seg button { min-height: 30px; padding: 5px 14px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.search {
  width: 100%; min-height: 40px; padding: 8px 12px; margin-bottom: 6px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); outline: none;
}
.search:focus { border-color: var(--accent); }
.procs .row {
  display: grid; grid-template-columns: minmax(0, 1fr) 56px 72px; gap: 8px; align-items: center;
  padding: 9px 4px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.procs .row:last-of-type { border-bottom: 0; }
.procs .row:active { background: var(--surface-2); }
.procs .name { min-width: 0; }
.procs .name b { font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.procs .name span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.procs .c, .procs .m { text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }
.procs .c.hot { font-weight: 600; }
.procs .head { cursor: default; font-size: 12px; color: var(--muted); padding-top: 2px; padding-bottom: 6px; }
.procs .head:active { background: none; }
.procs .more { width: 100%; margin-top: 8px; }
.procs .empty { padding: 16px 0; color: var(--muted); text-align: center; font-size: 14px; }

/* ---------- диски ---------- */
.disk { display: grid; gap: 6px; padding: 8px 0; }
.disk + .disk { border-top: 1px solid var(--border); }
.disk .line { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.disk .line span:last-child { color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------- вход, окна ---------- */
.login { max-width: 360px; margin: 12vh auto 0; padding: 24px 16px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.login img { border-radius: 16px; }
.login form { display: grid; gap: 10px; width: 100%; margin-top: 8px; }
.login input { min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }

.modal { position: fixed; inset: 0; z-index: 30; display: grid; align-items: end; justify-items: center; background: rgba(0, 0, 0, 0.5); padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.modal[hidden] { display: none; }
.modal-box { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.modal-box h3 { font-size: 18px; }
.modal-text { color: var(--text-2); font-size: 15px; white-space: pre-line; }
.modal-btns { display: grid; gap: 8px; margin-top: 6px; }
.modal-fields { display: grid; gap: 8px; }
.modal-fields:empty { display: none; }
.modal-fields input, .modal-fields select {
  width: 100%; min-height: 44px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); outline: none; font-size: 16px;
}
.modal-fields input:focus, .modal-fields select:focus { border-color: var(--accent); }
.modal-fields label { font-size: 13px; color: var(--text-2); display: grid; gap: 4px; }
.modal-box { max-height: calc(100vh - 32px); overflow-y: auto; }
@media (min-width: 640px) { .modal { align-items: center; } }

.viewer { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; }
.viewer[hidden] { display: none; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); background: #111; color: #eee; }
.viewer-bar span { flex: 1; color: #aaa; }
.viewer-bar .btn { color: #eee; border-color: rgba(255,255,255,0.2); }
.viewer-scroll { flex: 1; overflow: auto; display: flex; align-items: center; -webkit-overflow-scrolling: touch; }
.viewer-scroll img { width: 100%; height: auto; display: block; margin: auto; }
.viewer.zoom .viewer-scroll { align-items: flex-start; }
.viewer.zoom .viewer-scroll img { width: auto; max-width: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 50; max-width: calc(100% - 32px);
  padding: 11px 16px; border-radius: 12px;
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 14px;
}
.toast.err { border-color: color-mix(in srgb, var(--critical) 60%, transparent); }
.foot { text-align: center; margin: 4px 0 0; }

@media (max-width: 360px) {
  .tile .val { font-size: 22px; }
  .power .row3 .btn { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
