:root {
  --bg: #0e1621;
  --card: #182533;
  --card2: #1f2f42;
  --text: #e8eef4;
  --muted: #8b9bb0;
  --green1: #22c55e;
  --green2: #16a34a;
  --red1: #ef4444;
  --red2: #b91c1c;
  --blue1: #3b82f6;
  --blue2: #2563eb;
  --yellow: #eab308;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
#app { max-width: 520px; margin: 0 auto; padding: 0 16px 40px; }
.hidden { display: none !important; }

#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  background: rgba(14, 22, 33, .92);
  backdrop-filter: blur(8px);
  padding: 12px 0;
  border-bottom: 1px solid #1d2c3f;
}
.brand { font-weight: 800; font-size: 17px; letter-spacing: .3px; }
.role-tag {
  margin-left: auto; font-size: 11px; font-weight: 700;
  padding: 3px 10px; border-radius: 20px;
  background: var(--card2); color: var(--muted);
  text-transform: uppercase; letter-spacing: .6px;
}
.role-tag.owner { background: rgba(34,197,94,.15); color: var(--green1); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid #26394f; background: var(--card);
  color: var(--text); font-size: 22px; line-height: 1; cursor: pointer;
}

h2 { font-size: 19px; margin: 18px 0 6px; }
.sub { color: var(--muted); margin: 4px 0 14px; }
.muted { color: var(--muted); font-weight: 400; font-size: 14px; }
.warn { color: #fca5a5; }

.screen { display: none; animation: fadein .18s ease; }
.screen.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid #223448;
  border-radius: var(--radius);
  padding: 14px;
  margin: 10px 0;
}
.list { display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }

