/* === Design tokens === */
:root {
  /* Colors — premium dark graphite palette */
  --color-bg:               #0b0d10;
  --color-surface:          #13171d;
  --color-surface-2:        #1a2028;
  --color-surface-3:        #232b35;
  --color-border:           #242c36;
  --color-border-strong:    #35404d;
  --color-text-primary:     #eef2f6;
  --color-text-secondary:   #9aa7b6;
  --color-text-muted:       #5f6b78;
  --color-node-stroke:      #5b80aa;
  --color-node-fill-branch: #1d2631;
  --color-node-fill-leaf:   #0b0d10;
  --color-link:             #323c47;
  --color-link-hover:       #47586a;
  --color-noscript-bg:      #211a0a;
  --color-noscript-border:  #5c4208;
  --color-legend:           #dfe4ea;
  --color-header:           #f2f5f8;

  /* Status badge colors — consistent on dark and light */
  --badge-T: #4a9eda;
  --badge-D: #e8944a;
  --badge-R: #c8a030;
  --badge-M: #9a7eda;

  /* Identity blue (discreet) */
  --color-accent:           #4285f4;
  --color-accent-strong:    #2f6fe0;
  --color-accent-soft:      rgba(66, 133, 244, 0.12);
  --color-accent-border:    rgba(66, 133, 244, 0.38);

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-md:  0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-lg:  0 16px 48px rgba(0, 0, 0, 0.6);

  /* Border radius */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;

  /* Spacing (4px base scale) */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  24px;
  --space-6:  32px;

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
  --font-size-xs:   11px;
  --font-size-sm:   12px;
  --font-size-base: 14px;
  --font-size-lg:   16px;
  --font-size-xl:   19px;
}

body.light-mode {
  --color-bg:               #ffffff;
  --color-surface:          #f6f8fa;
  --color-surface-2:        #eef1f4;
  --color-surface-3:        #e4e8ec;
  --color-border:           #e0e5ea;
  --color-border-strong:    #c3ccd5;
  --color-text-primary:     #0d1117;
  --color-text-secondary:   #57606a;
  --color-text-muted:       #8b949e;
  --color-node-stroke:      #3f6fb0;
  --color-node-fill-branch: #e7eef7;
  --color-node-fill-leaf:   #ffffff;
  --color-link:             #d3d9e0;
  --color-link-hover:       #b6c0ca;
  --color-noscript-bg:      #fff3e0;
  --color-noscript-border:  #ffcc80;
  --color-legend:           #0d1117;
  --color-header:           #0d1117;
  --color-accent:           #2f6fe0;
  --color-accent-strong:    #1f5ed0;
  --color-accent-soft:      rgba(47, 111, 224, 0.10);
  --color-accent-border:    rgba(47, 111, 224, 0.35);
  --shadow-sm:              0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-md:              0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-lg:              0 16px 48px rgba(0, 0, 0, 0.16);
}

/* === Base === */
* { box-sizing: border-box; }

body {
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  margin: 0;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

noscript p {
  text-align: center;
  background-color: var(--color-noscript-bg);
  color: var(--color-text-primary);
  margin: 0 auto;
  width: 80vw;
  padding: 25px 0;
  margin-top: 80px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-noscript-border);
  margin-bottom: 20px;
}

.hidden { display: none !important; }

/* === App layout grid === */
#body {
  display: grid;
  height: 100dvh;
  grid-template-columns: 264px 1fr;
  grid-template-rows: auto auto auto 1fr auto;
  grid-template-areas:
    "banner  banner"
    "header  header"
    "search  search"
    "sidebar main"
    "footer  footer";
  position: relative;
  overflow: hidden;
}

#plan-banner {
  grid-area: banner;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-5);
  font-size: 0.85rem;
  color: var(--color-text-primary);
  background: rgba(255, 193, 7, 0.1);
  border-bottom: 1px solid rgba(255, 193, 7, 0.35);
  z-index: 21;
}

#plan-banner a {
  color: var(--color-text-primary);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px dashed currentColor;
}

#plan-banner a:hover {
  opacity: 0.85;
}

/* === Header === */
#header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  z-index: 20;
}

#header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

#header-title {
  font-size: var(--font-size-xl);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--color-header);
  white-space: nowrap;
}

#header-title .brand-accent {
  color: var(--color-accent);
}

#sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  flex-shrink: 0;
}

#sidebar-toggle:hover {
  color: var(--color-text-primary);
  border-color: var(--color-border-strong);
}

