/* ─────────────────────────────────────────────
   AHPC Leyes – Cuadernillo N° 6
   Estética: Archivo histórico, sepia editorial
───────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400&family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;1,8..60,300&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --ink:        #1c1008;
  --ink2:       #3a2410;
  --rust:       #8b2500;
  --rust2:      #b03a1a;
  --amber:      #c47a2a;
  --amber2:     #e09840;
  --parch:      #f2e8d5;
  --parch2:     #ede0c4;
  --parch3:     #e4d0a8;
  --cream:      #faf6ef;
  --sand:       #d4c4a0;
  --sand2:      #c0aa7a;
  --muted:      #7a6040;
  --divider:    #c8b48a;
  --shadow:     rgba(60,30,5,.12);
  --shadow2:    rgba(60,30,5,.22);
  --card-bg:    #fdf8f0;
  --hover-row:  #f5eddc;
  --tag-bg:     rgba(139,37,0,.1);
  --tag-fg:     #8b2500;
  --tag2-bg:    rgba(196,122,42,.14);
  --tag2-fg:    #7a4800;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--cream);
  color: var(--ink);
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── TEXTURE OVERLAY ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* ── NAV ── */
.nav {
  background: var(--ink);
  border-bottom: 3px solid var(--amber);
  position: sticky;
  top: 0;
  z-index: 200;
  padding: 0 2rem;
}
.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 58px;
  gap: 0;
}
.nav-logo {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--amber2);
  text-decoration: none;
  letter-spacing: .03em;
  white-space: nowrap;
  padding-right: 1.5rem;
  border-right: 1px solid rgba(255,255,255,.12);
  margin-right: 1rem;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.nav-logo small {
  font-family: 'Source Serif 4', serif;
  font-size: .62em;
  font-weight: 300;
  color: var(--sand2);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: .15rem;
  flex: 1;
}
.nav-links a {
  color: var(--sand);
  text-decoration: none;
  font-family: 'Source Serif 4', serif;
  font-size: .88em;
  padding: .45rem 1rem;
  border-radius: 4px;
  transition: color .18s, background .18s;
  letter-spacing: .02em;
}
.nav-links a:hover,
.nav-links a.active {
  color: var(--amber2);
  background: rgba(255,255,255,.07);
}
.nav-portal {
  margin-left: auto;
  padding: .38rem 1rem;
  border: 1.5px solid var(--amber);
  border-radius: 4px;
  color: var(--amber);
  text-decoration: none;
  font-family: 'Source Serif 4', serif;
  font-size: .82em;
  font-weight: 600;
  letter-spacing: .03em;
  transition: background .18s, color .18s;
  white-space: nowrap;
}
.nav-portal:hover { background: var(--amber); color: var(--ink); }

/* ── LAYOUT ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  position: relative;
  z-index: 1;
}

/* ── PAGE HEADER ── */
.page-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--divider);
}
.page-header .eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: .72em;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--rust);
  margin-bottom: .45rem;
}
.page-header h1 {
  font-family: 'Playfair Display', serif;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
}
.page-header .subtitle {
  color: var(--muted);
  font-size: .92em;
  margin-top: .4rem;
  font-style: italic;
}

