/* =========================
   CSS VARIABLES
   ========================= */
:root {
  /* Colors */
  --color-bg: #0b0f13;
  --color-text: #e6eef8;
  --color-text-muted: rgba(230, 238, 248, 0.7);
  --color-text-faint: rgba(230, 238, 248, 0.4);
  --color-accent: #60a5fa;
  --color-accent-light: #93c5fd;
  --color-danger: #ef4444;
  --color-danger-light: #fca5a5;
  --color-success: #10b981;

  /* Glassmorphism */
  --glass-bg: rgba(17, 24, 39, 0.75);
  --glass-bg-light: rgba(17, 24, 39, 0.65);
  --glass-bg-lighter: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-border-light: rgba(255, 255, 255, 0.08);
  --glass-blur: blur(40px) saturate(180%);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4),
                   0 4px 16px rgba(0, 0, 0, 0.3),
                   inset 0 1px 0 rgba(255, 255, 255, 0.08);

  /* Transitions */
  --transition-fast: 0.13s ease;
  --transition-medium: 0.2s ease;
  --transition-smooth: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  /* Spacing */
  --spacing-xs: 0.5rem;
  --spacing-sm: 0.75rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;

  /* Borders */
  --border-radius-sm: 6px;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;
  --border-radius-xl: 16px;
  --border-radius-pill: 22px;
}

/* =========================
   BASE STYLES
   ========================= */
html, body {
  height: 100%;
  margin: 0;
  font-family: Inter, Roboto, system-ui, sans-serif;
  overflow: hidden;
  background-color: var(--color-bg);
  color: var(--color-text);
}

/* =========================
   FORM CONTROLS - Unified
   ========================= */
.form-control,
.form-select {
  background: var(--glass-bg-lighter);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  color: var(--color-text);
  border-radius: var(--border-radius-md);
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: border-color var(--transition-smooth),
              box-shadow var(--transition-smooth),
              background var(--transition-smooth);
}

.form-control:focus,
.form-select:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(59, 130, 246, 0.4);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12),
              0 0 0 3px rgba(59, 130, 246, 0.12),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
  outline: none;
  color: #ffffff;
}

.form-control::placeholder {
  color: var(--color-text-faint);
}

/* Select dropdown - light background for readability */
.form-select option {
  background: #f8fafc;
  color: #1e293b;
  padding: 0.625rem;
  font-weight: 500;
}

.form-select option:hover,
.form-select option:checked {
  background: #e2e8f0;
  color: #0f172a;
}

/* Textarea specific */
textarea.form-control {
  resize: none;
  transition: none !important;
}

/* Form labels */
.form-label {
  color: rgba(230, 238, 248, 0.9);
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: var(--spacing-xs);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.9;
}

/* =========================
   TOP BAR
   ========================= */
.top-bar {
  background: var(--glass-bg-light);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border-light);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12),
              inset 0 1px 0 rgba(255, 255, 255, 0.06);
  padding: var(--spacing-sm) var(--spacing-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  z-index: 60;
  position: relative;
  flex-shrink: 0;
  height: 64px;
  padding-right: 12px;
}

.top-bar-left {
  flex-shrink: 0;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--color-accent);
  font-weight: 700;
  font-size: 1.5rem;
  user-select: none;
  text-decoration: none;
}

.app-logo svg {
  color: var(--color-accent);
}

.app-name {
  background: linear-gradient(135deg, var(--color-accent) 0%, #F0604D 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.02em;
}

.top-bar-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  margin-left: auto;
}

/* Icon buttons — matched to the view-switcher container height
   (3px wrapper padding + 5px inner = 8px vertical, same border-radius) */
.btn-icon {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--glass-bg-lighter);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius-md);
  color: var(--color-text);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-medium);
  white-space: nowrap;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-icon:active {
  transform: translateY(0) scale(0.98);
}

.btn-icon img,
.btn-icon svg {
  flex-shrink: 0;
  opacity: 0.9;
  width: 16px;
  height: 16px;
}

.btn-icon:hover img,
.btn-icon:hover svg {
  opacity: 1;
}

.btn-icon.btn-danger {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--color-danger-light);
}

.btn-icon.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fee2e2;
}

/* =========================
   OFFCANVAS
   ========================= */
.offcanvas {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: white;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35),
              0 4px 16px rgba(0, 0, 0, 0.25),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  margin: 12px;
  height: calc(100% - 25px);
  max-width: 400px;
  display: flex;
  flex-direction: column;
  transition: transform 0.22s ease-out !important;
}

.offcanvas.offcanvas-end {
  right: 0;
  border-top-right-radius: 20px;
  border-bottom-right-radius: 20px;
}

.offcanvas.offcanvas-start {
  left: 0;
  border-top-left-radius: 20px;
  border-bottom-left-radius: 20px;
}

/* =========================
   SEARCH RESULTS OFFCANVAS
   ========================= */
.search-results-header-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.search-results-email {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

/* Loader / Spinner */
.search-results-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 48px 0;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
}

.search-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: #10b981;
  border-radius: 50%;
  animation: search-spin 0.7s linear infinite;
}

@keyframes search-spin {
  to { transform: rotate(360deg); }
}

/* Error */
.search-results-error {
  padding: 20px;
  color: #f87171;
  font-size: 0.875rem;
  text-align: center;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--border-radius-md);
}

/* Results list */
.search-results-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  border: 1px solid transparent;
}

.search-result-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.search-result-item.not-found {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.search-result-check {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: #10b981;
  cursor: pointer;
}

.search-result-dash {
  width: 16px;
  flex-shrink: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.3);
  font-size: 0.8rem;
}

.search-result-icon {
  flex-shrink: 0;
  opacity: 0.8;
}

.search-result-text {
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

.search-result-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #e6eef8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-desc {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.search-result-url {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  opacity: 0.5;
  transition: opacity var(--transition-fast), background var(--transition-fast);
  cursor: pointer;
  text-decoration: none;
}

.search-result-url:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

.search-result-url img {
  pointer-events: none;
}

/* Provider groups (accordion) */
.search-group {
  border: 1px solid var(--glass-border-light);
  border-radius: var(--border-radius-md);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.search-group + .search-group {
  margin-top: 8px;
}

.search-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: none;
  color: #e6eef8;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition-fast);
}

.search-group-header:hover {
  background: rgba(255, 255, 255, 0.07);
}

.search-group-chevron {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.5);
  transform: rotate(90deg);
  transition: transform var(--transition-fast);
}

.search-group.collapsed .search-group-chevron {
  transform: rotate(0deg);
}

.search-group-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-group-badge {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--border-radius-pill, 22px);
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.search-group-badge.empty {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.4);
}

.search-group-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
}

.search-group.collapsed .search-group-body {
  display: none;
}

.offcanvas .offcanvas-header {
  background: transparent;
  color: inherit;
  border-bottom: 1px solid var(--glass-border-light);
  padding: 0.75rem var(--spacing-lg);
  flex-shrink: 0;
}

.offcanvas .offcanvas-title {
  font-weight: 600;
  font-size: 1.125rem;
  color: #ffffff;
}

.offcanvas .offcanvas-body {
  background: transparent;
  color: inherit;
  padding: var(--spacing-lg);
  padding-top: 10px;
  padding-bottom: 0px;
  flex: 1;
  overflow-y: auto;
  transition: opacity 0.15s ease;
  /* Thin discreet scrollbar (Firefox + modern Chromium) */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

/* Thin discreet scrollbar (WebKit/Blink: Chrome, Edge, Safari, Opera) */
.offcanvas .offcanvas-body::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.offcanvas .offcanvas-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}
.offcanvas .offcanvas-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}
.offcanvas .offcanvas-body::-webkit-scrollbar-track {
  background: transparent;
}

