/* =====================================================
   FINISHLINE TEMPLATE BUILDER - CSS
   Version: 1.0
   ===================================================== */

/* ===== CSS Variables ===== */
:root {
  --bg: #0a0a0a;
  --bg-elevated: #111111;
  --bg-surface: #1a1a1a;
  --bg-surface-hover: #222222;
  --border: #2a2a2a;
  --border-light: #333333;
  --text: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #ff4500;
  --accent-hover: #ff5722;
  --accent-glow: rgba(255, 69, 0, 0.3);
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  
  --header-height: 56px;
  --toolbar-width: 200px;
  --properties-width: 280px;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===== Auth Overlay ===== */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.auth-overlay.hidden {
  display: none;
}

.auth-message {
  text-align: center;
  padding: 40px;
}

.auth-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.auth-message h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.auth-message p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* ===== Builder App Container ===== */
.builder-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ===== Header ===== */
.builder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition-fast);
}

.back-link:hover {
  background: var(--bg-surface);
  color: var(--text);
}

.template-name-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.template-name-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  max-width: 200px;
  transition: all var(--transition-fast);
}

.template-name-input:hover {
  border-color: var(--border);
}

.template-name-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-surface);
}

.edit-name-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.edit-name-btn:hover {
  background: var(--bg-surface);
  color: var(--text);
}

.header-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.save-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.save-status.saving {
  color: var(--warning);
}

.save-status.saved {
  color: var(--success);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

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

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px;
}

.btn-ghost:hover {
  background: var(--bg-surface);
  color: var(--text);
}

/* ===== Main Layout ===== */
.builder-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== Left Toolbar ===== */
.toolbar-left {
  width: var(--toolbar-width);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  gap: 8px;
  overflow-y: auto;
  flex-shrink: 0;
}

.tool-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tool-section-title {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  margin-bottom: 4px;
}

.tool-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}

.tool-btn .tool-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.tool-btn .tool-label {
  font-size: 0.8rem;
  font-weight: 500;
}

@media (max-width: 900px) {
  .tool-btn {
    flex-direction: column;
    padding: 10px 4px;
    gap: 4px;
    text-align: center;
  }
  
  .tool-btn .tool-label {
    font-size: 0.65rem;
  }
}

.tool-btn:hover {
  background: var(--bg-surface);
  color: var(--text);
  border-color: var(--border);
}

.tool-btn:active {
  transform: scale(0.95);
}

.tool-btn .tool-icon {
  font-size: 1.25rem;
}

.tool-btn .tool-label {
  font-size: 0.65rem;
  font-weight: 500;
}

.tool-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 4px;
}

/* ===== Activity Selector ===== */
.activity-section {
  padding: 0;
}

.activity-selector {
  margin-bottom: 8px;
}

.activity-loaded {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  background: linear-gradient(135deg, var(--accent), #e03d00);
  border-radius: var(--radius-md);
  padding: 12px;
  color: white;
}

.activity-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.activity-name {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-stats {
  display: block;
  font-size: 0.7rem;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-change-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 0.85rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.activity-change-btn:hover {
  background: rgba(255,255,255,0.3);
}

/* Activity source buttons */
.activity-sources {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
}

.activity-source-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  background: #252525;
  border: 2px dashed #444;
  border-radius: var(--radius-md);
  color: #ccc;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
  width: 100%;
}

.activity-source-btn:hover {
  background: #333;
  border-color: var(--accent);
  border-style: solid;
  color: #fff;
}

.activity-source-btn .source-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.activity-source-btn .source-label {
  flex: 1;
  font-weight: 500;
}

.activity-source-btn.strava:hover {
  border-color: #fc4c02;
}

/* Only hide sources when activity is loaded AND not in change mode */
.activity-section.has-activity .activity-sources {
  display: none;
}

.activity-section.has-activity.changing-activity .activity-sources {
  display: flex;
}

.activity-section.has-activity.changing-activity .activity-loaded {
  display: none !important;
}

@media (max-width: 900px) {
  .activity-source-btn {
    padding: 10px 8px;
    flex-direction: column;
    text-align: center;
    gap: 4px;
  }
  
  .activity-source-btn .source-label {
    font-size: 0.65rem;
  }
}

/* ===== Layers Panel ===== */
.layers-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.layers-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.layer-item:hover {
  background: var(--bg-surface);
}

.layer-item.selected {
  background: var(--accent);
  color: white;
}

.layer-item .layer-icon {
  font-size: 0.9rem;
}

.layer-item .layer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Canvas Area ===== */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #050505;
  background-image: 
    linear-gradient(45deg, #0d0d0d 25%, transparent 25%),
    linear-gradient(-45deg, #0d0d0d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #0d0d0d 75%),
    linear-gradient(-45deg, transparent 75%, #0d0d0d 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  overflow: hidden;
  position: relative;
}

.canvas-container {
  position: relative;
  margin: auto;
  /* Width/Height werden per JS gesetzt */
}

.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
}

#builderCanvas {
  display: block;
  background: var(--bg);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  /* Scale wird per JS gesetzt */
}

.selection-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 10;
  /* Size wird durch den Container bestimmt */
}

/* Selection Handles */
.selection-box {
  position: absolute;
  border: 2px solid var(--accent);
  pointer-events: auto;
  cursor: move;
  box-sizing: border-box;
}

.selection-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: white;
  border: 2px solid var(--accent);
  border-radius: 2px;
  pointer-events: auto;
  box-sizing: border-box;
}

