/* ===== BRAND FONTS (Myriad Pro, local from assets/fonts) ===== */
@font-face {
  font-family: 'Myriad Pro';
  src: url('../assets/fonts/MyriadPro-Light.otf') format('opentype');
  font-weight: 300; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Myriad Pro';
  src: url('../assets/fonts/MYRIADPRO-REGULAR.OTF') format('opentype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Myriad Pro';
  src: url('../assets/fonts/MYRIADPRO-SEMIBOLD.OTF') format('opentype');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Myriad Pro';
  src: url('../assets/fonts/MYRIADPRO-SEMIBOLDIT.OTF') format('opentype');
  font-weight: 600; font-style: italic; font-display: swap;
}
@font-face {
  font-family: 'Myriad Pro';
  src: url('../assets/fonts/MYRIADPRO-BOLD.OTF') format('opentype');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Myriad Pro';
  src: url('../assets/fonts/MYRIADPRO-BOLDIT.OTF') format('opentype');
  font-weight: 700; font-style: italic; font-display: swap;
}

/* ============================================================
   DESIGN TOKENS — "mirar al cen-tro"
   Single source of truth. graph.js reads --org-* / --graph-*
   via getComputedStyle, so canvas and DOM never diverge.
   ============================================================ */

/* ----- Brand tokens (theme-independent) ----- */
:root {
  --paper: #f2eee7;          /* warm cream */
  --ink: #181614;            /* warm near-black */
  --brand-rose: #c89aaa;     /* logo / decorative rose */
  --brand-rose-deep: #a85c74;/* readable interactive rose */

  /* Organization palette (mirrored into the graph) */
  --org-espira: #a78bfa;     /* violet  */
  --org-eat:    #e0899b;     /* rose (was orange) */
  --org-cap:    #2dd4bf;     /* teal    */

  --font-brand: 'Myriad Pro', -apple-system, sans-serif;
  --font-body: 'Myriad Pro', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 8px;
}

/* ===== LIGHT / PAPER THEME (default) ===== */
:root {
  --bg-deep: var(--paper);
  --bg-surface: #fbf9f5;
  --bg-hover: #ece7de;
  --text-primary: #1a1817;
  --text-secondary: #6b655c;
  --text-muted: #9a9186;
  --accent: var(--brand-rose-deep);
  --accent-hover: #8c4460;
  --accent-dim: rgba(168, 92, 116, 0.12);
  --border: #e2dcd1;
  --legend-bg: rgba(251, 249, 245, 0.0);
  --lightbox-bg: rgba(242, 238, 231, 0.95);
  --graph-node-default: #b4afa6;
  --graph-node-label: #3a362f;
  --graph-node-label-org: #1a1817;
  --graph-node-border: #fbf9f5;
  --graph-label-bg: #f2eee7;
  --graph-edge: rgba(24, 22, 20, 0.14);
  --graph-edge-highlight: rgba(24, 22, 20, 0.42);
  --graph-edge-dim: rgba(24, 22, 20, 0.05);
  --note-strong: #1a1817;
}

/* ===== DARK THEME (warm, on-brand) ===== */
[data-theme="dark"] {
  --bg-deep: #16130f;
  --bg-surface: #201c17;
  --bg-hover: #2a251e;
  --text-primary: #ede7dd;
  --text-secondary: #a79f92;
  --text-muted: #6f685c;
  --accent: #d2a0af;
  --accent-hover: #e0b4c0;
  --accent-dim: rgba(210, 160, 175, 0.15);
  --border: #332d25;
  --legend-bg: rgba(32, 28, 23, 0.0);
  --lightbox-bg: rgba(0, 0, 0, 0.92);
  --graph-node-default: #6b6459;
  --graph-node-label: #d8d2c6;
  --graph-node-label-org: #ffffff;
  --graph-node-border: #16130f;
  --graph-label-bg: #16130f;
  --graph-edge: rgba(237, 231, 221, 0.14);
  --graph-edge-highlight: rgba(237, 231, 221, 0.45);
  --graph-edge-dim: rgba(237, 231, 221, 0.05);
  --note-strong: #ffffff;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

#app { display: flex; height: 100vh; position: relative; }

/* ===== VIEW CONTROLS (grouped, bottom-left) ===== */
#view-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}
#graph-container.with-note #view-controls { opacity: 0.4; }

/* ===== THEME TOGGLE ===== */
#theme-toggle {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--text-secondary);
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: scale(1.1);
}
/* Light is default: show sun; dark: show moon */
#theme-toggle .icon-moon { display: none; }
#theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] #theme-toggle .icon-moon { display: inline; }
[data-theme="dark"] #theme-toggle .icon-sun { display: none; }

/* ===== ZOOM CONTROLS ===== */
#zoom-controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#zoom-controls button {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--text-secondary);
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#zoom-controls button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

/* ===== GRAPH ===== */
#graph-container {
  flex: 1;
  position: relative;
  background: var(--bg-deep);
  transition: flex 0.35s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease;
}
#graph-container.with-note { flex: 0.55; }

