:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --ok: #059669;
  --warn: #b45309;
  --bad: #dc2626;
  --running: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
  padding: 0.85rem 0;
}

.brand span {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-left: 0.5rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.tabs button {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  color: var(--text-muted);
  padding: 0.9rem 0.9rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tabs button:hover { color: var(--text); }

.tabs button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.refresh-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

#btn-refresh {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
}

#btn-refresh:hover { color: var(--primary); border-color: var(--primary); }

.banner {
  padding: 0.6rem 1.25rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

.banner.warn { background: #fef3c7; color: #92400e; }
.banner.error { background: #fee2e2; color: #991b1b; }
.hidden { display: none; }

main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem;
}

.view { display: none; }
.view.active { display: block; }

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

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.85rem 1rem;
}

.kpi-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-size: 1.55rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 940px) {
  .charts-row { grid-template-columns: 1fr; }
}

.chart-box {
  position: relative;
  height: 280px;
}

.chart-box.spark { height: 120px; }

.chart-box.empty canvas { display: none; }

.chart-box.empty::after {
  content: "Sin datos todavía";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.filters .grow { flex: 1; min-width: 200px; }

.filters select,
.filters input {
  font: inherit;
  font-size: 0.875rem;
  color: var(--text);
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.filters input:focus,
.filters select:focus {
  outline: 2px solid rgb(37 99 235 / 0.3);
  border-color: var(--primary);
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.855rem;
}

th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.82rem; }
.muted { color: var(--text-muted); }

td.desc {
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#table-diffs tbody tr { cursor: pointer; }
#table-diffs tbody tr:hover td { background: #f8fafc; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sort-asc::after { content: " ▲"; font-size: 0.6rem; }
th.sort-desc::after { content: " ▼"; font-size: 0.6rem; }

.diff-zero { color: var(--ok); }
.diff-warn { color: var(--warn); font-weight: 600; }
.diff-bad { color: var(--bad); font-weight: 700; }

.loading, td.empty {
  color: var(--text-muted);
  text-align: center;
  padding: 1.5rem 0.5rem;
  font-size: 0.875rem;
}

.empty-block {
  grid-column: 1 / -1;
  color: var(--text-muted);
  text-align: center;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding-top: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.pager-controls { display: flex; align-items: center; gap: 0.6rem; }

.pager-controls button {
  appearance: none;
  font: inherit;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  color: var(--text);
}

.pager-controls button:disabled { opacity: 0.4; cursor: default; }
.pager-controls button:not(:disabled):hover { border-color: var(--primary); color: var(--primary); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.4;
}

.badge-ok { background: #d1fae5; color: #065f46; }
.badge-error { background: #fee2e2; color: #991b1b; }
.badge-running { background: #fef3c7; color: #92400e; }
.badge-neutral { background: #e2e8f0; color: #475569; }

.brand-badge {
  display: inline-block;
  min-width: 1.6rem;
  text-align: center;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #475569;
}

.brand-P { background: #dbeafe; color: #1d4ed8; }
.brand-W { background: #d1fae5; color: #047857; }
.brand-F { background: #ede9fe; color: #6d28d9; }
.brand-C { background: #ffedd5; color: #c2410c; }
.brand-V { background: #fce7f3; color: #be185d; }

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  appearance: none;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  color: var(--text);
}

.btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #1d4ed8; color: #fff; }

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(440px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgb(15 23 42 / 0.12);
  transform: translateX(102%);
  transition: transform 0.2s ease;
  z-index: 60;
  display: flex;
  flex-direction: column;
}

.detail-panel.open { transform: translateX(0); }

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.detail-head h2 { margin: 0; font-size: 1rem; }
.detail-head .muted { font-size: 0.8rem; margin-top: 0.2rem; }

#detail-close {
  appearance: none;
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.1rem 0.4rem;
}

#detail-close:hover { color: var(--text); }

.detail-content {
  padding: 1rem 1.1rem;
  overflow-y: auto;
  flex: 1;
}

.detail-content h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 1.25rem 0 0.5rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem 1rem;
}

.detail-grid .field { font-size: 0.85rem; }
.detail-grid .field .label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}
.detail-grid .field .value { font-variant-numeric: tabular-nums; font-weight: 500; }
.detail-grid .field.wide { grid-column: 1 / -1; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 0.35);
  z-index: 50;
  display: none;
}

.overlay.show { display: block; }

#toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #f8fafc;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  max-width: min(480px, 90vw);
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: #991b1b; }

td.run-detail {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table.mini { font-size: 0.8rem; }
table.mini th, table.mini td { padding: 0.35rem 0.5rem; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 0.25rem; padding-bottom: 0.25rem; }
  .refresh-area { display: none; }
  main { padding: 0.75rem; }
  td.desc { max-width: 180px; }
}

/* --- Pestaña Sincro (dry-run) --------------------------------------------- */

.badge-propuesto  { background: #d1fae5; color: #065f46; }
.badge-excluido   { background: #e2e8f0; color: #475569; }
.badge-cuarentena { background: #fef3c7; color: #92400e; }

/* Aviso permanente de que esta pestaña no escribe en Odoo. No es decoración:
   es lo que impide que alguien lea la propuesta como si ya se hubiera aplicado. */
.dryrun-aviso {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid #bfdbfe;
  border-left: 4px solid #2563eb;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 0.85rem;
}

.dryrun-aviso strong { font-weight: 700; }
.dryrun-aviso .sep { color: #93c5fd; }

.sincro-abortada {
  border-color: #fecaca;
  border-left-color: #dc2626;
  background: #fef2f2;
  color: #991b1b;
}

tr.tramo-grande td { background: #fffbeb; font-weight: 600; }

td.reincidencia-alta { color: #b91c1c; font-weight: 700; }

.nota-tabla {
  padding: 0 1.1rem 0.9rem;
  margin: -0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Tarjetas KPI de Diferencias que actúan como filtro (pestañas) */
.kpi-btn {
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  width: 100%;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.kpi-btn:hover { border-color: var(--primary); }
.kpi-btn.kpi-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgb(37 99 235 / 0.25);
  background: #eff6ff;
}

/* Cabecera de tarjeta con un control a la derecha (histórico de Diferencias) */
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.card-head h2 { margin-bottom: 0.75rem; }
.inline-select {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}
.inline-select select {
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  padding: 0.25rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

/* Columna «En cola» de Diferencias: hay movimientos pendientes de enviar a Odoo */
.cola-pendiente { color: var(--primary); font-weight: 600; }

/* Tarjeta desplegable (histórico de Diferencias): cerrada por defecto */
details.card-details > summary {
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  list-style: none;
}
details.card-details > summary::-webkit-details-marker { display: none; }
details.card-details > summary::before {
  content: "▸";
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: transform 0.12s;
}
details.card-details[open] > summary::before { transform: rotate(90deg); }
details.card-details > summary h2 { margin: 0; display: inline; }
details.card-details > summary:hover h2 { color: var(--primary); }
details.card-details[open] > summary { margin-bottom: 0.75rem; }
details.card-details[open] .summary-hint { display: none; }
.summary-hint { font-size: 0.78rem; }

/* Check en la barra de filtros (omitir explicadas por la cola) */
.filters label.check {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--text);
  padding-bottom: 0.45rem;
  cursor: pointer;
}
.filters label.check input { accent-color: var(--primary); width: 15px; height: 15px; margin: 0; }
