:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #667085;
  --border: #e3e6ea;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --ok: #1a9b5b;
  --ok-bg: #e5f6ed;
  --bad: #d4382c;
  --bad-bg: #fdecea;
  --warn: #b7791f;
  --warn-bg: #fdf4e3;
  --term-bg: #0f1720;
  --term-text: #d7e0ea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --c-cpu: #2f6fed;
  --c-ram: #d9480f;
  --c-disk: #2b8a3e;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --panel-2: #1f242c;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --border: #2a303a;
    --accent: #5b8cff;
    --ok: #3ccb7f;
    --ok-bg: #12301f;
    --bad: #ff6b5e;
    --bad-bg: #3a1714;
    --warn: #f0b429;
    --warn-bg: #3a2c0c;
    --shadow: none;
    --c-cpu: #5b8cff;
    --c-ram: #ff8a4c;
    --c-disk: #4cc66a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 10px;
}
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 16px; }
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 8px;
  color: var(--text); margin-bottom: 2px;
}
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--panel-2); font-weight: 600; }
.sidebar .me { margin-top: auto; padding: 10px; color: var(--muted); font-size: 13px; }
.main { flex: 1; min-width: 0; padding: 20px 24px 40px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.mobile-bar { display: none; }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { display: none; width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar.open { display: flex; }
  .mobile-bar {
    display: flex; align-items: center; justify-content: space-between; padding: 10px 16px;
    background: var(--panel); border-bottom: 1px solid var(--border);
  }
  .main { padding: 16px; }
}

/* ---------- elements ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .v { font-size: 22px; font-weight: 700; }
.tile .l { color: var(--muted); font-size: 12px; }

button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
button:hover { background: var(--panel-2); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.small { padding: 3px 8px; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 14px; }
.check { display: inline-flex; align-items: center; gap: 6px; }
.check input { width: auto; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { max-width: 260px; }
.filters select { width: auto; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--panel-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

.bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; }
.tabs button.active { border-bottom-color: var(--accent); font-weight: 600; }

.chart-box { position: relative; height: 280px; }
.legend { display: flex; gap: 14px; font-size: 13px; margin-bottom: 8px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

.alert { padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); margin-bottom: 12px; }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 560px; padding: 20px; border: 1px solid var(--border); }
.modal.wide { max-width: 820px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Полноэкранные окна: position: fixed на весь экран + собственный фон, чтобы страница
   под ними не просвечивала (Lessons Learned 1.5) */
.fullscreen { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 60; background: var(--bg); display: flex; flex-direction: column; }
.fullscreen-head { height: 48px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--border); }
.fullscreen iframe { width: 100%; height: calc(100vh - 48px); border: 0; display: block; background: #000; }

/* ---------- console ---------- */
.term { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--term-bg); color: var(--term-text); }
.term-out { flex: 1; overflow-y: auto; padding: 12px 14px; margin: 0; white-space: pre-wrap; word-break: break-word; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.term-out .err { color: #ff8b80; }
.term-out .cmd { color: #8fd18f; }
.term-out .sys { color: #8aa0b6; font-style: italic; }
.term-in { display: flex; align-items: flex-start; gap: 8px; padding: 8px 14px; border-top: 1px solid #22303e; }
.term-in .prompt { color: #8fd18f; font: 13px/1.9 ui-monospace, Menlo, Consolas, monospace; white-space: nowrap; }
.term-in textarea { background: transparent; color: var(--term-text); border: 0; min-height: 28px; height: 28px; font: 13px/1.6 ui-monospace, Menlo, Consolas, monospace; padding: 2px 0; }
.term-in textarea:focus { outline: none; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 10px; background: var(--panel-2); }
.msg.staff { align-self: flex-start; }
.msg.client { align-self: flex-end; background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg img { max-width: 100%; max-height: 320px; border-radius: 6px; margin-top: 6px; display: block; }

.toast { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast div { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 360px; box-shadow: var(--shadow); }
.toast div.bad { background: var(--bad); color: #fff; }

.login { max-width: 360px; margin: 12vh auto; }
.secret { display: inline-flex; gap: 6px; align-items: center; }
