:root {
  --c-bg: #0f172a;
  --c-card: #1e293b;
  --c-border: #334155;
  --c-text: #e2e8f0;
  --c-muted: #94a3b8;
  --c-primary: #3b82f6;
  --c-primary-dark: #2563eb;
  --c-code-bg: #0b1220;
  --c-error: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

/* Utilidades: estado oculto generico (sobrescribe display flex, etc.). */
.hidden { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.5;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  background: rgba(148, 163, 184, 0.15);
  color: #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---- Login ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}

.login-card .brand { text-align: center; margin-bottom: 24px; }
.login-card .brand h1 { margin: 0 0 4px; font-size: 1.35em; }
.login-card .brand p { margin: 0; color: var(--c-muted); font-size: 0.95em; }

.login-card label {
  display: block;
  font-size: 0.9em;
  font-weight: 600;
  margin: 14px 0 6px;
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  background: var(--c-bg);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  font-size: 1em;
}

.login-card input:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.hint { color: var(--c-muted); font-size: 0.85em; }

/* ---- Layout ---- */
.topbar {
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar-user { color: var(--c-muted); font-size: 0.9em; }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ---- Cards ---- */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card h2 { margin: 0 0 6px; font-size: 1.15em; }
.card p.muted { margin: 0 0 18px; color: var(--c-muted); }

/* ---- Botones ---- */
.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  background: var(--c-primary);
  color: #fff;
  transition: background 0.15s ease;
}

.btn:hover { background: var(--c-primary-dark); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-block { width: 100%; margin-top: 20px; }

/* ---- Bloques de codigo (estilo Markdown) ---- */
.cmd-block { margin: 0 0 20px; }
.cmd-block h3 { margin: 0 0 8px; font-size: 1em; }

.cmd-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.cmd-box {
  flex: 1;
  background: var(--c-code-bg);
  border: 1px solid var(--c-border);
  color: #e2e8f0;
  border-radius: 8px;
  padding: 12px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  white-space: pre-wrap;
  word-break: break-word;
}

.btn-copy {
  align-self: center;
  flex-shrink: 0;
  background: #334155;
  color: #e2e8f0;
  border: 1px solid #475569;
  padding: 10px 16px;
}

.btn-copy:hover { background: #475569; }

/* ---- Informacion del cron ---- */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin: 0;
}

.info-item dt {
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-muted);
}

.info-item dd { margin: 4px 0 0; font-weight: 600; }

/* ---- Ficha colapsable ---- */
.collapsible {
  margin-top: 16px;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  overflow: hidden;
}

.collapsible-header {
  padding: 12px 16px;
  background: var(--c-bg);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95em;
  user-select: none;
  transition: background 0.15s ease;
}

.collapsible-header:hover {
  background: var(--c-border);
}

.collapsible-header::before {
  content: "▶";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.2s ease;
  font-size: 0.8em;
}

.collapsible[open] .collapsible-header::before {
  transform: rotate(90deg);
}

.collapsible-content {
  padding: 16px;
  border-top: 1px solid var(--c-border);
}

.collapsible-content .cmd-block:last-child {
  margin-bottom: 0;
}

.relative-time {
  border-bottom: 1px dotted var(--c-muted);
  cursor: help;
}

/* ---- Memoria del sistema ---- */
.mem-bar {
  height: 8px;
  background: var(--c-code-bg);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 16px;
}

.mem-bar-fill {
  height: 100%;
  background: var(--c-primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* ---- Log ---- */
.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin: 0 0 16px;
  background: var(--c-code-bg);
  border: 1px solid var(--c-border);
  border-radius: 10px;
}

.tab {
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--c-muted);
  padding: 8px 18px;
  cursor: pointer;
  font-size: 0.95em;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab:hover {
  color: var(--c-text);
  background: rgba(148, 163, 184, 0.08);
}

.tab.active {
  color: #fff;
  background: var(--c-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.tab-panel.hidden { display: none; }

.log-box {
  background: var(--c-code-bg);
  border: 1px solid var(--c-border);
  color: #cbd5e1;
  border-radius: 8px;
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82em;
  max-height: 480px;
  overflow-y: auto;
}

.log-line { white-space: pre-wrap; word-break: break-word; }

/* ---- Alerts ---- */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin: 0 0 20px;
  font-size: 0.95em;
  border: 1px solid;
}

.alert-error {
  background: rgba(220, 38, 38, 0.15);
  border-color: #7f1d1d;
  color: #fca5a5;
}

.alert-success {
  background: rgba(34, 197, 94, 0.15);
  border-color: #14532d;
  color: #86efac;
}

/* ---- CRUD de sitios ---- */
.sites-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.sites-header .muted { margin-bottom: 0; }

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

.sites-count {
  color: var(--c-muted);
  font-size: 0.85em;
  white-space: nowrap;
}

/* ---- Tabla de datos ---- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
}

.data-table th {
  text-align: left;
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-border);
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
  word-break: break-word;
}

.data-table tbody tr:hover {
  background: rgba(59, 130, 246, 0.06);
}

.data-table .col-actions {
  text-align: right;
  white-space: nowrap;
  width: 1%;
}

.btn-group {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.inline-form {
  display: inline;
  margin: 0;
}

/* ---- Botones auxiliares ---- */
.btn-sm {
  padding: 6px 12px;
  font-size: 0.88em;
  border-radius: 6px;
}

.btn-danger {
  background: var(--c-error);
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-ghost {
  background: transparent;
  color: var(--c-muted);
  border: 1px solid var(--c-border);
}

.btn-ghost:hover {
  background: rgba(148, 163, 184, 0.12);
  color: var(--c-text);
}

/* ---- Formulario de sitio ---- */
.site-form {
  max-width: 560px;
}

.form-field {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 0.9em;
  font-weight: 600;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--c-bg);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  font-size: 1em;
  font-family: inherit;
}

.form-input:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.form-textarea {
  resize: vertical;
}

.toggle-password {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.85em;
  color: var(--c-muted);
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 24px;
}

/* ---- Boton de llave y modal de contrasena ---- */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.btn-key {
  background: transparent;
  color: var(--c-muted);
  border: 1px solid var(--c-border);
}

.btn-key:hover {
  color: var(--c-primary);
  border-color: var(--c-primary);
  background: rgba(59, 130, 246, 0.1);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(2, 6, 23, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1em;
}

.modal-close {
  background: none;
  border: none;
  color: var(--c-muted);
  font-size: 1.5em;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--c-text);
}

.modal-body {
  padding: 20px;
}

.cred-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  margin: 0 0 16px;
  align-items: center;
}

.cred-grid dt {
  color: var(--c-muted);
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cred-grid dd {
  margin: 0;
  font-weight: 500;
  word-break: break-word;
}

/* ---- Responsive (movil) ---- */

/* Tablets y moviles en horizontal */
@media (max-width: 768px) {
  .container {
    padding: 16px;
  }
}

/* Moviles en vertical */
@media (max-width: 640px) {
  .btn-block { margin-top: 16px; }

  /* Barra superior: se apila y permite que el usuario/enlaces salten de linea */
  .topbar-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 12px 16px;
  }

  .topbar-user {
    font-size: 0.85em;
    white-space: normal;
    line-height: 1.7;
  }

  /* Tarjetas con menos padding, mas superficie util */
  .card { padding: 16px; }

  /* Cabecera del CRUD: apilar titulo + boton */
  .sites-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  /* Toolbar de filtro: el contador bajo el campo */
  .sites-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .sites-toolbar .form-input { flex: 1 1 auto; }

  /* Los comandos copiables pasan a apilarse: caja arriba, boton debajo */
  .cmd-row {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-copy {
    align-self: stretch;
  }

  /* La tabla se convierte en tarjetas por fila */
  .data-table thead { display: none; }

  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 10px;
    padding: 4px 0;
    margin-bottom: 14px;
  }

  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
    padding: 10px 14px;
    border-bottom: 1px solid var(--c-border);
  }

  .data-table td:last-child {
    border-bottom: none;
  }

  /* Etiqueta del campo (data-label) a la izquierda */
  .data-table td::before {
    content: attr(data-label);
    flex-shrink: 0;
    color: var(--c-muted);
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  /* Columna de acciones: sin nowrap y con botones que cabe aportan bien */
  .data-table .col-actions {
    width: 100%;
    white-space: normal;
    text-align: right;
  }

  .btn-group {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

/* Pantallas muy estrechas: formularios y rejilla condensados */
@media (max-width: 400px) {
  .cred-grid {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }

  .cred-grid dd {
    margin-bottom: 10px;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions .btn,
  .form-actions .btn-ghost {
    text-align: center;
  }
}