/* Пульт DSH — тёмная Metro-тема, та же палитра, что в car-expenses. */

:root {
  --bg: #0f1416;
  --surface: #141b1e;
  --surface-2: #1d262a;
  --surface-3: #243034;
  --line: #2b363a;
  --text: #e6ecee;
  --muted: #9aa7ac;
  --teal: #7ed6df;
  --teal-deep: #00b7c3;
  --ok: #5bd6a5;
  --warn: #ffc46b;
  --err: #ff8585;
  --radius: 16px;
  --tabbar-h: 62px;
  --topbar-h: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любой display из наших правил
   (иначе скрытые баннер и поле ввода остаются на экране). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior-y: none;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}

h1, h2, h3, p { margin: 0; }

/* ---------------------------------------------------------------- шапка */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 18px 10px;
  background: rgba(15, 20, 22, 0.78);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid rgba(43, 54, 58, 0.7);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  color: #04191b;
  background: linear-gradient(150deg, var(--teal), var(--teal-deep));
  box-shadow: 0 0 0 1px rgba(126, 214, 223, 0.25), 0 6px 18px -8px rgba(0, 183, 195, 0.8);
  flex: 0 0 auto;
}

.brand-text { min-width: 0; }
.brand-text h1 { font-size: 17px; font-weight: 650; letter-spacing: 0.01em; }
.brand-text p {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: rgba(29, 38, 42, 0.6);
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.live.is-offline i { background: var(--err); box-shadow: 0 0 8px var(--err); }

/* ---------------------------------------------------------------- экраны */

main {
  padding: 4px 16px 84px;
  max-width: 720px;
  margin: 0 auto;
}

.screen { display: none; animation: fade 0.18s ease-out; }
.screen.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 22px 2px 10px;
}

.section-head h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-note { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- ноды */

.nodes { display: grid; gap: 10px; }

.node {
  position: relative;
  padding: 14px 14px 12px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(29, 38, 42, 0.9), rgba(20, 27, 30, 0.9));
  border: 1px solid var(--line);
  overflow: hidden;
}
.node::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  background: var(--ok);
  opacity: 0.75;
}
.node.is-off::before { background: var(--err); }

.node-top { display: flex; align-items: center; gap: 8px; }
.node-name { font-size: 15.5px; font-weight: 620; }
.node-role { font-size: 12px; color: var(--muted); margin-left: auto; text-align: right; }
.node-ip {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); flex: 0 0 auto; }
.node.is-off .dot { background: var(--err); box-shadow: 0 0 8px var(--err); }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(62px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.metric { background: rgba(15, 20, 22, 0.55); border: 1px solid rgba(43, 54, 58, 0.7); border-radius: 10px; padding: 7px 8px; }
.metric-label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.metric-value { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 1px; }

/* ---------------------------------------------------------------- плитки */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 10px;
}

.tile {
  position: relative;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(36, 48, 52, 0.55), rgba(20, 27, 30, 0.95));
  border: 1px solid var(--line);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.tile:active { transform: scale(0.985); }
.tile-label { font-size: 12px; color: var(--muted); letter-spacing: 0.02em; }
.tile-value {
  margin-top: 6px;
  font-size: 25px;
  font-weight: 660;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--teal);
  line-height: 1.15;
}
.tile-hint { margin-top: 3px; font-size: 12px; color: var(--muted); }
.tile[data-state="warn"] .tile-value { color: var(--warn); }
.tile[data-state="err"] .tile-value { color: var(--err); }

/* ---------------------------------------------------------------- события */

.events { display: grid; gap: 8px; }

.event {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 10px;
  align-items: start;
  padding: 11px 12px 11px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid rgba(43, 54, 58, 0.65);
}
.event-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.event-source { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.event-text { font-size: 14px; margin-top: 2px; }
.event[data-level="warn"] { border-color: rgba(255, 196, 107, 0.35); }
.event[data-level="warn"] .event-source { color: var(--warn); }
.event[data-level="err"] { border-color: rgba(255, 133, 133, 0.4); }
.event[data-level="err"] .event-source { color: var(--err); }
.event[data-level="ok"] .event-source { color: var(--ok); }

/* ---------------------------------------------------------------- установка */

.install-banner {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  margin-top: 12px;
  padding: 12px 14px;
  text-align: left;
  font: inherit;
  color: var(--text);
  border-radius: 12px;
  border: 1px dashed rgba(126, 214, 223, 0.4);
  background: rgba(29, 38, 42, 0.55);
  transition: transform 0.12s ease;
}
.install-banner:active { transform: scale(0.99); }
.install-main { font-size: 14px; font-weight: 560; color: var(--teal); }
.install-sub { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- обновление */

/* Кнопка висит справа над нижним баром — на уровне последнего события,
   ничего не перекрывает и не уезжает под полупрозрачную панель. */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 22;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: 16px;
  color: #04191b;
  background: linear-gradient(150deg, var(--teal), var(--teal-deep));
  box-shadow:
    0 0 0 1px rgba(126, 214, 223, 0.35),
    0 10px 24px -10px rgba(0, 183, 195, 0.85);
  transition: transform 0.12s ease, opacity 0.2s ease;
}
.fab:active { transform: scale(0.93); }
.fab svg { transition: transform 0.2s ease; }
.fab.is-busy { opacity: 0.75; }
.fab.is-busy svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

body.is-chat .fab { display: none; }

/* ---------------------------------------------------------------- чат */

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 0 8px;
  min-height: 40vh;
}