/* ── STAT BOXES ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2.5rem;
}
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-top: 3px solid var(--rust);
  border-radius: 6px;
  padding: 1.25rem 1.1rem;
  box-shadow: 0 2px 8px var(--shadow);
  text-align: center;
}
.stat-card .num {
  font-family: 'Playfair Display', serif;
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--rust);
  line-height: 1;
  display: block;
}
.stat-card .desc {
  font-size: .75em;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: .3rem;
  font-family: 'JetBrains Mono', monospace;
}

/* ── CARDS ── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 6px;
  padding: 1.75rem;
  box-shadow: 0 2px 10px var(--shadow);
  margin-bottom: 1.5rem;
}
.card-heading {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink2);
  margin-bottom: 1.25rem;
  padding-bottom: .6rem;
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ── TWO-COL GRID ── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media(max-width:720px){ .two-col { grid-template-columns: 1fr; } }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; border-radius: 6px; border: 1px solid var(--divider); }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875em;
  background: var(--card-bg);
}
thead {
  background: var(--parch2);
  border-bottom: 2px solid var(--divider);
}
thead th {
  padding: .7rem 1rem;
  text-align: left;
  font-family: 'JetBrains Mono', monospace;
  font-size: .78em;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  font-weight: 500;
}
tbody tr {
  border-bottom: 1px solid var(--parch3);
  transition: background .12s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--hover-row); }
tbody td {
  padding: .65rem 1rem;
  vertical-align: top;
  color: var(--ink2);
  line-height: 1.4;
}
tbody td a { color: var(--rust2); text-decoration: none; border-bottom: 1px dotted var(--sand2); }
tbody td a:hover { color: var(--rust); border-bottom-color: var(--rust); }

/* ── TAGS / BADGES ── */
.tag {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 3px;
  font-size: .75em;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: .03em;
}
.tag-rust  { background: var(--tag-bg);  color: var(--tag-fg);  border: 1px solid rgba(139,37,0,.2); }
.tag-amber { background: var(--tag2-bg); color: var(--tag2-fg); border: 1px solid rgba(196,122,42,.3); }
.tag-grey  { background: rgba(122,96,64,.08); color: var(--muted); border: 1px solid rgba(122,96,64,.2); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-family: 'Source Serif 4', serif;
  font-size: .88em;
  font-weight: 600;
  text-decoration: none;
  transition: all .18s;
  letter-spacing: .02em;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--rust);
  color: #fff;
  box-shadow: 0 2px 6px rgba(139,37,0,.3);
}
.btn-primary:hover { background: var(--rust2); }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--divider);
  color: var(--muted);
}
.btn-outline:hover { border-color: var(--rust2); color: var(--rust2); }
.btn-csv {
  background: rgba(139,37,0,.08);
  border: 1.5px solid rgba(139,37,0,.3);
  color: var(--rust);
}
.btn-csv:hover { background: rgba(139,37,0,.16); }
.btn-amber {
  background: var(--amber);
  color: var(--ink);
  font-weight: 700;
}
.btn-amber:hover { background: var(--amber2); }

/* ── SEARCH FORM ── */
.search-form {
  background: var(--parch);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 1.75rem;
  margin-bottom: 1.75rem;
  box-shadow: 0 2px 8px var(--shadow);
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.1rem; margin-bottom: 1.1rem; }
.form-group label {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: .72em;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .4rem;
}
.form-group input,
.form-group select {
  width: 100%;
  background: var(--cream);
  border: 1.5px solid var(--sand);
  border-radius: 4px;
  padding: .55rem .85rem;
  color: var(--ink);
  font-family: 'Source Serif 4', serif;
  font-size: .92em;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--rust2);
  box-shadow: 0 0 0 3px rgba(139,37,0,.1);
}
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }

/* ── PAGINATION ── */
.pagination {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}
.pagination button {
  padding: .4rem .75rem;
  border-radius: 4px;
  border: 1.5px solid var(--divider);
  background: var(--card-bg);
  color: var(--muted);
  cursor: pointer;
  font-family: 'Source Serif 4', serif;
  font-size: .85em;
  transition: all .15s;
}
.pagination button:hover:not(:disabled) { border-color: var(--rust2); color: var(--rust2); }
.pagination button.active { border-color: var(--rust); color: var(--rust); font-weight: 700; background: rgba(139,37,0,.06); }
.pagination button:disabled { opacity: .3; cursor: default; }
.pag-info { font-size: .82em; color: var(--muted); font-style: italic; margin-left: .5rem; }

/* ── RESULT COUNT ── */
.result-meta {
  font-size: .84em;
  color: var(--muted);
  margin-bottom: .75rem;
  font-style: italic;
}
.result-meta strong { color: var(--rust); font-style: normal; font-weight: 700; }

