:root {
  --bg: #f8f9fa;
  --panel: #ffffff;
  --line: #e2e8f0;
  --text: #222222;
  --muted: #667085;
  --header: #1a365d;
  --accent: #2f5d8a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 20px 28px;
  background: var(--header);
  color: #ffffff;
}

.topbar h1,
.login-card h1 {
  margin: 6px 0 0;
  font-size: 32px;
  line-height: 1.1;
}

.eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-links {
  display: flex;
  gap: 16px;
}

.nav-links a {
  color: #ffffff;
  text-decoration: none;
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-shell {
  padding: 24px;
}

.panel {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.chart-panel {
  margin-bottom: 0;
}

.bar-list {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.bar-track {
  height: 8px;
  margin-top: 5px;
  background: #e8edf3;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
}

.metric-card {
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 16px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 10px;
  font-size: 34px;
  font-weight: 700;
}

.panel-title {
  padding: 12px 16px;
  background: #eef2f6;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.results-meta {
  padding: 10px 16px 0;
  color: var(--muted);
  font-size: 13px;
}

.filters-grid,
.search-row,
.detail-grid,
.table-actions,
.table-footer,
.stack-form {
  padding: 16px;
}

.filters-layout {
  display: flex;
  flex-direction: column;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.filter-block,
.stack-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-help {
  color: var(--muted);
  font-size: 12px;
}

.check-control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.check-control input {
  width: auto;
  min-height: auto;
}

.inline-actions {
  display: flex;
  gap: 10px;
}

.text-button {
  min-height: auto;
  padding: 0;
  border: 0;
  color: var(--accent);
  background: transparent;
  font-size: 12px;
  text-decoration: underline;
}

.filter-actions,
.search-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.action-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px 16px;
  border-top: 1px solid var(--line);
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.search-row {
  border-top: 1px solid var(--line);
}

.search-row input[type="search"] {
  min-width: 260px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fbfcfe;
}

.summary-item span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-nav {
  margin-bottom: 18px;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 0;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--header);
}

.detail-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.detail-wrapper {
  max-width: 1100px;
}

.detail-grid-2col {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1px;
  background: var(--line);
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 20px;
  background: #ffffff;
}

.field-key {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.field-value {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  word-break: break-word;
  color: var(--text);
}

.edit-layout {
  padding: 20px;
}

.edit-inline {
  display: grid;
  gap: 16px;
}

.edit-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
}

.edit-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

.edit-input {
  flex: 1;
}

.label-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.edit-label select,
.edit-label input {
  min-width: 200px;
}

.edit-checks {
  display: grid;
  gap: 8px;
}

.check-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.check-item input[type="checkbox"] {
  width: 14px;
  min-width: 14px;
  height: 14px;
  min-height: 14px;
  margin: 0;
  flex-shrink: 0;
}

.detail-list {
  display: grid;
  gap: 0;
  padding: 0 16px 16px;
}

.detail-list div {
  display: grid;
  gap: 4px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.detail-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.detail-list dd {
  margin: 0;
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 260px);
  border-bottom: 1px solid var(--line);
}

.table-wrap::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.table-wrap::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.table-wrap table {
  min-width: 1100px;
}

.table-wrap thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.table-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.page-status {
  color: var(--muted);
  font-size: 13px;
}

.empty-state-cell {
  text-align: center;
  color: var(--muted);
  padding: 24px 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: #f1f5f9;
  font-weight: 700;
}

.sort-header {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: inherit;
  text-decoration: none;
}

.sort-header:hover {
  color: var(--accent);
}

.sort-header.sorted {
  color: var(--accent);
}

.sort-inactive {
  color: var(--muted);
  font-size: 12px;
  opacity: 0.5;
}

.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.column-filter {
  display: inline-flex;
  flex-shrink: 0;
}

.column-filter .dropdown-trigger {
  width: auto;
  min-height: 28px;
  padding: 4px 6px;
  border: 0;
  background: transparent;
  font-size: 14px;
}

.column-filter .dropdown-trigger:hover {
  color: var(--accent);
}

.column-filter.is-active .dropdown-trigger {
  color: var(--accent);
  background: #eef6ff;
  border-radius: 4px;
}

.column-filter .dropdown-panel {
  min-width: 220px;
  right: 0;
  left: auto;
  top: 100%;
}

.column-filter .dropdown-apply {
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  text-align: right;
}

tbody tr:nth-child(even) {
  background: #fafbfd;
}

input,
select,
button,
a.button {
  min-height: 40px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 8px 10px;
}

button,
a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
}

.button.primary {
  background: var(--header);
  color: #ffffff;
  border-color: var(--header);
}

.button.secondary {
  background: #ffffff;
}

.button.small {
  min-height: 34px;
  padding: 6px 10px;
}

.muted {
  color: var(--muted);
}

.alert {
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid #ef4444;
  color: #991b1b;
  background: #fef2f2;
}

.alert-ok {
  border: 1px solid #16a34a;
  color: #14532d;
  background: #f0fdf4;
}

.history-conflict {
  color: #991b1b;
  font-size: 12px;
}

.panel-note {
  margin: 0;
  padding: 10px 12px;
  border-left: 3px solid #d97706;
  background: #fffbeb;
  color: #78350f;
  font-size: 13px;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card,
.narrow-panel {
  width: min(100%, 520px);
}

.login-card {
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 24px;
}

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.history-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.history-list li:last-child {
  border-bottom: 0;
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-shell {
    padding: 16px;
  }
}

.checkbox-dropdown {
  position: relative;
}

.checkbox-dropdown.is-active .dropdown-trigger {
  border-color: var(--accent);
  background: #eef6ff;
  font-weight: 700;
}

.checkbox-dropdown.is-active .dropdown-trigger::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.checkbox-dropdown.is-active .dropdown-trigger {
  padding-left: 22px;
}

.dropdown-trigger {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.dropdown-trigger:hover {
  border-color: var(--accent);
}

.dropdown-trigger[aria-expanded="true"] {
  border-color: var(--accent);
}

.trigger-arrow {
  font-size: 10px;
  color: var(--muted);
  flex-shrink: 0;
}

.dropdown-panel {
  position: absolute;
  z-index: 100;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 2px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.1);
  max-height: 280px;
  overflow-y: auto;
}

.dropdown-actions {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #f8f9fa;
  position: sticky;
  top: 0;
  z-index: 1;
}

.dropdown-options {
  padding: 6px 0;
}

.dropdown-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
}

.dropdown-option:hover {
  background: #f0f4f8;
}

.dropdown-search {
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  font: inherit;
  font-size: 13px;
  outline: none;
  position: sticky;
  top: 41px;
  z-index: 1;
}

.dropdown-search:focus {
  border-bottom-color: var(--accent);
}

.sin-dato-option {
  border-bottom: 1px solid var(--line);
  margin-bottom: 2px;
  padding-bottom: 7px;
  font-weight: 600;
}

.dropdown-option input[type="checkbox"] {
  width: 14px;
  min-width: 14px;
  height: 14px;
  min-height: 14px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.nav-dropdown {
  position: relative;
}

.nav-link {
  background: transparent;
  border: 0;
  color: #ffffff;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  min-height: auto;
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 220px;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.12);
  z-index: 150;
}

.nav-dropdown-menu a {
  display: block;
  padding: 10px 14px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}

.nav-dropdown-menu a:hover {
  background: #f0f4f8;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
  display: block;
}

.admin-help {
  padding: 12px 16px;
  color: var(--muted);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

.admin-list {
  padding: 8px 16px 16px;
}

.admin-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  margin-bottom: 6px;
  background: #ffffff;
  cursor: grab;
}

.admin-list-item.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.admin-list-item.drag-over {
  border-color: var(--accent);
  background: #eef6ff;
}

.admin-list-item .drag-handle {
  color: var(--muted);
  font-size: 16px;
  cursor: grab;
  user-select: none;
}

.admin-list-item .field-label {
  flex: 1;
  font-size: 14px;
}

.admin-list-item .check-item {
  margin: 0;
}

.stack-form {
  display: grid;
  gap: 16px;
  max-width: 720px;
}

.stack-form textarea {
  min-height: 80px;
  resize: vertical;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-side-panel {
  width: 50%;
  height: 100%;
  background: var(--bg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.15);
}

@media (max-width: 900px) {
  .modal-side-panel {
    width: 100%;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.modal-body {
  padding: 16px;
  flex: 1;
}

.record-edit-form .field-input {
  margin-top: 6px;
}

.record-edit-form .field-input input,
.record-edit-form .field-input select {
  min-height: 36px;
}

.record-edit-form .multi-checkboxes {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}

.record-edit-form .multi-option {
  font-size: 13px;
  font-weight: 400;
}

.record-edit-form .edit-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.admin-search {
  padding: 12px 16px;
}

.admin-search input {
  max-width: 400px;
}

.field-labels-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  padding: 8px 12px;
  min-height: auto;
}

.tab-button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.field-labels-search {
  padding: 12px 16px;
}

.field-labels-search input {
  max-width: 400px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.field-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-path {
  font-size: 12px;
  color: var(--muted);
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 3px;
}

.field-current-label {
  font-size: 14px;
  font-weight: 500;
}

.override-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: #eef6ff;
  padding: 2px 8px;
  border-radius: 10px;
  align-self: flex-start;
}

/* === UI/UX audit: a11y, feedback, responsive, callouts === */

:root {
  --focus: #1d4ed8;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* callouts (notas / advertencias) */
.callout {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-left: 4px solid var(--warn);
  background: #fffbeb;
  color: #78350f;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 4px;
}
.callout-warning {
  border-left-color: var(--warn);
}

/* flashes persistentes fuera de cada vista */
.app-flash {
  display: grid;
  gap: 8px;
  padding: 12px 24px 0;
  max-width: 100%;
}
.flash {
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 14px;
  border: 1px solid transparent;
}
.flash--error {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}
.flash--ok {
  background: #f0fdf4;
  color: #14532d;
  border-color: #bbf7d0;
}

/* Ultima sincronizacion: estado visible siempre */
.last-sync {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 4px;
  font-size: 13px;
}
.last-sync-label {
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 11px;
}
.last-sync-status {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.status-success, .status-synced {
  background: #dcfce7;
  color: #14532d;
}
.status-running {
  background: #dbeafe;
  color: #1e3a8a;
}
.status-failed, .status-conflict {
  background: #fee2e2;
  color: #991b1b;
}

/* Truncado en celdas largas */
.cell-truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td.cell-truncate {
  cursor: help;
}

/* fieldset sustituye label como contenedor de filtros (markup valido) */
fieldset.filter-block {
  border: 0;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
fieldset.filter-block legend {
  padding: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* skeleton ligero */
.skeleton {
  display: inline-block;
  background: linear-gradient(90deg, #eef2f6 25%, #f8fafc 50%, #eef2f6 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s infinite;
  border-radius: 4px;
  color: transparent;
  min-width: 80px;
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* narracion accesible en dropdown de filtros */
.checkbox-dropdown .dropdown-trigger[aria-expanded="true"] + .dropdown-panel {
  /* helper visual: panel abierto debe verse sin importar version de browsers */
}

/* responsivo tablet y movil */
@media (max-width: 768px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 14px 16px;
    gap: 12px;
  }
  .nav-links {
    flex-wrap: wrap;
    gap: 10px;
  }
  .page-shell {
    padding: 14px;
  }
  .filters-grid {
    grid-template-columns: 1fr;
  }
  .modal-side-panel {
    width: 100%;
  }
  .action-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .action-group {
    justify-content: stretch;
  }
  .action-group .button {
    flex: 1;
  }
  .cell-truncate {
    max-width: 160px;
  }
}

@media (max-width: 480px) {
  .topbar h1 {
    font-size: 22px;
  }
  .login-card,
  .narrow-panel {
    width: 100%;
  }
  .search-row input[type="search"] {
    min-width: 100%;
  }
  .table-wrap table {
    min-width: 720px;
  }
}