.offcanvas .offcanvas-body.loading {
  opacity: 0;
}

/* NEW: Offcanvas Footer (fixed at bottom like header) */
.offcanvas-footer {
  background: transparent;
  border-top: 1px solid var(--glass-border-light);
  padding: 0.9rem var(--spacing-lg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* CRITICAL FIX: Reduce spacing between form elements in offcanvas only */
.offcanvas .mb-3 {
  margin-bottom: 0.8rem !important;
}

.offcanvas .btn-close {
  filter: invert(1) brightness(2);
  opacity: 0.8;
  transition: opacity var(--transition-medium);
}

.offcanvas .btn-close:hover {
  opacity: 1;
}

/* Offcanvas buttons */
.offcanvas .btn {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--color-text);
  border-radius: var(--border-radius-md);
  padding: 0.625rem 1.25rem;
  font-weight: 600;
  font-size: 0.875rem;
  transition: border-color var(--transition-smooth),
            box-shadow var(--transition-smooth),
            background var(--transition-smooth),
            transform var(--transition-smooth),
            color var(--transition-smooth);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.offcanvas .btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15),
              inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
  color: #ffffff;
}

.offcanvas .btn:active {
  transform: translateY(0) scale(0.98);
}

.offcanvas .btn-success {
  background: linear-gradient(135deg,
    rgba(16, 185, 129, 0.8) 0%,
    rgba(5, 150, 105, 0.8) 100%
  );
  border-color: rgba(16, 185, 129, 0.5);
  color: #ffffff;
  box-shadow: 0 2px 12px rgba(16, 185, 129, 0.3),
              0 1px 4px rgba(16, 185, 129, 0.2),
              inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.offcanvas .btn-success:hover {
  background: linear-gradient(135deg,
    rgba(16, 185, 129, 0.9) 0%,
    rgba(5, 150, 105, 0.9) 100%
  );
  border-color: rgba(16, 185, 129, 0.6);
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4),
              0 2px 8px rgba(16, 185, 129, 0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
  color: #ffffff;
}

.offcanvas .btn-success:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 1px 8px rgba(16, 185, 129, 0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* NEW: Save button in footer - takes almost full width */
.btn-save-footer {
  width: calc(100% - 10px);
  max-width: 100%;
  padding: 0.75rem 1.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
}

.offcanvas .btn-link {
  background: transparent;
  border: none;
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-medium);
  padding: 0;
  box-shadow: none;
  font-weight: 500;
}

.offcanvas .btn-link:hover {
  color: var(--color-accent-light);
  background: transparent;
  transform: none;
  box-shadow: none;
}

/* Drop zone */
#dropZone {
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--border-radius-md);
  background: rgba(255, 255, 255, 0.02);
   transition: border-color 0.3s ease,
               background 0.3s ease;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 1.5rem;
  height: 125px;
}

#dropZone:hover {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.04);
}

/* =========================
   MAIN CANVAS
   ========================= */
#cy {
  height: calc(100vh - 64px);
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  flex: 1;
  overflow: hidden;
}

/* =========================
   REACT FLOW NODES
   ========================= */
.react-flow .react-flow__node {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--border-radius-pill);
  background: linear-gradient(180deg, rgba(10,12,16,0.96), rgba(12,14,18,0.96));
  border: 1px solid rgba(255,255,255,0.06);
  color: #ffffff;
  min-width: 100px;
  max-width: none;
  width: auto;
  box-shadow: 0 6px 16px rgba(3,6,12,0.6);
  transition: border-color 0.15s ease;
  font-weight: 600;
  font-size: 14px;
  user-select: none;
  position: absolute;
  overflow: visible;
  justify-content: space-between;
  z-index: 1;
  cursor: grab;
  white-space: nowrap;
}

/* Node hover: subtly brighten the border, matching the Investigation
   Preview viewer (.node:hover). The transition is declared on the node above. */
.react-flow .react-flow__node:hover {
  border-color: rgba(255,255,255,0.18);
}

/* Grabbing cursor while dragging a node */
.react-flow .react-flow__node:active,
.react-flow .react-flow__node.dragging {
  cursor: grabbing;
}

/* Node preview image */
.node-preview-image {
  position: absolute;
  left: 50%;
  top: -75px;
  transform: translateX(-50%) scale(0.95);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  box-shadow: 0 8px 22px rgba(2,6,12,0.75);
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease, top 180ms ease;
  z-index: 12;
  pointer-events: auto;
  cursor: pointer;
}

.node-preview-image.visible {
  opacity: 1;
  transform: translateX(-50%) scale(1);
  top: -75px;
}

.node-preview-image:hover {
  transform: translateX(-50%) scale(1.02);
  box-shadow: 0 8px 28px rgba(2,6,12,0.85);
}

/* Confidence badge */
.node-confidence-badge {
  position: absolute !important;
  left: -2px !important;
  top: -2px !important;
  width: 14px !important;
  height: 14px !important;
  z-index: 10 !important;
  pointer-events: none !important;
  opacity: 1;
}

.node-confidence-badge img {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

/* Search result badge (top-right) */
.node-search-badge {
  position: absolute !important;
  right: -2px !important;
  top: -2px !important;
  width: 14px !important;
  height: 14px !important;
  z-index: 10 !important;
  pointer-events: none !important;
  opacity: 1;
}

.node-search-badge img {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.react-flow .react-flow__node .thumbnail,
.react-flow .react-flow__node > img {
  display: none;
}

.thumbnail {
  height: 125px;
  width: 150px;
  object-fit: cover;
  border-radius: var(--border-radius-md);
  display: block;
}

/* React Flow touch-action */
.react-flow__node,
.react-flow__viewport,
.react-flow__pane {
  touch-action: auto;
  -ms-touch-action: auto;
  -webkit-user-select: none;
}

/* Grab cursor on the graph background for panning */
.react-flow__pane {
  cursor: grab;
}

.react-flow__pane:active {
  cursor: grabbing;
}

/* Node icon */
.react-flow .react-flow__node::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  background-image: var(--rf-node-icon, none);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 20;
}

.react-flow .react-flow__node[style*="--rf-node-has-icon: 1"]::after,
.react-flow .react-flow__node[style*="--rf-node-has-icon:1"]::after {
  opacity: 1;
}

.react-flow .react-flow__node[style*="--rf-node-has-icon: 1"],
.react-flow .react-flow__node[style*="--rf-node-has-icon:1"] {
  padding-left: 44px;
}

/* Social "tile" logos use a 24x24 viewBox with inner padding, so at the shared
   18px icon size their glyph reads smaller than the 16x16 type icons. Enlarge
   the icon box for social logos only, so they match the base type icons.
   Tune the two values below to taste (18px = default type-icon size). */
.react-flow .react-flow__node[style*="/static/icons/social/"]::after {
  width: 24px;
  height: 24px;
}

/* =========================
   CONTEXT MENU
   ========================= */
#rf-context-menu {
  position: fixed;
  display: none;
  min-width: 150px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--color-text);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  z-index: 9999;
  padding: 8px;
  font-size: 14px;
  user-select: none;
  opacity: 0;
  transform: scale(0.95) translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

#rf-context-menu.visible {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

#rf-context-menu .cm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  color: inherit;
  font-weight: 500;
}

#rf-context-menu .cm-item:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateX(2px);
}

#rf-context-menu .cm-item:active {
  transform: translateX(0px);
}