#graph-canvas { width: 100%; height: 100%; }

/* ===== BRAND PANEL (dark cohesive: logo shape merges into the panel) ===== */
#brand-panel {
  position: absolute;
  top: 55px;
  left: 0;
  height:100vh;
  width: 240px;
  padding: 72px 28px 42px;
  background: var(--ink);
  border-radius: 0 90px 0 0;   /* organic rounded top-right shoulder */
  box-shadow: 0 10px 40px rgba(24, 22, 20, 0.18);
  z-index: 8;
  transition: opacity 0.3s;
}
.brand-logo {
  display: block;
  width: 168px;
  height: auto;
}
.brand-desc {
  margin-top: 18px;
  font-weight: 300;
  font-size: 14px;
  line-height: 1.5;
  color: #f5f1ea;
  max-width: 188px;
}
#brand-nav {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}
#brand-nav button {
  background: none;
  border: none;
  padding: 0 0 1px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.5px;
  color: #b9b2a6;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
#brand-nav button:hover,
#brand-nav button.active { color: var(--brand-rose); border-bottom-color: var(--brand-rose); }
#graph-container.with-note #brand-panel { opacity: 0; pointer-events: none; }

/* ===== DECORATIVE WORDMARK (bottom-right) ===== */
#site-wordmark {
  position: absolute;
  bottom: 24px;
  right: 28px;
  text-align: right;
  z-index: 5;
  pointer-events: none;
  transition: opacity 0.3s;
}
#site-wordmark .wm-img {
  display: block;
  width: 170px;
  height: auto;
  margin-left: auto;
}
#site-wordmark .wm-dark { display: none; }
[data-theme="dark"] #site-wordmark .wm-light { display: none; }
[data-theme="dark"] #site-wordmark .wm-dark { display: block; }
#site-wordmark .wm-tagline {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  max-width: 300px;
  margin-left: auto;
}
#graph-container.with-note #site-wordmark { opacity: 0; pointer-events: none; }

#graph-legend {
  position: absolute;
  top: 26px;
  right: 32px;
  background: var(--legend-bg);
  padding: 0;
  font-size: 13px;
  z-index: 10;
  text-align: left;
  transition: opacity 0.3s;
}
#graph-container.with-note #graph-legend { opacity: 0.35; }
#graph-legend h4 {
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-primary);
  margin-bottom: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 7px 0;
  color: var(--text-primary);
  cursor: pointer;
  transition: color 0.15s, transform 0.15s;
}
.legend-item.active { color: var(--accent); font-weight: 600; }
.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: transform 0.15s;
}
.legend-item.active .legend-dot { transform: scale(1.6); }

/* ===== NOTE PANEL ===== */
#note-panel {
  width: 0;
  overflow: hidden;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s;
  display: flex;
  flex-direction: column;
}
#note-panel.open {
  width: 45%;
  min-width: 400px;
}

#note-header {
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
  transition: border-color 0.3s;
}

#note-header-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  position: absolute;
  top: 14px;
  right: 14px;
}

#note-back, #note-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
#note-back:hover, #note-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
#note-back.disabled {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}
#note-close {
  font-size: 28px;
}

