:root {
  --bg: #0c1117;
  --bg-elev: #131a22;
  --bg-soft: #1a2330;
  --line: #2a3644;
  --text: #e8eef5;
  --muted: #8b9aab;
  --accent: #3ecf8e;
  --accent-dim: rgba(62, 207, 142, 0.15);
  --warn: #e6b84d;
  --danger: #e85d5d;
  --primary: #4db6e8;
  --primary-dim: rgba(77, 182, 232, 0.18);
  --radius: 12px;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(62, 207, 142, 0.12), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(77, 182, 232, 0.1), transparent 50%),
    linear-gradient(180deg, #0e141c 0%, #0c1117 40%, #0a0f14 100%);
  z-index: -1;
}
.bg-grid::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(42, 54, 68, 0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 54, 68, 0.35) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, #000 0%, transparent 70%);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.75rem;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  background: rgba(12, 17, 23, 0.75);
  animation: fadeDown 0.5s ease;
}

.brand { display: flex; gap: 0.9rem; align-items: center; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), #1a8f5c);
  box-shadow: 0 0 0 1px rgba(62, 207, 142, 0.35), 0 8px 24px rgba(62, 207, 142, 0.2);
}
.brand h1 { margin: 0; font-size: 1.35rem; font-weight: 650; letter-spacing: -0.02em; }
.subtitle { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.85rem; }
.top-meta { display: flex; flex-wrap: wrap; gap: 0.65rem; align-items: center; }
.refresh { text-align: right; }
.refresh .label { display: block; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.refresh time { font-family: var(--mono); font-size: 0.85rem; }

.pill {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--muted);
}
.pill.ok { color: var(--accent); border-color: rgba(62, 207, 142, 0.4); background: var(--accent-dim); }
.pill.bad { color: var(--danger); border-color: rgba(232, 93, 93, 0.4); background: rgba(232, 93, 93, 0.12); }

.layout {
  display: grid;
  grid-template-columns: 1fr minmax(300px, 360px);
  gap: 1.25rem;
  padding: 1.25rem 1.75rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: rgba(19, 26, 34, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1.25rem;
  animation: fadeUp 0.55s ease;
}
.panel-head h2 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.hint { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.8rem; }
.hint code, code {
  font-family: var(--mono);
  font-size: 0.78em;
  background: var(--bg-soft);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.table-wrap { overflow-x: auto; margin-top: 1rem; }
.nodes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.nodes-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--line);
}
.nodes-table td {
  padding: 0.85rem 0.6rem;
  border-bottom: 1px solid rgba(42, 54, 68, 0.65);
  vertical-align: middle;
}
.nodes-table tr:hover td { background: rgba(26, 35, 48, 0.55); }
.empty { color: var(--muted); text-align: center; padding: 2rem !important; }
.host-cell { font-family: var(--mono); font-size: 0.82rem; }
.host-cell .tags { display: flex; gap: 0.35rem; margin-top: 0.35rem; flex-wrap: wrap; }
.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  letter-spacing: 0.02em;
}
.badge.primary { background: var(--primary-dim); color: var(--primary); }
.badge.secondary { background: var(--accent-dim); color: var(--accent); }
.badge.down, .badge.unknown, .badge.recovering { background: rgba(232, 93, 93, 0.15); color: var(--danger); }
.badge.original { background: rgba(230, 184, 77, 0.15); color: var(--warn); }
.badge.scaler { background: rgba(77, 182, 232, 0.12); color: var(--primary); }

.meter {
  width: 88px;
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.meter > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #2aa870);
  border-radius: inherit;
  transition: width 0.6s ease;
}
.meter.hot > span { background: linear-gradient(90deg, var(--warn), var(--danger)); }
.meter-label { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); margin-top: 0.25rem; }
.inst { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }
.inst strong { color: var(--text); font-weight: 500; }

