:root {
  --bg: #f1f4f9;
  --surface: #ffffff;
  --border: #e5e7ee;
  --border-strong: #cbd5e1;
  --text: #1f2430;
  --text-muted: #7a8094;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-dark: #1e40af;
  --primary-soft: #eaf1ff;
  --header-grad: linear-gradient(135deg, #1e40af 0%, #2563eb 55%, #3b82f6 100%);
  --danger: #e5484d;
  --danger-hover: #d33c41;
  --success: #16a34a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 22, 40, 0.04), 0 8px 24px rgba(20, 22, 40, 0.06);
}

* { 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);
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  color: var(--text);
}

.brand img.logo {
  height: 38px;
  width: auto;
  display: block;
}

.brand .brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand .brand-text small {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.nav-tabs {
  display: flex;
  gap: 8px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.nav-tabs a {
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  transition: all 0.15s ease;
}

.nav-tabs a:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.nav-tabs a.active {
  background: var(--primary);
  color: #fff;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--header-grad);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

/* ---------- Layout containers ---------- */

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 32px 60px;
}

.container-fluid {
  width: 100%;
  margin: 0;
  padding: 20px 24px 40px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 {
  font-size: 22px;
  margin: 0 0 4px;
}

.page-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13.5px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.card-flush {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---------- Search + filters banner ---------- */

.search-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.search-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  font-size: 14.5px;
  border-radius: 10px;
}

.btn-toggle-filters {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid #d6e4ff;
}

.btn-toggle-filters:hover { background: #dfeaff; }

.btn-toggle-filters .chev {
  transition: transform 0.2s ease;
}

.btn-toggle-filters.open .chev {
  transform: rotate(180deg);
}

.filters-panel {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.25s ease;
  padding: 0 18px;
  border-bottom: 1px solid transparent;
}

.filters-panel.open {
  max-height: 220px;
  opacity: 1;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: #fafbff;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

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

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 14px;
  display: block;
}

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fbfbfd;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: #fff;
}

textarea { resize: vertical; min-height: 70px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-success { background: #ecfdf3; color: var(--success); border: 1px solid #c6f0d6; }
.btn-success:hover { background: #dcfce7; }

.btn-danger { background: #fef1f1; color: var(--danger); border: 1px solid #f7d3d4; }
.btn-danger:hover { background: #fde2e2; }

.btn-edit { background: var(--primary); color: #fff; }
.btn-edit:hover { background: var(--primary-hover); }

.btn-delete { background: var(--danger); color: #fff; }
.btn-delete:hover { background: var(--danger-hover); }

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

/* ---------- Table (Excel-like grid) ---------- */

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 320px);
  min-height: 300px;
}

.container-fluid:fullscreen {
  background: var(--bg);
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 20px 24px 40px;
}

.container-fluid:fullscreen .table-wrap {
  max-height: calc(100vh - 260px);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  padding: 13px 14px;
  border: 1px solid var(--primary-hover);
  border-top: none;
  position: sticky;
  top: 0;
  z-index: 5;
}

tbody td {
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  vertical-align: middle;
}

tbody tr:nth-child(even) { background: #f8fafc; }
tbody tr:hover { background: #eaf1ff; }

.thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--primary-soft);
  border: 1px solid var(--border);
}

.thumb-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--primary-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-activo { background: #ecfdf3; color: #16a34a; }
.badge-baja { background: #fef1f1; color: #e5484d; }
.badge-proceso { background: #fff7ed; color: #c2410c; }
.badge-default { background: #f1f2f6; color: #565e73; }

.actions-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  min-height: 34px;
}

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}

/* ---------- Form (captura) ---------- */

.form-section {
  margin-bottom: 26px;
}

.form-section:last-child { margin-bottom: 0; }

.form-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-section-title .num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
}

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

.form-grid .field.full { grid-column: 1 / -1; }
.form-grid .field.span2 { grid-column: span 2; }

@media (max-width: 900px) {
  .form-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .container { padding: 20px 16px 40px; }
  .container-fluid { padding: 16px; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .nav-tabs { order: 3; width: 100%; justify-content: flex-start; }
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.photo-box {
  display: flex;
  align-items: center;
  gap: 16px;
}

.photo-preview {
  width: 96px;
  height: 96px;
  border-radius: 12px;
  border: 1px dashed var(--border-strong);
  object-fit: cover;
  background: #fbfbfd;
}

.file-drop {
  flex: 1;
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.file-drop:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  z-index: 100;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.results-count {
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px 18px 0;
}

/* ---------- Modal (seleccionar personal) ---------- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

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

.modal-header h3 { margin: 0; font-size: 16px; }

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

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

.modal-box input[type="text"] {
  margin: 14px 20px 0;
  width: calc(100% - 40px);
}

.modal-list {
  padding: 12px 20px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.modal-item:hover { border-color: var(--primary); background: var(--primary-soft); }

.modal-item .name { font-weight: 600; font-size: 14px; }
.modal-item .meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.modal-photo { max-width: 640px; }

.modal-photo-body {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.modal-photo-body img {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 10px;
  object-fit: contain;
}

.modal-photo-footer {
  padding: 14px 20px 20px;
  display: flex;
  justify-content: flex-end;
}

.thumb { cursor: pointer; }
.thumb:hover { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ---------- Login page ---------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-top: 4px solid var(--primary);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
  padding: 36px 32px 32px;
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.login-logo img {
  width: 100%;
  max-width: 260px;
  height: auto;
}

.login-card h1 {
  text-align: center;
  font-size: 19px;
  margin: 0 0 4px;
}

.login-card p.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
  margin: 0 0 22px;
}

.login-card .field { margin-bottom: 16px; }

.login-card .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 15px;
}

.login-error {
  background: #fef1f1;
  color: var(--danger);
  border: 1px solid #f7d3d4;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px;
  margin-bottom: 16px;
  text-align: center;
}

/* ---------- Usuarios page ---------- */

.users-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfbfd;
}

.user-row .who {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}