#rf-context-menu .cm-item .cm-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
  transition: opacity 0.15s ease;
}

#rf-context-menu .cm-item:hover .cm-icon {
  opacity: 1;
}

#rf-context-menu .cm-item.delete {
  color: #f91629;
}

#rf-context-menu .cm-item.delete:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #fee2e2;
}

/* =========================
   NODE PALETTE
   ========================= */
.node-palette {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  gap: 16px;
  padding: 16px 24px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-xl);
  box-shadow: var(--glass-shadow);
  user-select: none;
}

.palette-item {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-bg-lighter);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius-lg);
  cursor: grab;
  transition: all 0.16s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.palette-item:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3),
              0 2px 8px rgba(0, 0, 0, 0.2),
              inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.palette-item:active {
  cursor: grabbing;
}

.palette-item img {
  width: 28px;
  height: 28px;
  pointer-events: none;
  opacity: 0.9;
  transition: opacity var(--transition-medium);
}

.palette-item:hover img {
  opacity: 1;
}

/* =========================
   THUMBNAILS
   ========================= */
.thumb-wrap {
  position: relative;
  display: inline-block;
}

.thumb-wrap .thumb-del {
  position: absolute;
  right: 6px;
  top: 6px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border-radius: var(--border-radius-sm);
  padding: 3px 7px;
  font-size: 11px;
  cursor: pointer;
  user-select: none;
  transition: all var(--transition-medium);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.thumb-wrap .thumb-del:hover {
  background: rgba(0,0,0,0.85);
}

.thumb-wrap.marked {
  opacity: 0.45;
  filter: grayscale(0.35);
}

.thumb-badge-pending,
.thumb-badge-delete {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 3px 8px;
  border-radius: var(--border-radius-sm);
  font-size: 10px;
  font-weight: 600;
  color: #000;
  user-select: none;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.thumb-badge-pending {
  background: rgba(250, 204, 21, 0.95);
  color: #000;
}

.thumb-badge-delete {
  background: rgba(220, 53, 69, 0.95);
  color: #fff;
}

/* =========================
   UTILITIES
   ========================= */
.hidden {
  display: none;
}

#toastContainer {
  position: fixed;
  top: 80px;
  width: 200px;
  right: 20px;
  z-index: 11000;
}

.position-fixed.custom-toast {
  top: 80px;
  right: 20px;
  z-index: 11000;
  /* Allow clicks to pass through to elements underneath (map controls) */
  pointer-events: none;
}

.position-fixed.custom-toast .toast {
  pointer-events: auto;
}

.toast {
  margin-top: 8px;
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* =========================
   REACT FLOW HANDLES
   ========================= */
.react-flow .react-flow__handle {
  opacity: 0;
  pointer-events: none;
}

/* =========================
   EDGE INTERACTION
   ========================= */
.floating-edge-group {
  cursor: pointer !important;
}

.edge-interaction-path {
  cursor: pointer !important;
}

.edge-label-text {
  fill: var(--color-text);
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
  user-select: none;
  stroke: var(--color-bg);
  stroke-width: 4px;
  stroke-linejoin: round;
  stroke-linecap: round;
  paint-order: stroke fill;
}

/* =========================
   REACT FLOW MINIMAP
   ========================= */
.react-flow__minimap {
  background-color: rgba(15, 23, 42, 0.95) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  border-radius: var(--border-radius-md) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
  overflow: hidden !important;
  bottom: 12px !important;
  right: 12px !important;
}

.react-flow__minimap-mask {
  fill: rgba(59, 130, 246, 0.15) !important;
  stroke: rgba(59, 130, 246, 0.5) !important;
  stroke-width: 2 !important;
}

.react-flow__minimap-node {
  stroke: rgba(255, 255, 255, 0.2) !important;
  stroke-width: 1.5 !important;
}

/* =========================
   IMAGE ZOOM MODAL
   ========================= */
#imageZoomModal .modal-dialog {
  max-width: 90vw;
}

#imageZoomModal .modal-content {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

#imageZoomModal .modal-backdrop {
  background-color: rgba(0, 0, 0, 0.92);
}

/* =========================
   MOBILE WARNING OVERLAY
   ========================= */
#app-mobile-warning {
  display: flex;
  width: 100%;
  height: 100vh;
  background: var(--color-bg);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.mobile-warning-content {
  max-width: 480px;
  width: 100%;
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  padding: 48px 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
              0 8px 24px rgba(0, 0, 0, 0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
  text-align: center;
  color: var(--color-text);
}

.mobile-warning-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 100px;
  margin: 0 auto 24px;
  color: var(--color-danger);
}

.mobile-warning-icon img,
.mobile-warning-icon svg {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.mobile-warning-title {
  font-size: 28px;
  font-weight: 700;
  color: #ffffff;
  margin: 0 0 16px 0;
  letter-spacing: -0.02em;
}

.mobile-warning-message {
  font-size: 16px;
  line-height: 1.6;
  color: rgba(230, 238, 248, 0.85);
  margin: 0 0 32px 0;
  font-weight: 500;
}

.mobile-warning-features {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 32px;
  text-align: left;
}

.mobile-warning-feature {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border-light);
  border-radius: var(--border-radius-lg);
  color: rgba(230, 238, 248, 0.9);
  font-size: 14px;
  font-weight: 500;
}

.mobile-warning-feature svg {
  flex-shrink: 0;
  color: #3b82f6;
}

.mobile-warning-footer {
  padding-top: 24px;
  border-top: 1px solid var(--glass-border-light);
}

.mobile-warning-footer p {
  font-size: 13px;
  line-height: 1.5;
  color: rgba(230, 238, 248, 0.6);
  margin: 0;
  font-weight: 500;
}

/* =========================
   REACT FLOW CONTROLS
   ========================= */
.react-flow__controls {
  background: var(--glass-bg) !important;
  backdrop-filter: var(--glass-blur) !important;
  -webkit-backdrop-filter: var(--glass-blur) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: 4px !important;
  box-shadow: var(--glass-shadow) !important;
  bottom: 12px !important;
  left: 12px !important;
}

.react-flow__controls-button {
  background: var(--glass-bg-lighter) !important;
  border: none !important;
  border-bottom: 1px solid var(--glass-border-light) !important;
  color: var(--color-text) !important;
}

.react-flow__controls-button:last-child {
  border-bottom: none !important;
}

.react-flow__controls-button svg {
  fill: var(--color-text) !important;
}

/* Detached actions panel (Organize + Edge Style) floating above the default
   zoom/fit-view controls. Higher specificity (.react-flow__controls.rf-controls-actions)
   overrides the default bottom offset.
   Offset breakdown: 12px base + ~84px default controls height + 12px visual gap = 108px */
.rf-controls-actions.react-flow__controls {
  bottom: 108px !important;
  left: 12px !important;
  top: auto !important;
}

/* Tutorial + Privacy mode, above the actions panel (not attached to it).
   Offset: 108px + ~109px actions panel (4 buttons) + 12px gap = 229px */
.rf-controls-settings.react-flow__controls {
  bottom: 229px !important;
  left: 12px !important;
  top: auto !important;
}

/* Undo / redo buttons: dimmed when there is nothing to undo / redo */
#undoBtn:disabled,
#redoBtn:disabled {
  opacity: 0.35;
  cursor: default;
}

.react-flow__attribution {
  display: none !important;
}

/* =========================
   EDGE OFFCANVAS SPECIFIC
   ========================= */
/* Color Selector Row - Horizontal layout with square preview */
.color-selector-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.color-selector-row .form-select {
  flex: 1;
}

