:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #1a222d;
  --border: #232d3a;
  --text: #d7e0ea;
  --muted: #7b8794;
  --accent: #3fa9f5;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --warn: #f5a623;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

input, button, textarea, select {
  font-family: inherit;
  font-size: 14px;
}

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: rgba(239, 68, 68, .12); }
button.ghost { background: transparent; }
button.small { padding: 4px 8px; font-size: 12px; }
a { color: var(--accent); }

/* ---------- Auth (login / enroll) — igual que ebalsoft-ssh-console ---------- */
.auth-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px; /* evita auto-zoom de iOS al enfocar inputs */
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-error {
  background: #2a1418; border: 1px solid #4a1f26; color: #ffb4bd;
  padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px;
}
.auth-card button[type="submit"] { width: 100%; padding: 12px; }
.qr-box { background: #fff; padding: 10px; border-radius: 8px; display: inline-block; margin: 6px 0 14px; }
.secret-fallback { font-size: 12px; color: var(--muted); word-break: break-all; margin-bottom: 14px; }

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
  cursor: pointer;
}
.checkbox-field input { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }

.auth-checking-msg { display: none; color: var(--muted); font-size: 14px; }
.auth-wrap.checking .auth-card { display: none; }
.auth-wrap.checking .auth-checking-msg { display: block; }

#submitBtn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
#submitBtn .btn-spinner {
  display: none;
  width: 14px; height: 14px;
  border: 2px solid rgba(4, 18, 31, .35);
  border-top-color: #04121f;
  border-radius: 50%;
  animation: btn-spin .6s linear infinite;
}
#submitBtn.loading .btn-spinner { display: inline-block; }
#submitBtn.loading { cursor: progress; opacity: .85; }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ---------- Dashboard ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.topbar h1 { font-size: 16px; margin: 0; }
.topbar .spacer { flex: 1; }
.topbar .username { color: var(--muted); font-size: 13px; }

.main { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; }

.version-tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 12px; }
.version-tabs button {
  border-radius: 999px; padding: 7px 14px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
}
.version-tabs button.active { color: var(--text); border-color: var(--accent); background: rgba(63, 169, 245, .12); }
.version-tabs button .count { color: var(--muted); font-size: 12px; margin-left: 4px; }

table.instances { width: 100%; border-collapse: collapse; font-size: 13px; }
table.instances th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  padding: 6px 10px; border-bottom: 1px solid var(--border);
}
table.instances td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.instances tr:last-child td { border-bottom: none; }
table.instances .name-cell .real-name { color: var(--muted); font-size: 11px; }
table.instances input.inline-edit, table.instances select.inline-edit {
  background: transparent; border: 1px solid transparent; color: var(--text); padding: 3px 5px; border-radius: 6px;
  width: 100%; font-size: 13px;
}
table.instances select.inline-edit { background: var(--panel-2); border-color: var(--border); }
table.instances input.inline-edit:hover, table.instances select.inline-edit:hover { border-color: var(--border); }
table.instances input.inline-edit:focus, table.instances select.inline-edit:focus { border-color: var(--accent); outline: none; background: var(--panel-2); }

.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; flex-shrink: 0; }
.status-dot.running { background: var(--accent-2); }
.status-dot.stopped { background: var(--danger); }
.status-dot.other { background: var(--warn); }
.status-cell { display: flex; align-items: center; white-space: nowrap; }

.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.repo-dirty { color: var(--warn); font-size: 11px; }

.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .panels { grid-template-columns: 1fr; } }

.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.form-row select, .form-row input[type="text"], .form-row textarea {
  width: 100%; padding: 9px 10px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
}
.form-row textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; min-height: 70px; resize: vertical; }
.form-row .hint { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.checkbox-inline { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-right: 12px; }
.checkbox-inline input { accent-color: var(--accent); }

.module-chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.module-chip {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 12px;
  display: inline-flex; align-items: center; gap: 6px;
}
.module-chip button { border: none; background: none; padding: 0; color: var(--muted); font-size: 13px; line-height: 1; }

/* ---------- Consola de log en vivo (modal) ---------- */
.log-modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 100;
  align-items: center; justify-content: center; padding: 20px;
}
.log-modal-backdrop.show { display: flex; }
.log-modal {
  width: 100%; max-width: 900px; height: 80vh; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; display: flex; flex-direction: column; overflow: hidden;
}
.log-modal-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.log-modal-head h3 { margin: 0; font-size: 14px; flex: 1; }
.log-modal-body {
  flex: 1; overflow-y: auto; padding: 12px 16px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; white-space: pre-wrap; word-break: break-word; background: #05070a;
}
.log-modal-body .done-ok { color: var(--accent-2); font-weight: 700; }
.log-modal-body .done-fail { color: var(--danger); font-weight: 700; }

.toast-wrap {
  position: fixed;
  bottom: calc(46px + env(safe-area-inset-bottom) + 12px);
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  font-size: 13px; box-shadow: 0 10px 26px rgba(0,0,0,.5); max-width: 320px;
}
.toast.error { border-color: var(--danger); color: #ffb4bd; }
.toast.ok { border-color: var(--accent-2); }

.empty-hint { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }

/* ---------- Statusbar (CPU/RAM/Disco) — fija al pie, siempre visible
   (no se va con el scroll de .main, a diferencia de ebalsoft-ssh-console
   donde alcanza con que sea el último elemento del flex column). ---------- */
.statusbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 12px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}
/* Espacio para que el contenido de .main no quede tapado detrás de la
   barra fija — mismo alto aproximado que ocupa .statusbar. */
.main { padding-bottom: calc(46px + env(safe-area-inset-bottom)); }
.stat-item { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.stat-label { font-weight: 700; letter-spacing: .02em; }
.stat-bar {
  width: 44px; height: 6px; border-radius: 3px;
  background: var(--panel-2); border: 1px solid var(--border);
  overflow: hidden; flex-shrink: 0;
}
.stat-bar-fill {
  height: 100%; width: 0%; background: var(--accent-2);
  transition: width .4s ease, background-color .4s ease;
}
.stat-bar-fill.warn { background: #f5b83f; }
.stat-bar-fill.danger { background: var(--danger); }
.stat-value { font-variant-numeric: tabular-nums; color: var(--text); }

/* ---------- Responsive (celular) ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
.table-scroll table.instances { min-width: 760px; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .topbar h1 { flex: 1 1 auto; }
  .topbar .username { display: none; }
  .main { padding: 12px; gap: 14px; }
  .card { padding: 12px; border-radius: 12px; }
  .version-tabs button { padding: 6px 11px; font-size: 12.5px; }
  .row-actions { flex-direction: column; align-items: stretch; }
  .row-actions button { width: 100%; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .checkbox-inline { margin-right: 0; }
  .log-modal { height: 92vh; max-width: 100%; border-radius: 10px; }
  .log-modal-backdrop { padding: 8px; }
  .statusbar { gap: 12px; font-size: 10.5px; }
  .stat-bar { width: 34px; }
}
