:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: rgba(15, 23, 42, 0.55);
  --soft: rgba(15, 23, 42, 0.38);
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.12);
  --surface: rgba(255, 255, 255, 0.85);
  --surface-soft: rgba(0, 0, 0, 0.04);
  --green: #10b981;
  --gold: #f59e0b;
  --red: #e11d48;
  --blue: #3b82f6;
  --unit-deesa: #3b82f6;
  --unit-deesa-rgb: 59, 130, 246;
  --unit-era: #10b981;
  --unit-era-rgb: 16, 185, 129;
  --unit-corporativo: #e11d48;
  --unit-corporativo-rgb: 225, 29, 72;
  --unit-hogares: #f59e0b;
  --unit-hogares-rgb: 245, 158, 11;
  --unit-empty: #94a3b8;
  --unit-empty-rgb: 148, 163, 184;
}

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

[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 20% 20%, #dce8ff 0%, #f0f3ff 45%, #ece8ff 100%) fixed;
  font-family: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.18); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.28); }

@keyframes drawEdge {
  to { stroke-dashoffset: 0; }
}
@keyframes slideInPanel {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

.app-shell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ───────────── Topbar ───────────── */
.topbar {
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(40px) saturate(200%);
  -webkit-backdrop-filter: blur(40px) saturate(200%);
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: linear-gradient(135deg, #e11d48 0%, #3b82f6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
  letter-spacing: -0.02em;
  box-shadow: 0 2px 12px rgba(59, 130, 246, 0.3);
}

.brand-text {
  line-height: 1;
}

.brand-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.brand-sub {
  font-size: 9.5px;
  color: rgba(15, 23, 42, 0.42);
  margin-top: 2px;
  letter-spacing: 0.03em;
}

.topbar-divider {
  width: 1px;
  height: 26px;
  background: rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  margin: 0 2px;
}

.search-wrap {
  position: relative;
  flex: 0 0 220px;
}

.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(15, 23, 42, 0.32);
  font-size: 13px;
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  height: 30px;
  padding: 0 10px 0 26px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.1);
  font-size: 11.5px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.search-wrap input:focus {
  border-color: rgba(59, 130, 246, 0.45);
  background: rgba(255, 255, 255, 0.85);
}

.unit-chips {
  display: flex;
  gap: 4px;
  align-items: center;
}

.unit-chip {
  height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: rgba(15, 23, 42, 0.5);
  transition: all 0.15s;
}

.unit-chip.active {
  background: rgba(var(--chip-rgb), 0.13);
  border-color: rgba(var(--chip-rgb), 0.45);
  color: var(--chip-color);
}

.profile-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}

.profile-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  width: 28px;
  height: 15px;
  border-radius: 8px;
  position: relative;
  background: rgba(0, 0, 0, 0.12);
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: left 0.2s;
}

.profile-toggle input:checked ~ .toggle-track {
  background: var(--green);
}

.profile-toggle input:checked ~ .toggle-track .toggle-knob {
  left: 15px;
}

.toggle-label {
  font-size: 10px;
  color: rgba(15, 23, 42, 0.55);
  white-space: nowrap;
}

.topbar-spacer {
  flex: 1;
}

.clear-btn {
  font-size: 10px;
  padding: 4px 9px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.09);
  color: rgba(15, 23, 42, 0.55);
  transition: all 0.15s;
}

.clear-btn:hover {
  background: rgba(0, 0, 0, 0.08);
}

.stats-mini {
  font-size: 9.5px;
  color: rgba(15, 23, 42, 0.45);
  text-align: right;
  line-height: 1.5;
  flex-shrink: 0;
}

.stats-mini > div:last-child {
  color: rgba(16, 185, 129, 0.8);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.09);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: rgba(15, 23, 42, 0.55);
  transition: background 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.08);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* ───────────── Workspace / Chart ───────────── */
.workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
}

.chart-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
}

.chart-area.dragging {
  cursor: grabbing;
}

.particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.viewport {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.edge-layer {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.node-layer {
  position: relative;
  z-index: 2;
}

/* ───────────── Node Card ───────────── */
.node-card {
  position: absolute;
  width: 190px;
  height: 78px;
  padding: 9px 11px 8px 13px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-left: 3px solid var(--unit-color, var(--unit-empty));
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0.65) 100%);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  box-shadow:
    0 2px 12px rgba(0, 0, 0, 0.07),
    0 1px 3px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  user-select: none;
  transition: opacity 0.25s, box-shadow 0.2s, background 0.15s, border-color 0.15s, transform 0.15s;
  cursor: pointer;
  z-index: 1;
}

