:root {
  color-scheme: light;
  --navy: #112d3d;
  --navy-deep: #09202d;
  --teal: #006d70;
  --teal-soft: #dff3f1;
  --coral: #ed6a4f;
  --ink: #1b2a33;
  --muted: #60717a;
  --line: #d7e0e3;
  --paper: #ffffff;
  --wash: #edf3f4;
  --shadow: 0 16px 45px rgba(9, 32, 45, .09);
}

* { box-sizing: border-box; }
html { background: var(--wash); }
body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(17, 45, 61, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17, 45, 61, .025) 1px, transparent 1px),
    var(--wash);
  background-size: 28px 28px;
  font-family: "Avenir Next", Avenir, system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(237, 106, 79, .45);
  outline-offset: 2px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  padding: 1.55rem clamp(1rem, 4vw, 4.5rem) 1.7rem;
  color: white;
  background:
    radial-gradient(circle at 82% 16%, rgba(237, 106, 79, .35), transparent 24rem),
    linear-gradient(120deg, var(--navy-deep), var(--navy));
  border-bottom: 5px solid var(--coral);
}

.association-logo {
  width: clamp(5.25rem, 8vw, 7rem);
  height: auto;
  flex: 0 0 auto;
  border-radius: .7rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.identity { margin-right: auto; }

.association, .kicker {
  margin: 0 0 .35rem;
  font-size: .82rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1, h2, h3, p { overflow-wrap: anywhere; }
h1 {
  margin: 0;
  font-family: Iowan Old Style, Palatino, Georgia, serif;
  font-size: clamp(2.25rem, 5vw, 4rem);
  font-weight: 600;
  line-height: .95;
}

.updated { margin: .65rem 0 0; color: #c7dde4; }
.archive-mark {
  display: grid;
  justify-items: end;
  padding-left: 1.25rem;
  border-left: 1px solid rgba(255,255,255,.25);
}
.archive-mark span { color: #c7dde4; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; }
.archive-mark strong { font-family: Iowan Old Style, Georgia, serif; font-size: 1.6rem; font-weight: 500; }

main { max-width: 1600px; margin: 0 auto; padding: 1.3rem clamp(1rem, 3vw, 2.5rem) 2.5rem; }
.intro {
  display: grid;
  grid-template-columns: minmax(16rem, .8fr) minmax(18rem, 1.2fr);
  align-items: end;
  gap: clamp(1rem, 4vw, 4rem);
  margin: 0 0 1rem;
}
.intro .kicker { color: var(--coral); }
.intro h2 { margin: 0; font-family: Iowan Old Style, Georgia, serif; font-size: clamp(1.55rem, 3vw, 2.35rem); line-height: 1.05; }
.intro > p { max-width: 55rem; margin: 0; color: var(--muted); }

.filters {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: .75rem;
  padding: 1rem;
  background: rgba(255,255,255,.93);
  border: 1px solid var(--line);
  border-radius: .8rem;
  box-shadow: var(--shadow);
}
.filters label { grid-column: span 2; display: grid; gap: .3rem; color: var(--muted); font-size: .88rem; font-weight: 700; }
.filters label.search-primary { grid-column: span 4; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 2.7rem;
  padding: .55rem .7rem;
  color: var(--ink);
  background: white;
  border: 1px solid #aebec5;
  border-radius: .45rem;
}
input:hover, select:hover { border-color: var(--teal); }
.clear {
  grid-column: 1 / span 2;
  align-self: end;
  min-height: 2.7rem;
  padding: .55rem .8rem;
  color: var(--teal);
  background: white;
  border: 1px solid var(--teal);
  border-radius: .45rem;
  font-weight: 800;
  cursor: pointer;
}
.clear:hover { background: var(--teal-soft); }
.tag-filters { grid-column: 1 / -1; padding-top: .65rem; border-top: 1px solid var(--line); }
.tag-filters summary { color: var(--teal); font-weight: 800; cursor: pointer; }
.tag-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin-top: .75rem; }
.tag-groups fieldset { min-width: 0; margin: 0; padding: .75rem; border: 1px solid var(--line); border-radius: .55rem; }
.tag-groups legend { padding: 0 .35rem; color: var(--navy); font-size: .88rem; font-weight: 800; }
.tag-options { display: flex; flex-wrap: wrap; gap: .4rem; }
.tag-filter {
  display: inline-flex;
  gap: .35rem;
  align-items: center;
  padding: .35rem .6rem;
  color: #38515d;
  background: #edf2f4;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
}
.tag-filter:hover { border-color: var(--teal); }
.tag-filter.active { color: #004e50; background: var(--teal-soft); border-color: var(--teal); }
.tag-filter:disabled { opacity: .45; cursor: not-allowed; }
.tag-count { min-width: 1.35rem; padding: .04rem .32rem; background: rgba(255,255,255,.7); border-radius: 999px; text-align: center; }
.tag-summary { margin: .55rem 0 0; color: var(--muted); font-size: .85rem; }

.results-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1rem .15rem .55rem; }
.results-heading p { margin: 0; color: var(--muted); font-weight: 700; }
.filename-note code { color: var(--navy); font-size: .78rem; font-weight: 500; }

.workspace {
  display: grid;
  grid-template-columns: minmax(22rem, .82fr) minmax(0, 1.35fr);
  height: min(68vh, 55rem);
  min-height: 34rem;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: .85rem;
  box-shadow: var(--shadow);
}
.document-list, .detail { min-height: 0; overflow-y: auto; }
.document-list { background: #f8fafb; border-right: 1px solid var(--line); }
.document-card { padding: 1rem; border-bottom: 1px solid #e2e8ea; background: transparent; }
.document-card.selected { background: var(--teal-soft); box-shadow: inset 5px 0 0 var(--teal); }
.document-card h3 { margin: 0; color: var(--navy); font-size: 1rem; line-height: 1.32; }
.card-meta { margin: .42rem 0; color: var(--muted); font-size: .82rem; }
.badges { display: flex; flex-wrap: wrap; gap: .35rem; }
.badge { padding: .17rem .45rem; color: #36505b; background: #e8eef0; border-radius: 999px; font-size: .75rem; font-weight: 800; }
.badge.instancia { color: #124d65; background: #dceef6; }
.badge.adjunto { color: #634075; background: #eee3f2; }
.badge.respuesta, .badge.alegaciones { color: #294f87; background: #e2ebfb; }
.badge.justificante { color: #37673c; background: #e3f1e4; }
.badge.theme { color: #80522b; background: #f9ead8; }
.card-actions { display: flex; gap: .5rem; margin-top: .75rem; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.4rem;
  padding: .45rem .8rem;
  border-radius: .42rem;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}
.button.primary { color: white; background: var(--teal); border: 1px solid var(--teal); }
.button.primary:hover { background: #00585b; }
.button.secondary { color: var(--navy); background: white; border: 1px solid var(--navy); }
.button.secondary:hover { color: white; background: var(--navy); }
.button.quiet { color: var(--teal); background: transparent; border: 1px solid #8fb7b8; }
.button.quiet:hover { background: white; border-color: var(--teal); }

.detail { padding: clamp(1.1rem, 3vw, 2.25rem); }
.detail-top { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.detail .kicker { color: var(--coral); }
.detail h2 { margin: 0; color: var(--navy); font-family: Iowan Old Style, Georgia, serif; font-size: clamp(1.45rem, 3vw, 2.25rem); line-height: 1.08; }
.detail > .badges { margin-top: .8rem; }
.description { margin: 1.15rem 0; padding: 1rem 1.1rem; background: #eef8f7; border-left: 5px solid var(--teal); border-radius: 0 .5rem .5rem 0; white-space: pre-wrap; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin: 1rem 0; }
.field { margin: 0; padding: .75rem; background: #f5f8f9; border: 1px solid #e5ebed; border-radius: .48rem; }
.field dt { color: var(--muted); font-size: .78rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.field dd { margin: .25rem 0 0; }
.section-title { margin: 1.6rem 0 .65rem; color: var(--navy); font-size: .9rem; letter-spacing: .06em; text-transform: uppercase; }
.relations { display: grid; gap: .55rem; }
.relation { display: grid; grid-template-columns: minmax(0, 1fr); gap: .65rem; width: 100%; padding: .72rem .8rem; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: .48rem; }
.relation:hover { background: #f2f9f8; border-color: var(--teal); }
.relation-copy { min-width: 0; }
.relation-copy strong { display: block; margin-top: .2rem; overflow-wrap: anywhere; word-break: break-word; }
.relation-heading, .relation-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.relation-actions { justify-content: start; }
.button.compact { min-height: 2.2rem; padding: .36rem .68rem; font-size: .86rem; }
.relation-label { color: var(--teal); font-size: .76rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.empty { color: var(--muted); }
.list-empty { padding: 1rem; }
.error { margin: 1rem; padding: 1rem; color: #7c3038; background: #f9e6e8; border-radius: .5rem; }

footer { padding: 1.2rem clamp(1rem, 4vw, 4.5rem) 2rem; color: var(--muted); background: var(--navy-deep); }
footer p { max-width: 76rem; margin: 0 auto; color: #bdd0d7; font-size: .88rem; }

@media (max-width: 1100px) {
  .filters label, .clear { grid-column: span 3; }
  .filters label.search-primary { grid-column: span 6; }
}

@media (max-width: 820px) {
  .masthead { align-items: start; }
  .intro { grid-template-columns: 1fr; gap: .55rem; }
  .filters label, .filters label.search-primary, .clear { grid-column: span 6; }
  .workspace { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .document-list { height: min(55vh, 31rem); border-right: 0; border-bottom: 1px solid var(--line); }
  .detail { min-height: 28rem; overflow: visible; }
}

@media (max-width: 560px) {
  .masthead { display: block; }
  .association-logo { width: 5rem; margin-bottom: .9rem; }
  .archive-mark { justify-items: start; margin-top: 1rem; padding: .8rem 0 0; border-top: 1px solid rgba(255,255,255,.25); border-left: 0; }
  .filters label, .filters label.search-primary, .clear { grid-column: 1 / -1; }
  .tag-groups, .detail-grid { grid-template-columns: 1fr; }
  .results-heading { align-items: start; flex-direction: column; gap: .25rem; }
  .detail-top { display: grid; }
  .detail-top .button { justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
