/* ATLAS — design system (Kinetic Noir x ledger tecnico)
   Spec en atlas/DESIGN.md. Cualquier divergencia es bug.
   NOTA: fonts se cargan desde el HTML via <link>, no via @import. */

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-elevated: #1c1c1c;
  --border: #2a2a2a;
  --border-subtle: #1f1f1f;
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --accent: #8b5cf6;

  --node-container: #3b82f6;
  --node-network: #10b981;
  --node-volume: #a78bfa;
  --node-domain: #f59e0b;
  --node-external: #ef4444;
  --node-note: #94a3b8;
  --node-tag: #94a3b8;
  --node-app: #525252;
  --node-dangling: #525252;

  --state-healthy: #10b981;
  --state-warning: #f59e0b;
  --state-stopped: #ef4444;

  --edge: #3f3f46;
  --edge-label: #71717a;

  --font-ui: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, monospace;

  --header-h: 56px;
  --toolbar-h: 48px;
  --panel-w: 380px;
  --bottom-nav-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.atlas-body { overflow: hidden; }

button { font-family: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--text-secondary); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* === Login page === */
.login-page {
  display: grid; place-items: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  width: min(360px, 90vw);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 48px 32px;
  text-align: center;
}
.login-card h1 {
  font-size: 42px; font-weight: 800; letter-spacing: -0.02em;
  margin: 0 0 4px;
}
.login-card .muted { font-size: 12px; margin: 0 0 32px; letter-spacing: 0.04em; text-transform: uppercase; }
.login-card .error {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 12px;
  font-size: 12px;
  margin-bottom: 16px;
}
.btn-primary {
  display: block;
  padding: 12px 16px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  transition: border-color 150ms ease-out;
}
.btn-primary:hover { border-color: var(--text-secondary); text-decoration: none; }

/* === Atlas shell === */
.app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--toolbar-h);
  height: 100vh; width: 100vw;
}

.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg);
}
.header-brand {
  display: flex; align-items: baseline; gap: 16px;
}
.brand-name {
  font-size: 22px; font-weight: 800; letter-spacing: -0.02em;
}
.tabs { display: flex; gap: 0; }
.tab {
  background: transparent;
  border: none;
  padding: 0 16px;
  height: 40px;
  color: var(--text-tertiary);
  font-size: 13px; font-weight: 500;
  position: relative;
}
.tab[aria-current="true"] { color: var(--text); }
.tab[aria-current="true"]::after {
  content: "";
  position: absolute; left: 16px; right: 16px; bottom: -1px;
  height: 2px; background: var(--accent);
}
.header-right { display: flex; align-items: center; gap: 12px; }
.search {
  display: flex; align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0 10px; height: 32px;
  transition: border-color 150ms;
}
.search:focus-within { border-color: var(--accent); }
.search input {
  background: transparent; border: none; outline: none;
  color: var(--text); font-family: var(--font-ui); font-size: 13px;
  width: 180px; padding-left: 8px;
}
.search svg { width: 14px; height: 14px; color: var(--text-tertiary); flex: 0 0 auto; }
.user-chip { font-size: 12px; color: var(--text-secondary); }

/* === Canvas + panel === */
.stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
}
#cy, #list-view {
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  background: var(--bg);
}
#list-view {
  overflow-y: auto;
  padding: 16px;
}
.stage.panel-open #cy,
.stage.panel-open #list-view {
  right: var(--panel-w);
}

/* === Panel detalle === */
.panel {
  display: none;
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: var(--panel-w);
  border-left: 1px solid var(--border-subtle);
  background: var(--surface);
  overflow-y: auto;
  padding: 24px;
}
.stage.panel-open .panel { display: block; }
.panel-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 16px;
}
.panel-title {
  font-size: 14px; font-weight: 700; letter-spacing: -0.01em;
  word-break: break-word;
}
.panel-close {
  background: transparent; border: none; color: var(--text-tertiary);
  font-size: 18px; line-height: 1; padding: 0;
}
.panel-close:hover { color: var(--text); }
.panel-subtitle {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 24px;
}
.panel-row {
  display: grid; grid-template-columns: 100px 1fr;
  gap: 12px; padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12px;
}
.panel-row .k {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-tertiary);
}
.panel-row .v {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--text); word-break: break-all;
}
.panel-row.block { grid-template-columns: 1fr; }
.panel-section {
  margin-top: 20px;
  font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-tertiary);
}
.panel-actions { margin-top: 24px; display: flex; gap: 8px; flex-wrap: wrap; }
.panel-actions .btn {
  padding: 8px 12px; height: 36px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
  font-size: 12px;
  transition: border-color 150ms;
}
.panel-actions .btn:hover { border-color: var(--text-secondary); }