.node-card:hover {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.82) 100%);
  box-shadow:
    0 8px 28px rgba(0, 0, 0, 0.1),
    0 2px 6px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
  transform: scale(1.03);
  z-index: 2;
}

.node-card.selected {
  background: linear-gradient(135deg, rgba(var(--unit-rgb, 130, 130, 130), 0.15) 0%, rgba(255, 255, 255, 0.72) 100%);
  border: 1px solid rgba(var(--unit-rgb, 130, 130, 130), 0.5);
  border-left: 3px solid var(--unit-color, var(--unit-empty));
  box-shadow:
    0 0 28px rgba(var(--unit-rgb, 130, 130, 130), 0.2),
    0 6px 24px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
  transform: scale(1);
  z-index: 3;
}

.node-card.dimmed {
  opacity: 0.3;
}

.node-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
}

.node-name {
  font-size: 12px;
  font-weight: 600;
  color: #111827;
  line-height: 1.35;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1;
}

.node-profile-dot {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-top: 4px;
  background: var(--green);
  box-shadow: 0 0 5px rgba(16, 185, 129, 0.55);
}

.node-puesto {
  font-size: 10.5px;
  color: rgba(15, 23, 42, 0.55);
  line-height: 1.35;
  margin-top: 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.node-footer {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 9px;
}

.node-unit-badge {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(var(--unit-rgb, 130, 130, 130), 0.13);
  color: var(--unit-color, var(--unit-empty));
  border: 1px solid rgba(var(--unit-rgb, 130, 130, 130), 0.25);
  flex-shrink: 0;
}

.node-depto {
  font-size: 9px;
  color: rgba(15, 23, 42, 0.38);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-collapse {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 9px;
  color: rgba(15, 23, 42, 0.55);
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  user-select: none;
  transition: background 0.15s;
}

.node-collapse:hover {
  background: rgba(0, 0, 0, 0.1);
}

.node-collapse .chevron {
  display: inline-block;
  transform: rotate(90deg);
  transition: transform 0.2s ease;
  line-height: 1;
}

.node-collapse.collapsed .chevron {
  transform: rotate(0deg);
}

/* ───────────── Zoom + Legend ───────────── */
.zoombar {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 15;
}

.zoombar button,
.zoombar .zoom-label {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  color: rgba(15, 23, 42, 0.65);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.zoombar button:hover {
  background: rgba(255, 255, 255, 1);
  color: var(--ink);
}

.zoombar .zoom-label {
  font-size: 9px;
  font-weight: 600;
  color: rgba(15, 23, 42, 0.45);
  cursor: default;
}

.legend {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 15;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  padding: 10px 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
}

.legend-item:last-child {
  margin-bottom: 0;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-label {
  font-size: 10px;
  color: rgba(15, 23, 42, 0.6);
  white-space: nowrap;
}

.legend-divider {
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  margin: 6px 0;
}

.empty-state {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  color: rgba(15, 23, 42, 0.6);
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.1);
}

.update-status {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  color: rgba(15, 23, 42, 0.7);
  max-width: 320px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.update-status:not(:empty) {
  opacity: 1;
}

.update-status.error {
  color: var(--red);
  border-color: rgba(225, 29, 72, 0.3);
}

.update-status.success {
  color: var(--green);
  border-color: rgba(16, 185, 129, 0.3);
}

/* ───────────── Detail Panel ───────────── */
.detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 440px;
  height: 100%;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(48px) saturate(220%);
  -webkit-backdrop-filter: blur(48px) saturate(220%);
  border-left: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 50;
  animation: slideInPanel 0.28s ease-out both;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.08);
}

.detail-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  background: var(--detail-header-bg, transparent);
  flex-shrink: 0;
}

.detail-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.detail-badges {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  flex: 1;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(var(--pill-rgb, 130, 130, 130), 0.15);
  color: var(--pill-color, var(--ink));
  border: 1px solid rgba(var(--pill-rgb, 130, 130, 130), 0.3);
}

.pill.good {
  font-weight: 500;
  background: transparent;
  border: 0;
  color: var(--green);
  padding: 2px 0;
}

.pill.good::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 5px rgba(16, 185, 129, 0.5);
}

.pill.warn {
  font-weight: 500;
  background: transparent;
  border: 0;
  color: rgba(161, 96, 0, 0.85);
  padding: 2px 0;
}

.pill.warn::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.7);
}

.icon-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: rgba(15, 23, 42, 0.55);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.icon-close:hover {
  background: rgba(0, 0, 0, 0.1);
}

