:root {
  --bg: #0f1420;
  --bg-panel: #161d2e;
  --bg-panel-2: #1c2438;
  --border: #2a3350;
  --text: #e7ebf5;
  --text-dim: #9aa5c0;
  --accent: #4f9dff;
  --accent-2: #7c5cff;
  --ok: #2ecc8f;
  --warn: #f5a623;
  --cond: #f5c518;
  --danger: #ff5d5d;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 24px;
  background: linear-gradient(135deg, #131a2b, #0f1420);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-weight: 800;
  font-size: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  padding: 8px 10px;
  border-radius: 8px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.topbar-brand h1 { font-size: 18px; margin: 0; }
.topbar-brand p { font-size: 12px; color: var(--text-dim); margin: 2px 0 0; }

.topbar-search { position: relative; flex: 1; max-width: 460px; min-width: 220px; }
#global-search {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  font-size: 13px;
}
#global-search:focus { outline: 2px solid var(--accent); }
.search-results {
  position: absolute;
  top: 42px;
  left: 0; right: 0;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 360px;
  overflow-y: auto;
  z-index: 40;
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}
.search-results.hidden { display: none; }
.search-result-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 13px; }
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-panel); }
.search-result-item .sr-tag { font-family: var(--mono); color: var(--accent); }
.search-result-item .sr-area { font-size: 11px; color: var(--text-dim); }

/* ---------------- Tabs ---------------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 24px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 10px 16px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-weight: 600;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

main { padding: 20px 24px 60px; max-width: 1400px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------------- Tipo selector ---------------- */
.tipo-selector { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tipo-btn {
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.tipo-btn .code { font-family: var(--mono); font-weight: 700; margin-right: 6px; color: var(--accent); }
.tipo-btn.active { background: var(--accent); border-color: var(--accent); color: #08101f; }
.tipo-btn.active .code { color: #08101f; }

.tipo-summary {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
  font-size: 13.5px;
}
.tipo-summary h3 { margin: 0 0 4px; font-size: 15px; }
.tipo-summary .oblig-counts { display: flex; gap: 14px; margin-top: 8px; flex-wrap: wrap; font-size: 12.5px; }

/* ---------------- Panels ---------------- */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}
.panel h2 { font-size: 15px; margin: 0 0 10px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; gap: 8px; }
.toggle { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; cursor: pointer; }

.explorar-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; align-items: start; }
.explorar-grid > .panel { min-width: 0; }
@media (max-width: 980px) { .explorar-grid { grid-template-columns: 1fr; } }

.fields-by-type { max-height: 640px; overflow-y: auto; }
.area-group { margin-bottom: 6px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.area-group-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg-panel-2); cursor: pointer; font-size: 12.5px; font-weight: 700;
}
.area-group-head .area-counts { display: flex; gap: 6px; font-weight: 400; }
.area-group-body { padding: 4px 0; }
.area-group.collapsed .area-group-body { display: none; }

.field-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 8px;
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  cursor: pointer;
  align-items: start;
}
.field-row:hover { background: var(--bg-panel-2); }
.field-row .fnum { color: var(--text-dim); font-family: var(--mono); }
.field-row .fname { }
.field-row .fname .tag { display: block; font-family: var(--mono); color: var(--accent); font-size: 11.5px; }
.field-row .fname .label { display: block; }

