:root {
  --primary-color: #2563eb;
  --bg-color: #f3f4f6;
  --sidebar-width: 320px;
  --right-sidebar-width: 300px;
  --header-height: 64px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  height: 100vh;
  overflow: hidden;
  color: #374151;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

/* --- Top Bar --- */
#top-bar {
  height: var(--header-height);
  background: white;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 30;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #6b7280;
  font-size: 14px;
  font-weight: 500;
  transition: color 0.2s;
}

.back-btn:hover {
  color: #111827;
}

.logo-divider {
  width: 1px;
  height: 24px;
  background: #e5e7eb;
}

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

.logo-icon {
    height: 32px;
    width: auto;
    object-fit: contain;
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
}

.top-bar-center {
  display: flex;
  align-items: center;
  gap: 12px;
}

.step-item {
  font-size: 14px;
  color: #9ca3af;
  font-weight: 500;
}

.step-item.active {
  color: var(--primary-color);
  font-weight: 600;
}

.step-line {
  width: 32px;
  height: 1px;
  background: #e5e7eb;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.history-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 12px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: #f3f4f6;
  color: #111827;
}

.btn-icon.danger:hover {
  background: #fee2e2;
  color: #ef4444;
}

/* --- Main Content Layout --- */
#main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Sidebar (Left) */
#sidebar {
  width: var(--sidebar-width);
  background: white;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.tabs {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
}

.tab-btn {
  flex: 1;
  padding: 12px 0;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s;
  gap: 4px;
}

.tab-btn:hover {
  background-color: #f9fafb;
}