.selection-handle.nw { top: -6px; left: -6px; cursor: nwse-resize; }
.selection-handle.n { top: -6px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.selection-handle.ne { top: -6px; right: -6px; cursor: nesw-resize; }
.selection-handle.e { top: 50%; right: -6px; transform: translateY(-50%); cursor: ew-resize; }
.selection-handle.se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.selection-handle.s { bottom: -6px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.selection-handle.sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.selection-handle.w { top: 50%; left: -6px; transform: translateY(-50%); cursor: ew-resize; }

/* Canvas Controls */
.canvas-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}

.zoom-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.zoom-btn:hover {
  background: var(--bg-surface-hover);
}

.zoom-level {
  min-width: 50px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.control-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 8px;
}

.grid-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.grid-toggle input {
  accent-color: var(--accent);
}

/* ===== Properties Panel ===== */
.properties-panel {
  width: var(--properties-width);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.properties-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.properties-content,
.properties-background {
  padding: 16px;
}

.prop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.prop-element-type {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.prop-delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.prop-delete-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--error);
  color: var(--error);
}

/* Property Sections */
.prop-section {
  margin-bottom: 20px;
}

.prop-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.prop-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.prop-row-2col > * {
  flex: 1;
}

.prop-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.prop-field label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.prop-field input[type="text"],
.prop-field input[type="number"],
.prop-field select,
.prop-field textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  transition: all var(--transition-fast);
}

.prop-field input:focus,
.prop-field select:focus,
.prop-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.prop-field select {
  cursor: pointer;
}

.prop-field textarea {
  resize: vertical;
  min-height: 60px;
}

.input-with-unit {
  display: flex;
  align-items: center;
}

.input-with-unit input {
  flex: 1;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  border-right: none;
}

.input-with-unit .unit {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Checkbox Row */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.checkbox-row input {
  accent-color: var(--accent);
}

/* Alignment Buttons */
.alignment-buttons,
.text-align-buttons {
  display: flex;
  gap: 4px;
}

.align-btn,
.text-align-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.align-btn:hover,
.text-align-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text);
}

.align-btn.active,
.text-align-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.align-divider {
  width: 1px;
  background: var(--border);
  margin: 0 4px;
}

/* Color Input */
.color-input-row {
  display: flex;
  gap: 8px;
}

.color-input-row input[type="color"] {
  width: 40px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--bg-surface);
}

.color-input-row input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.color-input-row input[type="color"]::-webkit-color-swatch {
  border-radius: 3px;
  border: none;
}

.color-input-row input[type="text"] {
  flex: 1;
  text-transform: uppercase;
  font-family: 'Roboto Mono', monospace;
  font-size: 0.8rem;
}

