:root {
  --bg: #17171a;
  --bg-elev: #1e1e22;
  --bg-panel: #1b1b1f;
  --bg-hover: #26262c;
  --border: #2c2c33;
  --border-soft: #24242a;
  --text: #dcdddf;
  --text-dim: #9a9aa3;
  --text-faint: #6d6d78;
  --accent: #a882ff;
  --accent-soft: rgba(168, 130, 255, 0.14);
  --gold: #d8b25a;
  --ok: #4ec9a0;
  --warn: #e0a458;
  --danger: #e56b6f;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------- top bar ------------------------------- */
.topbar {
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.brand-mark { color: var(--accent); display: grid; place-items: center; }
.brand-name { font-weight: 650; letter-spacing: 0.04em; font-size: 14px; }
.brand-sub { color: var(--text-faint); font-size: 12px; letter-spacing: 0.02em; }

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 260px;
  max-width: 420px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 10px;
  height: 34px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-icon { color: var(--text-faint); display: grid; place-items: center; margin-right: 7px; }
#search {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  min-width: 0;
}
#search::-webkit-search-cancel-button { filter: invert(0.6); }
.search-hint {
  font-size: 11px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  line-height: 16px;
}

.filters { display: flex; gap: 4px; flex: 0 0 auto; flex-wrap: nowrap; }
.chip {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { background: var(--bg-hover); color: var(--text); }
.chip.is-active {
  background: var(--accent-soft);
  border-color: rgba(168, 130, 255, 0.38);
  color: #cbb6ff;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ghost-btn:hover { background: var(--bg-hover); color: var(--text); border-color: #3a3a44; }

.gate-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(78, 201, 160, 0.08);
  border: 1px solid rgba(78, 201, 160, 0.3);
  color: #9fe6cd;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  flex: 0 0 auto;
}
.gate-badge.is-warn {
  background: rgba(224, 164, 88, 0.09);
  border-color: rgba(224, 164, 88, 0.35);
  color: #f0c48d;
}
.gate-label { font-weight: 600; letter-spacing: 0.05em; font-size: 11px; }
.gate-count { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.pulse-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(78, 201, 160, 0.55);
  animation: pulse 2.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(78, 201, 160, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(78, 201, 160, 0); }
  100% { box-shadow: 0 0 0 0 rgba(78, 201, 160, 0); }
}

/* ------------------------------ workspace ------------------------------ */
.workspace {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background:
    radial-gradient(circle at 30% 20%, rgba(168, 130, 255, 0.05), transparent 45%),
    radial-gradient(circle at 75% 75%, rgba(78, 201, 160, 0.04), transparent 50%),
    var(--bg);
  overflow: hidden;
}

#graph { display: block; width: 100%; height: 100%; cursor: grab; }
#graph.is-panning { cursor: grabbing; }

.canvas-meta {
  position: absolute;
  top: 12px;
  left: 14px;
  font-size: 11.5px;
  color: var(--text-faint);
  letter-spacing: 0.02em;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.legend {
  position: absolute;
  left: 14px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 11px;
  color: var(--text-faint);
  pointer-events: none;
  max-width: 60%;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.k-proyecto { background: #7f9cf5; }
.k-agente { background: #4ec9a0; }
.k-decision { background: #e0a458; }
.k-nota { background: #8f8f9c; }
.k-evento { background: #5fb3d4; }
.k-regla { background: #d8b25a; }
.k-vivo { background: #ff7b93; }

.zoom-controls {
  position: absolute;
  right: 14px;
  bottom: 12px;
  display: flex;
  gap: 4px;
  background: rgba(30, 30, 34, 0.86);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
  backdrop-filter: blur(6px);
}
.zoom-controls button {
  width: 28px; height: 26px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 15px;
  border-radius: 6px;
  cursor: pointer;
}
.zoom-controls button:hover { background: var(--bg-hover); color: var(--text); }

/* -------------------------------- panel -------------------------------- */
.panel {
  flex: 0 0 400px;
  width: 400px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs {
  display: flex;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  gap: 2px;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-faint);
  font-size: 12px;
  padding: 12px 4px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text-dim); }
.tab.is-active { color: #cbb6ff; border-bottom-color: var(--accent); }

.tab-body { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; }
.tab-pane {
  display: none;
  flex-direction: column;
  width: 100%;
  overflow-y: auto;
  padding: 16px;
  gap: 10px;
}
.tab-pane.is-active { display: flex; }
#pane-kia.tab-pane { padding: 0; }

.empty { color: var(--text-faint); padding: 24px 4px; }
.empty h3 { color: var(--text-dim); font-size: 14px; font-weight: 600; margin: 0 0 8px; }
.empty p { margin: 0; font-size: 12.5px; line-height: 1.6; }

.hidden { display: none !important; }

.note-folder {
  display: inline-block;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 2px 7px;
  margin-bottom: 8px;
}
#note-title { font-size: 19px; font-weight: 640; margin: 0 0 4px; line-height: 1.3; }
.note-path {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text-faint);
  word-break: break-all;
}

.markdown { font-size: 13px; line-height: 1.62; color: var(--text); }
.markdown h1 { font-size: 18px; margin: 16px 0 8px; font-weight: 650; }
.markdown h2 { font-size: 15.5px; margin: 18px 0 7px; font-weight: 640; color: #e8e8ea; }
.markdown h3 { font-size: 13.8px; margin: 15px 0 6px; font-weight: 620; }
.markdown h4, .markdown h5, .markdown h6 { font-size: 13px; margin: 12px 0 5px; font-weight: 600; color: var(--text-dim); }
.markdown p { margin: 0 0 9px; }
.markdown ul, .markdown ol { margin: 0 0 10px; padding-left: 20px; }
.markdown li { margin: 0 0 4px; }
.markdown code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  background: #26262c;
  border-radius: 4px;
  padding: 1.5px 5px;
  color: #d9c9ff;
}
.markdown pre {
  background: #202026;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0 0 10px;
}
.markdown pre code { background: none; padding: 0; color: #c8c8d0; font-size: 11.6px; }
.markdown blockquote {
  border-left: 2px solid var(--accent);
  margin: 0 0 10px;
  padding: 2px 0 2px 12px;
  color: var(--text-dim);
}
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.markdown a { color: var(--accent); text-decoration: none; }
.markdown a:hover { text-decoration: underline; }
.wikilink {
  color: #cbb6ff;
  background: rgba(168, 130, 255, 0.1);
  border-radius: 4px;
  padding: 0 4px;
  cursor: pointer;
  border-bottom: 1px solid rgba(168, 130, 255, 0.35);
}
.wikilink:hover { background: rgba(168, 130, 255, 0.2); }
.markdown table { border-collapse: collapse; width: 100%; margin: 0 0 10px; font-size: 12px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }
.markdown th { background: #232329; color: var(--text-dim); font-weight: 600; }

.events-block { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--border); }
.events-block h4 {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-faint); margin: 0 0 8px; font-weight: 600;
}
.event-item {
  font-size: 11.8px;
  color: var(--text-dim);
  padding: 6px 0;
  border-bottom: 1px solid var(--border-soft);
}
.event-item:last-child { border-bottom: none; }
.event-item b { color: var(--text); font-weight: 550; }
.event-item time { color: var(--text-faint); font-size: 10.5px; display: block; margin-top: 2px; }

/* gate tab */
.gate-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  padding: 9px 11px;
}
.stat b { display: block; font-size: 17px; font-weight: 640; color: #e9e9ec; font-variant-numeric: tabular-nums; }
.stat span { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; }

.sect {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin: 14px 0 4px;
  font-weight: 600;
}
.list { display: flex; flex-direction: column; gap: 7px; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 12px;
}
.card .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card .who { font-weight: 600; color: #e6e6e9; font-size: 12.4px; }
.card .meta { color: var(--text-faint); font-size: 11px; margin-top: 3px; }
.card .body { color: var(--text-dim); font-size: 11.5px; margin-top: 5px; line-height: 1.5; word-break: break-word; }
.badge {
  font-size: 9.6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 4px;
  padding: 2px 6px;
  white-space: nowrap;
}
.badge.active { background: rgba(78, 201, 160, 0.15); color: #8fe3c4; }
.badge.closed { background: rgba(154, 154, 163, 0.12); color: var(--text-faint); }
.badge.lvl { background: rgba(168, 130, 255, 0.14); color: #c3aaff; }
.muted { color: var(--text-faint); font-size: 11.5px; padding: 6px 0; }

.reglamento {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  padding: 10px 12px;
}
.reglamento summary {
  cursor: pointer;
  font-size: 12px;
  color: #cbb6ff;
  font-family: ui-monospace, Menlo, monospace;
}
.reglamento .markdown { margin-top: 10px; max-height: 420px; overflow-y: auto; }

/* chat tab */
#pane-kia { display: none; }
#pane-kia.is-active { display: flex; }
.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.msg { max-width: 92%; font-size: 12.8px; line-height: 1.58; }
.msg p { margin: 0 0 6px; }
.msg p:last-child { margin-bottom: 0; }
.msg-kia {
  align-self: flex-start;
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: 12px 12px 12px 3px;
  padding: 9px 12px;
  color: var(--text);
}
.msg-user {
  align-self: flex-end;
  background: rgba(168, 130, 255, 0.16);
  border: 1px solid rgba(168, 130, 255, 0.28);
  border-radius: 12px 12px 3px 12px;
  padding: 9px 12px;
  color: #ede7ff;
}
.msg .cites { margin-top: 7px; padding-top: 6px; border-top: 1px solid var(--border-soft); }
.msg .cites div {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10.4px;
  color: var(--text-faint);
  word-break: break-all;
  line-height: 1.5;
}
.msg .engine-tag {
  font-size: 9.6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-top: 6px;
  display: block;
}
.msg.is-error { border-color: rgba(229, 107, 111, 0.4); color: #f0b6b8; }

.chat-input {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}
#chat-text {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 12.8px;
  outline: none;
  min-width: 0;
}
#chat-text:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#send-btn {
  background: var(--accent);
  color: #17131f;
  border: none;
  border-radius: 9px;
  padding: 0 15px;
  font-size: 12.5px;
  font-weight: 620;
  cursor: pointer;
}
#send-btn:hover { background: #b795ff; }
#send-btn:disabled { opacity: 0.55; cursor: default; }
.mic {
  width: 34px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text-dim);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.mic:hover { color: var(--text); border-color: #3a3a44; }
.mic.is-rec {
  color: #ff9db1;
  border-color: rgba(255, 123, 147, 0.55);
  background: rgba(255, 123, 147, 0.1);
  animation: pulse 1.6s infinite;
}
.chat-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 10px;
  font-size: 11px;
  color: var(--text-faint);
}
.toggle { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.engine { font-family: ui-monospace, Menlo, monospace; font-size: 10px; }

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #33333c; border-radius: 6px; border: 2px solid var(--bg-panel); }
::-webkit-scrollbar-thumb:hover { background: #43434f; }

@media (max-width: 1080px) {
  .panel { flex-basis: 340px; width: 340px; }
  .filters { display: none; }
}
@media (max-width: 780px) {
  .workspace { flex-direction: column; }
  .panel { flex: 1 1 46%; width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .brand-sub { display: none; }
}
