/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap');

:root {
  /* New FLB Brand Colors */
  --flb-cyan: #0086cb;
  --flb-blue: #00255e;

  /* Semantic Variables - Default (Dark Mode) */
  --bg-color: var(--flb-blue);
  --text-main: #ffffff;
  --text-muted: rgba(255, 255, 255, 0.7);
  --primary: var(--flb-cyan);
  --secondary: #10b981;
  --card-bg: rgba(255, 255, 255, 0.1);
  --card-border: rgba(255, 255, 255, 0.2);
  --glass-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

/* Light Mode Overrides */
body.light-mode {
  --bg-color: #ffffff;
  --text-main: var(--flb-blue);
  --text-muted: rgba(0, 37, 94, 0.75);
  --card-bg: rgba(0, 134, 203, 0.05);
  --card-border: rgba(0, 40, 94, 0.15);
  --glass-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.05);
}

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

body {
  font-family: 'Calibri', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
  /* Prevent body scroll, we scroll content */
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* App Header */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  z-index: 1001;
  backdrop-filter: blur(10px);
}

.header-toggle-btn {
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 1.5rem;
  cursor: pointer;
  margin-right: 1rem;
  padding: 0.5rem;
  border-radius: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-title {
  font-size: 1.25rem;
  margin: 0;
  font-weight: 700;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--card-bg);
  border-right: 1px solid var(--card-border);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  flex-shrink: 0;
  height: calc(100vh - 60px);
  position: fixed;
  top: 60px;
  left: -280px;
  z-index: 1000;
  transition: transform 0.3s ease-in-out, left 0.3s ease-in-out;
  backdrop-filter: blur(10px);
  overflow-y: auto;
}

.sidebar.open {
  left: 0;
}

@media (min-width: 769px) {
  .sidebar {
    left: 0;
    padding-top: 1.5rem;
    /* Reset, since it's just a flex child in some layouts, but here it's fixed */
    transform: translateX(0);
  }

  body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
  }

  body.sidebar-collapsed .main-content {
    margin-left: 0;
  }

  .main-content {
    margin-left: 280px;
    /* Sidebar width */
    transition: margin-left 0.3s ease-in-out;
  }

  .sidebar-header-mobile {
    display: none;
  }
}

.sidebar-header-mobile {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.close-sidebar-btn {
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 2rem;
  cursor: pointer;
}

.logo-area h1 {
  font-size: 1.5rem;
  color: var(--primary);
  margin-bottom: 0.2rem;
}

.control-group label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  font-weight: 600;
}

/* Nav Buttons */
.nav-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-btn {
  width: 100%;
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  padding: 0.8rem;
  cursor: pointer;
  border-radius: 0.25rem;
  transition: all 0.2s ease;
  font-weight: 600;
  font-size: 1rem;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.nav-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

body.light-mode .nav-btn {
  background: #f1f5f9;
  color: var(--flb-blue);
  border: 1px solid #e2e8f0;
}

body.light-mode .nav-btn.active {
  background: var(--flb-cyan);
  color: white;
  border-color: var(--flb-cyan);
}

body.light-mode .nav-btn:hover:not(.active) {
  background: #e2e8f0;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 1.5rem;
  padding-top: 80px;
  position: relative;
  width: 100%;
}

.section {
  display: none;
  max-width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.5s ease-out;
}

.section.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Buttons */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border: 1px solid var(--card-border);
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

body.light-mode .btn-secondary {
  background: #f1f5f9;
  color: var(--flb-blue);
  border-color: #e2e8f0;
}

/* Impressum & Cards */
.card {
  background: var(--card-bg);
  padding: 1.5rem;
  border-radius: 1rem;
  border: 1px solid var(--card-border);
}

/* --- Mindmap Styles --- */

#mindmap-viewport {
  transform-origin: 0 0;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.connection-group {
  cursor: pointer;
  pointer-events: all;
}

.connection-group:hover .visual-line {
  stroke: var(--primary) !important;
  stroke-width: 3;
  filter: drop-shadow(0 0 3px var(--primary));
}

.visual-line {
  transition: stroke 0.2s, stroke-width 0.2s, filter 0.2s;
}

.hit-area {
  stroke: var(--text-muted);
  stroke-width: 25; /* Larger hit area for touch */
  opacity: 0;
}

.connection-label {
  position: absolute;
  transform: translate(-50%, -50%);
  background: var(--card-bg);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  pointer-events: auto;
  user-select: none;
  backdrop-filter: blur(4px);
  border: 1px solid transparent;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all 0.2s;
  text-align: center;
}

.connection-label:hover {
  border-color: var(--text-muted);
  background: var(--bg-color);
  color: var(--text-main);
  z-index: 20;
}

.connection-label:empty {
  /* define min size for empty label so it can be hovered if needed, or maybe hide it until hovered? */
  /* actually, let's keep it invisible if empty unless hovered? No, difficult to hover invisible. */
  /* We will give it a placeholder in JS if empty? Or just depend on line hover context menu -> rename */
  display: none;
}

.connection-label.visible {
  display: block;
}

.connection-label:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-color);
  color: var(--text-main);
  z-index: 20;
  min-width: 60px; /* Sligthly larger min-width */
  min-height: 30px; /* Touch target */
  display: flex;
  align-items: center;
  justify-content: center;
}

