:root {
  --purple: #62259D;
  --purple-light: #8B4FC7;
  --orange: #FC6A39;
  --bg: #14121A;
  --bg-panel: #1C1926;
  --bg-panel-2: #241F32;
  --border: #322C42;
  --text: #EDEAF5;
  --text-dim: #9993AC;
  --green: #3DD68C;
  --red: #FF5C6C;
  --yellow: #FFC857;
  --mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  --sans: 'Inter', -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #2A1D42 0%, #14121A 60%);
}
.login-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 320px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.login-logo {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.5px;
  color: var(--text);
  margin-bottom: 4px;
}
.login-logo span { color: var(--orange); }
.login-title {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 28px;
}
#login-form input {
  width: 100%;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 13px;
  border-radius: 7px;
  margin-bottom: 12px;
  font-size: 14px;
}
#login-form input:focus {
  outline: none;
  border-color: var(--purple-light);
}
#login-form button {
  width: 100%;
  background: var(--purple);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
#login-form button:hover { background: var(--purple-light); }
.login-error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------- Layout ---------- */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  flex-shrink: 0;
}
.sidebar-logo {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.5px;
}
.sidebar-logo span { color: var(--orange); }
.sidebar-sub { color: var(--text-dim); font-size: 12px; margin-top: 2px; margin-bottom: 24px; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 14px;
  cursor: pointer;
  font-family: var(--sans);
}
.nav-item:hover { background: var(--bg-panel-2); color: var(--text); }
.nav-item.active { background: var(--purple); color: white; }

.ns-selector { margin-top: 26px; }
.ns-selector label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.ns-selector select {
  width: 100%;
  margin-top: 6px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-dim);
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.sidebar-footer button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.sidebar-footer button:hover { border-color: var(--orange); color: var(--orange); }

.content { flex: 1; overflow-y: auto; padding: 32px 40px; }
.view h1 { font-size: 20px; margin: 0 0 20px 0; font-weight: 600; }
.view h2 { font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin: 28px 0 14px 0; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}
.card .card-value { font-family: var(--mono); font-size: 26px; font-weight: 700; }
.card .card-label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.card .card-value.orange { color: var(--orange); }
.card .card-value.green { color: var(--green); }
.card .card-value.purple { color: var(--purple-light); }

/* ---------- Node grid ---------- */
.node-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.node-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.node-card .node-name { font-family: var(--mono); font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.node-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
.node-dot.off { background: var(--red); }
.node-roles { font-size: 11px; color: var(--text-dim); margin: 4px 0 12px 0; }
.node-metric { margin-bottom: 8px; }
.node-metric-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.bar-bg { height: 6px; background: var(--bg-panel-2); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; background: var(--purple-light); transition: width 0.3s; }
.bar-fill.warn { background: var(--yellow); }
.bar-fill.crit { background: var(--red); }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
}
.data-table tr:hover td { background: var(--bg-panel); }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
}
.badge.Running, .badge.Normal { background: rgba(61,214,140,0.15); color: var(--green); }
.badge.Pending, .badge.Warning { background: rgba(255,200,87,0.15); color: var(--yellow); }
.badge.Failed, .badge.Error { background: rgba(255,92,108,0.15); color: var(--red); }

.row-actions button {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 9px;
  border-radius: 5px;
  font-size: 11px;
  cursor: pointer;
  margin-right: 5px;
  font-family: var(--sans);
}
.row-actions button:hover { border-color: var(--purple-light); }
.row-actions button.danger:hover { border-color: var(--red); color: var(--red); }

.scale-controls { display: flex; align-items: center; gap: 6px; }
.scale-controls button {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 22px; height: 22px;
  border-radius: 5px;
  cursor: pointer;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(10,8,15,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-box {
  width: 85vw; height: 78vh;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}
.modal-title { font-family: var(--mono); font-size: 13px; color: var(--text-dim); flex: 1; }
.modal-tabs { display: flex; gap: 4px; }
.modal-tab {
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.modal-tab.active { background: var(--purple); color: white; border-color: var(--purple); }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--red); }
.modal-body { flex: 1; overflow: hidden; position: relative; }
.log-panel {
  margin: 0; padding: 14px 16px;
  height: 100%; overflow-y: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
  color: #C7C2D9;
  white-space: pre-wrap; word-break: break-all;
}
.exec-panel { height: 100%; padding: 8px; }

@media (max-width: 900px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .sidebar { width: 180px; }
  .content { padding: 20px; }
}

/* ---------- Wizard Nuova App ---------- */
.wizard-grid { max-width: 640px; display: flex; flex-direction: column; gap: 16px; }

.wizard-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 24px;
}

.wizard-step-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.step-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--purple);
  color: white;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.step-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.step-optional {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  padding: 2px 9px;
  border-radius: 20px;
  margin-left: auto;
}

.text-input {
  width: 100%;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-family: var(--sans);
  box-sizing: border-box;
}
.text-input::placeholder { color: #6E6684; }
.text-input:focus { outline: none; border-color: var(--purple-light); box-shadow: 0 0 0 3px rgba(139,79,199,0.15); }
select.text-input { appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%239993AC'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px;
}

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600; }
.form-group-checkbox { flex-direction: row; align-items: center; padding-top: 20px; }
.form-group-checkbox label {
  text-transform: none; font-size: 13px; font-weight: 400; color: var(--text);
  display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.form-group-checkbox input[type="checkbox"] {
  width: 16px; height: 16px; accent-color: var(--purple); cursor: pointer; margin: 0;
}

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 8px;
  padding: 11px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--sans);
}
.btn-primary { background: var(--purple); color: white; }
.btn-primary:hover { background: var(--purple-light); }
.btn-deploy { width: 100%; padding: 13px; font-size: 14px; }
.btn-secondary { background: var(--bg-panel-2); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--purple-light); }

.dh-results { margin-top: 10px; display: flex; flex-direction: column; gap: 7px; max-height: 220px; overflow-y: auto; }
.dh-result-item {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 13px;
  cursor: pointer;
  font-size: 12px;
}
.dh-result-item:hover { border-color: var(--purple-light); background: #2A2438; }
.dh-result-name { font-family: var(--mono); font-weight: 600; color: var(--text); }
.dh-result-desc { color: var(--text-dim); margin-top: 3px; }
.dh-result-stars { color: var(--orange); float: right; font-weight: 600; }

.env-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-bottom: 10px; }
.env-row:last-child { margin-bottom: 0; }
.env-row button {
  background: transparent; border: 1px solid var(--border); color: var(--red);
  border-radius: 7px; cursor: pointer; padding: 0 12px; font-size: 14px;
}
.env-row button:hover { background: rgba(255,92,108,0.1); border-color: var(--red); }

#deploy-result { margin-top: 2px; }
.deploy-success { background: rgba(61,214,140,0.1); border: 1px solid var(--green); border-radius: 10px; padding: 16px; font-size: 13px; }
.deploy-error { background: rgba(255,92,108,0.1); border: 1px solid var(--red); border-radius: 10px; padding: 16px; font-size: 13px; color: var(--red); }

.code-block {
  background: #0F0D15;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 12px;
  color: #C7C2D9;
  overflow-x: auto;
  white-space: pre;
  margin: 10px 0;
}

.webhook-box { width: 640px; height: auto; max-height: 80vh; }
.webhook-body { padding: 16px; overflow-y: auto; }
.webhook-intro { font-size: 13px; color: var(--text-dim); margin: 0 0 4px 0; }
