/* App Like Layout - High Density */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

:root {
  --bg-app: #f1f5f9;
  --bg-panel: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f172a;
  --primary-fg: #ffffff;
  --accent: #f8fafc;
  --radius: 0.5rem;
  --header-height: 50px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Inter", sans-serif;
  color: var(--text-main);
  background-color: var(--bg-app);
  margin: 0;
  height: 100vh;
  overflow: hidden; /* Prevent body scroll, use inner scroll */
  display: flex;
  flex-direction: column;
}

/* Compact Header */
.compact-header {
  height: var(--header-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.header-inner {
  max-width: 100%;
  height: 100%;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo h1 {
  font-size: 1.1rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.nav-link {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
}
.nav-link:hover {
  color: var(--primary);
}

/* Layout Wrapper */
#wrapper {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
}

.editor-layout {
  width: 100%;
  max-width: 1600px;
  display: flex;
  height: 100%;
}

/* Left/Center: Preview Panel */
.preview-panel {
  flex: 1;
  background-color: #e2e8f0; /* Darker bg for contrast */
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
/* Subtle pattern for preview bg */
.preview-panel {
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 20px 20px;
}

.preview-card {
  background: white;
  padding: 1rem;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.15);
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.canvas-wrapper {
  position: relative;
  max-width: 100%;
  max-height: calc(100vh - 180px); /* Leave room for header/buttons */
  overflow: auto;
  display: flex;
  justify-content: center;
  background: repeating-conic-gradient(#f1f5f9 0% 25%, white 0% 50%) 50% / 20px
    20px;
}

#result-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.preview-empty-state {
  padding: 3rem;
  text-align: center;
  color: var(--text-muted);
}
.empty-icon {
  opacity: 0.2;
  margin-bottom: 1rem;
}
.preview-empty-state h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
}
.preview-empty-state p {
  font-size: 0.9rem;
  margin: 0;
}

.preview-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 1rem;
}
.hint-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Right: Controls Panel */
.controls-panel {
  width: 400px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  z-index: 20;
}

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

.control-group {
  border-bottom: 1px solid var(--border);
}
.group-header {
  padding: 0.75rem 1rem;
  background: #f8fafc;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.collapse-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.collapse-btn:hover {
  background-color: var(--border);
  color: var(--text-main);
}
.step-badge {
  background: var(--primary);
  color: white;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.group-content {
  padding: 1.25rem 1.25rem 0.5rem 1.25rem;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease, opacity 0.3s ease;
  max-height: 2000px;
  opacity: 1;
}

.group-content.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  pointer-events: none;
}

/* Scrollable Form Content */
.scrollable-content {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 1rem;
}

/* Micro Form Elements */
.form-row {
  margin-bottom: 1rem;
}
.form-row.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.micro-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.compact-select,
input[type="text"],
input[type="number"],
select {
  width: 100%;
  height: 36px;
  font-size: 0.9rem;
  padding: 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text-main);
  font-family: inherit;
}
.compact-select:focus,
input:focus,
select:focus {
  border-color: var(--primary);
  outline: none;
}

/* Loading Spinners Mini */
.select-wrapper {
  position: relative;
  width: 100%;
}
.mini-spinner {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border: 2px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  display: none; /* JS toggles this */
  animation: spin 0.6s linear infinite;
}

/* Tabs */
.visual-tabs {
  display: flex;
  gap: 4px;
  padding: 0 1rem 0 1rem;
  margin-top: -1px; /* Align with border */
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  border: none;
  background: transparent;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn:hover {
  color: var(--text-main);
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-pane {
  display: none;
  padding: 1rem 0;
}
.tab-pane.active {
  display: block;
}

/* Grid Selectors High Density */
.visual-selector {
  display: grid;
  gap: 0.5rem;
}
.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}
.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.visual-item {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: #fff;
  position: relative;
  overflow: hidden;
}
.visual-item:hover {
  border-color: var(--text-muted);
}
.visual-item.selected {
  border-color: var(--primary);
  background: var(--bg-app);
  box-shadow: inset 0 0 0 1px var(--primary);
}
.visual-item img {
  width: 80%;
  height: 80%;
  object-fit: contain;
}
.visual-item span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Footer Actions */
.controls-footer {
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}
.big-btn {
  width: 100%;
  height: 48px;
  font-size: 1rem;
  font-weight: 600;
}

/* Button Styles */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
}
.button.primary {
  background: var(--primary);
  color: white;
}
.button.primary:hover {
  background: #1e293b;
}
.button.outline {
  background: white;
  border-color: var(--border);
  color: var(--text-main);
  height: 36px;
  padding: 0 1rem;
  font-size: 0.85rem;
}
.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #cbd5e1;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

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

/* Toggle Switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
}

.toggle-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-main);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

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

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

.toggle-switch input:focus + .toggle-slider {
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.2);
}

.toggle-switch:hover .toggle-slider {
  background-color: #94a3b8;
}

.toggle-switch input:checked:hover + .toggle-slider {
  background-color: #1e293b;
}

/* Mobile Adapt */
@media (max-width: 900px) {
  .editor-layout {
    flex-direction: column-reverse;
    height: auto;
  }
  .controls-panel {
    width: 100%;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .preview-panel {
    min-height: 400px;
    padding: 1rem;
  }
  body {
    overflow: auto;
    height: auto;
  }
  .canvas-wrapper {
    max-height: 60vh;
  }
}