.detail-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.25;
  margin-top: 2px;
}

.detail-puesto {
  font-size: 12px;
  color: rgba(15, 23, 42, 0.55);
  margin-top: 3px;
}

.detail-depto {
  font-size: 11px;
  color: rgba(15, 23, 42, 0.4);
  margin-top: 2px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 12px;
}

.meta-chip {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: rgba(15, 23, 42, 0.6);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.meta-chip-icon {
  opacity: 0.55;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.detail-actions button {
  flex: 1;
  min-width: 80px;
  height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: rgba(15, 23, 42, 0.75);
  font-size: 11px;
  font-weight: 600;
  transition: background 0.15s;
  white-space: nowrap;
}

.detail-actions button:hover {
  background: rgba(0, 0, 0, 0.08);
}

.btn-edit {
  background: rgba(225, 29, 72, 0.1) !important;
  border-color: rgba(225, 29, 72, 0.3) !important;
  color: var(--red) !important;
}

.btn-edit:hover {
  background: rgba(225, 29, 72, 0.18) !important;
}

/* ───────────── Tabs ───────────── */
.detail-tabs {
  display: flex;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
  flex-shrink: 0;
  padding: 0 20px;
}

.tab {
  flex: 1;
  padding: 10px 4px;
  font-size: 10.5px;
  font-weight: 400;
  background: none;
  border: none;
  color: rgba(15, 23, 42, 0.4);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  letter-spacing: 0.02em;
  transition: color 0.15s, border-color 0.15s;
}

.tab.active {
  font-weight: 600;
  color: var(--tab-color, var(--ink));
  border-bottom-color: var(--tab-color, var(--ink));
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 24px;
}

.tab-panel {
  display: none;
  animation: fadeUp 0.2s ease both;
}

.tab-panel.active {
  display: block;
}

/* Detail content */
.detail-section {
  margin-bottom: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
  gap: 8px;
}

.section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent, rgba(15, 23, 42, 0.7));
}

.section-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 24px;
  min-width: 24px;
  padding: 0 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.12);
  color: rgba(15, 23, 42, 0.75);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}

.icon-action:hover {
  background: rgba(var(--accent-rgb, 59, 130, 246), 0.12);
  border-color: rgba(var(--accent-rgb, 59, 130, 246), 0.4);
  color: var(--accent, var(--ink));
  transform: translateY(-1px);
}

.icon-action.btn-tiny {
  height: 22px;
  min-width: 22px;
  padding: 0 4px;
  font-size: 11px;
}

.icon-glyph {
  line-height: 1;
}

.missing-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.15);
  color: rgba(180, 100, 0, 0.95);
  border: 1px solid rgba(245, 158, 11, 0.4);
  vertical-align: middle;
}

.detail-paragraph {
  font-size: 11.5px;
  color: rgba(15, 23, 42, 0.7);
  line-height: 1.6;
}

.detail-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-list .list-item {
  font-size: 11.5px;
  color: rgba(15, 23, 42, 0.78);
  line-height: 1.45;
  padding: 5px 4px 5px 16px;
  position: relative;
  border-radius: 6px;
  transition: background 0.15s;
}

.detail-list .list-item:hover {
  background: rgba(0, 0, 0, 0.03);
}

.detail-list .list-item::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 12px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent, rgba(15, 23, 42, 0.55));
}

.li-view {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.li-text {
  flex: 1;
  word-break: break-word;
}

.li-actions {
  display: flex;
  gap: 3px;
  opacity: 0.55;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.detail-list .list-item:hover .li-actions {
  opacity: 1;
}

.li-edit,
.section-edit,
.add-inline {
  margin-top: 6px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.06);
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.add-inline {
  margin-top: 10px;
  background: rgba(16, 185, 129, 0.07);
  border-color: rgba(16, 185, 129, 0.3);
}

.inline-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  background: white;
  font-size: 11.5px;
  font-family: inherit;
  line-height: 1.4;
  resize: vertical;
  outline: none;
}

.inline-textarea:focus {
  border-color: var(--accent, rgba(59, 130, 246, 0.6));
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb, 59, 130, 246), 0.12);
}

.inline-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.inline-actions button {
  flex: 0 0 auto;
  height: 28px;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.8);
  color: rgba(15, 23, 42, 0.75);
  transition: background 0.15s;
}