/* === Toolbar === */
.toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg);
  overflow-x: auto;
  white-space: nowrap;
}
.chips { display: flex; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 12px; height: 28px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.chip[aria-pressed="true"] {
  background: var(--surface-elevated);
  border-color: var(--text-secondary);
  color: var(--text);
}
.chip .dot {
  width: 8px; height: 8px;
  border: 2px solid currentColor;
  background: transparent;
  flex: 0 0 auto;
}
.chip[aria-pressed="true"] .dot { background: currentColor; }

.toolbar-meta {
  margin-left: auto;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-tertiary);
  display: flex; align-items: center; gap: 16px;
}
.live-dot {
  display: inline-block; width: 8px; height: 8px;
  background: var(--state-healthy);
  border-radius: 50%;
  margin-right: 6px;
}
.live-dot.pulse { animation: pulse 1.2s ease-out; }
@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  70% { transform: scale(2.2); opacity: 0; }
  100% { transform: scale(1); opacity: 0; }
}
.btn-ghost {
  background: transparent; border: none; color: var(--text-secondary);
  padding: 4px 8px; font-size: 14px; cursor: pointer;
}
.btn-ghost:hover { color: var(--text); }

/* === States === */
.state-message {
  display: flex; align-items: center; justify-content: center;
  height: 100%; width: 100%;
  padding: 48px 16px;
  text-align: center;
  color: var(--text-secondary);
}
.state-message .inner { max-width: 360px; }
.state-message h2 {
  font-size: 16px; font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}
.state-message p { font-size: 13px; margin: 0 0 16px; }
.state-message a { font-size: 13px; }
.state-error {
  position: absolute; top: 0; left: 0; right: 0;
  background: rgba(239, 68, 68, 0.08);
  border-bottom: 1px solid #ef4444;
  color: #fca5a5;
  padding: 12px 16px;
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  z-index: 10;
}
.state-error .btn {
  background: transparent; border: 1px solid #ef4444;
  color: #fca5a5; padding: 4px 10px; font-size: 12px;
}

/* === First-run overlay === */
.first-run-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
}
.first-run-backdrop.show { display: flex; }
.first-run-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 32px;
  width: min(420px, 90vw);
}
.first-run-card h2 {
  font-size: 22px; font-weight: 800; letter-spacing: -0.02em;
  margin: 0 0 16px;
}
.first-run-card ul {
  list-style: none; padding: 0; margin: 0 0 24px;
}
.first-run-card li {
  font-size: 13px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.first-run-card .btn {
  width: 100%; padding: 12px; height: 40px;
  background: var(--accent); color: white;
  border: none; font-weight: 600; font-size: 13px;
}

/* === List view (mobile default for Datos, fallback general) === */
.list-group { margin-bottom: 24px; }
.list-group-title {
  font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-tertiary);
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between;
}
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 100ms;
}
.list-row:hover { background: var(--surface); }
.list-row .shape {
  width: 12px; height: 12px; flex: 0 0 auto;
  border: 2px solid currentColor;
  background: var(--bg);
}
.list-row .label { font-size: 13px; flex: 1; }
.list-row .meta {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}
.list-row[data-tipo="container"] .shape { color: var(--node-container); border-radius: 50%; }
.list-row[data-tipo="network"] .shape { color: var(--node-network); transform: rotate(45deg); }
.list-row[data-tipo="volume"] .shape { color: var(--node-volume); }
.list-row[data-tipo="domain"] .shape { color: var(--node-domain); clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }
.list-row[data-tipo="external"] .shape { color: var(--node-external); clip-path: polygon(50% 0, 100% 100%, 0 100%); background: transparent; }
.list-row[data-tipo="note"] .shape { color: var(--node-note); border-radius: 50%; }
.list-row[data-tipo="tag"] .shape { background: var(--node-tag); border: none; }
.list-row[data-tipo="person"] .shape { border-radius: 50%; border: none; }
.list-row[data-tipo="app"] .shape { color: var(--node-app); }
.list-row[data-tipo="dangling"] .shape { color: var(--node-dangling); border-style: dashed; border-radius: 50%; }

/* === Legenda === */
.legend {
  display: inline-flex; gap: 12px; align-items: center;
  font-size: 11px; color: var(--text-tertiary);
}
.legend-item { display: inline-flex; align-items: center; gap: 4px; }
.legend-shape { width: 8px; height: 8px; }

/* === Responsive === */
@media (max-width: 767px) {
  :root {
    --header-h: 52px;
    --panel-w: 100%;
    --toolbar-h: 44px;
  }
  body.atlas-body { padding-bottom: 0; }
  .app {
    grid-template-rows: var(--header-h) 1fr var(--toolbar-h);
    height: 100vh;
  }
  .header-right .search input { width: 110px; }
  .brand-name { font-size: 18px; }
  .tab { padding: 0 10px; font-size: 12px; height: 36px; }

  .toolbar {
    padding: 0 12px;
    gap: 8px;
  }
  .toolbar-meta { margin-left: 8px; gap: 10px; font-size: 10px; }
  .toolbar-meta #meta-counts { display: none; }
  .legend { display: none; }
  .chip { height: 26px; padding: 0 10px; font-size: 10px; }

  .stage.panel-open .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 55vh;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    padding: 16px;
  }
  .stage.panel-open #cy,
  .stage.panel-open #list-view {
    right: 0;
    bottom: 55vh;
  }
  #cy { display: none; }
  #list-view { display: block; }
  .mobile-cy #cy { display: block; }
  .mobile-cy #list-view { display: none; }
}

@media (min-width: 768px) {
  #list-view { display: none; }
  .mobile-cy-toggle { display: none; }
}
