*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f0f0f;
  --sidebar-bg:  #161616;
  --card-bg:     #1a1a1a;
  --border:      #2a2a2a;
  --text:        #e8e8e8;
  --text-muted:  #888;
  --accent:      #7c6fe0;
  --accent-dim:  #7c6fe020;
  --green:       #4ade80;
  --yellow:      #fbbf24;
  --red:         #f87171;
  --radius:      8px;
}

/* ── BASE ────────────────────────────────────────────────────────────────── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── LOGIN ───────────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 24px;
  letter-spacing: -0.5px;
}

.login-logo span { color: var(--text); }

.login-card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text);
}

.login-error {
  background: #f8717120;
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── FORMS ───────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.form-group select {
  appearance: none;
  cursor: pointer;
}

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── MOBILE HEADER ───────────────────────────────────────────────────────── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  z-index: 200;
}

/* ── HAMBURGER ───────────────────────────────────────────────────────────── */
#hamburger-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  padding: 8px;
  cursor: pointer;
}

/* ── SIDEBAR OVERLAY ─────────────────────────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 149;
}

/* ── APP LAYOUT ──────────────────────────────────────────────────────────── */
#app {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 24px 20px 16px;
}

.sidebar-logo {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.sidebar-logo span { color: var(--text); }

nav {
  flex: 1;
  padding: 8px 12px;
}

.nav-item {
  padding: 9px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  transition: background 0.12s, color 0.12s;
  margin-bottom: 2px;
  user-select: none;
}

.nav-item:hover {
  background: var(--accent-dim);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border);
}

.sidebar-footer button {
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.sidebar-footer button:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ── CONTENT ─────────────────────────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 28px;
}

/* ── SECTION HEADER ──────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
}

.section-header h1 { margin-bottom: 0; }

section h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text);
}

/* ── INFO BUTTON ─────────────────────────────────────────────────────────── */
.info-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  margin-left: 10px;
  vertical-align: middle;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.info-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── CARDS ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.section-row {
  display: flex;
  gap: 16px;
}

.half {
  flex: 1;
}

.full-width {
  width: 100%;
}

/* ── PROGRESS BARS ───────────────────────────────────────────────────────── */
.progress-bar-wrap {
  background: var(--border);
  border-radius: 4px;
  height: 6px;
  margin-top: 8px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* ── TABLES ──────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

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

.data-table td {
  padding: 10px 12px 10px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
}

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

.data-table tr:hover td {
  background: #ffffff05;
}

/* ── BADGES ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-green  { background: #4ade8020; color: var(--green);  }
.badge-red    { background: #f8717120; color: var(--red);    }
.badge-yellow { background: #fbbf2420; color: var(--yellow); }
.badge-gray   { background: #88888820; color: var(--text-muted); }
.badge-accent { background: var(--accent-dim); color: var(--accent); }

/* ── SPINNER ─────────────────────────────────────────────────────────────── */
.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 20px auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── TOOLBAR ─────────────────────────────────────────────────────────────── */
.toolbar {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.log-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filter-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.filter-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.filter-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ── LOG LINES ───────────────────────────────────────────────────────────── */
.log-lines {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.7;
  overflow-x: auto;
}

.log-line {
  padding: 2px 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-line.error { color: var(--red); }
.log-line.warn  { color: var(--yellow); }
.log-line.info  { color: var(--text-muted); }

.log-service-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 6px;
  font-weight: 700;
  text-transform: uppercase;
}

.tag-n8n     { background: var(--accent-dim); color: var(--accent); }
.tag-traefik { background: #4ade8015; color: var(--green); }

/* ── EMPTY STATE ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── MODALS ──────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}

.modal-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 480px;
}

.modal-box h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.modal-actions button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.modal-actions button:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.modal-actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── INFO MODAL ──────────────────────────────────────────────────────────── */
.info-modal-box {
  max-width: 480px;
}

.info-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.info-modal-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  transition: color 0.15s;
}

.info-modal-header button:hover {
  color: var(--text);
}

#info-modal-body {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.7;
}

#info-modal-body strong { color: var(--text); }
#info-modal-body p + p  { margin-top: 10px; }

/* ── WARN BOX ────────────────────────────────────────────────────────────── */
.warn-box {
  background: #fbbf2415;
  border: 1px solid #fbbf2440;
  color: var(--yellow);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 4px;
}

/* ── UPDATE MODAL ────────────────────────────────────────────────────────── */
.update-steps {
  margin: 16px 0;
  font-size: 13px;
  line-height: 1.8;
  max-height: 200px;
  overflow-y: auto;
  font-family: 'Menlo', 'Consolas', monospace;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.update-steps:empty {
  display: none;
}

.step-done   { color: var(--green); }
.step-error  { color: var(--red); }
.step-active { color: var(--accent); }

#update-result {
  margin-top: 12px;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius);
}

#update-result.success {
  background: #4ade8015;
  border: 1px solid #4ade8040;
  color: var(--green);
}

#update-result.error-result {
  background: #f8717115;
  border: 1px solid #f8717140;
  color: var(--red);
}

/* ── N8N VERSION CARD ────────────────────────────────────────────────────── */
.version-card-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 4px;
}

.update-available-tag {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.btn-update {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-update:hover { opacity: 0.88; }
.btn-update:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── ACTION BUTTONS (editar/eliminar en tablas) ───────────────────────────── */
.action-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}

.action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.action-btn.danger:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ── RESPONSIVE: 768px ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }

  #app {
    padding-top: 52px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 150;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    height: 100%;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  #sidebar-overlay.open {
    display: block;
  }

  .sidebar-header {
    padding-top: 64px;
  }

  .content {
    padding: 20px 16px;
  }

  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .section-row {
    flex-direction: column;
  }

  .half {
    flex: none;
    width: 100%;
  }

  .data-table {
    font-size: 12px;
  }

  .data-table th,
  .data-table td {
    padding: 8px 8px 8px 0;
  }

  .modal-box {
    width: 95vw;
    padding: 20px;
  }

  .log-lines {
    font-size: 11px;
  }

  .cards-grid[style*="repeat(2"] {
    grid-template-columns: 1fr !important;
  }
}

/* ── RESPONSIVE: 480px ───────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }

  .stat-value {
    font-size: 22px;
  }

  .login-card {
    padding: 28px 20px;
  }
}
