:root {
  --bg: #11151c;
  --bg-2: #171c26;
  --bg-3: #1f2632;
  --border: #2a3442;
  --text: #dbe2ec;
  --muted: #8b96a5;
  --accent: #4f8cff;
  --accent-2: #3b6fd0;
  --danger: #e5534b;
  --ok: #3fb950;
  --warn: #d29922;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

h1 { font-size: 18px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; }
.spacer { flex: 1; }

button {
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid transparent;
  font: inherit;
}
button.primary {
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
}
button.primary:hover { background: var(--accent-2); }
button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  padding: 5px 10px;
}
button.ghost:hover { border-color: var(--muted); }
button.danger { color: var(--danger); border-color: var(--border); }
button.danger:hover { border-color: var(--danger); }

input, select, textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  margin-top: 4px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; }
label { display: block; margin-bottom: 12px; }
.row { display: flex; gap: 10px; }
.grow { flex: 1; }
.narrow { width: 110px; }

/* --- экраны входа --- */
.auth-screen {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: 380px;
  max-width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  text-align: center;
}
.auth-card button { width: 100%; margin-top: 8px; }
.auth-card .muted { font-size: 13px; }
.auth-card .error { min-height: 18px; margin: 6px 0 0; }

/* --- главный экран --- */
#screen-app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }

.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 320px;
  min-width: 240px;
  border-right: 1px solid var(--border);
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
}
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.sidebar-head button { padding: 5px 8px; font-size: 13px; }

.server-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }

.server-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
}
.server-item:hover { background: var(--bg-3); }
.server-item.active { background: #26314a; }
.server-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.server-item.connected .dot { background: var(--ok); }
.server-item.failed .dot { background: var(--danger); }
.server-item .meta { flex: 1; min-width: 0; }
.server-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.server-item .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.server-item .auth { font-size: 12px; flex: none; }
.server-item .ops { display: flex; gap: 2px; opacity: 0; }
.server-item:hover .ops { opacity: 1; }
.server-item .ops button {
  background: none; border: none; color: var(--muted); padding: 2px 5px; font-size: 13px;
}
.server-item .ops button:hover { color: var(--text); }
.server-item .ops button.del:hover { color: var(--danger); }

.empty-hint { text-align: center; padding: 20px 12px; }

/* --- терминал --- */
.terminal-pane { flex: 1; display: flex; min-width: 0; flex-direction: column; background: #0a0d12; }

.empty-state {
  flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center;
}

#terminal-shell { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.term-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.term-title { font-weight: 600; }
.term-status { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--bg-3); color: var(--muted); }
.term-status.connecting { color: var(--warn); }
.term-status.connected { color: var(--ok); }
.term-status.error, .term-status.closed { color: var(--danger); }
.term-message { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#terminal { flex: 1; min-height: 0; padding: 4px 0 4px 8px; }
#terminal .xterm { height: 100%; }

/* --- модалка --- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid; place-items: center;
  z-index: 50;
}
.modal-card {
  width: 520px; max-width: calc(100vw - 30px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.modal-card .error { min-height: 18px; margin: 0 0 6px; }
.note {
  font-size: 12px;
  color: var(--ok);
  background: rgba(63, 185, 80, 0.08);
  border: 1px solid rgba(63, 185, 80, 0.25);
  border-radius: 6px;
  padding: 6px 10px;
  margin: 0 0 10px;
}
