:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b93a3;
  --accent: #4f8cff;
  --accent-2: #3a74e0;
  --ok: #2fbf71;
  --fail: #ef5a5a;
  --run: #f2b632;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 1.05rem; margin-bottom: 14px; }
h3 { font-size: 1.1rem; }

.mono { font-family: var(--mono); font-size: .9em; word-break: break-all; }
.muted { color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
}

/* ---------- buttons & inputs ---------- */

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 16px;
}
button:disabled { opacity: .55; cursor: default; }

.primary { background: var(--accent); color: #fff; font-weight: 600; }
.primary:hover:not(:disabled) { background: var(--accent-2); }

.ghost { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.ghost:hover:not(:disabled) { border-color: var(--accent); }

.link { background: none; color: var(--accent); padding: 0; border: 0; }
.link:hover { text-decoration: underline; }

label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: .85rem; }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.row { display: flex; gap: 8px; }
.row input { flex: 1; font-family: var(--mono); }

/* ---------- login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; }
.login-card h1, .brand { font-size: 1.3rem; letter-spacing: .2px; }
.login-card h1 span, .brand span { color: var(--accent); }

.alert {
  margin: 0;
  background: rgba(239, 90, 90, .12);
  border: 1px solid rgba(239, 90, 90, .4);
  color: #ffb4b4;
  border-radius: 8px;
  padding: 10px 12px;
}

/* ---------- layout ---------- */

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.who { display: flex; align-items: center; gap: 16px; color: var(--muted); }
.who form { margin: 0; }

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------- instance cards ---------- */

.instances { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }

.inst { display: flex; flex-direction: column; gap: 10px; border-top: 3px solid var(--line); }
.inst.ok { border-top-color: var(--ok); }
.inst.failed { border-top-color: var(--fail); }
.inst.running { border-top-color: var(--run); }

.inst-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.inst-url { color: var(--muted); font-size: .85rem; text-decoration: none; }
.inst-url:hover { color: var(--accent); }

.inst dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: .9rem; }
.inst dt { color: var(--muted); }
.inst dd { margin: 0; }

.inst-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 6px; }
.inst-actions button { padding: 6px 12px; font-size: .85rem; }

/* ---------- badges ---------- */

.badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--panel-2);
  color: var(--muted);
}
.badge.ok { background: rgba(47, 191, 113, .15); color: var(--ok); }
.badge.fail { background: rgba(239, 90, 90, .15); color: var(--fail); }
.badge.run { background: rgba(242, 182, 50, .15); color: var(--run); }

/* ---------- deploy form ---------- */

#deploy-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
#deploy-form > label:first-child { flex: 0 0 160px; }
#deploy-form .grow { flex: 1 1 320px; }
#deploy-btn { padding: 9px 26px; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: .85rem; }

/* ---------- log ---------- */

.log-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.log-head h2 { margin: 0; font-family: var(--mono); font-size: .95rem; word-break: break-all; }

#log {
  margin: 0;
  background: #0a0c10;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  max-height: 460px;
  overflow: auto;
  font: 12.5px/1.55 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- history ---------- */

.table-wrap { overflow-x: auto; }
.history { width: 100%; border-collapse: collapse; font-size: .9rem; }
.history th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.history td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.history tr:last-child td { border-bottom: 0; }

@media (max-width: 600px) {
  .top { padding: 12px 16px; }
  #deploy-form > label:first-child, #deploy-btn { flex: 1 1 100%; }
}
