:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-muted: #f1f3f6;
  --border: #dfe3ea;
  --border-strong: #c7ceda;
  --text: #151b26;
  --text-muted: #526075;
  --accent: #1d4ed8;
  --accent-soft: #e8f0fe;
  --accent-hover: #1e40af;
  --green-bg: #e7f6ee;
  --green-text: #13653b;
  --amber-bg: #fef6e4;
  --amber-border: #f0c36d;
  --amber-text: #854d0e;
  --red-bg: #fdecec;
  --red-text: #991b1b;
  --slate-bg: #eceff4;
  --slate-text: #475569;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
}

body {
  overflow-x: clip;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface-muted);
  padding: 0.12em 0.35em;
  border-radius: 5px;
}

pre {
  background: #141923;
  color: #edf2f7;
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.5;
}

pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.local-banner {
  background: var(--amber-bg);
  border-bottom: 1px solid var(--amber-border);
  color: var(--amber-text);
  font-size: 0.85rem;
  padding: 0.45rem 1.25rem;
  text-align: center;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  color: var(--text);
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
}

.brand-tag {
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.top-search {
  flex: 1 1 260px;
  display: flex;
  gap: 0.4rem;
}

.top-search input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 0.94rem;
  background: var(--bg);
  color: var(--text);
}

.top-search input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--surface);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.nav-links a {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.65rem;
  border-radius: 7px;
}

.nav-links a:hover,
.nav-links a.active {
  background: var(--surface-muted);
  color: var(--text);
  text-decoration: none;
}

.container {
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}

.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
}

.hero h1 {
  margin: 0 0 0.4rem;
  font-size: 1.65rem;
  line-height: 1.25;
}

.hero p {
  margin: 0 0 1.2rem;
  color: var(--text-muted);
}

.search-form-lg {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-form-lg input[type="search"] {
  flex: 1 1 280px;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.55rem 0.95rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
  color: #fff;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn-ghost:hover {
  background: var(--surface-muted);
  text-decoration: none;
}

.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.8rem;
}

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

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

.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.1rem;
  margin-bottom: 1.5rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.9rem;
}

.folder-tile {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
}

.folder-tile:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--slate-bg);
  color: var(--slate-text);
  white-space: nowrap;
}

.pill-vigente,
.pill-verde {
  background: var(--green-bg);
  color: var(--green-text);
}

.pill-heredado,
.pill-amarillo {
  background: var(--amber-bg);
  color: var(--amber-text);
}

.pill-obsoleto {
  background: var(--slate-bg);
  color: var(--slate-text);
}

.pill-rojo {
  background: var(--red-bg);
  color: var(--red-text);
}

.pill-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.alert {
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.1rem;
  border: 1px solid var(--border);
  font-size: 0.93rem;
}

.alert-warning {
  background: var(--amber-bg);
  border-color: var(--amber-border);
  color: var(--amber-text);
}

.alert-info {
  background: var(--accent-soft);
  border-color: #bfdbfe;
  color: #1e3a8a;
}

.doc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 1.5rem;
  align-items: start;
}

.doc-main {
  min-width: 0;
}

.doc-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem;
  margin-bottom: 1.25rem;
}

.doc-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.doc-code {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--accent);
}

.doc-header h1 {
  margin: 0.35rem 0 0.75rem;
  font-size: 1.65rem;
  line-height: 1.25;
}

.doc-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.65rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.meta-item dt {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.meta-item dd {
  margin: 0.15rem 0 0;
  font-weight: 600;
}

.relations-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.relations-panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.relations-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
}

.rel-group h3 {
  margin: 0 0 0.4rem;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.rel-group ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rel-chip {
  display: block;
  padding: 0.38rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.85rem;
  background: var(--bg);
}

.rel-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}

.rel-chip code {
  background: transparent;
  padding: 0;
  font-weight: 700;
  margin-right: 0.3rem;
}

.doc-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.65rem;
  overflow-wrap: anywhere;
}

.doc-body h1:first-child {
  display: none;
}

.doc-body h2 {
  margin-top: 2rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
  font-size: 1.3rem;
  scroll-margin-top: 5rem;
}

.doc-body h3 {
  margin-top: 1.4rem;
  font-size: 1.08rem;
  scroll-margin-top: 5rem;
}

.doc-body blockquote {
  margin: 1rem 0;
  padding: 0.65rem 1rem;
  border-left: 4px solid var(--accent);
  background: var(--bg);
  color: var(--text-muted);
}

.doc-sidebar {
  position: sticky;
  top: 4.8rem;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
}

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

.toc-box h2 {
  margin: 0 0 0.6rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.86rem;
}

.toc-list li.toc-h3 {
  padding-left: 0.85rem;
  font-size: 0.82rem;
}

.toc-list a {
  color: var(--text-muted);
}

.toc-list a:hover {
  color: var(--accent);
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.nowrap {
  white-space: nowrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--surface);
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

thead th {
  background: var(--surface-muted);
  font-weight: 600;
  white-space: nowrap;
}

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

.mermaid-card {
  margin: 1.25rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}

.mermaid-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.8rem;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.mermaid-actions {
  display: flex;
  gap: 0.4rem;
}

.mermaid-viewport {
  padding: 1rem;
  overflow-x: auto;
  background: var(--surface);
  text-align: center;
}

pre.mermaid {
  background: transparent;
  color: var(--text);
  padding: 0;
  margin: 0;
  overflow: visible;
}

.mermaid-viewport svg {
  max-width: 100%;
  height: auto;
}

.mermaid-source {
  margin: 0;
  border-radius: 0;
  border-top: 1px solid var(--border);
}

.is-hidden {
  display: none;
}

.mermaid-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.mermaid-modal[hidden] {
  display: none;
}

.mermaid-modal-inner {
  background: var(--surface);
  border-radius: var(--radius);
  width: min(1200px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mermaid-modal-body {
  padding: 1.5rem;
  overflow: auto;
  text-align: center;
}

.mermaid-modal-body svg {
  max-width: 100%;
  height: auto;
}

.filters-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  min-width: 150px;
}

.field input[type="search"],
.field select {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
}

.field-check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  color: var(--text);
  padding: 0.45rem 0;
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.result-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}

.result-item h3 {
  margin: 0.25rem 0 0.4rem;
  font-size: 1.05rem;
}

.result-snippet {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.results-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin: 0.85rem 0;
}

.results-meta .pagination {
  margin: 0;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 500;
}

.page-link:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.page-current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.page-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.page-ellipsis {
  padding: 0 0.3rem;
  color: var(--text-muted);
}

.link-outside {
  color: var(--text-muted);
  border-bottom: 1px dashed var(--border-strong);
}

.footer {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

@media (max-width: 960px) {
  .doc-layout {
    grid-template-columns: 1fr;
  }
  .doc-sidebar {
    position: static;
    max-height: none;
  }
}

@media (max-width: 640px) {
  .topbar-inner {
    padding: 0.65rem 0.9rem;
    gap: 0.6rem;
  }
  .top-search {
    flex: 1 1 100%;
  }
  .container {
    padding: 1rem 0.9rem 2.25rem;
  }
  .doc-body,
  .doc-header,
  .hero,
  .card {
    padding: 1rem;
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .search-form-lg input[type="search"] {
    flex: 1 1 100%;
  }
  h1,
  .doc-header h1,
  .hero h1 {
    font-size: 1.32rem;
    overflow-wrap: anywhere;
  }
  h2 {
    font-size: 1.12rem;
    overflow-wrap: anywhere;
  }
}