.color-preview-square {
  width: 40px;
  height: 40px;
  border-radius: var(--border-radius-md);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: background var(--transition-medium);
  flex-shrink: 0;
}


/* =========================
   PRIVACY MODE TOGGLE
   ========================= */

/* Button in the floating controls (rf-app.js). ON state: red, like
   btn-danger, with the lock icon (set by rf-privacy.js) */
#privacyModeToggle.active {
  background: rgba(239, 68, 68, 0.28) !important;
}

#privacyModeToggle.active:hover {
  background: rgba(239, 68, 68, 0.4) !important;
}

/* =========================
   CUSTOM CONFIRMATION MODAL
   ========================= */

/* Overlay */
.confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(11, 15, 19, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10001;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.confirm-overlay.show {
  display: flex;
  opacity: 1;
}

/* Dialog box */
.confirm-dialog {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-xl);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
              0 8px 24px rgba(0, 0, 0, 0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
  padding: 32px;
  max-width: 420px;
  width: calc(100% - 48px);
  text-align: center;
  transform: scale(0.9);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.confirm-overlay.show .confirm-dialog {
  transform: scale(1);
  opacity: 1;
}

/* Icon */
.confirm-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
}

.confirm-icon img {
  width: 48px;
  height: 48px;
  filter: none;
}

/* Title */
.confirm-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #ffffff;
  margin: 0 0 12px 0;
  letter-spacing: -0.02em;
}

/* Message */
.confirm-message {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: rgba(230, 238, 248, 0.85);
  margin: 0 0 28px 0;
  font-weight: 500;
}

/* VARIANTE C - Cancel subtil + Delete accentué */
.confirm-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.confirm-btn {
  width: 100%;
  padding: 12px 24px;
  border-radius: var(--border-radius-md);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-smooth);
  border: 1px solid;
}

/* Delete button - PRIMARY (on top) */
.confirm-btn-delete {
  background: linear-gradient(135deg,
    rgba(239, 68, 68, 0.9) 0%,
    rgba(220, 38, 38, 0.9) 100%
  );
  border-color: rgba(239, 68, 68, 0.5);
  color: #ffffff;
  box-shadow: 0 2px 12px rgba(239, 68, 68, 0.4),
              inset 0 1px 0 rgba(255, 255, 255, 0.2);
  order: 1;
}

.confirm-btn-delete:hover {
  background: linear-gradient(135deg,
    rgba(239, 68, 68, 1) 0%,
    rgba(220, 38, 38, 1) 100%
  );
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.5);
}

/* Cancel button - SUBTLE (on bottom) */
.confirm-btn-cancel {
  background: transparent;
  border: none;
  color: rgba(230, 238, 248, 0.7);
  box-shadow: none;
  order: 2;
  padding: 10px 24px;
}

.confirm-btn-cancel:hover {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(230, 238, 248, 0.9);
  transform: none;
}

/* =========================
   PRIVACY MODE - WHITE REDACTION BAR
   ========================= */

/* Pixelated mosaic effect */
body.privacy-mode .react-flow__node .node-label {
  position: relative;
  color: transparent;
  image-rendering: pixelated;
  background: rgba(255,255,255,0.8);
  border-radius: 4px;
}

body.privacy-mode .app-timeline .tl-row-name {
  color: transparent;
  background: rgba(255,255,255,0.8);
  border-radius: 4px;
}

body.privacy-mode .edge-label-text {
  display: none;
}

/* Blur photos as well (same principle as the "mask values" preview) */
body.privacy-mode .node-preview-image,
body.privacy-mode #thumbnails .thumbnail,
body.privacy-mode #imageZoomModal .carousel-item img {
  filter: blur(4px);
}

/* =========================
   BOOTSTRAP CAROUSEL - CENTERED & NO ANIMATIONS
   ========================= */

/* 1. Configuration de la Modal pour qu'elle prenne tout l'écran */
#imageZoomModal .modal-dialog {
  max-width: 100%;
  margin: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#imageZoomModal .modal-content {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  height: 100%;
  width: 100%;
}

#imageZoomModal .modal-body {
  padding: 0 !important;
  height: 100%;
  width: 100%;
  display: flex; /* Permet au carrousel de prendre toute la place */
  align-items: center;
  justify-content: center;
}

/* Override Bootstrap slide-down with context-menu-style scale + fade */
#imageZoomModal.fade .modal-dialog {
  transform: scale(0.95);
  transition: transform 0.15s ease;
}

#imageZoomModal.show .modal-dialog {
  transform: scale(1);
}

#imageZoomModal .modal-backdrop {
  background-color: rgba(0, 0, 0, 0.95); /* Fond très sombre */
}

/* 2. Configuration du Carrousel pour le centrage */
#imageZoomCarousel {
  width: 100%;
  height: 100%;
}

#imageZoomCarousel .carousel-inner {
  height: 100%; /* Prend toute la hauteur de la modal */
  width: 100%;
}

/* LE POINT CRUCIAL : Chaque item devient une boîte flexible centrée */
#imageZoomCarousel .carousel-item {
  height: 100%; /* Force l'item à être aussi grand que l'écran */
  width: 100%;
  transition: none !important; /* Désactive l'animation */

  /* Flexbox pour centrer l'image */
  display: flex !important;
  align-items: center;     /* Centrage Vertical */
  justify-content: center; /* Centrage Horizontal */
}

/* Gestion de l'affichage actif/inactif sans animation */
#imageZoomCarousel .carousel-item:not(.active) {
  display: none !important;
}

/* 3. Style de l'image */
#imageZoomCarousel .carousel-item img {
  max-height: 70vh;
  max-width: 75vw;
  width: auto;
  height: auto;
  object-fit: contain; /* Garde les proportions */
  box-shadow: 0 8px 32px rgba(0,0,0,0.8);
  border-radius: 8px;
}

/* 4. Contrôles et Indicateurs */
#imageZoomCarousel .carousel-control-prev,
#imageZoomCarousel .carousel-control-next {
  width: 10%;
  z-index: 100; /* S'assure qu'ils sont au-dessus de l'image */
}

#imageZoomCarousel .carousel-indicators {
  bottom: 80px;
}


/* =========================
   THUMBNAIL CAROUSEL (OFFCANVAS)
   ========================= */

.thumbnail-carousel-container {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0;
  margin-top: 0.5rem;
  padding: 0;
}

/* Thumbnails container - scrollable horizontally */
#thumbnails {
  flex: 1;
  overflow-x: hidden;
  overflow-y: visible;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
  position: relative;
}

#thumbnails::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

/* Ensure thumbnails don't wrap and match dropZone height */
#thumbnails .thumb-wrap {
  flex-shrink: 0;
  height: 125px;
}

/* Carousel arrows - Always visible, superposed over images */
.thumbnail-carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all var(--transition-medium);
  color: var(--color-text);
  padding: 0;
  opacity: 0.85;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3),
              0 2px 6px rgba(0, 0, 0, 0.2);
}

.thumbnail-carousel-arrow:hover:not(:disabled) {
  opacity: 1;
  background: rgba(17, 24, 39, 0.9);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4),
              0 3px 8px rgba(0, 0, 0, 0.3);
}

.thumbnail-carousel-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.thumbnail-carousel-arrow svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2.5;
}

/* Position arrows on left and right sides */
.thumbnail-carousel-prev {
  left: 4px;
}

.thumbnail-carousel-next {
  right: 4px;
}

/* --- RF-UPLOAD COMPONENT STYLES --- */

.thumbnail-carousel-container {
  position: relative;
  transition: all 0.3s ease;
  min-height: 110px;
}

