:root {
  --bg-primary: #0d0f15;
  --bg-secondary: #151821;
  --bg-tertiary: #1e2230;
  --bg-hover: #282e42;
  --surface-border: #2b3247;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  --accent-pink: #ec4899;
  --accent-purple: #8b5cf6;
  --accent-amber: #f59e0b;
  --accent-emerald: #10b981;
  
  --primary-gradient: linear-gradient(135deg, #ec4899 0%, #8b5cf6 50%, #3b82f6 100%);
  --warm-gradient: linear-gradient(135deg, #f59e0b 0%, #ec4899 100%);
  --gold-gradient: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 24px rgba(236, 72, 153, 0.25);
  
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--surface-border);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-purple);
}

/* Header */
.app-header {
  height: 56px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 20;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  background: var(--primary-gradient);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
}

.brand-logo svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(90deg, #fff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  background: rgba(236, 72, 153, 0.15);
  color: var(--accent-pink);
  border: 1px solid rgba(236, 72, 153, 0.3);
  border-radius: var(--radius-full);
}

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

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-icon-only {
  padding: 7px 9px;
}

.btn-secondary {
  background: var(--bg-tertiary);
  border-color: var(--surface-border);
  color: var(--text-main);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: #3f4761;
}

.btn-primary {
  background: var(--primary-gradient);
  color: #fff;
  box-shadow: 0 2px 10px rgba(139, 92, 246, 0.3);
}
.btn-primary:hover {
  opacity: 0.93;
  transform: translateY(-1px);
}

.btn-donate {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.15) 0%, rgba(236, 72, 153, 0.15) 100%);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}
.btn-donate:hover {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.25) 0%, rgba(236, 72, 153, 0.25) 100%);
  border-color: #fbbf24;
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.3);
}

.btn-compare {
  background: var(--bg-tertiary);
  border-color: var(--surface-border);
  color: var(--text-muted);
}
.btn-compare.active {
  background: rgba(236, 72, 153, 0.2);
  border-color: var(--accent-pink);
  color: #fff;
}

/* Main Layout */
.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Viewport Area */
.viewport-area {
  flex: 1;
  background-color: var(--bg-primary);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background-image: 
    linear-gradient(45deg, #12151c 25%, transparent 25%),
    linear-gradient(-45deg, #12151c 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #12151c 75%),
    linear-gradient(-45deg, transparent 75%, #12151c 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.canvas-wrapper {
  position: relative;
  max-width: 95%;
  max-height: 95%;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-sm);
  display: inline-block;
  line-height: 0;
}

#mainCanvas {
  max-width: 100%;
  max-height: calc(100vh - 120px);
  object-fit: contain;
  border-radius: var(--radius-sm);
  display: block;
}

/* Floating Info Bar */
.viewport-bottom-bar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(21, 24, 33, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--surface-border);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  box-shadow: var(--shadow-md);
  z-index: 10;
}

.viewport-info-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Empty State / Upload Zone */
.upload-dropzone {
  position: absolute;
  inset: 20px;
  border: 2px dashed var(--surface-border);
  border-radius: var(--radius-lg);
  background: rgba(21, 24, 33, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  cursor: pointer;
  transition: all 0.25s ease;
  z-index: 5;
}

.upload-dropzone.drag-over {
  border-color: var(--accent-pink);
  background: rgba(236, 72, 153, 0.08);
  box-shadow: var(--shadow-glow);
}

.dropzone-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  color: var(--accent-purple);
}

.dropzone-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
  color: #fff;
}

.dropzone-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 420px;
  line-height: 1.5;
  margin-bottom: 20px;
}

.sample-photos-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.sample-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.sample-chip {
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-full);
  font-size: 12px;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sample-chip:hover {
  border-color: var(--accent-purple);
  background: var(--bg-hover);
  color: #fff;
}

/* Sidebar / Controls Panel */
.sidebar-panel {
  width: 380px;
  background-color: var(--bg-secondary);
  border-left: 1px solid var(--surface-border);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 15;
}

/* Tabs Header */
.panel-tabs {
  display: flex;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--surface-border);
  padding: 4px;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  padding: 9px 4px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  color: #fff;
  background: var(--bg-tertiary);
  box-shadow: var(--shadow-sm);
}

.tab-btn svg {
  width: 16px;
  height: 16px;
}

/* Panel Content */
.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
}

/* Presets Tab */
.preset-filter-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.filter-pill {
  padding: 5px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-full);
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.filter-pill.active {
  background: var(--accent-purple);
  border-color: var(--accent-purple);
  color: #fff;
}

.preset-slider-box {
  background: var(--bg-tertiary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 16px;
}

.preset-slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.preset-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  position: relative;
}

