/* Homeland Consens — estética oscura. Sin estilos en línea (CSP estricta: style-src 'self'). */
:root {
  --bg: #0f1117; --bg2: #161a22; --bg3: #1d222c; --line: #2a303c;
  --ink: #e6e9ef; --muted: #8b93a3; --accent: #7aa2f7; --warn: #f7768e;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, select, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

#top { height: 48px; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--bg2); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; font-size: 15px; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 20px; height: 20px; flex: none; }
.mode-tag { font-size: 10px; font-weight: 500; color: #e0af68; border: 1px solid #e0af68; border-radius: 4px; padding: 0 4px; text-transform: uppercase; letter-spacing: .04em; }
.search-wrap { position: relative; flex: 0 1 460px; }
#search { width: 100%; background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; outline: none; }
#search:focus { border-color: var(--accent); }
.results { position: absolute; top: 36px; left: 0; right: 0; max-height: 60vh; overflow: auto; z-index: 20;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px #0008; }
.results { min-width: 560px; max-height: 70vh; }
.results .rhead { padding: 6px 10px; font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg2); }
.results .hit { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.results .hit:hover, .results .hit.sel { background: var(--bg3); }
.results .hit .t { font-weight: 600; display: flex; align-items: baseline; gap: 6px; }
.results .hit .k { font-size: 10px; font-weight: 400; color: var(--muted); text-transform: uppercase; flex: none; }
.results .hit .d { margin-left: auto; font-size: 11px; font-weight: 400; color: var(--muted); white-space: nowrap; }
.results .hit .s { color: var(--muted); font-size: 12px; margin-top: 3px; line-height: 1.4; }
mark { background: rgba(224, 175, 104, 0.28); color: #f5d9a8; border-radius: 2px; padding: 0 1px; }
#chips { position: absolute; top: 44px; left: 8px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 4; }
.fchip { display: inline-flex; align-items: center; gap: 6px; background: #2b2417; border: 1px solid #e0af68; color: #f5d9a8;
  border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px; }
.fchip button { border: 0; background: transparent; padding: 0 6px; color: inherit; border-radius: 999px; }
.fchip button:hover { background: #e0af6833; }
.fclear { font-size: 12px; padding: 2px 10px; border-radius: 999px; }
.tl-right { display: inline-flex; align-items: center; gap: 8px; }
#tl-clear { font-size: 11px; padding: 0 8px; border-color: var(--accent); color: var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
button { background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: #24304a; border-color: var(--accent); }
button.danger { background: #3a1d26; border-color: var(--warn); color: #ffb3c1; }

/* --- disposición: chat | separador | grafo | separador | nota (anchos en layout.js) --- */
#main { display: grid; grid-template-columns: var(--lw, 340px) var(--lg, 5px) minmax(0, 1fr) var(--rg, 5px) var(--rw, 360px);
  height: calc(100% - 48px); }
.side { background: var(--bg2); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }
.side.collapsed { visibility: hidden; border: 0; }
#main { overflow: hidden; }
.side-head { height: 44px; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 8px 0 12px; border-bottom: 1px solid var(--line); }
#right .side-head { padding: 0 12px 0 8px; justify-content: flex-start; }
.small-title { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
button.icon { padding: 2px 8px; line-height: 1.2; }
.gutter { cursor: col-resize; background: var(--bg); position: relative; z-index: 8; }
.gutter::before { content: ""; position: absolute; top: 0; bottom: 0; left: -5px; right: -5px; } /* zona de agarre más ancha */
.gutter:hover, .gutter.drag { background: #24304a; }
.gutter.off { cursor: default; pointer-events: none; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing #graph { pointer-events: none; }

#toolbar { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; align-items: center; gap: 8px; z-index: 6; pointer-events: none; }
#toolbar > * { pointer-events: auto; }
#toolbar .spacer { flex: 1; pointer-events: none; }
#filters-btn { position: relative; background: var(--bg2); }
#filters-btn.on { border-color: var(--accent); background: #24304a; }
#filters-btn .caret { font-size: 10px; color: var(--muted); }
.dot { position: absolute; top: -3px; right: -3px; width: 8px; height: 8px; border-radius: 50%; background: #e0af68; }
.rail { background: var(--bg2); font-size: 12px; }
#filters-pop { position: absolute; top: 42px; left: 8px; width: min(460px, calc(100% - 16px)); max-height: calc(100% - 150px);
  overflow: auto; z-index: 7; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 12px 32px #000a; padding: 4px 14px 12px; }
#filters-pop h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 0 6px; }
.pop-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
#legend { columns: 2; column-gap: 16px; }
.chk { display: flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; }
.chk .n { margin-left: auto; color: var(--muted); font-size: 11px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0; }
select { background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on { background: #24304a; border-color: var(--accent); }
.seg.small button { padding: 2px 9px; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.legend-item { display: flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; }
.legend-item:hover { color: var(--accent); }
.legend-item .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-item .n { margin-left: auto; padding-left: 6px; }

#center { position: relative; display: flex; flex-direction: column; min-width: 0; }
#graph { flex: 1; min-height: 0; width: 100%; position: relative; }
#overlay { font-size: 12px; pointer-events: none !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#banner { position: absolute; top: 44px; left: 50%; transform: translateX(-50%); background: #24304a; border: 1px solid var(--accent);
  border-radius: 6px; padding: 6px 12px; z-index: 5; }
#banner button { margin-left: 8px; }
#timeline-wrap { height: 92px; border-top: 1px solid var(--line); padding: 6px 12px 8px; background: var(--bg2); }
.tl-head { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 4px; }
#tl-range { color: var(--accent); font-weight: 600; }
#timeline { width: 100%; height: 62px; display: block; cursor: crosshair; }

#panel { padding: 14px 16px 24px; overflow: auto; flex: 1; min-height: 0; }
#panel h2 { font-size: 15px; margin: 4px 0 8px; line-height: 1.3; }
#panel .kicker { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 8px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; font-size: 11px; }
.chip.warn { border-color: var(--warn); color: var(--warn); }
.meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; word-break: break-all; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 12px; }
.actions button.primary { background: #24304a; border-color: var(--accent); }
.body { white-space: pre-wrap; word-wrap: break-word; font-size: 12.5px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 10px; max-height: 42vh; overflow: auto; }
.body a, .links a { color: var(--accent); cursor: pointer; text-decoration: none; }
.body a:hover, .links a:hover { text-decoration: underline; }
.body .missing { color: var(--muted); }
h4 { font-size: 11px; text-transform: uppercase; color: var(--muted); margin: 14px 0 4px; letter-spacing: .04em; }
.links { list-style: none; padding: 0; margin: 0; }
.links li { padding: 2px 0; display: flex; gap: 6px; align-items: baseline; }
.links li .d { color: var(--muted); font-size: 11px; white-space: nowrap; }
.tasks { padding-left: 18px; margin: 4px 0; }

/* --- barras de desplazamiento finas en toda la app --- */
* { scrollbar-width: thin; scrollbar-color: #2f3646 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2f3646; border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #3d4659; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
textarea, #panel, .body, #filters-pop, .results, .chat-log, .f-channels, .user-pop { scrollbar-width: thin; scrollbar-color: #2f3646 transparent; }

/* --- menú de usuario --- */
.user { position: relative; }
.user-btn { width: 30px; height: 30px; padding: 0; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: #2d3a5c; color: var(--accent); font-weight: 700; }
.user-btn.on { border-color: var(--accent); }
.user-btn img, .user-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-pop { position: absolute; top: 38px; right: 0; z-index: 30; min-width: 240px; max-width: 320px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 12px 32px #000a; padding: 12px; }
.user-card { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-width: 0; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; overflow: hidden; display: grid; place-items: center; flex: none;
  background: #2d3a5c; color: var(--accent); font-weight: 700; font-size: 15px; }
.user-who { min-width: 0; }
.user-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-email { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-logout { width: 100%; }

/* --- canales del usuario en Filtros --- */
.f-channels { max-height: 180px; overflow: auto; padding-right: 4px; }
.f-channels .chk .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channels-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.channels-actions .muted { font-size: 11px; }

/* --- estado vacío del grafo --- */
.empty-state { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -60%); z-index: 3; max-width: 420px;
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding: 20px 24px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px #0008; }
.empty-state .spin { width: 18px; height: 18px; border-width: 3px; }

/* --- página de entrada --- */
body.login { display: grid; place-items: center; min-height: 100%; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2236 0%, var(--bg) 60%); }
.login-card { width: min(380px, 100%); background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 16px 48px #000a; padding: 32px 28px 24px; text-align: center; }
.login-mark { width: 56px; height: 56px; display: block; margin: 0 auto 14px; }
.login-card h1 { font-size: 20px; margin: 0 0 6px; font-weight: 600; }
.login-card .lead { color: var(--muted); margin: 0 0 22px; }
.login-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 10px 14px;
  background: #24304a; border: 1px solid var(--accent); border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 600; }
.login-btn:hover { background: #2b3a5a; }
.login-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.login-note { margin: 14px 0 0; font-size: 12px; color: var(--muted); }
.login-error { margin: 0 0 16px; padding: 8px 10px; border-radius: 8px; background: #2c1a20; border: 1px solid var(--warn);
  color: #ffb3c1; font-size: 12.5px; text-align: left; }