.inline-actions .btn-save {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.inline-actions .btn-save:hover {
  background: #0ea271;
}

.inline-actions .btn-cancel:hover {
  background: rgba(0, 0, 0, 0.06);
}

.inline-actions .btn-danger {
  margin-left: auto;
  color: var(--red);
  border-color: rgba(225, 29, 72, 0.3);
  background: rgba(225, 29, 72, 0.06);
}

.inline-actions .btn-danger:hover {
  background: rgba(225, 29, 72, 0.12);
}

.detail-empty {
  font-size: 11px;
  color: rgba(15, 23, 42, 0.45);
  font-style: italic;
  padding: 4px 0;
}

.warn-banner {
  padding: 11px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.warn-banner-title {
  font-size: 11px;
  color: rgba(180, 100, 0, 0.9);
  font-weight: 500;
}

.warn-banner-sub {
  font-size: 10px;
  color: rgba(15, 23, 42, 0.5);
  margin-top: 4px;
}

.empty-tab {
  font-size: 11.5px;
  color: rgba(15, 23, 42, 0.4);
  text-align: center;
  padding-top: 24px;
}

/* Hierarchy */
.hierarchy-block {
  margin-bottom: 16px;
}

.hier-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent, rgba(15, 23, 42, 0.6));
  margin-bottom: 8px;
}

.hier-label .count {
  font-weight: 400;
  opacity: 0.6;
  margin-left: 4px;
}

.hier-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.025);
  border: 1px solid rgba(0, 0, 0, 0.06);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.hier-card:hover {
  background: rgba(0, 0, 0, 0.05);
}

.hier-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  background: rgba(var(--avatar-rgb, 130, 130, 130), 0.15);
  border: 1px solid rgba(var(--avatar-rgb, 130, 130, 130), 0.2);
  color: var(--avatar-color, var(--ink));
}

.hier-card .info {
  flex: 1;
  min-width: 0;
}

.hier-name {
  font-size: 12px;
  font-weight: 500;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hier-role {
  font-size: 10.5px;
  color: rgba(15, 23, 42, 0.45);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hier-arrow {
  font-size: 11px;
  color: rgba(15, 23, 42, 0.25);
  flex-shrink: 0;
}

/* Audit log */
.audit-entry {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.025);
  border: 1px solid rgba(0, 0, 0, 0.06);
  margin-bottom: 6px;
  font-size: 11px;
  color: rgba(15, 23, 42, 0.65);
}

.audit-date {
  font-size: 9.5px;
  color: rgba(15, 23, 42, 0.4);
  margin-bottom: 2px;
  letter-spacing: 0.02em;
}

/* ───────────── Edit Form ───────────── */
.edit-form {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.04);
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.edit-field {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.edit-field.wide {
  grid-column: 1 / -1;
}

.edit-field label {
  display: grid;
  gap: 5px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(15, 23, 42, 0.55);
}

.edit-grid input,
.edit-grid textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 11.5px;
  text-transform: none;
  letter-spacing: 0;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.edit-grid input:focus,
.edit-grid textarea:focus {
  border-color: rgba(59, 130, 246, 0.5);
  background: white;
}

.edit-grid input[readonly],
.edit-grid textarea[readonly] {
  background: rgba(0, 0, 0, 0.03);
  color: rgba(15, 23, 42, 0.55);
}

.field-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.field-actions button {
  height: 26px;
  padding: 0 6px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.04);
  color: rgba(15, 23, 42, 0.7);
  font-size: 10px;
  font-weight: 600;
  transition: background 0.15s;
}

.field-actions button:hover {
  background: rgba(0, 0, 0, 0.08);
}

.field-actions [data-action="apply"] {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.field-actions [data-action="apply"]:hover {
  background: #0ea271;
}

.form-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
}

.form-actions button {
  height: 34px;
  padding: 0 14px;
  border-radius: 7px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(0, 0, 0, 0.04);
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 600;
  transition: background 0.15s;
}

#saveEdit {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

#saveEdit:hover {
  background: #0ea271;
}

#cancelEdit:hover {
  background: rgba(0, 0, 0, 0.08);
}

/* ───────────── Print ───────────── */
@media print {
  .topbar, .legend, .zoombar, .detail-tabs, .detail-actions, .edit-form, .particles, .icon-close { display: none !important; }
  .workspace { display: block; }
  .detail-panel { position: static; width: 100%; background: white; backdrop-filter: none; border: 0; box-shadow: none; }
}

@media (max-width: 1080px) {
  .detail-panel { width: 380px; }
  .search-wrap { flex: 0 0 160px; }
}

@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 6px; }
  .search-wrap { flex: 1 1 100%; order: 99; }
  .stats-mini { display: none; }
  .detail-panel { width: 100%; }
}
