:root {
  --bg: #0f1115;
  --panel: #161922;
  --border: #262a36;
  --text: #e7e9ee;
  --muted: #8a90a0;
  --accent: #4f8cff;
  --ok: #50c878;
  --error: #ff6b6b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ============ login ============ */
body.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
}
body.login .card {
  width: 320px;
  padding: 32px;
  display: grid;
  gap: 16px;
}
body.login .card h1 { margin: 0; font-size: 18px; font-weight: 600; }
body.login .card label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
body.login .card input,
body.login .card button {
  font: inherit;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
body.login .card button {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 600;
}
body.login .card .error { color: var(--error); margin: 0; min-height: 1.2em; font-size: 12px; }

/* ============ topbar ============ */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar h1 { margin: 0; font-size: 14px; font-weight: 600; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.tab.active { color: var(--text); background: var(--bg); border-color: var(--border); }
.link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  margin-left: auto;
  font: inherit;
}
.link:hover { color: var(--text); }
main { padding: 24px; }
.panel { display: none; }
.panel.active { display: block; }
.placeholder { color: var(--muted); }

/* ============ shared ============ */
.muted { color: var(--muted); }
.spacer { flex: 1; }
.hidden { display: none !important; }

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

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.card h2, .card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.card h3 { font-size: 13px; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }

.btn {
  font: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.warn { color: var(--error); }
.btn.warn:hover { border-color: var(--error); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.small { padding: 4px 8px; font-size: 12px; }

/* ============ deploy ============ */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  margin-bottom: 12px;
  transition: border-color 120ms;
}
.dropzone.dragging { border-color: var(--accent); background: rgba(79, 140, 255, 0.05); }
.dropzone p { margin: 0 0 8px; color: var(--muted); }
.dropzone code { background: var(--bg); padding: 1px 6px; border-radius: 4px; }
.dropzone label.btn { display: inline-block; }
.upload-progress {
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  margin-top: 12px;
  overflow: hidden;
}
.upload-progress .bar { height: 100%; width: 0; background: var(--accent); transition: width 120ms; }

.rel-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rel-table th, .rel-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.rel-table th { font-weight: 600; color: var(--muted); font-size: 12px; }
.rel-table tr.active { background: rgba(79, 140, 255, 0.05); }
.rel-table .actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  font-size: 10px;
  background: var(--accent);
  color: white;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
}

/* ============ pm2 ============ */
.status {
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.status.online { background: rgba(80, 200, 120, 0.15); color: var(--ok); }
.status.stopped { background: rgba(140, 140, 140, 0.15); color: var(--muted); }
.status.errored, .status.error { background: rgba(255, 107, 107, 0.15); color: var(--error); }

.logs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50vh;
  background: var(--panel);
  border-top: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}
.logs-head {
  display: flex;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.logs-head span { flex: 1; font-weight: 600; font-size: 13px; }
.logs pre {
  flex: 1;
  margin: 0;
  padding: 12px 16px;
  overflow: auto;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  white-space: pre-wrap;
}

/* ============ nginx ============ */
.nginx-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
  height: calc(100vh - 140px);
}
.nginx-files {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
}
.nginx-files ul { list-style: none; padding: 0; margin: 0; }
.nginx-files li { margin-bottom: 2px; }
.file-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
}
.file-btn:hover { background: var(--bg); }
.file-btn.active { background: var(--bg); border-color: var(--accent); color: var(--accent); }

.nginx-editor-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
#nginx-editor {
  flex: 1;
  min-height: 300px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.output {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 0;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  max-height: 120px;
  overflow: auto;
  white-space: pre-wrap;
}