#note-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  padding-right: 80px;
  line-height: 1.3;
}

#note-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  line-height: 1.75;
  font-size: 15px;
}
#note-content h1 { font-size: 20px; margin: 24px 0 10px; font-weight: 600; }
#note-content h2 {
  font-size: 17px;
  margin: 20px 0 8px;
  color: var(--accent);
  font-weight: 600;
}
#note-content h3 { font-size: 15px; margin: 16px 0 6px; font-weight: 600; }
#note-content h4 { font-size: 14px; margin: 12px 0 4px; font-weight: 600; color: var(--text-secondary); }
#note-content p { margin: 8px 0; }
#note-content ul, #note-content ol { margin: 8px 0; padding-left: 24px; }
#note-content li { margin: 4px 0; }
#note-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 16px;
  margin: 12px 0;
  color: var(--text-secondary);
  background: var(--accent-dim);
  border-radius: 0 var(--radius) var(--radius) 0;
}
#note-content strong { color: var(--note-strong); font-weight: 600; }
#note-content em { color: var(--text-secondary); }
#note-content a {
  color: var(--accent);
  text-decoration: none;
}
#note-content a:hover { text-decoration: underline; }
#note-content code {
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
  color: var(--accent-hover);
}
#note-content img {
  max-width: 100%;
  border-radius: var(--radius);
  cursor: pointer;
  margin: 12px 0;
  transition: opacity 0.2s, transform 0.2s;
  display: block;
}
#note-content img:hover {
  opacity: 0.9;
  transform: scale(1.01);
}

/* PDF embed links */
.pdf-embed {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--accent-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  margin: 8px 0;
  transition: background 0.2s, border-color 0.2s;
  word-break: break-all;
}
.pdf-embed:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  text-decoration: none;
}

/* Wikilinks in rendered notes */
.wikilink {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
  cursor: pointer;
  transition: border-color 0.2s, text-shadow 0.2s;
}
.wikilink:hover {
  border-bottom-color: var(--accent);
  text-shadow: 0 0 8px var(--accent-dim);
}
.wikilink.unresolved {
  color: var(--text-muted);
  border-bottom-style: dotted;
  border-bottom-color: var(--text-muted);
}

/* Backlinks */
#note-backlinks {
  border-top: 1px solid var(--border);
  padding: 16px 28px;
  flex-shrink: 0;
  transition: border-color 0.3s;
}
#note-backlinks h3 {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 500;
}
#backlinks-list { list-style: none; }
#backlinks-list li { margin: 3px 0; }
#backlinks-list a {
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  transition: color 0.15s;
}
#backlinks-list a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ===== LIGHTBOX ===== */
#lightbox {
  position: fixed;
  inset: 0;
  background: var(--lightbox-bg);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  transition: background 0.3s;
}
#lightbox.hidden { display: none; }
#lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 40px;
  cursor: pointer;
  transition: color 0.15s;
  z-index: 1001;
  line-height: 1;
}
#lightbox-close:hover { color: var(--text-primary); }
#lightbox-img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 4px;
  cursor: default;
}

/* ===== PDF VIEWER ===== */
#pdf-viewer {
  position: fixed;
  inset: 0;
  background: var(--bg-deep);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}
#pdf-viewer.hidden { display: none; }

#pdf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#pdf-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40%;
}
#pdf-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}
#pdf-controls button,
#pdf-controls a {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 10px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  text-decoration: none;
}
#pdf-controls button:hover,
#pdf-controls a:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-color: var(--accent);
}
#pdf-page-info {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 60px;
  text-align: center;
}
#pdf-download {
  font-size: 18px;
}

#pdf-canvas-container {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 20px;
}
#pdf-canvas {
  box-shadow: 0 2px 20px rgba(0,0,0,0.3);
  max-width: 100%;
}

/* ===== INTRO OVERLAY (welcome) ===== */
#intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: rgba(24, 22, 20, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#intro-overlay.hidden { display: none; }
#intro-card {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 70px rgba(24, 22, 20, 0.28);
}
#intro-body {
  overflow-y: auto;
  padding: 44px 46px 40px;
}
#intro-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
}
#intro-close:hover { color: var(--text-primary); }

