:root {
  --bg: #0e1421;
  --sidebar: #121a2b;
  --sidebar-2: #0b1120;
  --surface: #f6f7fb;
  --card: #ffffff;
  --ink: #1a2233;
  --ink-soft: #5b6478;
  --line: #e4e7ef;
  --brand: #3b6cf6;
  --brand-ink: #1e40af;
  --ok: #16a34a;
  --ok-bg: #e7f6ec;
  --partial: #d98a00;
  --partial-bg: #fdf3e0;
  --fail: #dc2626;
  --fail-bg: #fdeaea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --shadow-lg: 0 24px 60px rgba(8,12,24,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }

.app { display: grid; grid-template-columns: 288px 1fr; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #cdd6ea;
  display: flex;
  flex-direction: column;
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 22px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), #7aa2ff);
  color: #fff; font-family: "Space Grotesk", sans-serif; font-weight: 700;
  display: grid; place-items: center; font-size: 15px; letter-spacing: .5px;
  box-shadow: 0 6px 16px rgba(59,108,246,.4);
}
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-family: "Space Grotesk", sans-serif; font-weight: 600; color: #fff; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: #7f8bab; text-transform: uppercase; letter-spacing: .8px; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: 0; cursor: pointer;
  color: #aeb8d4; font-size: 14.5px; font-weight: 500;
  padding: 11px 12px; border-radius: 10px; text-align: left;
  font-family: inherit; transition: background .15s, color .15s;
}
.nav-item svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: rgba(255,255,255,.05); color: #e6ebf7; }
.nav-item.is-active { background: rgba(59,108,246,.18); color: #fff; }
.nav-item.is-active svg { stroke: #93b0ff; }

.sidebar-foot { margin-top: auto; }
.estate-card {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 3px;
}
.estate-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: #7f8bab; }
.estate-addr { font-weight: 600; color: #fff; font-size: 14px; }
.estate-meta { font-size: 11.5px; color: #8b96b5; line-height: 1.4; }
.estate-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: rgba(59,108,246,.18); color: #a9c1ff; font-weight: 500;
}

/* ---------- Main ---------- */
.main { padding: 34px 40px 60px; max-width: 1120px; }
.view { display: none; animation: fade .25s ease; }
.view.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.view-head h1 { font-family: "Space Grotesk", sans-serif; font-size: 26px; margin: 0 0 4px; letter-spacing: -.3px; }
.view-head p { margin: 0; color: var(--ink-soft); font-size: 14px; }

.legend { display: flex; gap: 16px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-soft); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.partial { background: var(--partial); }
.dot.fail { background: var(--fail); }

/* ---------- Documentos ---------- */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; }
.doc-card {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; cursor: pointer; text-align: left; font-family: inherit;
  box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s, border-color .15s;
}
.doc-card:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(16,24,40,.12); border-color: #cdd7f5; }
.doc-thumb {
  width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, #eef3ff, #dfe8ff); color: var(--brand-ink);
}
.doc-thumb .ic { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.doc-info { display: flex; flex-direction: column; gap: 5px; flex: 1; }
.doc-format { font-size: 11px; font-weight: 600; letter-spacing: .5px; color: var(--brand-ink); text-transform: uppercase; }
.doc-info h3 { margin: 0; font-size: 17px; font-family: "Space Grotesk", sans-serif; }
.doc-titulo { margin: 0; font-size: 13px; color: var(--ink); font-weight: 500; }
.doc-resumen { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-soft); line-height: 1.5; }
.doc-meta { margin-top: 4px; font-size: 11.5px; color: #98a1b8; }
.doc-open {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  font-size: 13px; font-weight: 600; color: var(--brand);
}
.doc-open svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Actividades ---------- */
.tree { display: flex; flex-direction: column; gap: 12px; }
.node {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.node-head {
  display: grid; grid-template-columns: 22px 1fr auto 120px; align-items: center; gap: 16px;
  padding: 16px 20px; cursor: pointer; list-style: none;
}
.node-head::-webkit-details-marker { display: none; }
.node-caret svg { width: 18px; height: 18px; fill: none; stroke: #9aa4bd; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .18s; }
.node[open] .node-caret svg { transform: rotate(90deg); }
.node-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.node-name { font-weight: 600; font-size: 15.5px; font-family: "Space Grotesk", sans-serif; }
.node-code { font-size: 12px; color: var(--ink-soft); }
.node-score {
  display: inline-flex; align-items: center; gap: 6px; font-size: 14px;
  padding: 5px 11px; border-radius: 999px; font-weight: 500; white-space: nowrap;
}
.node-score b { font-size: 15px; }
.node-score .score-ic { width: 15px; height: 15px; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.score--ok { background: var(--ok-bg); color: var(--ok); }
.score--partial { background: var(--partial-bg); color: var(--partial); }
.score--fail { background: var(--fail-bg); color: var(--fail); }
.node-bar { display: block; height: 7px; width: 120px; background: #eef0f6; border-radius: 999px; overflow: hidden; }
.node-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), #7aa2ff); border-radius: 999px; }

.cond-list { list-style: none; margin: 0; padding: 4px 20px 16px; display: flex; flex-direction: column; gap: 2px; }
.cond {
  display: grid; grid-template-columns: 30px 1fr 150px 96px; align-items: center; gap: 14px;
  padding: 12px 8px; border-top: 1px solid #f0f2f7;
}
.cond-mark { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; }
.cond-mark .ic { width: 16px; height: 16px; fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.cond--ok .cond-mark { background: var(--ok-bg); } .cond--ok .cond-mark .ic { stroke: var(--ok); }
.cond--partial .cond-mark { background: var(--partial-bg); } .cond--partial .cond-mark .ic { stroke: var(--partial); }
.cond--fail .cond-mark { background: var(--fail-bg); } .cond--fail .cond-mark .ic { stroke: var(--fail); }
.cond-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cond-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.cond-materia { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--brand-ink); background: #eef3ff; padding: 2px 7px; border-radius: 6px; font-weight: 600; }
.cond-texto { font-size: 14px; font-weight: 500; }
.cond-detalle { font-size: 12.5px; color: var(--ink-soft); }
.cond-fuente { font-size: 12px; color: #98a1b8; font-variant-numeric: tabular-nums; }
.cond-estado { font-size: 12px; font-weight: 600; text-align: center; padding: 4px 0; border-radius: 7px; }
.cond-estado.ok { color: var(--ok); background: var(--ok-bg); }
.cond-estado.partial { color: var(--partial); background: var(--partial-bg); }
.cond-estado.fail { color: var(--fail); background: var(--fail-bg); }

/* ---------- Visor ---------- */
.viewer { position: fixed; inset: 0; display: none; z-index: 50; }
.viewer.is-open { display: block; }
.viewer-backdrop { position: absolute; inset: 0; background: rgba(8,12,24,.6); backdrop-filter: blur(3px); }
.viewer-panel {
  position: absolute; inset: 4vh 4vw; background: #fff; border-radius: 16px;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-lg);
}
.viewer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.viewer-title { font-weight: 600; font-family: "Space Grotesk", sans-serif; font-size: 15px; }
.viewer-actions { display: flex; align-items: center; gap: 10px; }
.btn { font-family: inherit; font-size: 13px; font-weight: 500; border-radius: 9px; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn.ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn.icon { padding: 8px; }
.btn.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.viewer-body { flex: 1; background: #525659; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; }
  .brand { padding-bottom: 0; }
  .nav { flex-direction: row; margin: 0; }
  .sidebar-foot { display: none; }
  .main { padding: 24px 18px 40px; }
  .node-head { grid-template-columns: 20px 1fr auto; }
  .node-bar { display: none; }
  .cond { grid-template-columns: 26px 1fr auto; }
  .cond-fuente { display: none; }
  .view-head { flex-direction: column; align-items: flex-start; gap: 12px; }
}