/* ---------------- Badges de obligatoriedad ---------------- */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 5px; font-size: 11px; font-weight: 700; font-family: var(--mono);
}
.oblig-0 { background: #2a3350; color: var(--text-dim); }
.oblig-1 { background: rgba(46,204,143,0.18); color: var(--ok); border: 1px solid rgba(46,204,143,0.4); }
.oblig-2 { background: rgba(245,197,24,0.15); color: var(--cond); border: 1px solid rgba(245,197,24,0.4); }
.oblig-3 { background: rgba(79,157,255,0.15); color: var(--accent); border: 1px solid rgba(79,157,255,0.4); }

.legend { display: flex; gap: 10px; margin: 10px 0 14px; flex-wrap: wrap; }

/* ---------------- XML viewer ---------------- */
.xml-actions { display: flex; gap: 8px; }
.btn-small {
  background: var(--bg-panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.btn-small:hover { border-color: var(--accent); color: var(--accent); }
.scenario-desc { font-size: 12.5px; color: var(--text-dim); margin: 0 0 10px; }
.xml-view {
  background: #0b101c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  max-height: 560px;
  overflow: auto;
  white-space: pre;
}
.xml-line { display: block; padding: 1px 4px; border-radius: 3px; cursor: pointer; }
.xml-line:hover, .xml-line.hl { background: rgba(79,157,255,0.18); }
.xml-tag { color: #7cc4ff; }
.xml-value { color: #d9dff0; }
.xml-comment { color: #6b7593; font-style: italic; }
.xml-note { font-size: 11.5px; color: var(--text-dim); margin: 10px 0 0; }

.field-row.hl { background: rgba(124,92,255,0.22); }

.panel-rules-inline .rules-list { max-height: 420px; overflow-y: auto; }

/* ---------------- Reglas ---------------- */
.rules-list { display: flex; flex-direction: column; gap: 10px; }
.rule-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: var(--bg-panel-2); }
.rule-card h4 { margin: 0 0 4px; font-size: 13.5px; }
.rule-card .rule-cat { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); font-weight: 700; }
.rule-card p { margin: 6px 0; font-size: 13px; color: var(--text); }
.rule-card .rule-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.rule-tag { font-family: var(--mono); font-size: 11px; background: var(--bg-panel); border: 1px solid var(--border); padding: 2px 6px; border-radius: 5px; color: var(--accent); cursor: pointer; }
.rule-tipo-chip { font-size: 10.5px; background: var(--bg-panel); border: 1px solid var(--border); padding: 2px 6px; border-radius: 5px; color: var(--text-dim); }

/* ---------------- Matriz completa ---------------- */
.matrix-controls { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.matrix-controls input, .matrix-controls select {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-panel); color: var(--text); font-size: 13px;
}
.matrix-controls input { flex: 1; min-width: 220px; }
.matrix-scroll { overflow: auto; border: 1px solid var(--border); border-radius: 10px; max-height: 70vh; }
.matrix-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.matrix-table th, .matrix-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.matrix-table thead th { position: sticky; top: 0; background: var(--bg-panel-2); z-index: 5; }
.matrix-table td.mfield { white-space: normal; min-width: 220px; cursor: pointer; }
.matrix-table td.mfield .tag { display: block; font-family: var(--mono); color: var(--accent); font-size: 11px; }
.matrix-table tr:hover td { background: rgba(255,255,255,0.03); }
.matrix-table td.mtipo { text-align: center; }
.matrix-table .area-sep td { background: var(--bg-panel-2); font-weight: 700; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------------- Catalogos ---------------- */
.catalog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .catalog-grid { grid-template-columns: 1fr; } }
.table-scroll { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.cat-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.cat-table th, .cat-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.cat-table thead th { position: sticky; top: 0; background: var(--bg-panel-2); }
.hint { font-size: 11.5px; color: var(--text-dim); margin: 8px 2px 0; }

/* ---------------- Acerca ---------------- */
.prose h2 { font-size: 18px; }
.prose h3 { font-size: 14px; margin-top: 18px; }
.prose p, .prose li { font-size: 13.5px; color: var(--text); }
.prose code { background: var(--bg-panel-2); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: 12px; }
.disclaimer { color: var(--text-dim); font-size: 12px; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 16px; }

/* ---------------- Overlay (detalle de campo) ---------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(5,8,16,0.65);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  max-width: 640px; width: 100%; max-height: 84vh; overflow-y: auto; padding: 22px; position: relative;
}
.overlay-close {
  position: absolute; top: 12px; right: 14px; background: transparent; border: none;
  color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1;
}
.overlay-close:hover { color: var(--text); }
#overlay-body h3 { margin: 0 0 2px; font-size: 17px; }
#overlay-body .of-tag { font-family: var(--mono); color: var(--accent); font-size: 13px; }
#overlay-body .of-section { margin-top: 14px; }
#overlay-body .of-section h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); margin: 0 0 6px; }
#overlay-body pre.of-validation { white-space: pre-wrap; font-family: var(--sans); font-size: 13px; background: var(--bg-panel-2); padding: 10px; border-radius: 8px; margin: 0; }
#overlay-body .of-matrix { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
#overlay-body .of-matrix-cell { text-align: center; border: 1px solid var(--border); border-radius: 6px; padding: 6px 4px; font-size: 11px; }
#overlay-body .of-matrix-cell .t { display: block; color: var(--text-dim); font-family: var(--mono); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- Footer ---------------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px 28px;
  text-align: center;
}
.site-footer p { margin: 0; font-size: 12px; color: var(--text-dim); }
.site-footer a { color: var(--accent); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
