:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-light: #eff6ff;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --ok: #16a34a;
  --ok-light: #f0fdf4;
  --warn: #d97706;
  --warn-light: #fffbeb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.16), 0 4px 12px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

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

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

/* ── Auth ───────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #eff6ff 0%, #f0f2f5 100%);
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 380px;
  padding: 36px 32px;
}
.auth-card h1 { font-size: 22px; margin: 0 0 4px; color: var(--text); }
.auth-card p.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

label { display: block; font-weight: 600; margin: 14px 0 5px; font-size: 13px; color: #374151; }

input, select {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: #fff;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
input:disabled { background: #f9fafb; color: var(--muted); cursor: not-allowed; }

/* ── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  transition: background .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-hover); box-shadow: 0 2px 8px rgba(37,99,235,.25); }
.btn:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }
.btn-block { width: 100%; margin-top: 20px; }

.btn-ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: #f9fafb; box-shadow: none; }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; box-shadow: 0 2px 8px rgba(220,38,38,.25); }

.btn-ok { background: var(--ok); }
.btn-ok:hover { background: #15803d; box-shadow: 0 2px 8px rgba(22,163,74,.25); }

/* ── Alerts ─────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin: 10px 0;
  font-size: 13px;
  font-weight: 500;
  border-left: 4px solid transparent;
}
.alert::before { font-size: 15px; line-height: 1.4; flex-shrink: 0; }
.alert-error {
  background: var(--danger-light);
  color: #991b1b;
  border-left-color: var(--danger);
}
.alert-error::before { content: "✕"; color: var(--danger); }
.alert-ok {
  background: var(--ok-light);
  color: #166534;
  border-left-color: var(--ok);
}
.alert-ok::before { content: "✓"; color: var(--ok); }
.alert-warn {
  background: var(--warn-light);
  color: #92400e;
  border-left-color: var(--warn);
}
.alert-warn::before { content: "⚠"; color: var(--warn); }
.alert-info {
  background: var(--primary-light);
  color: #1e40af;
  border-left-color: var(--primary);
}
.alert-info::before { content: "ℹ"; color: var(--primary); }

.muted { color: var(--muted); }
.center { text-align: center; }
.mt { margin-top: 14px; }

/* ── Topbar ─────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .user {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}
.topbar .user strong { color: var(--text); }

/* ── Layout ─────────────────────────────────────── */
.container { padding: 20px 24px; max-width: 1440px; margin: 0 auto; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Toolbar / Filters ─────────────────────────── */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; min-width: 220px; }

.filters-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  border: 1px solid #bfdbfe;
  color: #1e40af;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
}
.filter-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: #1e40af;
  font-weight: 700;
  padding: 0 0 0 2px;
  font-size: 13px;
  line-height: 1;
}
.filter-chip button:hover { color: var(--danger); }

.filter-builder { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-top: 14px; }
.filter-builder > div { display: flex; flex-direction: column; }
.filter-builder label { margin: 0 0 4px; }
.filter-builder select, .filter-builder input { min-width: 140px; }

/* ── Table ──────────────────────────────────────── */
.table-scroll { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  background: #f8fafc;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
}
th:hover { background: #f1f5f9; color: var(--text); }
th .arrow { color: var(--primary); font-size: 10px; margin-left: 3px; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
td.actions { display: flex; gap: 6px; align-items: center; }

/* ── Badges ─────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.badge-yes { background: #dcfce7; color: #166534; }
.badge-no  { background: #fee2e2; color: #991b1b; }
.badge-neutral { background: #f1f5f9; color: #475569; }

/* ── Pagination ─────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.pagination .pages { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ── Spinner ────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #c7d2fe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); font-size: 14px; }
.empty::before { display: block; font-size: 32px; margin-bottom: 8px; content: "📭"; }

[x-cloak] { display: none !important; }

/* ── Tabs ───────────────────────────────────────── */
.tabs {
  display: flex;
  background: #fff;
  border-bottom: 2px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 56px; /* altura del topbar */
  z-index: 40;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); background: #f9fafb; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn .tab-count {
  background: #e0e7ff;
  color: var(--primary);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
}

/* ── Modals ─────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .18s ease;
}
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { margin: 0; font-size: 17px; font-weight: 700; color: var(--text); }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .1s, color .1s;
}
.modal-close:hover { background: #f1f5f9; color: var(--text); }

.modal-body {
  padding: 20px 24px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-body .field { display: flex; flex-direction: column; gap: 5px; }
.modal-body .field label { margin: 0; }
.modal-body .field-row { display: flex; gap: 12px; }
.modal-body .field-row .field { flex: 1; }

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* checkbox inline */
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
}
.check-row input[type=checkbox] {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  accent-color: var(--primary);
}
.check-row label {
  margin: 0;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.check-row .hint { font-weight: 400; color: var(--muted); font-size: 12px; }

/* section title */
.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