.drop-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: var(--border-radius-md);
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: none;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
  color: var(--color-text-muted);
  font-size: 1rem;
  font-weight: 400;
  text-transform: none;
  transition: all 0.3s ease;
}

.thumbnail-carousel-container.drag-active .drop-overlay {
  display: flex;
}

.thumb-add-btn {
  min-width: 80px;
  height: 125px;
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--border-radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.02);
  transition: all 0.3s ease;
  flex-shrink: 0;
  color: var(--color-text-muted);
}

.thumb-add-btn:hover {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text);
}

/* =========================
   REPORT DROPDOWN MENU
   (mirrors context menu style)
   ========================= */
.report-dropdown-wrapper {
  position: relative;
}

.report-dropdown-wrapper .report-chevron {
  opacity: 0.6;
  transition: transform 0.2s ease, opacity 0.2s ease;
  flex-shrink: 0;
}

.report-dropdown-wrapper .btn-icon[aria-expanded="true"] .report-chevron {
  transform: rotate(180deg);
  opacity: 1;
}

.report-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: none;
  min-width: 140px;
  background: rgba(13, 18, 27, 0.92);
  backdrop-filter: blur(40px) saturate(200%);
  -webkit-backdrop-filter: blur(40px) saturate(200%);
  color: var(--color-text);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  z-index: 9999;
  padding: 8px;
  font-size: 14px;
  user-select: none;
  opacity: 0;
  transform: scale(0.95) translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.report-dropdown-menu.visible {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

.report-dropdown-menu .cm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  color: inherit;
  font-weight: 500;
}

.report-dropdown-menu .cm-item:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateX(2px);
}

.report-dropdown-menu .cm-item:active {
  transform: translateX(0px);
}

.report-dropdown-menu .cm-item .cm-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
  transition: opacity 0.15s ease;
}

.report-dropdown-menu .cm-item .cm-icon img {
  width: 16px;
  height: 16px;
}

.report-dropdown-menu .cm-item:hover .cm-icon {
  opacity: 1;
}

/* =========================
   HOME PAGE (PROJECT DASHBOARD)
   ========================= */

/* Root layout — full-height, non-scrollable */
.home-root {
  height: 100vh;
  max-height: 100vh;
  width: 100%;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at top, rgba(96, 165, 250, 0.10) 0%, transparent 55%),
              radial-gradient(ellipse at bottom, rgba(240, 96, 77, 0.07) 0%, transparent 55%),
              var(--color-bg);
}

.home-main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 3rem 2rem 1rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  overflow: hidden;
}

/* =========================
   COMPACT STORAGE GAUGE (top-right corner)
   ========================= */
.home-storage-mini {
  position: absolute;
  top: 1.25rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.4rem 0.75rem;
  background: var(--glass-bg-light);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border-light);
  border-radius: var(--border-radius-pill);
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  user-select: none;
}

.home-storage-mini-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.home-storage-mini-bar {
  position: relative;
  width: 110px;
  height: 5px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.home-storage-mini-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-accent), #4b8fe3);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease;
}

.home-storage-mini-fill.is-warn {
  background: linear-gradient(90deg, #f59e0b, #f97316);
}

.home-storage-mini-fill.is-danger {
  background: linear-gradient(90deg, #ef4444, #dc2626);
}

.home-storage-mini-values {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
  min-width: 110px;
  text-align: right;
}

/* =========================
   HERO (logo + tagline)
   ========================= */
.home-hero {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

.home-hero-logo {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  user-select: none;
}

.home-hero-logo img {
  flex-shrink: 0;
  filter: drop-shadow(0 4px 16px rgba(96, 165, 250, 0.25));
}

.home-hero-brand {
  margin: 0;
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
  background: linear-gradient(135deg, var(--color-accent) 0%, #F0604D 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.home-hero-tagline {
  margin: 0;
  font-size: 1rem;
  font-weight: 400;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

/* Local-first storage notice, displayed under the tagline */
.home-hero-privacy {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 16px;
  background: var(--glass-bg-lighter);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-pill);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  letter-spacing: 0.01em;
}

.home-hero-privacy svg {
  flex-shrink: 0;
  color: var(--color-accent);
  opacity: 0.9;
}

/* =========================
   BOARD (projects list)
   ========================= */
.home-board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  overflow: hidden;
}

.home-board-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.home-board-title {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.home-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.55rem 1rem;
  background: linear-gradient(135deg, var(--color-accent) 0%, #4b8fe3 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--border-radius-md);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-medium), box-shadow var(--transition-medium), filter var(--transition-medium);
  box-shadow: 0 4px 14px rgba(96, 165, 250, 0.25),
              inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.home-btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: 0 6px 18px rgba(96, 165, 250, 0.32),
              inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.home-btn-primary:active {
  transform: translateY(0);
  filter: brightness(0.95);
}

.home-btn-primary img {
  filter: brightness(0) invert(1);
  opacity: 0.95;
}

/* =========================
   PROJECTS GRID
   ========================= */
.home-projects-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  grid-auto-rows: 128px; /* Fixed row height for consistent card sizing */
  gap: 0.875rem;
  overflow-y: auto;
  padding: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
  align-content: start;
}

.home-projects-grid::-webkit-scrollbar {
  width: 8px;
}
.home-projects-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}
.home-projects-grid::-webkit-scrollbar-track {
  background: transparent;
}

.home-card {
  position: relative;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-lg);
  padding: 0.875rem 1rem;
  cursor: pointer;
  transition: transform var(--transition-medium), border-color var(--transition-medium), box-shadow var(--transition-medium);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18),
              inset 0 1px 0 rgba(255, 255, 255, 0.05);
  height: 128px; /* Locked height matches grid-auto-rows */
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  outline: none;
  overflow: hidden; /* Safety net: never overflow */
}

.home-card:hover,
.home-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(96, 165, 250, 0.4);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3),
              0 0 0 1px rgba(96, 165, 250, 0.15),
              inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.home-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
  min-height: 0; /* Allows the title to shrink if needed without breaking layout */
}

.home-card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
  padding-right: 60px;
  /* Reserve space for exactly 2 lines so the layout never shifts */
  min-height: calc(1rem * 1.3 * 2);
  max-height: calc(1rem * 1.3 * 2);
}

/* Live session copy (rf-collab.js) */
.home-card-live {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-success);
}
.home-card-live::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.home-card-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.home-card-meta-dot {
  color: var(--color-text-faint);
}

.home-card-footer {
  margin-top: auto;
  padding-top: 0.35rem;
  flex-shrink: 0;
}

.home-card-date {
  font-size: 0.6875rem;
  color: var(--color-text-faint);
  font-weight: 500;
}

.home-card-actions {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition-medium);
}

.home-card:hover .home-card-actions,
.home-card:focus-within .home-card-actions {
  opacity: 1;
}

.home-card-action-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-bg-lighter);
  border: 1px solid var(--glass-border-light);
  border-radius: var(--border-radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-medium);
  padding: 0;
}

.home-card-action-btn:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.1);
}

.home-card-action-delete:hover {
  color: var(--color-danger-light);
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
}

/* =========================
   EMPTY STATE (compact)
   ========================= */
.home-empty {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 1.5rem;
  background: var(--glass-bg-light);
  border: 1px dashed var(--glass-border);
  border-radius: var(--border-radius-lg);
  min-height: 0;
}

.home-empty-text {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  text-align: center;
}

.home-empty-text strong {
  color: var(--color-text);
  font-weight: 600;
}