#header-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

#header-actions button {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  white-space: nowrap;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

#header-actions button:hover {
  color: var(--color-text-primary);
  border-color: var(--color-border-strong);
  background: var(--color-surface-2);
}

/* === Search === */
#search-container {
  grid-area: search;
  position: relative;
  padding: var(--space-4) var(--space-5) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  z-index: 15;
}

#search-box {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 0 var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

#search-box:focus-within {
  border-color: var(--color-accent-border);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
  background: var(--color-surface-2);
}

#search-input {
  width: 100%;
  padding: var(--space-3) 0;
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  font-weight: 500;
  background: transparent;
  color: var(--color-text-primary);
  border: none;
  outline: none;
}

#search-input::placeholder {
  color: var(--color-text-muted);
  font-weight: 400;
}

#search-results {
  position: absolute;
  top: calc(100% - var(--space-1));
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - var(--space-6)));
  text-align: left;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 380px;
  overflow-y: auto;
  display: none;
  z-index: 50;
}

#search-results.visible {
  display: block;
}

.search-result-item {
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
  cursor: pointer;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--color-accent-soft);
}

.search-result-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-result-name {
  font-weight: 600;
  color: var(--color-text-primary);
}

.search-result-ext {
  font-size: 12px;
  color: var(--color-accent);
  text-decoration: none;
  flex-shrink: 0;
  line-height: 1;
}

.search-result-ext:hover {
  color: var(--color-accent-strong);
  text-decoration: none;
}

.search-result-path {
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  margin-top: 2px;
}

.search-no-results {
  padding: var(--space-3);
  color: var(--color-text-secondary);
  text-align: center;
}

/* === Sidebar === */
#sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  border-right: 1px solid var(--color-border);
  background: var(--color-bg);
  padding: var(--space-4) var(--space-3) var(--space-4);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}

#sidebar::-webkit-scrollbar {
  width: 8px;
}

#sidebar::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border-radius: 4px;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-1) var(--space-2) var(--space-3);
}

#sidebar-title {
  font-size: var(--font-size-xs);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

#sidebar-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
}

#sidebar-close:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-2);
}

#sidebar-categories {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-cat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease;
}

.sidebar-cat:hover {
  background: var(--color-surface);
  color: var(--color-text-primary);
  border-color: var(--color-border);
}

.sidebar-cat.active {
  background: var(--color-accent-soft);
  border-color: var(--color-accent-border);
  color: var(--color-accent);
  font-weight: 600;
}

.sidebar-cat-count {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1px 8px;
  min-width: 26px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.sidebar-cat.active .sidebar-cat-count {
  color: var(--color-accent);
  border-color: var(--color-accent-border);
  background: var(--color-bg);
}

.sidebar-cat-count.sidebar-locked-count {
  color: #f5c518;
  border-color: rgba(245, 197, 24, 0.4);
  background: rgba(245, 197, 24, 0.08);
  font-weight: 700;
}

.lock-glyph {
  font-size: 11px;
}

.lock-glyph + tspan {
  font-weight: 600;
}

/* Legend (lives in the sidebar) */
.legend {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-top: var(--space-6);
  padding: var(--space-4) var(--space-2) 0;
  border-top: 1px solid var(--color-border);
}

.legend-title {
  font-size: var(--font-size-xs);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

.legend-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.legend a {
  color: var(--color-node-stroke);
}

/* Status badge pills (T/D/R/M) */
.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  color: #fff;
  vertical-align: middle;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.badge-T { background-color: var(--badge-T); }
.badge-D { background-color: var(--badge-D); }
.badge-R { background-color: var(--badge-R); }
.badge-M { background-color: var(--badge-M); }

/* === Main tree area === */
#body svg {
  grid-area: main;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--color-surface) 0%, transparent 60%);
}

#body svg:active {
  cursor: grabbing;
}

/* D3 nodes */
.node {
  cursor: pointer;
}

.node circle {
  cursor: pointer;
  fill: var(--color-node-fill-leaf);
  stroke: var(--color-node-stroke);
  stroke-width: 1.5px;
  transition: stroke 120ms ease;
}

.node:hover circle {
  stroke: var(--color-accent);
}

.node text {
  font-size: 13px;
  fill: var(--color-text-primary);
  font-family: var(--font-family);
  pointer-events: none;
  text-shadow: 0 1px 3px var(--color-bg);
}

