/* ============================================================
   CRM Mindmap — Dark Neural Theme
   ============================================================ */

:root {
  --bg-primary:    #060a14;
  --bg-secondary:  #0c1220;
  --bg-tertiary:   #121a2e;
  --bg-card:       #141c30;
  --border:        #1e2a44;
  --text-primary:  #e8ecf4;
  --text-secondary:#8994a8;
  --text-muted:    #5a6478;
  --accent-blue:   #4A9EFF;
  --accent-glow:   rgba(74, 158, 255, 0.3);
  --font:          'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* CRM status */
  --status-prospect:  #4A9EFF;
  --status-contacte:  #00D4FF;
  --status-qualifie:  #FFD700;
  --status-client:    #00FF88;
  --status-perdu:     #FF4466;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ── Layout ── */

#app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  width: 100vw;
}

/* ── Top bar ── */

#topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 2px;
  white-space: nowrap;
}
.logo span {
  color: var(--accent-blue);
  font-weight: 300;
}

.search-container {
  position: relative;
  flex: 1;
  max-width: 480px;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 8px 14px 8px 38px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#search:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 12px var(--accent-glow);
}
#search::placeholder { color: var(--text-muted); }

#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
#search-results.hidden { display: none; }
.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-tertiary); }
.search-result-item .sr-name {
  font-size: 13px;
  font-weight: 500;
}
.search-result-item .sr-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
  white-space: nowrap;
}
.zoom-display {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 4px 10px;
  border-radius: 6px;
}
.zoom-display span { color: var(--accent-blue); font-weight: 600; }
.stats {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Sidebar ── */

#sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 16px 14px;
  overflow-y: auto;
  z-index: 50;
}

.sidebar-section {
  margin-bottom: 20px;
}
.sidebar-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: color 0.15s;
}
.filter-item:hover { color: var(--text-primary); }

.filter-item input[type="checkbox"] {
  display: none;
}
.filter-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: opacity 0.2s, box-shadow 0.2s;
}
.filter-item input:not(:checked) ~ .filter-dot {
  opacity: 0.25;
}
.filter-item input:checked ~ .filter-dot {
  box-shadow: 0 0 6px currentColor;
}
.filter-item .filter-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
}

.legend .hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Canvas ── */

#canvas-container {
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
  /* Subtle grid pattern */
  background-image:
    radial-gradient(circle at 50% 50%, rgba(74,158,255,0.03) 0%, transparent 70%),
    linear-gradient(rgba(30,42,68,0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30,42,68,0.15) 1px, transparent 1px);
  background-size: 100% 100%, 60px 60px, 60px 60px;
}

#canvas {
  width: 100%;
  height: 100%;
  cursor: grab;
}
#canvas:active { cursor: grabbing; }

/* ── Breadcrumb ── */

#breadcrumb {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.crumb {
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s;
}
.crumb:hover { color: var(--text-secondary); }
.crumb.active {
  color: var(--accent-blue);
  font-weight: 600;
}
.crumb-sep {
  color: var(--text-muted);
  font-size: 14px;
}

/* ── D3 Node styles ── */

/* Sector neural nodes */
.node-sector {
  cursor: pointer;
}
.node-sector .sector-core {
  transition: filter 0.3s;
}
.node-sector:hover .sector-core {
  filter: url(#glow-strong);
}
.node-sector:hover .sector-penetration-arc {
  stroke-width: 4;
}
.node-sector text {
  fill: var(--text-primary);
  font-family: var(--font);
  pointer-events: none;
  text-anchor: middle;
}
.node-sector .sector-name-label {
  font-size: 12px;
  font-weight: 600;
  fill: var(--text-primary);
}
.node-sector .sector-penetration-label {
  font-weight: 700;
}
.node-sector .sector-penetration-sub {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.node-sector .sector-count {
  fill: var(--text-muted);
  font-size: 9px;
  font-weight: 400;
}

/* Neural links */
.link-neural {
  fill: none;
  stroke-linecap: round;
  opacity: 0;
}

/* Pack labels in sector-detail view */
.layer-pack-labels {
  pointer-events: none;
}

.node-company {
  cursor: pointer;
}
.node-company rect {
  rx: 8;
  ry: 8;
  transition: filter 0.3s, stroke-opacity 0.3s;
}
.node-company:hover rect {
  filter: url(#glow-strong);
  stroke-opacity: 1;
}
.node-company .company-name {
  fill: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}
.node-company .company-meta {
  fill: var(--text-secondary);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 400;
  pointer-events: none;
}
.node-company .company-effectif {
  fill: var(--text-muted);
  font-family: var(--font);
  font-size: 10px;
  pointer-events: none;
}
.node-company .company-ats {
  pointer-events: none;
}
.node-company .company-insight {
  fill: #00DDAA;
  font-family: var(--font);
  font-size: 9px;
  font-weight: 400;
  pointer-events: none;
}
.node-company .company-ai-summary {
  fill: var(--text-muted);
  font-family: var(--font);
  font-size: 8.5px;
  font-style: italic;
  pointer-events: none;
}
.node-company .company-next-action {
  fill: var(--accent-blue);
  font-family: var(--font);
  font-size: 8.5px;
  font-weight: 500;
  pointer-events: none;
}

.link-neural {
  fill: none;
  stroke-linecap: round;
  opacity: 0.3;
  transition: opacity 0.3s;
}
.link-neural.highlight {
  opacity: 0.7;
}

/* Faded state for filtered-out nodes */
.node-faded { opacity: 0.08; pointer-events: none; }
.link-faded { opacity: 0.03; }

/* Search highlight */
.node-highlight circle,
.node-highlight rect {
  filter: url(#glow-strong) !important;
}

/* ── Orgchart panel ── */

#orgchart-panel {
  position: fixed;
  top: 52px;
  right: 0;
  width: 60%;
  height: calc(100vh - 52px);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 150;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 40px rgba(0,0,0,0.5);
}
#orgchart-panel.visible {
  transform: translateX(0);
}
#orgchart-panel.hidden {
  transform: translateX(100%);
}

#close-panel {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  z-index: 10;
  transition: color 0.15s;
}
#close-panel:hover { color: var(--text-primary); }