/* Slider Row */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider-row input[type="range"] {
  flex: 1;
  height: 4px;
  background: var(--bg-surface);
  border-radius: 2px;
  -webkit-appearance: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

.slider-value {
  min-width: 40px;
  text-align: right;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Collapsible Section */
.prop-section-collapsible {
  margin-bottom: 20px;
}

.prop-section-collapsible summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.prop-section-collapsible summary::before {
  content: '▶';
  font-size: 0.6rem;
  color: var(--text-muted);
  transition: transform var(--transition-fast);
}

.prop-section-collapsible[open] summary::before {
  transform: rotate(90deg);
}

.prop-section-content {
  padding-top: 10px;
}

/* Background Type Buttons */
.bg-type-buttons {
  display: flex;
  gap: 8px;
}

.bg-type-btn {
  flex: 1;
  padding: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.bg-type-btn:hover {
  background: var(--bg-surface-hover);
}

.bg-type-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Upload Area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.upload-area:hover {
  border-color: var(--accent);
  background: rgba(255, 69, 0, 0.05);
}

.upload-area.drag-over {
  border-color: var(--accent);
  background: rgba(255, 69, 0, 0.1);
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.upload-icon {
  font-size: 1.5rem;
}

.upload-preview {
  position: relative;
}

.upload-preview img {
  max-width: 100%;
  max-height: 120px;
  border-radius: var(--radius-sm);
}

.remove-bg-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  background: var(--error);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 1rem;
  cursor: pointer;
}

/* ===== Modals ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-preview {
  max-width: 400px;
}

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

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-surface);
  color: var(--text);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

/* Stat Picker Grid */
.stat-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-pick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.stat-pick-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent);
}

.stat-icon {
  font-size: 1.5rem;
}

.stat-name {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Preview Canvas */
.preview-canvas-wrapper {
  display: flex;
  justify-content: center;
}

#previewCanvas {
  max-width: 100%;
  max-height: 60vh;
  border-radius: var(--radius-sm);
}

/* ===== Strava Modal ===== */
.modal-strava {
  max-width: 450px;
  max-height: 70vh;
}

.strava-status {
  text-align: center;
  padding: 20px;
}

.strava-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.strava-not-connected {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.strava-icon {
  font-size: 2.5rem;
}

.strava-not-connected p {
  color: var(--text-secondary);
  margin: 0;
}

.strava-activities {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.strava-activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.strava-activity-item:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent);
}

.strava-activity-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border-radius: 50%;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.strava-activity-info {
  flex: 1;
  min-width: 0;
}

.strava-activity-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strava-activity-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.strava-activity-stats {
  text-align: right;
  flex-shrink: 0;
}

.strava-activity-distance {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.strava-activity-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ===== Toast Notifications ===== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: toastIn 0.3s ease;
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--error);
}

.toast-icon {
  font-size: 1.1rem;
}

.toast-message {
  font-size: 0.9rem;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  :root {
    --toolbar-width: 140px;
  }
}

@media (max-width: 900px) {
  :root {
    --toolbar-width: 72px;
    --properties-width: 240px;
  }
  
  .tool-btn .tool-label {
    display: none;
  }
  
  .tool-btn {
    flex-direction: column;
    padding: 10px 4px;
    gap: 4px;
  }
  
  .activity-source-btn {
    flex-direction: column;
    padding: 10px 6px;
    text-align: center;
    gap: 4px;
  }
  
  .activity-source-btn .source-label {
    font-size: 0.6rem;
  }
  
  .header-right .btn span {
    display: none;
  }
  
  .tool-section-title {
    font-size: 0.55rem;
    padding: 2px 4px;
  }
}

@media (max-width: 700px) {
  /* Mobile Layout: Full width canvas, bottom sheets */
  .builder-main {
    flex-direction: column;
  }
  
  .toolbar-left {
    width: 100%;
    flex-direction: row;
    padding: 8px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    gap: 4px;
  }
  
  .tool-section {
    flex-direction: row;
    flex-shrink: 0;
    gap: 4px;
  }
  
  .tool-section-title {
    display: none;
  }
  
  .tool-divider {
    width: 1px;
    height: 40px;
    margin: 0 4px;
  }
  
  .tool-btn {
    flex-direction: column;
    padding: 8px;
    min-width: 50px;
  }
  
  .tool-btn .tool-label {
    display: none;
  }
  
  .activity-section {
    flex-direction: row;
    align-items: center;
  }
  
  .activity-sources {
    flex-direction: row;
    gap: 4px;
  }
  
  .activity-source-btn {
    padding: 8px;
    min-width: auto;
    flex-direction: column;
    gap: 2px;
  }
  
  .activity-source-btn .source-label {
    font-size: 0.55rem;
  }
  
  .activity-loaded {
    padding: 8px 10px;
  }
  
  .activity-name {
    font-size: 0.75rem;
  }
  
  .activity-stats {
    font-size: 0.6rem;
  }
  
  /* Layers panel hidden on mobile */
  .layers-panel {
    display: none;
  }
  
  /* Canvas takes full remaining space */
  .canvas-area {
    flex: 1;
    padding: 10px;
    padding-bottom: 70px;
  }
  
  /* Properties panel as bottom sheet */
  .properties-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    max-height: 60vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 100;
    transform: translateY(100%);
    transition: transform var(--transition-normal);
  }
  
  .properties-panel.show {
    transform: translateY(0);
  }
  
  /* Mobile bottom action bar */
  .mobile-action-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    padding: 10px 16px;
    gap: 10px;
    z-index: 50;
  }
  
  .mobile-action-bar .btn {
    flex: 1;
  }
  
  /* Header adjustments */
  .builder-header {
    padding: 8px 12px;
  }
  
  .header-right .btn span {
    display: none;
  }
  
  .template-name-input {
    max-width: 120px;
    font-size: 0.9rem;
  }
}