.preset-card:hover {
  border-color: #4b557a;
  transform: translateY(-2px);
}

.preset-card.active {
  border-color: var(--accent-pink);
  background: rgba(236, 72, 153, 0.08);
  box-shadow: 0 0 12px rgba(236, 72, 153, 0.2);
}

.preset-preview-thumb {
  width: 100%;
  aspect-ratio: 16/10;
  border-radius: var(--radius-sm);
  background: #111;
  margin-bottom: 8px;
  overflow: hidden;
  position: relative;
}

.preset-preview-thumb canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preset-card-title {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preset-card-tag {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(139, 92, 246, 0.2);
  color: #c4b5fd;
}

.preset-card-desc {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Crop & Transform Tab */
.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin: 16px 0 8px 0;
}
.section-title:first-child {
  margin-top: 0;
}

.aspect-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.aspect-btn {
  padding: 8px 4px;
  background: var(--bg-tertiary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.aspect-btn:hover {
  background: var(--bg-hover);
  color: #fff;
}

.aspect-btn.active {
  border-color: var(--accent-purple);
  background: rgba(139, 92, 246, 0.15);
  color: #fff;
}

.transform-actions-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.resize-inputs-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.input-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
}

.pixel-input {
  background: var(--bg-tertiary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  color: #fff;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
  width: 100%;
}
.pixel-input:focus {
  outline: none;
  border-color: var(--accent-purple);
}

.lock-ratio-btn {
  padding: 8px;
  margin-top: 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
}
.lock-ratio-btn.active {
  color: var(--accent-pink);
  border-color: var(--accent-pink);
}

.crop-control-buttons {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* Adjustments / Lightroom Sliders Tab */
.slider-group {
  margin-bottom: 14px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.slider-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.slider-value {
  font-size: 11px;
  font-family: monospace;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--surface-border);
}

.glow-pill {
  font-size: 9px;
  padding: 1px 5px;
  background: rgba(236, 72, 153, 0.2);
  color: var(--accent-pink);
  border-radius: 4px;
  font-weight: 700;
}

/* Range Inputs */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-border);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s;
}

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

/* Interactive Crop Box Overlay */
.crop-overlay {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  z-index: 10;
}
.crop-overlay.hidden {
  display: none;
}

.crop-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.crop-box {
  position: absolute;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  border: 1.5px solid #fff;
  cursor: move;
  touch-action: none;
}

.crop-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.grid-line {
  position: absolute;
  background: rgba(255, 255, 255, 0.35);
}
.grid-line.h1 { top: 33.33%; left: 0; right: 0; height: 1px; }
.grid-line.h2 { top: 66.66%; left: 0; right: 0; height: 1px; }
.grid-line.v1 { left: 33.33%; top: 0; bottom: 0; width: 1px; }
.grid-line.v2 { left: 66.66%; top: 0; bottom: 0; width: 1px; }

.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 1px solid #000;
  border-radius: 2px;
}
.handle-nw { top: -6px; left: -6px; cursor: nwse-resize; }
.handle-ne { top: -6px; right: -6px; cursor: nesw-resize; }
.handle-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.handle-se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.handle-n  { top: -6px; left: calc(50% - 6px); cursor: ns-resize; }
.handle-s  { bottom: -6px; left: calc(50% - 6px); cursor: ns-resize; }
.handle-w  { left: -6px; top: calc(50% - 6px); cursor: ew-resize; }
.handle-e  { right: -6px; top: calc(50% - 6px); cursor: ew-resize; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 440px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  transform: translateY(12px) scale(0.97);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-backdrop.open .modal-card {
  transform: translateY(0) scale(1);
}

.modal-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-full);
}
.modal-close-btn:hover {
  background: var(--bg-tertiary);
  color: #fff;
}

.modal-header {
  margin-bottom: 18px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* Donation Modal Elements */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #fff;
  padding: 12px;
  border-radius: var(--radius-md);
  margin: 16px 0;
  box-shadow: var(--shadow-md);
}

.qr-image {
  max-width: 240px;
  height: auto;
  border-radius: 8px;
}

.nominal-chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.nominal-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 8px 4px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}
.nominal-btn:hover {
  border-color: #fbbf24;
  color: #fbbf24;
}

.qr-owner-tip {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-tertiary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-top: 12px;
  line-height: 1.4;
  border-left: 2px solid var(--accent-amber);
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Mobile Responsive */
@media (max-width: 860px) {
  body {
    overflow: auto;
  }
  .app-body {
    flex-direction: column;
    overflow: visible;
  }
  .sidebar-panel {
    width: 100%;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--surface-border);
  }
  .canvas-container {
    min-height: 380px;
  }
  #mainCanvas {
    max-height: 50vh;
  }
}