.btn {
  font-family: var(--font);
  font-weight: 550;
  font-size: 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); border-color: #3d4d60; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #55c4ef, #2f9bc9);
  border-color: transparent;
  color: #041018;
}
.btn.ghost { background: transparent; }
.btn.danger {
  background: linear-gradient(180deg, #f07575, #c94444);
  border-color: transparent;
  color: #1a0505;
}
.btn.warn {
  background: linear-gradient(180deg, #f0c96a, #c9982e);
  border-color: transparent;
  color: #1a1405;
}
.btn.sm { padding: 0.35rem 0.65rem; font-size: 0.78rem; }

.timeline {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}
.timeline li {
  position: relative;
  padding: 0.55rem 0 0.55rem 1.4rem;
  border-left: 2px solid var(--line);
  margin-left: 0.4rem;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -6px; top: 0.75rem;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--line);
}
.timeline li.running::before { background: var(--primary); box-shadow: 0 0 0 4px var(--primary-dim); animation: pulse 1.4s infinite; }
.timeline li.success::before { background: var(--accent); }
.timeline li.failed::before { background: var(--danger); }
.timeline .step-name { font-weight: 550; font-size: 0.88rem; display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.timeline .step-time {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--primary);
  white-space: nowrap;
}
.timeline li.success .step-time { color: var(--accent); }
.timeline li.failed .step-time { color: var(--danger); }
.timeline li.pending .step-time { color: var(--muted); }
.timeline .step-msg { color: var(--muted); font-size: 0.78rem; font-family: var(--mono); margin-top: 0.15rem; }
.ssh-hint { margin: 0.5rem 0 0; font-size: 0.75rem; }

.recent { margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: 0.9rem; }
.recent h3 { margin: 0 0 0.5rem; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.recent ul { list-style: none; margin: 0; padding: 0; }
.recent li {
  display: flex; justify-content: space-between; gap: 0.5rem;
  padding: 0.4rem 0; font-size: 0.8rem; border-bottom: 1px solid rgba(42,54,68,0.5);
  cursor: pointer;
}
.recent li:hover { color: var(--primary); }

.discovery {
  margin-top: 0.9rem;
  padding: 0.75rem 0.85rem;
  border-radius: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}
.discovery-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.discovery pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  line-height: 1.45;
}
.banner {
  margin-top: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  font-size: 0.85rem;
}
.banner.error { background: rgba(232, 93, 93, 0.12); border: 1px solid rgba(232, 93, 93, 0.35); color: #ffb4b4; }
.banner.warn { background: rgba(230, 184, 77, 0.12); border: 1px solid rgba(230, 184, 77, 0.35); color: #f5d98a; }
.hidden { display: none !important; }

.ec2-actions {
  margin-top: 1rem;
  padding: 0.85rem;
  border-radius: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}
.ec2-actions .row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }

.modal {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-elev);
  color: var(--text);
  padding: 0;
  max-width: 440px;
  width: calc(100% - 2rem);
  box-shadow: 0 24px 64px rgba(0,0,0,0.55);
}
.modal.modal-wide { max-width: 640px; }
.modal::backdrop { background: rgba(4, 8, 12, 0.72); backdrop-filter: blur(4px); }
.modal form { padding: 1.35rem 1.4rem 1.25rem; }
.modal h2 { margin: 0 0 0.5rem; font-size: 1.15rem; }
.modal p { color: var(--muted); font-size: 0.9rem; }
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 1rem 0 0.75rem;
}
.mode-tab {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-soft);
  cursor: pointer;
  font-size: 0.88rem;
}
.mode-tab:has(input:checked) {
  border-color: rgba(77, 182, 232, 0.55);
  background: var(--primary-dim);
}
.preview-box {
  margin: 0.5rem 0 0;
  padding: 0.7rem 0.8rem;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.74rem;
  white-space: pre-wrap;
  color: var(--text);
  max-height: 180px;
  overflow: auto;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 0.75rem;
  margin-top: 0.6rem;
}
.form-grid label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.form-grid label.full { grid-column: 1 / -1; }
.form-grid label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-size: 0.85rem;
}
.form-grid input[type="text"],
.form-grid input[type="number"] {
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .mode-tabs { grid-template-columns: 1fr; }
}
.modal-host { color: var(--text) !important; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.2rem; }
.field { margin-top: 0.9rem; }
.field label { display: flex; gap: 0.5rem; align-items: flex-start; font-size: 0.9rem; }
.triple { display: grid; gap: 0.65rem; margin-top: 0.85rem; }
.triple label { display: grid; gap: 0.3rem; font-size: 0.8rem; color: var(--muted); }
.triple input, .field input[type="text"] {
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
.triple input:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  max-width: 360px;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
  z-index: 50;
  animation: fadeUp 0.3s ease;
}
.toast.ok { border-color: rgba(62, 207, 142, 0.45); }
.toast.err { border-color: rgba(232, 93, 93, 0.45); }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--primary-dim); }
  50% { box-shadow: 0 0 0 7px transparent; }
}

.hidden { display: none !important; }
.login-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  animation: fadeUp 0.4s ease;
}
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); }
.login-card input {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 0.65rem 0.75rem;
  font: inherit;
}
.brand-mark.lg { width: 52px; height: 52px; border-radius: 14px; }
.btn.full { width: 100%; justify-content: center; }
.tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.75rem 1.75rem 0;
  border-bottom: 1px solid var(--line);
}
.tab {
  background: transparent;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  padding: 0.55rem 0.9rem;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
}
.tab.active {
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-bottom-color: var(--bg-elev);
  margin-bottom: -1px;
}
.layout.single { grid-template-columns: 1fr; }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.user-chip {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
  min-width: 11rem;
}
select {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.65rem;
  font: inherit;
  width: 100%;
}