/* tombol */
.menu { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.menu-btn {
  display: block; width: 100%;
  padding: 13px 16px;
  border: none; border-radius: var(--radius);
  background: var(--card2); color: var(--text);
  font-size: 15px; font-weight: 700; text-align: center;
  cursor: pointer; text-decoration: none;
  transition: transform .08s ease, filter .15s ease;
}
.menu-btn:active { transform: scale(.98); }
.menu-btn.primary {
  background: linear-gradient(135deg, var(--green1), var(--green2));
  color: #04120a;
  box-shadow: 0 0 18px rgba(34, 197, 94, .35);
}
.menu-btn.danger {
  background: linear-gradient(135deg, var(--red1), var(--red2));
  color: #fff;
  box-shadow: 0 0 18px rgba(239, 68, 68, .3);
}
.menu-btn.secondary {
  background: linear-gradient(135deg, var(--blue1), var(--blue2));
  color: #fff;
}
.menu-btn.ghost { background: transparent; border: 1px solid #2a3f57; color: var(--muted); }
.menu-btn.locked { opacity: .45; filter: grayscale(.6); }
.btn-row { display: flex; gap: 10px; margin-top: 10px; }
.btn-row .menu-btn { margin-top: 0; }

.tag {
  display: inline-block; margin-left: 8px;
  font-size: 10px; font-weight: 800; letter-spacing: .8px;
  text-transform: uppercase;
  background: rgba(0,0,0,.28); color: #fff;
  padding: 2px 8px; border-radius: 20px; vertical-align: 2px;
}
.menu-btn:not(.primary):not(.danger):not(.secondary) .tag {
  background: rgba(234,179,8,.18); color: var(--yellow);
}

/* runtime cards */
.runtime-row { display: flex; gap: 12px; }
.runtime-card {
  flex: 1; padding: 20px 12px;
  border-radius: var(--radius); cursor: pointer;
  background: var(--card); color: var(--text);
  border: 2px solid #223448;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  transition: border-color .15s ease, transform .08s ease;
}
.runtime-card:active { transform: scale(.97); }
.runtime-card.selected.node { border-color: var(--green1); box-shadow: 0 0 16px rgba(34,197,94,.35); }
.runtime-card.selected.python { border-color: var(--yellow); box-shadow: 0 0 16px rgba(234,179,8,.3); }
.rt-name { font-size: 17px; font-weight: 800; }
.runtime-card.node .rt-name { color: var(--green1); }
.runtime-card.python .rt-name { color: var(--yellow); }
.rt-desc { font-size: 12px; color: var(--muted); }

.input {
  width: 100%; padding: 12px 14px; margin: 6px 0 10px;
  background: #0b1220; color: var(--text);
  border: 1px solid #26394f; border-radius: 12px;
  font-size: 15px; outline: none;
}
.input:focus { border-color: var(--green1); }

/* progress */
.progress-card { text-align: center; }
.fire {
  font-size: 44px; display: inline-block;
  animation: flicker 1.1s ease-in-out infinite;
}
@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(-3deg); filter: drop-shadow(0 0 6px #ff9d00); }
  50% { transform: scale(1.18) rotate(3deg); filter: drop-shadow(0 0 16px #ff6a00); }
}
.stages { list-style: none; padding: 0; margin: 14px 0 0; text-align: left; }
.stages li { padding: 8px 4px; color: var(--muted); border-top: 1px solid #223448; }
.stages li:first-child { border-top: none; }
.stages li.doing { color: var(--text); }
.stages li.done { color: var(--green1); }
.stages li.fail { color: var(--red1); }
.stages li::before { content: "○ "; }
.stages li.doing::before { content: "◌ "; }
.stages li.done::before { content: "● "; }
.stages li.fail::before { content: "✕ "; }

.typewriter { white-space: pre-wrap; font-family: inherit; margin: 0; min-height: 60px; }
.typewriter::after { content: "▍"; color: var(--green1); animation: blink 1s steps(1) infinite; }
.typewriter.finished::after { content: ""; }
@keyframes blink { 50% { opacity: 0; } }

/* server cards */
.server-card {
  background: var(--card); border: 1px solid #223448;
  border-radius: var(--radius); padding: 14px;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; text-align: left; width: 100%; color: var(--text);
  font-size: 15px;
}
.server-card .name { font-weight: 700; }
.server-card .meta { color: var(--muted); font-size: 13px; }
.dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.dot.running { background: var(--green1); box-shadow: 0 0 10px rgba(34,197,94,.8); }
.dot.stopped, .dot.offline { background: var(--red1); box-shadow: 0 0 10px rgba(239,68,68,.7); }
.dot.starting, .dot.unknown { background: var(--yellow); box-shadow: 0 0 10px rgba(234,179,8,.7); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stats div { background: #0b1220; border-radius: 10px; padding: 10px; }
.stats .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stats .v { font-size: 16px; font-weight: 700; }

/* terminal */
.terminal { background: #070d16; border-color: #1a2a3f; }
.terminal pre, #analyze-text {
  margin: 0; white-space: pre-wrap; word-break: break-all;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; color: #9fe8b8; max-height: 380px; overflow-y: auto;
}
#log-view:empty::before { content: "belum ada output."; color: var(--muted); }

/* chat */
.chat { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; max-height: 55vh; overflow-y: auto; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--blue2); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--card); border: 1px solid #223448; border-bottom-left-radius: 4px; }
.msg.typing { color: var(--muted); }
.chat-input-row { display: flex; gap: 8px; position: sticky; bottom: 0; padding: 10px 0; background: var(--bg); }
.chat-input-row .input { margin: 0; }
.chat-input-row .menu-btn { width: auto; margin: 0; }

/* user rows */
.user-row { display: flex; align-items: center; gap: 10px; }
.user-row .name { font-weight: 700; }
.user-row .uid { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }
.user-row .del {
  margin-left: auto; background: none; border: 1px solid #5b2b2b;
  color: var(--red1); border-radius: 10px; padding: 6px 12px; cursor: pointer;
}

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #24384e; color: var(--text);
  padding: 11px 18px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); z-index: 50;
  max-width: 90%; text-align: center;
  animation: fadein .15s ease;
}