path.link {
  fill: none;
  stroke: var(--color-link);
  stroke-width: 1.2px;
}

/* === Zoom controls === */
#zoom-controls {
  grid-area: main;
  justify-self: end;
  align-self: end;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  z-index: 30;
  margin: 0 var(--space-4) var(--space-4) 0;
}

#zoom-controls button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--color-surface-2);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

#zoom-controls button:hover {
  color: var(--color-accent);
  border-color: var(--color-accent-border);
  background: var(--color-surface-3);
}

/* === Footer === */
#app-footer {
  grid-area: footer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

#app-footer .footer-sep {
  color: var(--color-border-strong);
}

/* === Misc === */
h3 {
  color: var(--color-text-primary);
}

a {
  color: var(--color-node-stroke);
}

/* Notes source (also rendered inside the notes panel) */
#notes-content {
  display: none;
}

/* Mobile floating notes button (hidden on desktop; header button used instead) */
#mobile-notes-btn {
  display: none;
}

/* Notes overlay */
#notes-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 299;
}

#notes-overlay.visible {
  display: block;
}

/* Notes panel (desktop: side panel) */
#notes-panel {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  max-width: 100vw;
  height: 100dvh;
  background: var(--color-surface-2);
  z-index: 300;
  transform: translateX(100%);
  transition: transform 250ms ease;
  will-change: transform;
  box-shadow: var(--shadow-md);
}

#notes-panel.open {
  transform: translateX(0);
}

#notes-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

#notes-panel-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--color-text-primary);
}

#notes-panel-close {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px var(--space-1);
  border-radius: var(--radius-sm);
}

#notes-panel-close:hover {
  color: var(--color-text-primary);
  background: var(--color-bg);
}

#notes-panel-body {
  flex: 1;
  padding: var(--space-4);
  overflow-y: auto;
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  line-height: 1.6;
}

#notes-panel-body a {
  color: var(--color-node-stroke);
}

#notes-panel-body h3 {
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
}

#notes-panel-body h3:first-child {
  margin-top: 0;
}

/* === Sidebar backdrop (mobile) === */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 389;
}

#sidebar-backdrop.visible {
  display: block;
}

/* === Responsive === */
@media (max-width: 960px) {
  #body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto 1fr auto;
    grid-template-areas:
      "banner"
      "header"
      "search"
      "main"
      "footer";
  }

  #sidebar-toggle {
    display: inline-flex;
  }

  /* Sidebar becomes an off-canvas drawer on mobile/tablet */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 86vw);
    z-index: 390;
    transform: translateX(-104%);
    transition: transform 260ms ease;
    border-right: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    background: var(--color-surface);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar-close {
    display: inline-flex;
  }

  /* Hide desktop notes button on mobile (floating button used instead) */
  #header-notes-btn {
    display: none;
  }

  #header {
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
  }

  #header-actions button {
    padding: var(--space-1) var(--space-2);
  }

  #search-container {
    padding: var(--space-3) var(--space-3) var(--space-2);
  }

  #search-input {
    padding: var(--space-2) 0;
    font-size: 13px;
  }

  /* Floating notes button (mobile only) */
  #mobile-notes-btn {
    display: block;
    position: fixed;
    bottom: calc(var(--space-4) + 40px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-surface-2);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border-strong);
    border-radius: 20px;
    padding: var(--space-2) var(--space-5);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    z-index: 100;
  }

  #mobile-notes-btn:hover {
    background: var(--color-surface-3);
  }

  /* Full-width notes panel on mobile */
  #notes-panel {
    width: 100vw;
    box-shadow: none;
  }

  #app-footer {
    padding: var(--space-2) var(--space-3);
    font-size: 10.5px;
    gap: var(--space-2);
  }
}

@media (max-width: 400px) {
  #header-title {
    font-size: var(--font-size-lg);
  }
}
/* Faixa do ARGOS: o OSINT é aberto e leva as visitas ao ARGOS. */
#plan-banner.banner-argos {
  background: rgba(37, 99, 235, 0.12);
  border-bottom-color: rgba(37, 99, 235, 0.45);
}

/* Frase de apresentação e link "Sobre" */
.intro-line {
  margin: 0;
  padding: var(--space-2) 0 var(--space-3);
  font-size: 13px;
  color: var(--color-text-secondary);
}
.intro-line a,
.footer-link {
  color: var(--color-text-secondary);
  text-decoration: underline;
  text-underline-offset: 3px;
}