#panel-company-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  overflow-y: auto;
  max-height: 60%;
}
.panel-company-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}
.panel-company-sector {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}
.panel-company-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  font-size: 13px;
}
.panel-company-meta dt {
  color: var(--text-muted);
  font-weight: 400;
}
.panel-company-meta dd {
  color: var(--text-secondary);
  font-weight: 500;
}
.panel-status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--bg-primary);
  margin-top: 10px;
}

/* ── Panel company extras ── */

.panel-company-name {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.panel-linkedin-btn {
  font-size: 11px;
  color: var(--accent-blue);
  text-decoration: none;
  border: 1px solid var(--accent-blue);
  border-radius: 10px;
  padding: 2px 10px;
  white-space: nowrap;
  transition: background 0.15s;
}
.panel-linkedin-btn:hover { background: var(--accent-glow); }

.panel-signal {
  font-size: 11px;
  color: #FFD700;
  margin: 6px 0 4px;
  font-weight: 500;
}
.panel-description {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 8px 0 6px;
  font-style: italic;
}

/* ── Panel AI Section ── */

.panel-ai-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.panel-ai-header {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.panel-ai-score {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2.5px solid;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}
.panel-ai-score-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}
.panel-ai-score-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.panel-ai-summary {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  font-style: italic;
}

.panel-ai-subtitle {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.panel-ai-benefices {
  margin-bottom: 12px;
}
.panel-ai-benefice-item {
  font-size: 12px;
  color: var(--text-primary);
  line-height: 1.6;
  padding-left: 4px;
}
.panel-ai-benefice-item .benefit-check {
  color: #00DDAA;
  margin-right: 4px;
}
.panel-ai-risk {
  margin-bottom: 12px;
}
.panel-ai-risk-text {
  font-size: 12px;
  color: #FF8C42;
  line-height: 1.5;
  padding-left: 4px;
}
.panel-ai-action {
  margin-bottom: 8px;
}
.panel-ai-action-text {
  font-size: 12px;
  color: var(--accent-blue);
  font-weight: 500;
  line-height: 1.5;
  padding-left: 4px;
}

#orgchart-container {
  flex: 1;
  overflow: auto;
  padding: 10px;
}
#orgchart-svg {
  width: 100%;
  min-height: 400px;
}

/* Orgchart nodes */
.org-node rect {
  rx: 6;
  ry: 6;
  cursor: default;
}
.org-node .org-name {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  fill: var(--text-primary);
}
.org-node .org-poste {
  font-family: var(--font);
  font-size: 10px;
  fill: var(--text-secondary);
}
.org-node .org-contact-info {
  font-family: var(--font);
  font-size: 9px;
  fill: var(--text-muted);
}
.org-node .org-linkedin {
  font-family: var(--font);
  font-size: 9px;
  fill: var(--accent-blue);
  cursor: pointer;
  text-decoration: underline;
}
.org-link {
  fill: none;
  stroke: var(--border);
  stroke-width: 1.5;
}

/* ── Tooltip ── */

.tooltip {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 300;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
  max-width: 340px;
  opacity: 0;
  transition: opacity 0.15s;
}
.tooltip.visible { opacity: 1; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.8;
}
.tooltip .tt-label { color: var(--text-muted); }
.tooltip .tt-divider {
  border-top: 1px solid var(--border);
  margin: 6px 0;
}
.tooltip .tt-insight {
  font-size: 10px;
  color: var(--text-secondary);
  font-style: italic;
  line-height: 1.4;
  margin: 4px 0;
}
.tooltip .tt-benefit {
  font-size: 10px;
  color: #00DDAA;
  line-height: 1.4;
  margin-top: 4px;
}
.tooltip .tt-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin: 4px 0 2px;
}
.tooltip .tt-client-list {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.tooltip .tt-client-name {
  color: #00FF88;
  font-weight: 500;
}

/* (old neural bg overrides removed) */

/* ── Scrollbar ── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ── */

@media (max-width: 768px) {
  #app {
    grid-template-columns: 1fr;
  }
  #sidebar { display: none; }
  #orgchart-panel { width: 100%; }
}