.intro-logo-band {
  background: var(--ink);
  margin: -44px -46px 24px;   /* bleed to the card edges (intro-body padding = 44/46) */
  padding: 34px 46px;
}
.intro-logo {
  display: block;
  width: 190px;
  height: auto;
}
.intro-more {
  display: inline-block;
  margin: 6px 0;
  padding: 0 0 1px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--accent);
  font-family: inherit;
  font-size: 14px;
  color: var(--accent);
  cursor: pointer;
}
.intro-more:hover { color: var(--accent-hover); border-bottom-color: var(--accent-hover); }
.intro-more-content.hidden { display: none; }

/* ===== EDITORIAL PAGES (intro body + Fuentes/Links/Autora) ===== */
.page-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: -4px 0 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.page-tabs button {
  background: none;
  border: none;
  padding: 0 0 2px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.4px;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.page-tabs button:hover { color: var(--text-primary); }
.page-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

#intro-body { font-size: 15px; line-height: 1.75; color: var(--text-primary); }
#intro-body h2 { font-size: 18px; margin: 22px 0 8px; color: var(--accent); font-weight: 600; }
#intro-body h3 { font-size: 15px; margin: 18px 0 6px; font-weight: 600; }
#intro-body p { margin: 10px 0; }
#intro-body ul { margin: 10px 0; padding-left: 22px; }
#intro-body li { margin: 5px 0; }
.lead { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.refs { list-style: none; padding-left: 0; }
.refs li { margin: 12px 0; line-height: 1.5; font-size: 14px; }
.refs a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; }
.refs a:hover { border-bottom-color: var(--accent); }
/* Editorial page top band (logo, + author photo on Autora) */
.page-logo-band {
  background: var(--ink);
  margin: -24px -28px 20px;   /* bleed to #note-content edges (padding 24/28) */
  padding: 26px 28px 24px;
  text-align: center;
}
.page-logo { display: block; width: 168px; height: auto; margin: 0 auto; }
.page-logo-photo {
  display: block;
  width: 190px;
  height: auto;
  border-radius: var(--radius);
  margin: 20px auto 0;
}
/* Autora contact band (bottom) */
.contacto-band {
  background: var(--ink);
  margin: 28px -28px -24px;   /* bleed to bottom + sides of #note-content */
  padding: 26px 28px 30px;
  text-align: center;
}
.contacto-label {
  font-size: 12px;
  letter-spacing: 2px;
  color: #b9b2a6;
  margin-bottom: 8px;
}
.contacto-mail {
  font-size: 20px;
  color: var(--brand-rose);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.contacto-mail:hover { border-bottom-color: var(--brand-rose); }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  #note-panel.open {
    width: 100%;
    min-width: unset;
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    z-index: 100;
  }
  #graph-container.with-note { flex: 1; }
  #brand-panel { top: 44px; left: 0; width: 158px; padding: 44px 14px 22px; border-radius: 0 60px 0 0; }
  #brand-panel .brand-logo { width: 120px; }
  .brand-desc { display: none; }
  #brand-nav { margin-top: 10px; gap: 4px 10px; }
  #brand-nav button { font-size: 11px; }
  #site-wordmark { bottom: 16px; right: 18px; }
  #site-wordmark .wm-img { width: 120px; }
  #site-wordmark .wm-tagline { display: none; }
  /* Compact card top-right, clearing the search row and the brand panel */
  #graph-legend {
    top: 52px;
    right: 12px;
    left: auto;
    max-width: 180px;
    font-size: 10px;
    background: var(--bg-surface);
    padding: 10px 12px;
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(24, 22, 20, 0.12);
  }
  #graph-legend h4 { font-size: 11px; margin-bottom: 8px; letter-spacing: 1px; }
  .legend-item { margin: 5px 0; align-items: flex-start; }
  .legend-dot { margin-top: 2px; }
  #view-controls { bottom: 14px; left: 14px; }
  #theme-toggle { width: 32px; height: 32px; font-size: 16px; }
  #zoom-controls button { width: 32px; height: 32px; font-size: 16px; }
}