.home-error {
  grid-column: 1 / -1;
  padding: 1rem 1.5rem;
  text-align: center;
  color: var(--color-danger-light);
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--border-radius-lg);
  font-size: 0.875rem;
}

.home-drop-hint {
  flex-shrink: 0;
  margin: 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-text-faint);
  letter-spacing: 0.02em;
}

.home-drop-hint strong {
  color: var(--color-text-muted);
  font-weight: 600;
}

/* =========================
   FOOTER WATERMARK
   ========================= */
.home-footer {
  flex-shrink: 0;
  padding: 0.75rem 2rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--glass-border-light);
}

.home-watermark {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--color-text-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  user-select: none;
}

/* =========================
   FULL-PAGE DROP OVERLAY
   ========================= */
.home-drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 19, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.home-drop-overlay.visible {
  opacity: 1;
  pointer-events: none; /* overlay doesn't block drops on window */
}

.home-drop-overlay-inner {
  padding: 3rem 4rem;
  border: 2px dashed rgba(96, 165, 250, 0.6);
  border-radius: var(--border-radius-xl);
  background: rgba(96, 165, 250, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

.home-drop-overlay-icon {
  color: var(--color-accent);
  margin-bottom: 0.25rem;
}

.home-drop-overlay-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: 0.01em;
}

.home-drop-overlay-subtitle {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
}

.home-drop-overlay-subtitle strong {
  color: var(--color-text);
  font-weight: 600;
}

/* =========================
   HOME MODAL (prompt / confirm)
   ========================= */
.home-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  transition: opacity var(--transition-medium);
  padding: 1rem;
}

.home-modal-overlay.visible {
  opacity: 1;
}

.home-modal {
  width: 100%;
  max-width: 420px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-xl);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.home-modal-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
}

.home-modal-message {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.home-modal-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.625rem 0.875rem;
  background: var(--glass-bg-lighter);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  color: var(--color-text);
  font-size: 0.9375rem;
  font-family: inherit;
  transition: border-color var(--transition-smooth), box-shadow var(--transition-smooth);
}

.home-modal-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

.home-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.home-modal-btn {
  padding: 0.55rem 1rem;
  border-radius: var(--border-radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-medium);
  border: 1px solid var(--glass-border);
  background: var(--glass-bg-lighter);
  color: var(--color-text);
}

.home-modal-btn-primary {
  background: linear-gradient(135deg, var(--color-accent) 0%, #4b8fe3 100%);
  border-color: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.home-modal-btn-primary:hover {
  filter: brightness(1.08);
}

.home-modal-btn-cancel:hover {
  background: rgba(255, 255, 255, 0.1);
}

.home-modal-btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  border-color: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.home-modal-btn-danger:hover {
  filter: brightness(1.08);
}

/* Inline toast on the home page */
.home-toast {
  position: fixed;
  bottom: 3rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 0.7rem 1.1rem;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  color: var(--color-text);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
}

.home-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
/* =========================
   VIEW SWITCHER (topbar segmented control)
   ========================= */
.view-switcher {
  display: inline-flex;
  background: var(--glass-bg-lighter);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius-md);
  padding: 3px;
  gap: 2px;
  /* Always centered in the topbar regardless of siblings */
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.view-switch-btn {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--color-text);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-medium);
  white-space: nowrap;
}

.view-switch-btn img {
  flex-shrink: 0;
  opacity: 0.9;
  width: 16px;
  height: 16px;
}

.view-switch-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text);
}

.view-switch-btn:hover:not(.active) img {
  opacity: 1;
}

/* The active look is drawn by .view-switch-indicator, which slides from
   one button to the other (placed by moveViewIndicator in rf-topbar.js) */
.view-switch-btn.active {
  color: #ffffff;
}

.view-switch-indicator {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  width: 0;
  z-index: 0;
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.22), rgba(240, 96, 77, 0.18));
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
  pointer-events: none;
}

.view-switch-indicator.ready {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
  .view-switch-indicator.ready {
    transition: none;
  }
}

.view-switch-btn.active img {
  opacity: 1;
}

/* =========================
   OFFCANVAS — GEO / DATE FIELDS
   ========================= */
.label-optional {
  color: var(--color-text-faint);
  font-weight: 500;
  font-size: 0.6875rem;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 4px;
}

.geo-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 8px;
}

.geo-row .geo-address {
  flex: 1;
}

.btn-geo-find {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  background: var(--glass-bg-lighter);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  color: var(--color-text);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-medium);
}

.btn-geo-find:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(59, 130, 246, 0.4);
  color: #ffffff;
}

.btn-geo-find:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.geo-status {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  min-height: 16px;
  line-height: 1.3;
  transition: color 0.2s ease;
}

/* Smart geo input — status states (set via dataset.kind in rf-actions.js) */
.geo-status[data-kind="ok"] {
  color: #4ade80;
}

.geo-status[data-kind="error"] {
  color: #f87171;
}

.geo-status[data-kind="pending"] {
  color: #60a5fa;
}

.geo-status[data-kind="hint"] {
  color: var(--color-text-muted);
  font-style: italic;
}

/* =========================
   MAP VIEW LAYOUT
   Container sits where #cy would be — rf-views toggles display
   between them. Single full-height map (no more split with timeline).
   ========================= */
.app-maptime {
  height: calc(100vh - 64px);
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  background: var(--color-bg);
  position: relative;
}

