/* Importing Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Inter:wght@300;400;500;600;700&family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* HSL Color System - Clean Light Academic Theme */
  --bg-base: hsl(210, 20%, 97%);
  --bg-surface: hsl(0, 0%, 100%);
  --bg-card: hsl(210, 15%, 95%);
  --border-color: hsl(210, 14%, 87%);
  --border-glow: hsl(210, 14%, 75%);
  
  --text-primary: hsl(220, 20%, 15%);
  --text-secondary: hsl(220, 12%, 35%);
  --text-muted: hsl(220, 8%, 55%);
  
  --primary: hsl(217, 85%, 50%); /* Academic Blue */
  --primary-glow: hsla(217, 85%, 50%, 0.15);
  --primary-hover: hsl(217, 90%, 42%);
  
  --accent-cyan: hsl(190, 85%, 38%);
  --accent-emerald: hsl(152, 70%, 35%);
  --accent-rose: hsl(350, 75%, 45%);
  --accent-amber: hsl(35, 85%, 40%);
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: 'Lora', Georgia, "Times New Roman", serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --transition-fast: 0.1s ease;
  --transition-normal: 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
}

code {
  font-family: var(--font-mono);
  background-color: var(--bg-base);
  padding: 2px 5px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--text-primary);
  white-space: nowrap;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: hsla(220, 10%, 30%, 0.2);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: hsla(220, 10%, 30%, 0.4);
}

/* App Layout */
.app-container {
  display: flex;
  width: 100%;
  height: 100vh;
  position: relative;
}

/* Sidebar Styling - Academic Minimalist */
aside.sidebar {
  width: 360px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 10;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-base);
}

.sidebar-header h1 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-header p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Main Canvas Area */
main.canvas-container {
  flex: 1;
  position: relative;
  height: 100%;
  background-color: #ffffff; /* Clean white canvas for publication figures */
  cursor: grab;
}

main.canvas-container:active {
  cursor: grabbing;
}

#hypergraph-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Form Controls & Styling */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.select-wrapper {
  position: relative;
}

select, input[type="text"], textarea {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition-fast);
}

select:focus, input[type="text"]:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

select {
  cursor: pointer;
  appearance: none;
}

.select-wrapper::after {
  content: '▼';
  font-size: 0.65rem;
  color: var(--text-secondary);
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

/* Slider Controls */
.slider-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.slider-val {
  font-family: var(--font-mono);
  color: var(--primary);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  outline: none;
  appearance: none;
  cursor: pointer;
  margin: 0;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: var(--shadow-sm);
  transition: var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  background: var(--primary-hover);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-weight: 550;
  font-size: 0.9rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: var(--bg-base);
  border-color: var(--border-glow);
}

.btn-danger {
  background: hsl(0, 100%, 97%);
  border-color: hsl(0, 100%, 90%);
  color: hsl(0, 85%, 45%);
}

.btn-danger:hover {
  background: hsl(0, 100%, 94%);
  border-color: hsl(0, 85%, 45%);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
  border-radius: 4px;
}

/* Button Group */
.btn-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Sidebar Sections / Cards */
.sidebar-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Switch / Toggle Option */
.toggle-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.toggle-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

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

.slider-round {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-base);
  border: 1px solid var(--border-color);
  transition: .2s;
  border-radius: 20px;
}

.slider-round:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-secondary);
  transition: .2s;
  border-radius: 50%;
}

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

input:checked + .slider-round:before {
  transform: translateX(18px);
  background-color: #fff;
}

/* Floating Controls on Canvas */
.floating-controls {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 10px;
  z-index: 5;
}

.floating-pill {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 30px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-sm);
}

.floating-pill button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: var(--transition-fast);
}

.floating-pill button:hover {
  background: var(--bg-base);
  color: var(--text-primary);
}

.floating-pill button.active {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

#btn-recenter {
  transform: translateY(-1px);
}

.floating-help {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-width: 280px;
  box-shadow: var(--shadow-md);
  pointer-events: none;
}

.floating-help h4 {
  font-family: var(--font-serif);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.floating-help ul {
  list-style: none;
}

.floating-help li {
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.floating-help li::before {
  content: '•';
  color: var(--primary);
}

/* Hypergraph Visual Elements (SVG) */
svg {
  user-select: none;
}

.list-container {
  height: auto;
  min-height: 80px;
  resize: vertical;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-base);
}

/* Default state: no user resizing yet */
.list-container:not([style*="height"]) {
  max-height: 330px; /* Fits approx 10 edges before scrolling */
}

/* User has resized: allow resizing up to all hyperedges */
.list-container[style*="height"] {
  max-height: var(--content-h, 1000px);
}

.list-container::-webkit-resizer {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 10 10"><path d="M10,0 L0,10 M10,4 L4,10 M10,8 L8,10" stroke="%23888888" stroke-width="1.2"/></svg>');
  background-repeat: no-repeat;
  background-position: bottom right;
  width: 10px;
  height: 10px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  gap: 8px;
}

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

.list-item-content {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.item-color-pill {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.item-text {
  font-weight: 500;
  word-break: break-all;
}

.list-item input.list-item-edit-input {
  font-size: 0.8rem;
  padding: 3px 6px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  width: 100%;
  outline: none;
  font-family: var(--font-sans);
}

.list-item input.list-item-edit-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.list-item-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

/* Modal Styling */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 500px;
  max-width: 90%;
  box-shadow: var(--shadow-lg);
  transform: translateY(15px);
  transition: transform var(--transition-normal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-base);
}

.modal-header h3 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-base);
}

.modal textarea {
  height: 120px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.import-error {
  color: var(--accent-rose);
  font-size: 0.8rem;
  margin-top: 4px;
  display: none;
}

/* Presets grid */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.preset-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px;
  text-align: left;
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preset-btn:hover {
  border-color: var(--primary);
  background: var(--bg-base);
}

.preset-btn h5 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.preset-btn span {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Control subgroups for visual hierarchy and structure */
.control-subgroup {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 16px;
  margin-bottom: 4px;
}

.control-subgroup:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

.subgroup-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

/* Slider Number Inputs styling */
.slider-number-input {
  min-width: 45px;
  max-width: 80px;
  text-align: right;
  padding: 3px 8px 3px 6px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast);
}

.slider-number-input:focus {
  border-color: var(--primary);
}

/* Hide spin buttons for standard inputs */
.slider-number-input::-webkit-outer-spin-button,
.slider-number-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.slider-number-input[type="number"] {
  -moz-appearance: textfield;
}

/* Consistent color picker styling */
.color-picker-wrapper {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--bg-surface);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.color-picker-wrapper:hover {
  border-color: var(--border-glow);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.color-picker-wrapper input[type="color"] {
  position: absolute;
  top: -5px;
  left: -5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  cursor: pointer;
}
