/* ---------------------------------------------------------------------------
   Viernes — tokens
   Paleta categorica limitada a 3 ranuras + neutro: en un grafo todos los pares
   de color son visibles a la vez, y solo las tres primeras ranuras superan los
   umbrales de daltonismo en modo "all-pairs". El resto de los tipos cae en
   "Otros" y la forma del nodo refuerza la identidad sin depender del color.
--------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --hairline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-other: #898781;

  --link-stroke: #c3c2b7;
  --dot: #d5d4cb;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 8px 24px rgba(11, 11, 11, .08);

  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --hairline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --link-stroke: #383835;
    --dot: #35352f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --hairline: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.06);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --link-stroke: #383835;
  --dot: #35352f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--plane);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

button, input, select { font: inherit; color: inherit; }

/* --- login ---------------------------------------------------------------- */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background-image: radial-gradient(circle at center, var(--dot) 1px, transparent 1px);
  background-size: 24px 24px;
}

.login-card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 28px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card h1 { margin: 0; font-size: 22px; }
.login-card .muted { margin: 0 0 12px; color: var(--text-secondary); }
.login-card label { font-size: 12px; color: var(--text-secondary); }

.login-card input[type="password"] {
  padding: 9px 11px;
  background: var(--plane);
  border: 1px solid var(--axis);
  border-radius: 6px;
}

.login-card button {
  margin-top: 12px;
  padding: 10px;
  border: 0;
  border-radius: 6px;
  background: var(--series-1);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.login-card .error { margin: 4px 0 0; color: #d03b3b; font-size: 13px; }

/* --- estructura ----------------------------------------------------------- */

.app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--hairline);
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }

.brand-mark {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--series-1);
  box-shadow: 8px 6px 0 -3px var(--series-2), -8px 6px 0 -3px var(--series-3);
}

.search { flex: 1; max-width: 460px; }

.search input {
  width: 100%;
  padding: 7px 11px;
  background: var(--plane);
  border: 1px solid var(--axis);
  border-radius: 6px;
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-actions form { margin: 0; }
.stats { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.ghost-btn {
  padding: 6px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
}
.ghost-btn:hover { background: var(--wash); color: var(--text-primary); }

/* La tercera columna es el panel de nota: con `hidden` mide 0 y no ocupa lugar. */
.layout { flex: 1; display: grid; grid-template-columns: 250px minmax(0, 1fr) auto; min-height: 0; }

/* --- sidebar -------------------------------------------------------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--hairline);
}

.sidebar h2 {
  margin: 14px 0 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.filters { padding: 4px 14px 14px; border-bottom: 1px solid var(--hairline); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { background: var(--wash); }
.chip[aria-pressed="true"] { background: var(--wash); color: var(--text-primary); border-color: var(--axis); }
.chip[aria-pressed="false"] { opacity: .45; }
.chip .swatch { width: 9px; height: 9px; border-radius: 2px; }

.switch {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.listing { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 14px 14px; }
.listing h2 { flex: none; }

.note-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.note-list li { border-bottom: 1px solid var(--hairline); }

.note-list button {
  width: 100%;
  padding: 8px 6px;
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
  border-radius: 4px;
}
.note-list button:hover { background: var(--wash); }
.note-list .row { display: flex; align-items: center; gap: 7px; }
.note-list .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.note-list .title { font-size: 13px; color: var(--text-primary); }
.note-list .snippet { display: block; margin-top: 2px; font-size: 12px; color: var(--text-muted); }
.note-list mark { background: transparent; color: var(--series-1); font-weight: 600; }
.note-list .empty { padding: 12px 0; color: var(--text-muted); font-size: 13px; }

/* --- grafo ---------------------------------------------------------------- */

/* Retícula de puntos: el tamaño y la posición los ajusta el manejador de zoom
   para que la trama acompañe el paneo, como el lienzo de un editor. */
.graph-area {
  position: relative;
  min-width: 0;
  background-color: var(--surface-1);
  background-image: radial-gradient(circle at center, var(--dot) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0 0;
}
#graph { width: 100%; height: 100%; display: block; cursor: grab; background: transparent; }
#graph.dragging { cursor: grabbing; }

.node-label {
  font-size: 10px;
  fill: var(--text-secondary);
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--surface-1);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.link-label {
  font-size: 9px;
  fill: var(--text-muted);
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--surface-1);
  stroke-width: 3px;
}

.legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  max-width: 60%;
  padding: 8px 11px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-secondary);
}
.legend .item { display: flex; align-items: center; gap: 6px; }

.graph-controls { position: absolute; right: 14px; top: 14px; display: flex; gap: 5px; }
.graph-controls .ghost-btn { background: var(--surface-1); }
.graph-controls .ghost-btn[disabled] { opacity: .5; cursor: default; }

.refresh-msg {
  position: absolute;
  right: 14px;
  top: 50px;
  margin: 0;
  padding: 4px 9px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
.refresh-msg[data-visible="true"] { opacity: 1; }

.tooltip {
  position: absolute;
  z-index: 5;
  max-width: 280px;
  padding: 9px 11px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s;
}
.tooltip[data-visible="true"] { opacity: 1; }
.tooltip .tip-title { font-weight: 600; margin-bottom: 2px; }
.tooltip .tip-meta { color: var(--text-muted); font-size: 12px; }
.tooltip .tip-excerpt { margin-top: 6px; color: var(--text-secondary); font-size: 12px; }

/* --- panel de nota -------------------------------------------------------- */

.note-panel {
  position: relative;
  width: 400px;
  overflow-y: auto;
  padding: 18px 20px 40px;
  background: var(--surface-1);
  border-left: 1px solid var(--hairline);
}
.note-panel[hidden] { display: none; }
.note-panel .close { position: absolute; top: 12px; right: 12px; }

.note-panel h1 { margin: 0 34px 6px 0; font-size: 19px; line-height: 1.25; }
.note-panel .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; font-size: 12px; color: var(--text-muted); }
.note-panel .tag { padding: 1px 7px; border: 1px solid var(--border); border-radius: 999px; }

.note-content { font-size: 14px; color: var(--text-primary); overflow-wrap: anywhere; }
.note-content h1, .note-content h2, .note-content h3 { margin: 18px 0 6px; font-size: 15px; }
.note-content p { margin: 0 0 10px; }
.note-content a { color: var(--series-1); }
.note-content ul, .note-content ol { margin: 0 0 10px; padding-left: 20px; }
.note-content blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 2px solid var(--axis); color: var(--text-secondary); }
.note-content code { padding: 1px 4px; background: var(--wash); border-radius: 4px; font-size: 13px; }
.note-content pre { padding: 10px; overflow-x: auto; background: var(--wash); border-radius: 6px; }
.note-content pre code { padding: 0; background: none; }
.note-content table { display: block; overflow-x: auto; border-collapse: collapse; }
.note-content th, .note-content td { padding: 4px 8px; border: 1px solid var(--hairline); }
.note-content img { max-width: 100%; }

.relations { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--hairline); }
.relations h2 { margin: 0 0 6px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.relations ul { margin: 0 0 16px; padding: 0; list-style: none; }
.relations li { padding: 3px 0; }
.relations button { background: none; border: 0; padding: 0; color: var(--series-1); cursor: pointer; text-align: left; }
.relations .rel-label { color: var(--text-muted); font-size: 12px; }
.relations .pending { color: var(--text-muted); font-style: italic; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar { max-height: 34vh; border-right: 0; border-bottom: 1px solid var(--hairline); }
  .note-panel { position: fixed; inset: 0; width: auto; z-index: 20; }
  .legend { max-width: calc(100% - 28px); }
}
