@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg: #0b0e14;
  --surface: #121722;
  --surface-2: #1a2130;
  --surface-3: #212a3d;
  --border: #232b3d;
  --ink: #e8eaf0;
  --muted: #8891a6;
  --muted-2: #5c6478;
  --accent: #c9a24b;
  --accent-soft: #e8c878;
  --accent-dim: rgba(201, 162, 75, 0.14);
  --pulse: #4fb8a8;
  --pulse-dim: rgba(79, 184, 168, 0.16);
  --danger: #e0555a;
  --warn: #e0a83e;
  --radius: 10px;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}
a { color: inherit; }
button { font-family: inherit; cursor: pointer; }
::selection { background: var(--accent-dim); color: var(--accent-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- estados vivos ---------- */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot--ok { background: var(--pulse); box-shadow: 0 0 0 3px var(--pulse-dim); }
.dot--warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(224,168,62,0.16); }
.dot--off { background: var(--muted-2); }
.dot--pulsing { animation: pulse-dot 2.2s ease-in-out infinite; }
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px var(--pulse-dim); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 296px 1fr; min-height: 100vh; }

.rail {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand .mark { font-family: var(--font-display); font-size: 22px; font-weight: 600; letter-spacing: 0.02em; color: var(--accent-soft); }
.brand .sub { font-size: 10.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.12em; }

.org {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12.5px;
}
.org-node {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; border-radius: 7px;
  color: var(--muted);
  border: 1px solid transparent;
}
.org-node.self { color: var(--ink); font-weight: 600; }
.org-node .name { flex: 1; }
.org-node .tag { font-family: var(--font-mono); font-size: 10px; color: var(--muted-2); }
.org-connector { width: 1px; background: var(--border); height: 12px; margin-left: 17px; }
.org-group { margin-left: 14px; border-left: 1px solid var(--border); padding-left: 10px; display: flex; flex-direction: column; gap: 2px; }
.org-esp { padding: 5px 8px; border-radius: 6px; font-size: 12px; color: var(--muted); display: flex; gap: 7px; align-items: center; }
.org-esp:hover { background: var(--surface-2); color: var(--ink); }

.rail-foot { margin-top: auto; font-size: 11px; color: var(--muted-2); display: flex; flex-direction: column; gap: 6px; }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(11,14,20,0.86); backdrop-filter: blur(8px); z-index: 20;
}
.topbar h1 { font-family: var(--font-display); font-size: 19px; font-weight: 500; margin: 0; }
.topbar .clock { font-family: var(--font-mono); font-size: 12px; color: var(--muted); margin-left: 4px; }
.topbar .spacer { flex: 1; }
.tabs { display: flex; gap: 2px; }
.tab {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 500;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--surface-2); color: var(--accent-soft); border-color: var(--border); }

.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink);
  width: 34px; height: 34px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent-soft); }

.content { padding: 26px 28px 60px; max-width: 1180px; width: 100%; }

@media (max-width: 720px) {
  .topbar { padding: 12px 14px; flex-wrap: wrap; row-gap: 8px; }
  .topbar h1 { font-size: 16px; }
  .topbar .clock { display: none; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .content { padding: 16px 14px 50px; }
  .grid2 { grid-template-columns: 1fr; }
  .stat-row { gap: 8px; }
}
.view { display: none; }
.view.active { display: block; animation: fade-in .25s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.grid2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.card + .card { margin-top: 16px; }
.card h2 { font-family: var(--font-display); font-size: 15.5px; font-weight: 500; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.card .eyebrow { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted-2); margin-bottom: 6px; }
.card p.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 0; }

.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.stat { flex: 1; min-width: 120px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.stat .num { font-family: var(--font-mono); font-size: 20px; color: var(--accent-soft); }
.stat .lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }

.list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 10px; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--border); }
.list .meta { font-size: 11px; color: var(--muted-2); font-family: var(--font-mono); }
.list .txt { font-size: 13px; }
.empty { color: var(--muted); font-size: 12.5px; padding: 14px 4px; }
.empty .fix { color: var(--accent-soft); }

/* ---------- flujo guarda templos ---------- */
.flow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 20px 0 6px; }
.flow-node { flex: 1; text-align: center; padding: 16px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.flow-node .t { font-family: var(--font-display); font-size: 14px; margin-top: 6px; }
.flow-node .s { font-size: 11px; color: var(--muted); margin-top: 3px; }
.flow-wire { flex: 0 0 60px; height: 2px; position: relative; background: linear-gradient(90deg, var(--border), var(--border)); overflow: visible; }
.flow-wire::after {
  content: ''; position: absolute; top: -3px; left: -6px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--pulse); box-shadow: 0 0 8px var(--pulse);
  animation: travel 2.4s linear infinite;
}
.flow-wire.idle::after { display: none; }
@keyframes travel { from { left: -6px; } to { left: 100%; } }
@media (max-width: 620px) {
  .flow { flex-direction: column; align-items: stretch; }
  .flow-wire { width: 2px; height: 28px; flex: none; margin: 0 auto; }
  .flow-wire::after { top: -6px; left: -3px; animation: travel-v 2.4s linear infinite; }
  @keyframes travel-v { from { top: -6px; } to { top: 100%; } }
}

pre.raw { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); white-space: pre-wrap; max-height: 260px; overflow: auto; }

/* ---------- organismo query ---------- */
.ask-row { display: flex; gap: 8px; margin-top: 10px; }
.ask-row input { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: var(--ink); padding: 10px 12px; font-size: 13px; }
.ask-row input:focus { outline: none; border-color: var(--accent); }
.btn { background: var(--accent); color: #17140a; border: none; border-radius: 8px; padding: 10px 16px; font-weight: 600; font-size: 13px; }
.btn:hover { background: var(--accent-soft); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--ink); }

.esp-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-dim); border: 1px solid rgba(201,162,75,0.3); color: var(--accent-soft); font-size: 11.5px; padding: 4px 9px; border-radius: 20px; margin: 3px 4px 0 0; }

/* ---------- chat drawer ---------- */
.chat-drawer {
  position: fixed; top: 0; right: -420px; width: 400px; height: 100vh; background: var(--surface);
  border-left: 1px solid var(--border); z-index: 50; display: flex; flex-direction: column;
  transition: right .28s ease; box-shadow: -20px 0 40px rgba(0,0,0,0.35);
}
.chat-drawer.open { right: 0; }
@media (max-width: 460px) { .chat-drawer { width: 100vw; right: -100vw; } }
.chat-head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.chat-head h3 { font-family: var(--font-display); margin: 0; font-size: 15px; font-weight: 500; }
.chat-body { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 10px; font-size: 13px; line-height: 1.45; }
.msg.user { align-self: flex-end; background: var(--accent-dim); border: 1px solid rgba(201,162,75,0.25); }
.msg.atlas { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }
.chat-foot { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.chat-foot input { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: var(--ink); padding: 10px 12px; font-size: 13px; }
.chat-foot input:focus { outline: none; border-color: var(--accent); }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .25s; }
.backdrop.open { opacity: 1; pointer-events: auto; }

/* focus visibility */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- responsive: shell (al final a propósito, gana la cascada sobre .rail base) ---------- */
@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .rail { display: none; }
}