@media (max-width: 400px) {
  .activity-source-btn .source-label {
    display: none;
  }
  
  .tool-btn .tool-icon {
    font-size: 1.1rem;
  }
}

/* ========================================
   EXPORT BUTTONS & PROGRESS
   ======================================== */
.export-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  padding: 0 8px;
}

.export-btn {
  flex: 1;
  padding: 14px 20px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.export-progress {
  margin-top: 16px;
  padding: 16px;
  background: var(--surface);
  border-radius: 8px;
}

.progress-bar {
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s;
  border-radius: 4px;
}

.progress-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  display: block;
}

@media (max-width: 500px) {
  .export-actions {
    flex-direction: column;
  }
}

/* =====================================================
   V2.0 ADDITIONS - Mobile Fixes, Photo Upload, Map
   ===================================================== */

/* Mobile Panel Close Button */
.panel-close-btn {
  display: none;
  position: absolute;
  top: 8px;
  right: 12px;
  width: 32px;
  height: 32px;
  background: var(--bg-surface-hover);
  border: none;
  border-radius: 50%;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  z-index: 10;
  align-items: center;
  justify-content: center;
}

.panel-drag-handle {
  display: none;
  width: 40px;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  margin: 8px auto 12px;
}

/* Save Status */
.save-status.unsaved {
  color: var(--warning);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 70px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  transform: translateX(120%);
  transition: transform 0.3s ease;
  max-width: 300px;
}

.toast.show {
  transform: translateX(0);
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--error); }
.toast-info { border-left: 4px solid var(--accent); }

/* ===== MOBILE RESPONSIVE V2 ===== */
@media (max-width: 700px) {
  .panel-close-btn {
    display: flex;
  }
  
  .panel-drag-handle {
    display: block;
  }
  
  /* CRITICAL: Show tool labels on mobile */
  .tool-btn .tool-label {
    display: block !important;
    font-size: 0.55rem;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 48px;
    text-align: center;
  }
  
  .tool-btn {
    min-width: 50px;
    padding: 6px 4px;
    flex-direction: column;
    align-items: center;
  }
  
  .tool-btn .tool-icon {
    font-size: 18px;
  }
  
  /* Activity buttons labels visible */
  .activity-source-btn .source-label {
    display: block !important;
    font-size: 0.5rem;
  }
  
  /* Properties panel improvements */
  .properties-panel {
    max-height: 40vh;
    overflow-y: auto;
    padding-top: 20px;
  }
  
  .properties-panel.show {
    box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  }
  
  /* Touch-friendly inputs */
  .prop-field input[type="number"],
  .prop-field input[type="text"],
  .prop-field select {
    min-height: 40px;
    font-size: 16px;
  }
  
  .checkbox-row {
    min-height: 40px;
    display: flex;
    align-items: center;
  }
  
  .checkbox-row input[type="checkbox"] {
    width: 22px;
    height: 22px;
    margin-right: 10px;
  }
  
  /* Canvas controls fixed position */
  .canvas-controls {
    position: fixed;
    bottom: 55px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 6px 12px;
    z-index: 40;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  }
  
  /* Toast on mobile */
  .toast-container {
    top: auto;
    bottom: 110px;
    left: 16px;
    right: 16px;
  }
  
  .toast {
    max-width: none;
    transform: translateY(100px);
  }
  
  .toast.show {
    transform: translateY(0);
  }
}

@media (max-width: 400px) {
  .tool-btn {
    min-width: 44px;
    padding: 5px 3px;
  }
  
  .tool-btn .tool-label {
    font-size: 0.5rem;
    max-width: 40px;
  }
  
  .tool-btn .tool-icon {
    font-size: 16px;
  }
}

/* ===== COLLAGE & MASONRY STYLES ===== */

.bg-type-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.bg-type-btn {
  flex: 1;
  min-width: 60px;
  padding: 8px 12px;
  font-size: 12px;
}