/* ── BAR CHART ── */
.bar-list { list-style: none; }
.bar-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .5rem;
  font-size: .84em;
}
.bar-label { width: 200px; flex-shrink: 0; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-label a { color: var(--rust2); text-decoration: none; border-bottom: 1px dotted var(--sand2); }
.bar-label a:hover { color: var(--rust); }
.bar-track { flex: 1; background: var(--parch3); border-radius: 3px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; transition: width .5s ease; }
.bar-fill-rust   { background: linear-gradient(90deg, var(--rust), var(--rust2)); }
.bar-fill-amber  { background: linear-gradient(90deg, var(--amber), var(--amber2)); }
.bar-count { width: 32px; text-align: right; font-family: 'JetBrains Mono', monospace; color: var(--rust); font-weight: 500; flex-shrink: 0; }

/* ── DETAIL PAGE ── */
.detail-ley-num {
  font-family: 'Playfair Display', serif;
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--rust);
  line-height: 1;
}
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 2rem; }
@media(max-width:600px){ .detail-grid { grid-template-columns: 1fr; } }
.field-lbl {
  font-family: 'JetBrains Mono', monospace;
  font-size: .7em;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .2rem;
}
.field-val { color: var(--ink2); font-size: .95em; line-height: 1.55; }

/* ── AUTOCOMPLETE ── */
.ac-wrap { position: relative; }
.ac-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0; right: 0;
  background: var(--cream);
  border: 1.5px solid var(--divider);
  border-radius: 4px;
  box-shadow: 0 6px 20px var(--shadow2);
  z-index: 50;
  max-height: 220px;
  overflow-y: auto;
}
.ac-item {
  padding: .55rem .9rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .88em;
  border-bottom: 1px solid var(--parch3);
  transition: background .1s;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--parch); }

/* ── SIDEBAR LIST ── */
.side-list { list-style: none; max-height: 440px; overflow-y: auto; }
.side-item {
  padding: .5rem 0;
  border-bottom: 1px solid var(--parch3);
}
.side-item:last-child { border-bottom: none; }
.side-item a { color: var(--rust2); text-decoration: none; font-size: .88em; font-weight: 600; }
.side-item a:hover { color: var(--rust); }
.side-item.current a { color: var(--rust); font-weight: 700; }
.side-item .side-snippet { color: var(--muted); font-size: .75em; line-height: 1.3; margin-top: .1rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ── EMPTY STATE ── */
.empty {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--muted);
}
.empty .empty-icon { font-size: 3rem; margin-bottom: .75rem; opacity: .5; }
.empty p { font-style: italic; font-size: .9em; }

/* ── LOADING ── */
.loading { color: var(--muted); font-style: italic; font-size: .9em; padding: 1rem 0; }

/* ── FOOTER ── */
footer {
  background: var(--ink);
  border-top: 3px solid var(--amber);
  padding: 1.5rem 2rem;
  text-align: center;
  font-size: .78em;
  color: var(--sand2);
  font-family: 'Source Serif 4', serif;
  position: relative;
  z-index: 1;
}
footer a { color: var(--amber); text-decoration: none; border-bottom: 1px dotted var(--amber2); }
footer a:hover { color: var(--amber2); }

/* ── QUICK ACCESS GRID ── */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.quick-card {
  background: var(--parch);
  border: 1px solid var(--divider);
  border-radius: 6px;
  padding: 1.25rem;
  text-decoration: none;
  color: var(--ink2);
  transition: box-shadow .18s, transform .18s;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.quick-card:hover { box-shadow: 0 6px 18px var(--shadow2); transform: translateY(-2px); }
.quick-card .qc-icon { font-size: 1.8rem; }
.quick-card .qc-title { font-family: 'Playfair Display', serif; font-size: .98rem; font-weight: 600; color: var(--ink); }
.quick-card .qc-desc  { font-size: .78em; color: var(--muted); font-style: italic; }

/* ── PAGE TRANSITIONS ── */
.page { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── DIVIDER ORNAMENT ── */
.ornament {
  text-align: center;
  color: var(--sand2);
  font-size: 1.2rem;
  margin: 2rem 0;
  opacity: .5;
}

@media(max-width:640px){
  .nav-logo small { display: none; }
  .page-header h1 { font-size: 1.75rem; }
}