.chat-empty { padding: 28px 6px; text-align: center; }
.chat-empty-title { font-size: 17px; font-weight: 600; }
.chat-empty-text { margin-top: 6px; font-size: 14px; color: var(--muted); line-height: 1.55; }

.msg {
  max-width: 88%;
  padding: 11px 13px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: fade 0.16s ease-out;
}
.msg--assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg--user {
  align-self: flex-end;
  background: linear-gradient(180deg, rgba(0, 183, 195, 0.22), rgba(0, 183, 195, 0.12));
  border: 1px solid rgba(0, 183, 195, 0.34);
  border-bottom-right-radius: 6px;
}
.msg--error {
  align-self: stretch;
  max-width: 100%;
  background: rgba(255, 133, 133, 0.1);
  border: 1px solid rgba(255, 133, 133, 0.4);
  color: #ffd7d7;
}

.cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -0.16em;
  background: var(--teal);
  border-radius: 1px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.tool {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 88%;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(29, 38, 42, 0.7);
  border: 1px dashed rgba(126, 214, 223, 0.35);
  font-family: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}
.tool b { color: var(--teal); font-weight: 600; }

/* ---------------------------------------------------------------- ввод */

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  z-index: 15;
  padding: 8px 12px;
  background: linear-gradient(180deg, rgba(15, 20, 22, 0), rgba(15, 20, 22, 0.92) 26%);
}
.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
  padding: 6px 6px 6px 14px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 -8px 26px -18px #000;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  max-height: 132px;
  padding: 8px 0;
}
.composer textarea::placeholder { color: #6e7c80; }

.send {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  color: #04191b;
  background: linear-gradient(150deg, var(--teal), var(--teal-deep));
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.send:active { transform: scale(0.94); }
.send:disabled { opacity: 0.4; }

body.is-chat main { padding-bottom: 128px; }

/* ---------------------------------------------------------------- вкладки */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(18, 24, 27, 0.9);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-top: 1px solid rgba(43, 54, 58, 0.8);
}

.tab {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  letter-spacing: 0.02em;
  transition: color 0.14s ease;
}
.tab.is-active { color: var(--teal); }
.tab:active { opacity: 0.7; }

/* ---------------------------------------------------------------- скелетоны */

.is-skeleton {
  min-height: 96px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}

/* ---------------------------------------------------------------- вход и настройка */

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  background: radial-gradient(120% 90% at 50% 0%, #162225 0%, var(--bg) 58%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 26px 22px 22px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(29, 38, 42, 0.94), rgba(18, 25, 28, 0.97));
  border: 1px solid var(--line);
  box-shadow: 0 26px 60px -34px #000;
}

.auth-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: 14px;
  border-radius: 12px;
  color: #04191b;
  background: linear-gradient(150deg, var(--teal), var(--teal-deep));
}

.auth-card h1 { font-size: 21px; font-weight: 650; }
.auth-sub { margin-top: 4px; font-size: 13.5px; line-height: 1.5; color: var(--muted); }

.auth-field { display: block; margin-top: 16px; }
.auth-field span {
  display: block;
  margin-bottom: 6px;
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.auth-field input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: rgba(15, 20, 22, 0.75);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
.auth-field input:focus {
  border-color: rgba(126, 214, 223, 0.5);
  box-shadow: 0 0 0 3px rgba(0, 183, 195, 0.12);
}
#code { letter-spacing: 0.3em; font-variant-numeric: tabular-nums; }

.auth-submit {
  width: 100%;
  margin-top: 20px;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #04191b;
  background: linear-gradient(150deg, var(--teal), var(--teal-deep));
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.auth-submit:active { transform: scale(0.985); }
.auth-submit:disabled { opacity: 0.6; }

.auth-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.45;
  color: #ffd7d7;
  background: rgba(255, 133, 133, 0.12);
  border: 1px solid rgba(255, 133, 133, 0.35);
}

.auth-hint { margin-top: 14px; font-size: 12px; line-height: 1.5; color: var(--muted); }

.secret {
  margin-top: 14px;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 15px;
  letter-spacing: 0.08em;
  text-align: center;
  color: var(--teal);
  background: rgba(15, 20, 22, 0.8);
  border: 1px dashed rgba(126, 214, 223, 0.4);
  border-radius: 12px;
  word-break: break-all;
}

/* ---------------------------------------------------------------- настройки */

.topbar-right { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(29, 38, 42, 0.6);
  color: var(--muted);
  transition: color 0.12s ease, transform 0.12s ease;
}
.icon-btn:active { transform: scale(0.94); }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.sheet {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 41;
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  box-shadow: 0 24px 50px -24px #000;
  animation: fade 0.16s ease-out;
}
.sheet h3 { font-size: 15px; font-weight: 620; margin-bottom: 2px; }
.sheet p { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(15, 20, 22, 0.6);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
}
.sheet-row span:last-child { color: var(--muted); font-size: 12.5px; }
.sheet-row.is-danger { border-color: rgba(255, 133, 133, 0.4); color: #ffd7d7; }