/* Collage Layout Selector */
.collage-layouts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.collage-layout-btn {
  aspect-ratio: 1;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  padding: 6px;
  color: var(--text-muted);
}

.collage-layout-btn:hover {
  border-color: var(--accent);
  color: var(--text-secondary);
}

.collage-layout-btn.active {
  border-color: var(--accent);
  background: rgba(255, 69, 0, 0.1);
  color: var(--accent);
}

.collage-layout-btn svg {
  width: 100%;
  height: 100%;
}

/* Collage/Masonry Upload Area */
.collage-upload-area,
.masonry-upload-area {
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: 8px;
}

.collage-thumbs,
.masonry-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.collage-thumb,
.masonry-thumb {
  position: relative;
  width: 50px;
  height: 50px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.collage-thumb img,
.masonry-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.collage-thumb .remove-thumb,
.masonry-thumb .remove-thumb {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: rgba(0,0,0,0.7);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.collage-thumb:hover .remove-thumb,
.masonry-thumb:hover .remove-thumb {
  opacity: 1;
}

.collage-add-btn,
.masonry-add-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.collage-add-btn:hover,
.masonry-add-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent);
  color: var(--text);
}

.collage-add-btn span:first-child,
.masonry-add-btn span:first-child {
  font-size: 18px;
  color: var(--accent);
}

/* Masonry columns select */
#masonryColumns {
  width: 100%;
}

@media (max-width: 700px) {
  .collage-layouts {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .collage-thumb,
  .masonry-thumb {
    width: 40px;
    height: 40px;
  }
}

/* ===== SHAPE SELECTOR MODAL ===== */
.shape-selector-modal,
.emoji-picker-modal,
.title-style-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.shape-selector-content,
.emoji-picker-content,
.title-style-content {
  background: var(--bg-elevated, #1a1a1a);
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
}

.shape-selector-content h3,
.emoji-picker-content h3,
.title-style-content h3 {
  margin: 0 0 16px;
  font-size: 1.1rem;
  color: #fff;
}

.shape-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.shape-option {
  background: var(--surface, #2a2a2a);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: #fff;
  transition: all 0.2s;
}

.shape-option:hover {
  border-color: var(--accent, #ff4500);
  background: var(--surface-hover, #333);
}

.shape-option svg {
  width: 40px;
  height: 40px;
  color: var(--accent, #ff4500);
}

.shape-option span {
  font-size: 0.75rem;
}

.shape-photo-option {
  margin-top: 16px;
  padding: 12px;
  background: var(--surface, #2a2a2a);
  border-radius: 8px;
}

.shape-photo-option label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  cursor: pointer;
}

/* Emoji Picker */
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
}

.emoji-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}

.emoji-btn:hover {
  background: rgba(255,255,255,0.1);
}

/* Title Styles */
.title-styles-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.title-style-btn {
  background: var(--surface, #2a2a2a);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 16px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.title-style-btn:hover {
  border-color: var(--accent, #ff4500);
}

.title-preview {
  font-size: 32px;
}

.style-name {
  font-size: 0.7rem;
  color: #999;
}

.modal-buttons {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.btn-cancel {
  background: var(--surface, #2a2a2a);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
}

.btn-cancel:hover {
  background: var(--surface-hover, #333);
}


/* ===== MULTI-STATS MODAL ===== */
.multistats-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.multistats-content {
  background: var(--bg-elevated, #1a1a1a);
  border-radius: 16px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.multistats-content h3,
.multistats-content h4 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: #fff;
}

.stats-checkboxes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px;
  background: var(--surface, #2a2a2a);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  color: #fff;
  font-size: 0.85rem;
}

.stat-checkbox:hover {
  background: var(--surface-hover, #333);
}

.stat-checkbox:has(input:checked) {
  background: var(--accent, #ff4500);
}

.stat-checkbox input {
  display: none;
}

.stat-icon {
  font-size: 1.1em;
}

.stat-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layout-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.layout-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: var(--surface, #2a2a2a);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  color: #fff;
}

.layout-option:hover {
  border-color: rgba(255,255,255,0.3);
}

.layout-option.selected {
  border-color: var(--accent, #ff4500);
  background: rgba(255,69,0,0.1);
}

.layout-option input {
  display: none;
}

.layout-icon {
  font-size: 1.5em;
}

.layout-label {
  font-size: 0.7rem;
  text-align: center;
}

@media (max-width: 500px) {
  .stats-checkboxes {
    grid-template-columns: repeat(2, 1fr);
  }
  .layout-options {
    grid-template-columns: repeat(2, 1fr);
  }
}