/* ============ deploys list ============ */
.deploys-list { display: flex; flex-direction: column; gap: 8px; }
.deploy-row-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.deploy-row {
  display: grid;
  grid-template-columns: 16px 1.2fr 2fr auto;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
}
.health {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block;
}
.health.ok { background: var(--ok); box-shadow: 0 0 6px rgba(80, 200, 120, 0.6); }
.health.bad { background: var(--error); box-shadow: 0 0 6px rgba(255, 107, 107, 0.5); }
.col-subdomain a {
  color: var(--text); text-decoration: none;
  font-size: 14px; font-weight: 600;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
}
.col-subdomain a:hover { color: var(--accent); }
.col-subdomain .muted { font-size: 11px; margin-top: 2px; }
.col-status { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.status-line { display: flex; align-items: center; gap: 8px; }
.status-line .muted { font-family: 'SF Mono', Monaco, Consolas, monospace; font-size: 11px; }
.status-line a.muted { color: var(--muted); text-decoration: none; }
.status-line a.muted:hover { color: var(--accent); }
.status-pill {
  padding: 2px 7px; border-radius: 3px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  min-width: 28px; text-align: center;
}
.status-pill.ok { background: rgba(80, 200, 120, 0.15); color: var(--ok); }
.status-pill.bad { background: rgba(255, 107, 107, 0.15); color: var(--error); }
.col-actions { display: flex; gap: 6px; }
.deploy-detail { padding: 12px 16px 16px; border-top: 1px solid var(--border); background: var(--bg); }
.deploy-detail .part { margin-top: 0; padding-top: 0; border-top: none; }
.deploy-detail .part + .part { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.deploy-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 12px; }
.part { padding-top: 12px; border-top: 1px solid var(--border); margin-top: 12px; }
.part h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
.part h3 .muted { font-weight: normal; font-size: 11px; }
.steps {
  list-style: none;
  padding: 0;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 12px;
}
.step { display: flex; gap: 8px; align-items: center; }
.step.done { color: var(--ok); }
.step.current { color: var(--accent); }
.step.pending { color: var(--muted); }
.step.fail { color: var(--error); }
.error-msg { color: var(--error); margin: 8px 0 0; font-size: 12px; }
.job-status details { margin-top: 8px; }
.job-status summary { cursor: pointer; color: var(--muted); font-size: 12px; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid; place-items: center;
  z-index: 300;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  width: 400px;
  max-width: 90vw;
}
.modal-card h2 { margin: 0 0 16px; font-size: 15px; font-weight: 600; }
.modal-card form { display: grid; gap: 14px; }
.modal-card label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.modal-card input[type=text],
.modal-card input[type=number],
.modal-card input:not([type]) {
  font: inherit; padding: 8px 10px;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.modal-card .checkbox-row {
  flex-direction: row; align-items: center; gap: 8px;
  display: flex; color: var(--text); font-size: 13px;
}
.modal-card .hint { color: var(--accent); font-family: 'SF Mono', Monaco, Consolas, monospace; min-height: 1.2em; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 8px; }
.error { color: var(--error); margin: 0; min-height: 1.2em; font-size: 12px; }

/* ============ env modal ============ */
.modal-card.env-card { width: 640px; max-width: 95vw; }
.env-help { margin: 0 0 8px; font-size: 12px; }
.env-help code { background: var(--bg); padding: 1px 6px; border-radius: 3px; }
#env-textarea {
  width: 100%;
  font: 12px/1.45 'SF Mono', Monaco, Consolas, monospace;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  min-height: 200px;
}

/* ============ shell area ============ */
.shell-area {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.shell-toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.shell-toolbar code { background: var(--bg); padding: 1px 6px; border-radius: 3px; }
.shell-form { display: flex; gap: 6px; }
.shell-input {
  flex: 1;
  font: 13px 'SF Mono', Monaco, Consolas, monospace;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.shell-output { max-height: 320px; }
.shell-output:empty { display: none; }

/* ============ system ============ */
.kv { display: flex; gap: 12px; padding: 4px 0; font-size: 13px; }
.kv span:first-child { color: var(--muted); width: 130px; flex-shrink: 0; }
.kv strong.warn { color: var(--error); }
.kv code {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
  word-break: break-all;
}

/* ============ toast ============ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 13px;
  max-width: 400px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  z-index: 200;
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--error); }
