/* Chilo Legal — Wiki layout (unified with app design system) */

/* ── Dark mode ── */
html.dark {
  --bg: #0D1416;
  --card: #151F22;
  --text: #F3F4F6;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --border: #2A363A;
  --sidebar-bg: #080E10;
  --sidebar-link: #D8DEDF;
  --sidebar-muted: #8FA3A8;
  --sidebar-hover: rgba(0, 188, 228, 0.10);
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  grid-template-rows: 50px 1fr;
  min-height: 100vh;
  background: var(--bg, #0F172A);
  color: var(--text, #F8FAFC);
  font-family: 'Inter', sans-serif;
}

body {
  margin: 0; padding: 0;
  background: var(--bg, #0F172A);
  color: var(--text, #F8FAFC);
  font-family: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

/* ── Layout body (main + TOC lateral) ── */
.layout-body { display: flex; gap: 1.5rem; align-items: flex-start; }
.layout-body main { flex: 1; min-width: 0; }

/* ── Top bar (unified) ── */
.top-bar-wiki {
  grid-column: 1 / -1;
  grid-row: 1;
  z-index: 60;
  position: sticky;
  top: 0;
}

/* ── Sidebar ── */
.nav-wrapper {
  grid-column: 1;
  grid-row: 2;
  position: sticky;
  top: 50px;
  height: calc(100vh - 50px);
  z-index: 50;
  overflow-y: auto;
  background: var(--sidebar-bg, #0F171A);
}

.nav-panel {
  width: 250px;
  min-height: 100%;
  background: var(--sidebar-bg, #0F171A);
  color: #fff;
  overflow-y: auto;
}

nav {
  width: 250px;
  padding: 1.25rem;
  overflow-y: auto;
}

nav::-webkit-scrollbar { width: 5px; }
nav::-webkit-scrollbar-track { background: transparent; }
nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

nav .logo-text { font-size: 1.3rem; font-weight: 700; color: var(--teal, #00BCE4); margin-bottom: 0.2rem; }
nav .logo-sub { font-size: 0.68rem; color: var(--sidebar-muted, #94A3B8); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 1.25rem; }

/* ── Sidebar search ── */
.vault-search { position: relative; margin-bottom: 1.25rem; }
.vault-search input {
  width: 100%; padding: 0.5rem 0.65rem 0.5rem 2rem; font-size: 0.8rem;
  border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  background: rgba(255,255,255,0.05); color: #fff; font-family: inherit; outline: none;
}
.vault-search input:focus { border-color: var(--teal, #00BCE4); }
.vault-search input::placeholder { color: rgba(255,255,255,0.3); }
.vault-search .search-icon { position: absolute; left: 0.55rem; top: 50%; transform: translateY(-50%); color: var(--sidebar-muted); display: flex; }
.vault-search .search-icon svg { width: 14px; height: 14px; }
.search-results { margin-top: 0.3rem; display: none; }
.search-results.active { display: block; }
.search-results a { display: block; padding: 0.35rem 0.5rem; font-size: 0.75rem; border-radius: 4px; color: var(--sidebar-link, #D8DEDF); text-decoration: none; line-height: 1.4; }
.search-results a:hover { background: rgba(0,188,228,0.1); color: var(--teal, #00BCE4); }
.search-results .no-results { font-size: 0.72rem; color: var(--sidebar-muted, #94A3B8); padding: 0.4rem; }

/* ── Sidebar nav ── */
nav a { color: var(--sidebar-link, #D8DEDF); text-decoration: none; display: flex; align-items: center; gap: 0.35rem; padding: 0.35rem 0.45rem; font-size: 0.82rem; border-radius: 4px; }
nav a:hover { color: #fff; background: rgba(0,188,228,0.1); }
nav .nav-section { margin: 1.25rem 0; }
nav .nav-toggle { color: var(--sidebar-muted, #94A3B8); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.1em; display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem; font-weight: 600; cursor: pointer; user-select: none; }
nav .nav-toggle:hover { color: #fff; }
nav .toggle-arrow { font-size: 0.6rem; transition: transform 0.2s; }
nav .nav-section.collapsed .nav-section-content { display: none; }
nav .nav-section.collapsed .toggle-arrow { transform: rotate(-90deg); }
.logout-link { margin-top: 1.5rem; padding-top: 0.75rem; border-top: 1px solid rgba(255,255,255,0.06); font-size: 0.75rem; }

/* ── Mobile header / menu ── */
.mobile-header { display: none; }
.nav-close { display: none; }
.topbar-menu-btn { display: none; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15); color: #D8DEDF; border-radius: 6px; cursor: pointer; padding: 0.35rem 0.5rem; align-items: center; justify-content: center; }
.topbar-menu-btn:hover { border-color: var(--teal, #00BCE4); color: var(--teal, #00BCE4); }

/* ── Main content ── */
main, .layout > header.mobile-header, .layout > .content-wrapper {
  grid-column: 2;
  grid-row: 2;
}
main {
  padding: 1.5rem 2.5rem 4rem;
  max-width: 1060px;
  min-width: 0;
  margin: 0;
}
main h1 { font-weight: 700; font-size: 1.75rem; margin-bottom: 1rem; color: var(--text, #F8FAFC); }
main h2 { font-weight: 600; font-size: 1.2rem; margin: 1.75rem 0 0.6rem; border-bottom: 1px solid var(--border, rgba(255,255,255,0.08)); padding-bottom: 0.3rem; }
main h3 { font-weight: 600; font-size: 0.95rem; margin: 1.25rem 0 0.4rem; }
main p { line-height: 1.7; margin-bottom: 0.85rem; font-size: 0.9rem; }
main a { color: var(--teal, #00BCE4); }
main a:hover { color: #00a8cc; }
.wikilink { border-bottom: 1px dashed rgba(0,188,228,0.35); text-decoration: none; }
.breadcrumb { font-size: 0.78rem; color: var(--text-muted, #94A3B8); margin-bottom: 1rem; }
.breadcrumb a { color: var(--text-muted, #94A3B8); text-decoration: none; }
.breadcrumb a:hover { color: var(--teal, #00BCE4); }

/* ── Doc lists ── */
.doc-list { list-style: none; padding: 0; }
.doc-list li { padding: 0.65rem 0.85rem; border: 1px solid var(--border, rgba(255,255,255,0.06)); border-radius: 8px; margin-bottom: 0.4rem; transition: border-color 0.15s; }
.doc-list li:hover { border-color: var(--teal, #00BCE4); }
.doc-list li a { font-size: 0.9rem; font-weight: 500; color: var(--text, #F8FAFC); text-decoration: none; display: flex; align-items: center; gap: 0.4rem; }
.doc-list li a:hover { color: var(--teal, #00BCE4); }
.doc-list .doc-decreto { font-size: 0.7rem; color: var(--teal, #00BCE4); }
.doc-list .art-count { float: right; font-size: 0.7rem; background: rgba(0,188,228,0.1); color: var(--teal, #00BCE4); padding: 0.1rem 0.45rem; border-radius: 999px; }
.dir-item a { font-weight: 600; }

/* ── Typography ── */
main blockquote { border-left: 3px solid var(--teal, #00BCE4); padding: 0.4rem 0.85rem; margin: 0.85rem 0; background: rgba(0,188,228,0.04); font-style: italic; }
main table { width: 100%; border-collapse: collapse; margin: 0.85rem 0; font-size: 0.82rem; }
main th { background: var(--sidebar-bg, #0F171A); color: #fff; padding: 0.45rem 0.6rem; text-align: left; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.72rem; }
main td { border: 1px solid var(--border, rgba(255,255,255,0.06)); padding: 0.35rem 0.55rem; font-size: 0.8rem; }
main code { background: rgba(255,255,255,0.06); padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.88em; }
main pre { background: var(--sidebar-bg, #0F171A); color: #fff; padding: 1rem; border-radius: 8px; overflow-x: auto; margin: 0.85rem 0; }
.table-wrap { overflow-x: auto; max-width: 100%; margin: 0.85rem 0; }

/* ── Search hero ── */
.search-hero {
  background: var(--card, rgba(255,255,255,0.03));
  border: 1px solid var(--border, rgba(255,255,255,0.06));
  border-radius: 10px;
  padding: 1.15rem;
  margin-bottom: 1.5rem;
}
.search-hero .search-box { position: relative; display: flex; align-items: center; }
.search-hero input { width: 100%; padding: 0.75rem 1rem 0.75rem 2.4rem; font-size: 0.95rem; border: 1px solid var(--border, rgba(255,255,255,0.08)); border-radius: 8px; background: var(--bg, #0F172A); color: var(--text); font-family: inherit; outline: none; }
.search-hero input:focus { border-color: var(--teal, #00BCE4); }
.search-hero .search-icon { position: absolute; left: 0.8rem; color: var(--text-muted); display: flex; }
.search-hero .search-icon svg { width: 18px; height: 18px; }
.search-hero .filters { display: flex; gap: 0.4rem; margin-top: 0.6rem; flex-wrap: wrap; }
.search-hero .filters select { padding: 0.35rem 0.55rem; font-size: 0.75rem; border: 1px solid var(--border, rgba(255,255,255,0.08)); border-radius: 4px; background: var(--bg, #0F172A); color: var(--text); font-family: inherit; cursor: pointer; }
.hero-results { margin-top: 0.85rem; }
.hero-results .result-item { padding: 0.7rem; border: 1px solid var(--border, rgba(255,255,255,0.06)); border-radius: 8px; margin-bottom: 0.45rem; background: var(--bg, #0F172A); }
.hero-results .result-item:hover { border-color: var(--teal, #00BCE4); }
.hero-results .result-item a { text-decoration: none; color: var(--text); display: block; }
.hero-results .result-title { font-weight: 600; color: var(--teal, #00BCE4); margin-bottom: 0.15rem; }
.hero-results .result-meta { font-size: 0.7rem; color: var(--text-muted); margin-bottom: 0.2rem; }
.hero-results .result-snippet { font-size: 0.8rem; line-height: 1.5; }

/* ── Extract + audit banners ── */
.extract-banner { display: flex; gap: 0.6rem; align-items: flex-start; background: rgba(0,188,228,0.06); border: 1px solid rgba(0,188,228,0.15); border-radius: 8px; padding: 0.85rem 1rem; margin-bottom: 1.25rem; font-size: 0.82rem; }
.audit-banner { display: flex; gap: 0.6rem; align-items: flex-start; border-radius: 8px; padding: 0.85rem 1rem; margin-bottom: 1.25rem; font-size: 0.82rem; }
.audit-banner-pending { background: rgba(202,138,4,0.08); border: 1px solid rgba(202,138,4,0.2); }
.audit-banner-rejected { background: rgba(185,28,28,0.08); border: 1px solid rgba(185,28,28,0.2); }

/* ── Vault Page Layout ── */
.vault-page { display: flex; gap: 2rem; align-items: flex-start; }
.article-content { flex: 1; min-width: 0; }

/* ── Article blocks ── */
.article-block { border: 1px solid var(--border, rgba(255,255,255,0.06)); border-radius: 8px; padding: 1rem; margin-bottom: 0.75rem; scroll-margin-top: 4.5rem; }
.article-block:hover { border-color: var(--teal, #00BCE4); }
.article-heading { font-size: 0.95rem; font-weight: 600; color: var(--teal, #00BCE4); margin-bottom: 0.5rem; }
.article-body { font-size: 0.9rem; line-height: 1.7; }
.article-body p { margin-bottom: 0.75rem; }
.article-actions { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: 0.75rem; padding-top: 0.6rem; border-top: 1px solid var(--border, rgba(255,255,255,0.05)); }
.art-btn { padding: 0.3rem 0.6rem; font-size: 0.7rem; background: transparent; border: 1px solid var(--border, rgba(255,255,255,0.1)); border-radius: 4px; cursor: pointer; color: var(--text); font-family: inherit; }
.art-btn:hover { border-color: var(--teal, #00BCE4); color: var(--teal, #00BCE4); }
.art-index { border: 1px solid var(--border, rgba(255,255,255,0.06)); border-radius: 8px; padding: 0.85rem; margin-bottom: 1.5rem; }
.art-index strong { display: block; font-size: 0.78rem; color: var(--teal, #00BCE4); margin-bottom: 0.6rem; }
.art-index-list { display: flex; flex-wrap: wrap; gap: 0.25rem; max-height: 180px; overflow-y: auto; }
.art-index-list a { display: inline-block; padding: 0.2rem 0.45rem; font-size: 0.7rem; background: rgba(0,188,228,0.08); color: var(--teal, #00BCE4); border-radius: 4px; text-decoration: none; }
.art-index-list a:hover { background: var(--teal, #00BCE4); color: #000; }

/* ── Article TOC — unified with chat sources panel & expediente timeline panel ── */
.article-toc {
  width: 300px; margin-left: auto; flex-shrink: 0; position: sticky; top: 4.5rem;
  max-height: calc(100vh - 6rem); overflow-y: auto;
  background: var(--sidebar-bg); color: #fff;
  border-left: 1px solid var(--border);
  font-size: 0.8rem; display: flex; flex-direction: column;
  transition: width 0.25s ease;
}
.article-toc.collapsed { width: 44px; }
.article-toc.collapsed .toc-body,
.article-toc.collapsed .toc-header strong { display: none; }
.article-toc.collapsed .toc-header {
  writing-mode: vertical-rl; text-orientation: mixed;
  padding: 1.25rem 0.6rem; justify-content: center;
}
.toc-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1rem; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toc-header strong {
  font-size: 0.72rem; color: var(--teal);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}
.toc-toggle-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.7rem; padding: 0.2rem; }
.toc-toggle-btn:hover { color: #fff; }
.toc-body { flex: 1; overflow-y: auto; padding: 0.5rem; }
.toc-list { display: flex; flex-direction: column; gap: 0.1rem; }
.toc-list a {
  display: block; padding: 0.35rem 0.6rem; border-radius: 4px;
  color: var(--sidebar-link, #D8DEDF); text-decoration: none; font-size: 0.78rem;
  transition: background 0.15s;
}
.toc-list a:hover, .toc-list a.active {
  background: var(--sidebar-hover, rgba(0,188,228,0.10)); color: var(--teal);
}
.toc-title { color: var(--sidebar-muted); font-size: 0.72rem; }
.toc-toggle { display: none; }
.toc-overlay { display: none; }

/* ── Theme button ── */
.theme-btn { position: fixed; bottom: 1rem; right: 1rem; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border, rgba(255,255,255,0.1)); background: var(--card); color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 10; }
.theme-btn:hover { border-color: var(--teal); color: var(--teal); }

/* ── Empty states ── */
.empty-state { text-align: center; padding: 2rem 1rem; }
.empty-state p { color: var(--text-secondary); margin-bottom: 1rem; max-width: 350px; margin-left: auto; margin-right: auto; }

/* ── Audit badges ── */
.badge-audit-pendiente { background: var(--warning-bg, #FEF3C7); color: var(--warning, #B45309); }
.badge-audit-verificado { background: var(--success-bg, #D1FAE5); color: var(--success, #047857); }
.badge-audit-rechazado { background: var(--error-bg, #FEE2E2); color: var(--error, #B91C1C); }

/* ── Spirit overlay ── */
.spirit-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200; align-items: center; justify-content: center; }
.spirit-overlay.visible { display: flex; }
.spirit-panel { background: var(--bg); border: 2px solid var(--teal); border-radius: 10px; padding: 1.5rem; max-width: 650px; width: 92%; max-height: 80vh; overflow-y: auto; }

/* ── TOC off-canvas en pantallas angostas ── */
@media (max-width: 900px) {
  .article-toc {
    position: fixed; right: 0; top: 0; bottom: 0;
    width: min(300px, 85vw); height: 100%; max-height: none;
    border-radius: 0; border-left: 1px solid var(--border); z-index: 400;
    background: var(--sidebar-bg);
    box-shadow: -8px 0 24px rgba(0,0,0,0.25);
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }
  body.toc-open .article-toc { transform: none; }
  .toc-toggle-btn { display: flex; }
  .toc-toggle {
    display: inline-flex; align-items: center; gap: 0.35rem;
    position: fixed; bottom: 1rem; right: 3.75rem; z-index: 150;
    padding: 0.55rem 0.9rem; border: none; border-radius: 999px;
    background: var(--teal, #00BCE4); color: #fff;
    font-size: 0.8rem; font-weight: 600; font-family: inherit; cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  }
  .toc-overlay { display: none; position: fixed; inset: 0; z-index: 350; background: rgba(0,0,0,0.5); }
  body.toc-open .toc-overlay { display: block; }
  .article-block { scroll-margin-top: 7rem; }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .layout { display: block; }
  .top-bar-wiki { position: sticky; top: 0; padding: 0 0.75rem !important; }
  .topbar-menu-btn { display: inline-flex; }
  .nav-wrapper { position: fixed; inset: 0; width: auto; height: auto; z-index: 100; pointer-events: none; }
  body.nav-open .nav-wrapper { pointer-events: auto; }
  .nav-panel { position: absolute; top: 0; left: 0; z-index: 2; transform: translateX(-100%); transition: transform 0.25s ease; width: 280px; }
  body.nav-open .nav-panel { transform: translateX(0); }
  .nav-overlay { display: block; position: absolute; inset: 0; z-index: 1; background: rgba(0,0,0,0.5); opacity: 0; transition: opacity 0.25s ease; }
  body.nav-open .nav-overlay { opacity: 1; }
  .nav-close { display: flex; }
  main { padding: 1rem; max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
