/* =========================
   Seismic Gateway Dashboard — Refreshed UI
   - Design tokens
   - Modern cards, headers, status pills
   - Accessible contrast, dark mode
   ========================= */

:root {
  /* Palette */
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --info: #0ea5e9;

  /* Accents */
  --chip-bg: #f3f4f6;
  --chip-text: #374151;

  /* Effects */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 8px 16px rgba(17, 24, 39, 0.08);
  --radius: 12px;

  /* Typography */
  --font-sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Inter, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --card: #111827;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #1f2937;
    --primary: #60a5fa;
    --primary-600: #3b82f6;
    --chip-bg: #0f172a;
    --chip-text: #cbd5e1;
    --shadow-md: 0 8px 24px rgba(2, 6, 23, 0.5);
  }
}

/* Base */
* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.45;
}

/* Page title */
.page-title {
  padding: 22px 24px 6px;
}
.page-title h1 {
  margin: 0;
  color: var(--text);
  font-size: 28px;
  letter-spacing: 0;
}
.page-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

main.grid { padding: 18px 24px 24px; }

/* Grid layout */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 20px;
}
@media (max-width: 1200px) {
  .grid { grid-template-columns: repeat(8, 1fr); }
}
@media (max-width: 768px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
}

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(0,0,0,0.02), transparent);
}
.card .card-header h3 {
  margin: 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card .card-body {
  padding: 16px;
}

/* Column spans */
.span-6 { grid-column: span 6; }
.span-4 { grid-column: span 4; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

@media (max-width: 1200px) {
  .span-8 { grid-column: span 8; }
  .span-6 { grid-column: span 8; }
  .span-4 { grid-column: span 8; }
}
@media (max-width: 768px) {
  .span-8, .span-6, .span-4, .span-12 { grid-column: span 4; }
}

/* KPI grid */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 768px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
.stat {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(2,6,23,0.03), rgba(2,6,23,0.00));
  padding: 12px;
  text-align: center;
}
.stat-value {
  font-size: 24px;
  font-weight: 700;
}
.stat-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-top: 4px;
}

/* Status pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--chip-text);
  border: 1px solid var(--border);
}
.pill.success { background: rgba(22,163,74,0.12); color: #16a34a; border-color: rgba(22,163,74,.3); }
.pill.danger  { background: rgba(220,38,38,0.12); color: #dc2626; border-color: rgba(220,38,38,.3); }
.pill.warn    { background: rgba(245,158,11,0.12); color: #b45309; border-color: rgba(245,158,11,.35); }
.pill.info    { background: rgba(14,165,233,0.12); color: #0284c7; border-color: rgba(14,165,233,.35); }

/* Sensors grid */
.sensors {
  display: grid;
  grid-template-columns: repeat( auto-fill, minmax(220px, 1fr) );
  gap: 12px;
}
.sensor {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(2,6,23,0.03), rgba(2,6,23,0.00));
}
.sensor > div:first-child {
  font-weight: 600;
  margin-bottom: 4px;
}
.sensor.connected { box-shadow: inset 0 0 0 1px rgba(22,163,74,.25); }
.sensor.disconnected { box-shadow: inset 0 0 0 1px rgba(220,38,38,.25); }
.sensor small { color: var(--muted); display: block; }

/* Buttons */
button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--primary);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
  box-shadow: 0 1px 0 rgba(0,0,0,0.05);
}
button:hover { background: var(--primary-600); transform: translateY(-1px); }
button:active { transform: translateY(0); }
button.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
button.danger { background: var(--warning); border-color: transparent; color: #111827; }
button.danger:hover { background: #d97706; }

/* Toolbar (actions row inside cards) */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Queue / DB breakdown */
#queue-status, #db-breakdown {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  font-size: 14px;
}
#db-breakdown .item, #queue-status .item {
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: rgba(2,6,23,0.02);
}

/* Logs */
.card-logs .card-body { padding: 0; }
.logs-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(0,0,0,0.03), transparent);
  position: sticky;
  top: 0;
  z-index: 5;
}
.logs {
  height: 420px;
  overflow-y: auto;
  background: #0b1220;
  color: #cbd5e1;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.log-entry {
  padding: 3px 0;
  border-bottom: 1px dashed rgba(148,163,184,0.18);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.badge { padding: 2px 6px; border-radius: 6px; font-weight: 700; font-size: 11px; }
.badge.info { background: rgba(37,99,235,.18); color: #93c5fd; }
.badge.warn { background: rgba(245,158,11,.18); color: #fcd34d; }
.badge.error { background: rgba(239,68,68,.2); color: #fecaca; }

.timestamp { color: #94a3b8; }
.source { color: #8b9db8; }

.footer-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

/* Utility visibility helpers */
.hidden { display: none !important; }

/* Fine-tuning older classes (backward compatibility) */
.status-good   { color: var(--success); }
.status-warning{ color: var(--warning); }
.status-error  { color: var(--danger); }

/* ── Botón info + modal de ayuda (panel Transport) ─────────────────────── */
.card-header-actions { display: flex; align-items: center; gap: 8px; }
.info-btn {
  border: 1px solid var(--border); background: var(--chip-bg); color: var(--chip-text);
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: 13px;
  line-height: 1; display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.info-btn:hover { border-color: var(--primary); }

.help-modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 9999;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.help-modal-bg.show { display: flex; }
.help-modal {
  background: var(--card); color: var(--text); border-radius: var(--radius);
  max-width: 720px; width: 100%; max-height: 88vh; overflow: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,.35); border: 1px solid var(--border);
}
.help-modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--card);
}
.help-modal-head h2 { font-size: 17px; margin: 0; }
.help-close { border: none; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; }
.help-close:hover { color: var(--text); }
.help-modal-body { padding: 8px 20px 20px; }
.help-modal-body h3 { font-size: 14px; margin: 18px 0 8px; color: var(--text); }
.help-modal-body p { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }

.help-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.help-table th, .help-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.help-table thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
.help-table td:first-child { white-space: nowrap; }
.help-table code, .help-flow code, .help-list code {
  font-family: var(--font-mono); background: var(--chip-bg); color: var(--chip-text);
  padding: 1px 5px; border-radius: 4px; font-size: 12px;
}
.help-flow {
  font-size: 12px; background: var(--chip-bg); border-radius: 8px; padding: 8px 12px;
  margin-top: 10px; color: var(--text);
}
.help-list { font-size: 13px; margin: 6px 0 0; padding-left: 20px; color: var(--text); }
.help-list li { margin: 5px 0; }