.app-map {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.app-map .maplibregl-map {
  width: 100%;
  height: 100%;
}

/* =========================
   MAP — Style selector (top-left overlay)
   ========================= */
.map-style-switcher {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.map-style-btn {
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.map-style-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text);
  transform: translateX(2px);
}

.map-style-btn:active:not(.active) {
  transform: translateX(0px) scale(0.98);
}

.map-style-btn.active {
  background: rgba(96, 165, 250, 0.2);
  color: #ffffff;
}

/* =========================
   MAP — Pin markers
   Single pins use MapLibre's native Marker (teardrop SVG, properly
   anchored). Cluster pins keep a custom div so we can render the
   "n nodes" count badge.
   ========================= */

/* Cluster pin — shows count when multiple nodes share a location */
.rf-pin-cluster {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.rf-pin-cluster:hover {
  transform: scale(1.1);
}

/* =========================
   MAP — Popup content
   ========================= */
.maplibregl-popup-content {
  background: rgba(15, 23, 36, 0.92) !important;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  color: var(--color-text);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-lg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  padding: 12px 14px;
  min-width: 220px;
  max-width: 320px;
  font-family: Inter, Roboto, system-ui, sans-serif;
}

.maplibregl-popup-tip {
  border-top-color: rgba(15, 23, 36, 0.92) !important;
  border-bottom-color: rgba(15, 23, 36, 0.92) !important;
}

.maplibregl-popup-close-button {
  display: none !important;
}

.rf-popup-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.9375rem;
  margin-bottom: 6px;
  color: #fff;
}

.rf-popup-title img {
  width: 18px;
  height: 18px;
}

.rf-popup-address {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-bottom: 10px;
  line-height: 1.3;
}

.rf-popup-section-title {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-faint);
  margin: 8px 0 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.rf-popup-linked {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.rf-popup-linked-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.8125rem;
  color: var(--color-text);
}

.rf-popup-linked-item:hover {
  background: rgba(96, 165, 250, 0.12);
  border-color: rgba(96, 165, 250, 0.3);
}

.rf-popup-linked-item img {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.9;
}

.rf-popup-linked-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rf-popup-linked-direction {
  font-size: 0.625rem;
  color: var(--color-text-faint);
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rf-popup-empty {
  font-size: 0.75rem;
  color: var(--color-text-faint);
  font-style: italic;
  text-align: center;
  padding: 8px 0;
}

/* =========================
   MAP — Navigation controls
   Exact replica of .react-flow__controls styling so both views
   share the same bottom-left control panel look.
   ========================= */

/* Force all MapLibre controls to bottom-left, matching React Flow */
.maplibregl-ctrl-top-right,
.maplibregl-ctrl-top-left,
.maplibregl-ctrl-bottom-right {
  display: none !important;
}

.maplibregl-ctrl-bottom-left {
  bottom: 0 !important;
  left: 0 !important;
}

/* Same 12px offset from the corner as .react-flow__controls
   (MapLibre's default margin is 10px) */
.maplibregl-ctrl-bottom-left .maplibregl-ctrl-group {
  margin: 0 0 12px 12px !important;
}

/* Container — mirrors .react-flow__controls (map + timeline controls) */
.maplibregl-ctrl-group,
.tl-controls {
  background: var(--glass-bg) !important;
  backdrop-filter: var(--glass-blur) !important;
  -webkit-backdrop-filter: var(--glass-blur) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: 4px !important;
  box-shadow: var(--glass-shadow) !important;
  overflow: hidden !important;
}

/* Buttons — mirrors .react-flow__controls-button (React Flow 10:
   16px content + 5px padding, 1px separator, no hover change) */
.maplibregl-ctrl-group button,
.tl-controls button {
  background: var(--glass-bg-lighter) !important;
  border: none !important;
  border-bottom: 1px solid var(--glass-border-light) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  color: var(--color-text) !important;
  box-sizing: content-box !important;
  width: 16px !important;
  height: 16px !important;
  padding: 5px !important;
  margin: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
}

.maplibregl-ctrl-group button:last-child,
.tl-controls button:last-child {
  border-bottom: none !important;
}

/* Zoom in / out / fit view icons — same as .react-flow__controls-button svg */
.maplibregl-ctrl-group button svg,
.tl-controls button svg {
  width: 100%;
  max-width: 12px;
  max-height: 12px;
  fill: var(--color-text) !important;
}

/* Compass: MapLibre's needle redrawn in the icon color (north solid, south
   dimmed). 20px icon = 12px needle, the size of the other icons. Its
   transform (rotation / tilt) is set inline by MapLibre. */
.maplibregl-ctrl-group button.maplibregl-ctrl-compass .maplibregl-ctrl-icon {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='29' height='29' viewBox='0 0 29 29'%3E%3Cpath fill='%23e6eef8' d='m10.5 14 4-8 4 8z'/%3E%3Cpath fill='%23e6eef8' fill-opacity='.4' d='m10.5 16 4 8 4-8z'/%3E%3C/svg%3E") !important;
  width: 20px !important;
  height: 20px !important;
  flex-shrink: 0;
  background-size: contain !important;
  background-position: center !important;
}

/* =========================
   TOPBAR — Map mode: instant hide/show
   When the user switches to the Map view, .map-mode is added to
   .top-bar. All buttons tagged .btn-graph-only are hidden instantly.
   The .view-switcher stays in its original position.
   ========================= */
.top-bar.map-mode .btn-graph-only {
  display: none;
}

/* =========================
   NODE PALETTE — Hidden in map mode
   The palette is a graph-only authoring tool (drag-and-drop to create
   nodes) and serves no purpose on the map view, so it is hidden
   instantly when .hidden-on-map is applied by rf-topbar.js.
   ========================= */
.node-palette.hidden-on-map {
  display: none;
}
/* =========================
   NODE DETAILS — DATES (rf-events.js)
   ========================= */
/* "Dates ⌄" collapsible header */
.event-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.event-toggle:hover {
  color: var(--color-text);
}

.event-toggle .form-label {
  cursor: pointer;
}

.event-count:not(:empty) {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--glass-bg-lighter);
  border: 1px solid var(--glass-border);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
  color: var(--color-text);
}

.event-chevron {
  transition: transform var(--transition-fast);
}

.event-toggle[aria-expanded="true"] .event-chevron {
  transform: rotate(180deg);
}

/* New blank date, until something is typed in it */
.event-item.is-draft {
  background: transparent;
  border-style: dashed;
}

.event-item.is-draft:only-child .event-remove {
  visibility: hidden;
}

/* "+" zone under the dates */
.event-add-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 34px;
  border: 1px dashed var(--glass-border);
  border-radius: var(--border-radius-md);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.125rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.event-add-zone:hover {
  background: var(--glass-bg-lighter);
  color: var(--color-text);
}

.event-item.is-draft .event-add-end {
  visibility: hidden;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--glass-bg-lighter);
  border: 1px solid var(--glass-border-light);
  border-radius: var(--border-radius-md);
}

.event-item .form-control,
.event-item .form-select {
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
  border-radius: 6px;
  color-scheme: dark;
}

.event-line {
  display: flex;
  gap: 6px;
  align-items: center;
}

.event-line > .event-kind {
  flex: 0 0 40%;
  min-width: 0;
}

/* Text field with the calendar button inside, on the right */
.event-date-field {
  position: relative;
  flex: 1;
  min-width: 0;
}

.event-item .event-date-text {
  padding-right: 30px;
}

.event-item .has-extra .event-date-text {
  padding-right: 56px;
}

.event-cal,
.event-add-end {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.event-add-end {
  right: 30px;
}

.event-cal:hover,
.event-add-end:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text);
}

/* Native date picker: invisible, only its popup is used */
.event-picker {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  pointer-events: none;
  color-scheme: dark;
}

/* "until" in the kind column, right-aligned against the End field */
.event-end-label {
  flex: 0 0 40%;
  text-align: right;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.event-hint {
  font-size: 0.6875rem;
  line-height: 1.3;
  padding: 0 2px;
  color: var(--color-text-faint);
  overflow-wrap: anywhere;
}

.event-hint:empty {
  display: none;
}

.event-hint[data-kind="error"] {
  color: #f87171;
}

.event-remove {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.event-remove:hover {
  background: rgba(239, 68, 68, 0.18);
  color: var(--color-danger-light);
}

/* Remove the end only: lighter than removing the whole date */
.event-remove-end {
  font-size: 0.6875rem;
  opacity: 0.6;
}

.event-remove-end:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text);
}

.form-select optgroup {
  background: #f8fafc;
  color: #1e293b;
}

/* =========================
   TIMELINE VIEW (rf-timeline.js, vis-timeline)
   One row per node. Overrides are scoped to .app-timeline so they win
   over the library stylesheet loaded after this one.
   ========================= */
.app-timeline {
  --tl-color: #94a3b8;   /* default; each row item / type button sets its color */
  height: calc(100vh - 64px);
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  background: var(--color-bg);
}

.tl-stage {
  position: relative;
  height: 100%;
  box-sizing: border-box;
  padding: 12px 12px 0;
}

/* vis-timeline sets its container to position: relative, so it is sized
   by width / height, not by inset */
.tl-host {
  width: 100%;
  height: 100%;
}

.tl-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 360px;
  text-align: center;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  padding: 16px 20px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  pointer-events: none;
  z-index: 5;
}

/* Bottom right: node type selector + zoom controls */
.tl-corner {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.tl-types {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  max-width: 60vw;
  padding: 6px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  box-shadow: var(--glass-shadow);
}

.tl-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border-light);
  border-radius: 999px;
  color: var(--color-text);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), opacity var(--transition-fast);
}

.tl-type:hover {
  background: rgba(255, 255, 255, 0.1);
}

.tl-type-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tl-color);
}