.tab-btn.active {
  color: var(--primary-color);
  background-color: #eff6ff;
  border-bottom: 2px solid var(--primary-color);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* Right Sidebar */
#right-sidebar {
  width: var(--right-sidebar-width);
  background: white;
  border-left: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.right-panel-section {
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.right-panel-section.footer-section {
  border-bottom: none;
  margin-top: auto;
  background: #f9fafb;
  border-top: 1px solid #e5e7eb;
}

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

.section-header h3 {
  font-size: 14px;
  font-weight: 700;
  color: #111827;
}

.layer-count {
  font-size: 12px;
  color: #9ca3af;
}

.layer-list {
  flex: 1;
  overflow-y: auto;
  min-height: 100px;
}

.empty-layers {
  text-align: center;
  padding: 32px 0;
  color: #9ca3af;
  font-size: 12px;
}

/* Layer Item */
.layer-item {
  display: flex;
  align-items: center;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  margin-bottom: 4px;
  cursor: pointer;
  transition: all 0.2s;
  background: white;
}

.layer-item:hover {
  background: #f9fafb;
}

.layer-item.active {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.layer-thumb {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  border: 1px solid #e5e7eb;
  margin-right: 8px;
  object-fit: cover;
  background: #f3f4f6;
}

.layer-info {
  flex: 1;
  overflow: hidden;
}

.layer-name {
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-type {
  font-size: 11px;
  color: #9ca3af;
}

.layer-item.dragging {
  opacity: 0.5;
  background: #f3f4f6;
  border: 1px dashed #3b82f6;
}

.layer-item.drag-over {
  border-top: 2px solid #3b82f6;
}

.layer-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.layer-item:hover .layer-actions,
.layer-item.active .layer-actions {
  opacity: 1;
}

.layer-action-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layer-action-btn:hover {
  background: #e5e7eb;
  color: #111827;
}

.layer-action-btn.delete:hover {
  background: #fee2e2;
  color: #ef4444;
}

/* Export Settings */
.export-settings h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
}

.setting-group {
  margin-bottom: 16px;
}

.setting-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
  margin-bottom: 8px;
}

.btn-group {
  display: flex;
  background: #e5e7eb;
  padding: 2px;
  border-radius: 8px;
}

.option-btn {
  flex: 1;
  padding: 6px 0;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.2s;
}

.option-btn.active {
  background: white;
  color: var(--primary-color);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* --- Main Canvas Area --- */
#main-area {
  flex: 1;
  position: relative;
  background-color: #f3f4f6;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvas-bg {
  position: absolute;
  inset: 0;
  opacity: 0.2;
  pointer-events: none;
  background-image: linear-gradient(45deg, #ccc 25%, transparent 25%), 
                    linear-gradient(-45deg, #ccc 25%, transparent 25%), 
                    linear-gradient(45deg, transparent 75%, #ccc 75%), 
                    linear-gradient(-45deg, transparent 75%, #ccc 75%);
  background-size: 20px 20px;
}

#canvas-wrapper {
  background: white;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

#empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  font-weight: 500;
  pointer-events: none;
  z-index: 10;
}

/* Common UI Components */
.section-title {
  font-size: 14px;
  font-weight: 700;
  color: #111827;
  margin-bottom: 12px;
}

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

.asset-btn {
  aspect-ratio: 1;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  background: #f3f4f6;
  transition: all 0.2s;
}
.asset-btn:hover { border-color: var(--primary-color); background-color: #eff6ff; }
.asset-btn img { width: 100%; height: 100%; object-fit: cover; }
.asset-btn.decor img { object-fit: contain; padding: 8px; }

.upload-box {
  border: 2px dashed #d1d5db;
  border-radius: 12px;
  height: 128px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background-color: #f9fafb;
  transition: 0.2s;
}
.upload-box:hover { background-color: #f3f4f6; border-color: var(--primary-color); }

.upload-mini {
  aspect-ratio: 1;
  border: 2px dashed #d1d5db;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #6b7280;
}
.upload-mini:hover { background-color: #f9fafb; color: var(--primary-color); border-color: var(--primary-color); }

.control-group { margin-bottom: 16px; }

.btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:hover { background-color: #f9fafb; }

.btn-primary { background-color: var(--primary-color); color: white; border: none; }
.btn-primary:hover { background-color: #1d4ed8; }
.btn-primary:disabled { background-color: #93c5fd; cursor: not-allowed; }

.btn-danger { background-color: #ef4444; color: white; border: none; }
.btn-danger:hover { background-color: #dc2626; }

.btn-block { width: 100%; }

.input-text {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 14px;
}
.input-text:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 2px rgba(37,99,235,0.2); }

.slider-container { margin-bottom: 12px; }
.slider-header { display: flex; justify-content: space-between; margin-bottom: 4px; font-size: 12px; color: #4b5563; }
.slider-input { width: 100%; accent-color: var(--primary-color); }

.color-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
.color-btn { aspect-ratio: 1; border-radius: 50%; border: 1px solid #e5e7eb; cursor: pointer; padding: 0; }
.color-btn.active { ring: 2px solid var(--primary-color); border-color: transparent; box-shadow: 0 0 0 2px var(--primary-color); }

.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* Mobile Controls */
#mobile-controls { display: none; }

/* Responsive */
@media (max-width: 768px) {
  #top-bar { padding: 0 12px; }
  .top-bar-center { display: none; }
  .top-bar-left .logo-text { display: none; }
  #right-sidebar { display: none; } /* Hide right sidebar on mobile for now */
  
  #sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60vh;
    border-right: none;
    border-top: 1px solid #e5e7eb;
    transform: translateY(100%);
    transition: transform 0.3s ease-in-out;
    z-index: 50;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
    border-radius: 16px 16px 0 0;
  }
  #sidebar.open { transform: translateY(0); }
  
  #mobile-controls {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e5e7eb;
    padding: 12px;
    justify-content: space-around;
    z-index: 40;
  }

  .mobile-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: none;
    border: none;
    font-size: 10px;
    color: #6b7280;
    gap: 4px;
  }
  .mobile-btn.active { color: var(--primary-color); }
  
  .tabs { display: none; }
  
  #mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 45;
    display: none;
  }
  #mobile-overlay.visible { display: block; }
}

/* Mobile Drag Styles */
.layer-ghost {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    opacity: 0.9;
    background: white;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--primary-color);
    border-radius: 6px;
    padding: 8px;
    display: flex;
    align-items: center;
    width: 280px; /* Fixed width for ghost */
}

.layer-handle {
    cursor: grab;
    padding: 4px;
    color: #9ca3af;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none; /* Prevent scroll when dragging */
}

.layer-handle:active {
    cursor: grabbing;
    color: var(--primary-color);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

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

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
    color: #111827;
}

.modal-message {
    color: #4b5563;
    font-size: 14px;
    margin-bottom: 24px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}
