:root {
  --bps-blue: #004B87;
  --bps-blue-light: #0066B3;
  --bps-yellow: #FFCC00;
  --bps-yellow-dark: #E6B800;
  --bg: #f0f4f8;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --card-hover: #f8fafc;
  --text: #1e293b;
  --muted: #64748b;
  --accent: var(--bps-blue);
  --accent-dim: var(--bps-blue-light);
  --safe: #166534;
  --safe-bg: #ecfdf5;
  --warn: #b45309;
  --error: #dc2626;
  --border: #e2e8f0;
  --sidebar-w: 250px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,75,135,.08), 0 4px 16px rgba(0,75,135,.06);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 15px;
}
a { color: var(--bps-blue-light); text-decoration: none; }
a:hover { color: var(--bps-blue); text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar — blanco corporativo */
.sidebar {
  width: var(--sidebar-w);
  background: #ffffff;
  border-right: 3px solid var(--bps-yellow);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  box-shadow: 2px 0 12px rgba(0,75,135,.06);
}
.sidebar-brand {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 2px solid var(--bps-blue);
  text-align: center;
}
.sidebar-brand img.logo {
  max-width: 180px;
  height: auto;
  display: block;
  margin: 0 auto .35rem;
}
.brand-sub { font-size: .72rem; color: var(--bps-blue); font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }
.sidebar-nav { flex: 1; padding: .75rem 0; overflow-y: auto; }
.nav-item {
  display: block;
  padding: .7rem 1.25rem;
  color: var(--text);
  font-weight: 500;
  border-left: 4px solid transparent;
  transition: .15s ease;
}
.nav-item:hover {
  background: #f0f7ff;
  color: var(--bps-blue);
  text-decoration: none;
  border-left-color: var(--bps-yellow);
}
.nav-item.active {
  color: var(--bps-blue);
  background: linear-gradient(90deg, #eef6ff 0%, #fff 100%);
  border-left-color: var(--bps-blue);
  font-weight: 600;
}
.sidebar-foot {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.main-area { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.75rem;
  background: var(--bg-elevated);
  border-bottom: 2px solid var(--bps-yellow);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 1.15rem; font-weight: 700; color: var(--bps-blue); }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem 1.75rem 2.5rem; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 440px; margin: 4rem auto; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 1.05rem; color: var(--bps-blue); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--bps-blue);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-card .value { font-size: 1.55rem; font-weight: 700; margin-top: .25rem; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-card .sub { font-size: .82rem; color: var(--muted); margin-top: .15rem; }
.stat-card.accent { border-top-color: var(--bps-yellow); }
.stat-card.accent .value { color: var(--bps-blue); }
.stat-card.ok { border-top-color: #22c55e; }
.stat-card.ok .value { color: #15803d; }
.stat-card.warn { border-top-color: var(--bps-yellow); }
.stat-card.warn .value { color: var(--warn); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 900px) {
  .sidebar { width: 72px; }
  .sidebar-brand img.logo, .brand-sub, .sidebar-foot .badge { display: none; }
  .nav-item { font-size: 0; padding: .85rem; text-align: center; }
  .main-area { margin-left: 72px; }
  .grid-2 { grid-template-columns: 1fr; }
}

.muted { color: var(--muted); }
.error { color: var(--error); }
.small { font-size: .85rem; }
.ok-text { color: #15803d; }
.warn { color: var(--warn); }
.num { font-variant-numeric: tabular-nums; }

.banner.safe, .badge.safe {
  background: var(--safe-bg);
  color: #166534;
  border: 1px solid #86efac;
}
.banner.safe { padding: .65rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .85rem; }
.banner.safe.compact { margin-bottom: .75rem; }
.badge.safe { font-size: .72rem; padding: .25rem .55rem; border-radius: 999px; font-weight: 600; }

label { display: block; margin: .75rem 0; font-size: .9rem; font-weight: 500; }
input, select, textarea {
  width: 100%;
  margin-top: .35rem;
  padding: .65rem .8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: .95rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(0,75,135,.2);
  border-color: var(--bps-blue);
}
button, .btn {
  margin-top: .5rem;
  padding: .6rem 1.1rem;
  border: none;
  border-radius: 8px;
  background: var(--bps-blue);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: .9rem;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}
button:hover, .btn:hover { background: var(--bps-blue-light); filter: none; }
button.secondary, .btn.secondary { background: #fff; color: var(--bps-blue); border: 2px solid var(--bps-blue); }
button.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.approve, .btn.approve { background: #16a34a; color: #fff; }
button.reject, .btn.reject { background: #dc2626; color: #fff; }
button.undo, .btn.undo { background: #7c3aed; color: #fff; }
button.small-btn, .btn-sm { margin-top: 0; padding: .35rem .7rem; font-size: .82rem; }
button:disabled { opacity: .45; cursor: not-allowed; }

.actions { display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; }
.actions form { margin: 0; }
.actions button { margin-top: 0; }
.btn-link { color: var(--bps-blue); font-weight: 600; align-self: center; }

.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
  align-items: end;
  margin-bottom: 1rem;
  padding: 1rem;
  background: #f8fafc;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.filter-bar label { margin: 0; font-size: .78rem; }
.filter-bar input, .filter-bar select { margin-top: .25rem; font-size: .88rem; padding: .5rem .65rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th {
  padding: .75rem .65rem;
  border-bottom: 2px solid var(--bps-blue);
  text-align: left;
  color: var(--bps-blue);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: #f8fafc;
}
td { padding: .75rem .65rem; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:hover td { background: #f0f7ff; }

.grid { display: grid; grid-template-columns: 160px 1fr; gap: .45rem 1rem; }
.grid dt { color: var(--muted); font-size: .88rem; }

.status, .map, .sev, .event-type {
  font-size: .75rem;
  padding: .2rem .5rem;
  border-radius: 6px;
  font-weight: 600;
  white-space: nowrap;
}
.map-mapeado, .sev-ok, .status-aprobado { background: #dcfce7; color: #166534; }
.map-pendiente, .map-sin_match, .map-manual, .sev-warning, .status-modificado { background: #fef9c3; color: #854d0e; }
.map-sin_excel, .sev-error, .status-rechazado { background: #fee2e2; color: #991b1b; }
.status-recibido { background: #e2e8f0; color: #334155; }
.event-approve { background: #dcfce7; color: #166534; }
.event-reject { background: #fee2e2; color: #991b1b; }
.event-modify { background: #dbeafe; color: #1e40af; }
.event-import { background: #ede9fe; color: #5b21b6; }
.event-undo { background: #f3e8ff; color: #6b21a8; }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.ok { background: #ecfdf5; border: 1px solid #86efac; color: #166534; }
.flash.warn { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }

.checklist, .warn-box, .info-box {
  background: #f8fafc;
  border-radius: 8px;
  padding: 1rem;
  margin: 1rem 0;
  font-size: .9rem;
}
.info-box { border-left: 4px solid var(--bps-blue); }
.checkbox-row { display: flex; align-items: center; gap: .5rem; margin: .75rem 0; }
.warn-box { border-left: 4px solid var(--bps-yellow); background: #fffbeb; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  border-left: 3px solid var(--bps-blue);
  padding: .75rem 0 .75rem 1rem;
  margin-left: .5rem;
}
.timeline .time { font-size: .78rem; color: var(--muted); }
.timeline.undone { opacity: .5; }

.tabs { display: flex; gap: .35rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab {
  padding: .5rem 1rem;
  border-radius: 8px;
  background: #fff;
  border: 2px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
}
.tab.active { background: var(--bps-blue); border-color: var(--bps-blue); color: #fff; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.chart-box { height: 300px; margin: 1rem 0; position: relative; }
.chart-box-tall { height: min(520px, 70vh); min-height: 380px; }
.chart-box canvas { max-width: 100%; }
.realtime-pill {
  font-size: .75rem;
  color: #15803d;
  background: #ecfdf5;
  padding: .25rem .6rem;
  border-radius: 999px;
  border: 1px solid #86efac;
  font-weight: 600;
}
.realtime-pill.off { color: var(--muted); background: #f1f5f9; border-color: var(--border); }

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.toast {
  background: #fff;
  border: 2px solid var(--bps-blue);
  padding: .75rem 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 360px;
}

pre {
  overflow: auto;
  max-height: 420px;
  background: #f8fafc;
  padding: 1rem;
  border-radius: 8px;
  font-size: .78rem;
  border: 1px solid var(--border);
}
code { background: #f1f5f9; padding: .15rem .4rem; border-radius: 4px; font-size: .85rem; color: var(--bps-blue); }
.notes { margin: .75rem 0 0; padding-left: 1.2rem; color: var(--muted); font-size: .9rem; }

/* Guía visual */
.guide-hero { text-align: center; padding: 2rem 1rem; border-bottom: 3px solid var(--bps-yellow); }
.guide-hero img { max-height: 64px; margin-bottom: 1rem; }
.flow-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.flow-step {
  background: #fff;
  border: 2px solid var(--border);
  border-top: 4px solid var(--bps-blue);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: relative;
}
.flow-step.highlight { border-top-color: var(--bps-yellow); }
.flow-step .num {
  display: inline-flex;
  width: 2rem; height: 2rem;
  background: var(--bps-blue);
  color: #fff;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  margin-bottom: .75rem;
}
.flow-step.highlight .num { background: var(--bps-yellow); color: var(--bps-blue); }
.flow-step h3 { margin: 0 0 .5rem; font-size: 1rem; color: var(--bps-blue); }
.flow-arrow { text-align: center; color: var(--bps-yellow); font-size: 1.5rem; font-weight: 700; margin: .5rem 0; }
.why-box {
  background: linear-gradient(135deg, #eef6ff 0%, #fffbeb 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1rem 0;
}
.why-box h3 { color: var(--bps-blue); margin-top: 0; }

.login-page { background: linear-gradient(135deg, #eef6ff 0%, #fff 50%, #fffbeb 100%); min-height: 100vh; }
.login-page .container { padding-top: 3rem; }
.login-page .card { border-top: 4px solid var(--bps-yellow); }
.login-page img.logo { display: block; margin: 0 auto 1rem; max-width: 220px; }

.form-stack label { display: block; margin-bottom: .85rem; font-weight: 500; font-size: .9rem; }
.form-stack input[type="text"],
.form-stack input[type="number"],
.form-stack select {
  display: block;
  width: 100%;
  margin-top: .25rem;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 720px) { .form-row { grid-template-columns: 1fr; } }