.mindmap-node {
  position: absolute;
  width: 120px;
  height: 60px;
  background: var(--card-bg);
  border: 2px solid var(--primary);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  z-index: 10;
  transition: border-color 0.2s, box-shadow 0.2s;
  pointer-events: auto;
}

body.light-mode .mindmap-node {
  background: white;
  border-color: var(--flb-cyan);
  color: black;
}

.mindmap-node:active {
  cursor: grabbing;
}

.mindmap-node.linking {
  border-color: var(--secondary);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

.node-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 5px;
  outline: none;
  font-size: 0.9rem;
  overflow: hidden;
  word-break: break-word;
}

.node-port {
  position: absolute;
  bottom: -10px; /* Larger offset */
  right: -10px;
  width: 24px; /* Larger size for touch */
  height: 24px;
  background: var(--text-muted);
  border-radius: 50%;
  cursor: crosshair;
  border: 4px solid var(--bg-color); /* Thicker border to separate from node */
  transition: transform 0.2s, background-color 0.2s;
  z-index: 15; /* Ensure above node border */
}

.node-port:hover {
  transform: scale(1.2);
  background-color: var(--secondary);
}

/* Slider (Theme Toggle) */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked+.slider {
  background-color: var(--primary);
}

input:checked+.slider:before {
  transform: translateX(20px);
}

/* Printing styles */
@media print {

  .app-header,
  .sidebar,
  .toolbar {
    display: none !important;
  }

  .main-content {
    margin: 0 !important;
    padding: 0 !important;
  }

  #mindmap-container {
    border: none !important;
    height: 100vh !important;
    width: 100vw !important;
    position: static !important;
  }

  .mindmap-node {
    border-color: black !important;
    color: black !important;
    background: white !important;
  }

  svg line {
    stroke: black !important;
  }
}

/* Context Menu */
.context-menu {
  position: fixed;
  background: var(--card-bg);
  /* Use card bg for glass effect */
  border: 1px solid var(--card-border);
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  padding: 0.5rem 0;
  z-index: 2000;
  min-width: 150px;
  display: none;
  /* hidden by default */
}

body.light-mode .context-menu {
  background: white;
  border-color: #e2e8f0;
  color: var(--flb-blue);
}

.menu-item {
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

body.light-mode .menu-item:hover {
  background: #f1f5f9;
}

.menu-item.delete {
  color: #ef4444;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  backdrop-filter: blur(5px);
}

.modal-content {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  padding: 2rem;
  border-radius: 1rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  min-width: 300px;
  backdrop-filter: blur(12px);
}

body.light-mode .modal-content {
  background: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.modal-content h3 {
  margin-bottom: 1rem;
  color: var(--primary);
}