.tl-type-count {
  color: var(--color-text-muted);
  font-weight: 500;
}

.tl-type.off {
  opacity: 0.45;
}

.tl-type.off .tl-type-dot {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--tl-color);
}

.tl-controls {
  display: flex;
  flex-direction: column;
}

/* --- vis-timeline dark theme --- */
.app-timeline .vis-timeline {
  border: none;
  font-family: inherit;
  color: var(--color-text);
}

.app-timeline .vis-panel.vis-center,
.app-timeline .vis-panel.vis-left,
.app-timeline .vis-panel.vis-right,
.app-timeline .vis-panel.vis-top,
.app-timeline .vis-panel.vis-bottom {
  border-color: var(--glass-border-light);
}

.app-timeline .vis-time-axis .vis-text {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.app-timeline .vis-time-axis .vis-text.vis-major {
  color: var(--color-text);
  font-weight: 600;
}

.app-timeline .vis-time-axis .vis-grid.vis-minor {
  border-color: rgba(255, 255, 255, 0.04);
}

.app-timeline .vis-time-axis .vis-grid.vis-major {
  border-color: rgba(255, 255, 255, 0.1);
}

.app-timeline .vis-labelset .vis-label {
  color: var(--color-text);
  border-bottom-color: var(--glass-border-light);
}

.app-timeline .vis-foreground .vis-group {
  border-bottom-color: var(--glass-border-light);
}

.app-timeline .vis-current-time {
  background-color: var(--color-accent);
  width: 1px;
}

/* Row label: node type icon + node name */
.tl-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
  padding: 0 12px 0 8px;
  font-size: 0.8125rem;
  font-weight: 600;
}

.tl-row-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.tl-row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Items: color of the node type in --tl-color (inline style) */
.app-timeline .vis-item {
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--tl-color);
  border-radius: 6px;
  color: var(--color-text);
  font-size: 0.75rem;
}

.app-timeline .vis-item.vis-range {
  background: color-mix(in srgb, var(--tl-color) 22%, rgba(17, 24, 39, 0.92));
}

/* Period with year / month precision: dashed, hatched bar */
.app-timeline .vis-item.vis-range.tl-approx {
  border-style: dashed;
  background:
    repeating-linear-gradient(135deg, transparent 0 6px, rgba(255, 255, 255, 0.05) 6px 12px),
    color-mix(in srgb, var(--tl-color) 14%, rgba(17, 24, 39, 0.92));
}

/* Short periods: the label may run past the end of the bar */
.app-timeline .vis-item.vis-range .vis-item-overflow {
  overflow: visible;
}

.app-timeline .vis-item.vis-point {
  background: transparent;
  border: none;
}

.app-timeline .vis-item .vis-dot {
  border-color: var(--tl-color);
  background: var(--tl-color);
  border-width: 4px;
  border-radius: 50%;
}

/* Approximate date (year / month only): hollow dot, dashed label */
.app-timeline .vis-item.vis-point.tl-approx .vis-dot {
  width: 6px;
  height: 6px;
  border-width: 2px;
  background: var(--color-bg);
}

.app-timeline .vis-item .vis-item-content {
  padding: 3px 6px;
}

.tl-item-kind {
  font-weight: 600;
  white-space: nowrap;
}

.app-timeline .vis-item.vis-point .tl-item-kind {
  display: inline-block;
  padding: 2px 6px;
  background: rgba(17, 24, 39, 0.85);
  border: 1px solid color-mix(in srgb, var(--tl-color) 60%, transparent);
  border-radius: 6px;
}

.app-timeline .vis-item.vis-point.tl-approx .tl-item-kind {
  border-style: dashed;
}

/* Tooltip (appended inside the timeline container) */
.app-timeline .vis-tooltip {
  background: rgba(15, 23, 36, 0.96);
  color: var(--color-text);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  font-family: inherit;
  font-size: 0.75rem;
  line-height: 1.5;
  padding: 8px 10px;
  max-width: 320px;
  white-space: normal;
}

/* =========================
   TOPBAR — SEARCH NODES (rf-node-search.js)
   Left of Import. The width shrinks with the window so it never reaches
   the centered view switcher (half switcher ~137px + right buttons
   ~404px + gaps = 577px); under 1440px only the magnifier is shown.
   ========================= */
.node-search {
  position: relative;
  display: flex;
  align-items: center;
  width: min(240px, calc(50vw - 577px));
  align-self: stretch;     /* same height as the topbar buttons */
}

.node-search-icon {
  position: absolute;
  left: 10px;
  color: var(--color-text-muted);
  pointer-events: none;
}

.node-search-input {
  width: 100%;
  height: 100%;
  padding: 0 52px 0 30px;
  background: var(--glass-bg-lighter);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius-md);
  color: var(--color-text);
  font-size: 0.8125rem;
  outline: none;
  transition: border-color var(--transition-medium), background var(--transition-medium);
}

.node-search-input::placeholder {
  color: var(--color-text-faint);
}

.node-search-input:focus {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(96, 165, 250, 0.5);
}

.node-search-kbd {
  position: absolute;
  right: 8px;
  padding: 1px 5px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  background: transparent;
  color: var(--color-text-faint);
  font-family: inherit;
  font-size: 0.625rem;
  pointer-events: none;
}

.node-search-input:focus ~ .node-search-kbd {
  display: none;
}

.node-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;                /* same width as the field */
  max-height: 360px;
  overflow-y: auto;
  padding: 4px;
  background: rgba(15, 23, 36, 0.96);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  z-index: 70;
}

.node-search-results[hidden] {
  display: none;
}

.ns-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.ns-item.active {
  background: rgba(96, 165, 250, 0.16);
}

.ns-icon {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
}

.ns-text {
  min-width: 0;
}

.ns-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ns-meta {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ns-empty {
  padding: 8px;
  font-size: 0.75rem;
  color: var(--color-text-faint);
}

/* Narrow windows: only the magnifier, the field opens to the left (over
   the switcher) while it has the focus */
@media (max-width: 1440px) {
  .node-search {
    width: 38px;           /* square button, as tall as the others */
    flex-shrink: 0;
  }
  .node-search-input {
    padding-right: 0;
    color: transparent;
    cursor: pointer;
  }
  .node-search-input::placeholder,
  .node-search-kbd {
    color: transparent;
    border-color: transparent;
  }
  .node-search:focus-within {
    z-index: 75;
  }
  .node-search:focus-within .node-search-input {
    position: absolute;
    right: 0;
    width: 240px;
    padding-right: 10px;
    color: var(--color-text);
    cursor: text;
    background: rgba(15, 23, 36, 0.98);
    z-index: 71;
  }
  .node-search:focus-within .node-search-icon {
    left: auto;
    right: 216px;            /* 240px - 24px: left end of the open field */
    z-index: 72;
  }
  .node-search-results {
    left: auto;
    width: 240px;            /* same width as the open field */
  }
}

/* Privacy mode: names and matched URL / notes masked like on the graph */
body.privacy-mode .ns-label,
body.privacy-mode .ns-snippet {
  color: transparent;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 4px;
}

body.privacy-mode .ns-label {
  width: fit-content;
  max-width: 100%;
}

/* Node found: one short pulse around it */
.react-flow__node.ns-flash {
  animation: ns-flash 0.9s ease-out;
}

@keyframes ns-flash {
  0%   { box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.9); }
  100% { box-shadow: 0 0 0 14px rgba(96, 165, 250, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .react-flow__node.ns-flash {
    animation: none;
    outline: 2px solid rgba(96, 165, 250, 0.9);
  }
}
