/* ----------------------------------------------------------------
   Portrait Studio – Design System
   Warm beige/teal palette inspired by StyleStudio mockup
   ---------------------------------------------------------------- */

:root {
  --background: #f6f2ed;
  --foreground: #184b4c;
  --primary: #2c7a7b;
  --primary-foreground: #ffffff;
  --primary-hover: #256768;
  --secondary: #e8f6f6;
  --secondary-foreground: #1f6162;
  --accent: #ffd66b;
  --accent-foreground: #6a4a00;
  --card: #ffffff;
  --card-foreground: #184b4c;
  --border: rgba(0, 0, 0, 0.08);
  --input: #e4e4e7;
  --muted: #f0ede9;
  --muted-foreground: #9aa3a3;
  --destructive: #ef4444;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.05);
}

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

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

/* ----------------------------------------------------------------
   Login Overlay
   ---------------------------------------------------------------- */

.login-overlay {
  position: fixed;
  inset: 0;
  background-color: var(--background);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 400px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-foreground);
  font-size: 22px;
}

.login-logo h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--foreground);
}

.login-card > p {
  color: var(--muted-foreground);
  font-size: 14px;
  margin-bottom: 24px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  padding: 0 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.login-form input:focus {
  border-color: var(--primary);
}

.login-form button {
  height: 44px;
  background: var(--primary);
  color: var(--primary-foreground);
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.2s;
}

.login-form button:hover {
  background: var(--primary-hover);
}

.error-text {
  color: var(--destructive);
  font-size: 13px;
  margin-top: 8px;
}

/* ----------------------------------------------------------------
   App Layout
   ---------------------------------------------------------------- */

.app-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
}

/* Header */
.top-bar {
  height: 64px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background-color: var(--card);
  flex-shrink: 0;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--foreground);
}

/* Workspace */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0; /* Required for flex children to scroll */
  overflow: hidden;
}

/* ----------------------------------------------------------------
   Config Panel (Left)
   ---------------------------------------------------------------- */

.config-panel {
  width: 380px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  background: var(--card);
  flex-shrink: 0;
}

.panel-section-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--foreground);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Style Reference Grid */
.style-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.style-option {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

.style-option img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

.style-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
  color: white;
  font-size: 11px;
  padding: 16px 8px 6px;
  font-weight: 500;
}

/* Upload Box */
.upload-box {
  border: 2px dashed var(--input);
  border-radius: var(--radius-lg);
  padding: 28px 20px;
  text-align: center;
  background-color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.upload-box:hover,
.upload-box.drag-over {
  border-color: var(--primary);
  background-color: var(--secondary);
}

.upload-icon {
  width: 44px;
  height: 44px;
  background: var(--card);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  box-shadow: var(--shadow-sm);
  color: var(--primary);
  font-size: 22px;
}

.upload-text {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--foreground);
}

.upload-hint {
  font-size: 12px;
  color: var(--muted-foreground);
}

/* Upload Preview (multi-file) */
.upload-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.upload-thumb {
  position: relative;
  display: inline-block;
}

.upload-thumb img {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-md);
  object-fit: cover;
}

.upload-thumb .remove-thumb {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--foreground);
  color: white;
  border: 2px solid var(--card);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.upload-add-more {
  width: 80px;
  height: 80px;
  border: 2px dashed var(--input);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted-foreground);
  font-size: 24px;
  transition: all 0.2s;
}

.upload-add-more:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Lightbox Modal */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 40px;
}

.lightbox-overlay img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.lightbox-download {
  position: absolute;
  bottom: 24px;
  right: 24px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  transition: background 0.2s;
}

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

/* Lightbox navigation arrows */
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.3);
}

.lightbox-prev {
  left: 16px;
}

.lightbox-next {
  right: 16px;
}

.lightbox-counter {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  font-weight: 500;
}

/* Generate Button */
.generate-btn {
  background-color: var(--primary);
  color: var(--primary-foreground);
  border: none;
  border-radius: var(--radius-md);
  height: 48px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: auto;
  transition: all 0.2s;
  width: 100%;
}

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

.generate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ----------------------------------------------------------------
   Canvas Area (Right)
   ---------------------------------------------------------------- */

.canvas-area {
  flex: 1;
  min-height: 0;
  background-color: var(--background);
  padding: 28px 32px;
  overflow-y: auto;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted-foreground);
  gap: 8px;
  min-height: 300px;
  padding: 60px 0;
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 8px;
  opacity: 0.6;
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--foreground);
}

.empty-state p {
  font-size: 14px;
}

/* Result Container */
.result-container {
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  margin-bottom: 24px;
}

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

.result-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.result-header span {
  font-size: 13px;
  color: var(--muted-foreground);
}

/* 2x2 Image Grid */
.image-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
}

.image-slot {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  cursor: pointer;
  border: 3px solid transparent;
  border-radius: var(--radius-md);
  transition: border-color 0.2s;
}

.image-slot:hover {
  border-color: var(--muted-foreground);
}

.image-slot.selected {
  border-color: var(--accent);
}

.image-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-slot .check-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  box-shadow: var(--shadow-md);
}

.image-slot.selected .check-badge {
  display: flex;
}

.image-slot .download-badge {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  opacity: 0;
  transition: opacity 0.2s;
  cursor: pointer;
}

.image-slot:hover .download-badge {
  opacity: 1;
}

/* Feedback Bar */
.feedback-bar {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.feedback-bar textarea {
  flex: 1;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
  min-height: 44px;
  max-height: 100px;
  outline: none;
  transition: border-color 0.2s;
}

.feedback-bar textarea:focus {
  border-color: var(--primary);
}

.refine-btn {
  background: var(--primary);
  color: var(--primary-foreground);
  border: none;
  border-radius: var(--radius-md);
  height: 44px;
  padding: 0 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background-color 0.2s;
}

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

.refine-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loading State */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 300px;
  padding: 60px 0;
}

.loading-state p {
  font-size: 14px;
  color: var(--muted-foreground);
  font-weight: 500;
}

.loading-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 400px;
  max-width: 100%;
}

.loading-card {
  aspect-ratio: 4 / 3;
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

/* Pulse animation */
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

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

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--primary-foreground);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

/* ----------------------------------------------------------------
   History Section
   ---------------------------------------------------------------- */

.history-section {
  margin-top: 24px;
  padding-bottom: 24px;
}

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

.history-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.history-grid {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 8px;
}

/* Custom scrollbar for history */
.history-grid::-webkit-scrollbar {
  height: 6px;
}

.history-grid::-webkit-scrollbar-track {
  background: transparent;
}

.history-grid::-webkit-scrollbar-thumb {
  background: var(--input);
  border-radius: 3px;
}

.history-card {
  width: 140px;
  flex-shrink: 0;
  cursor: pointer;
}

.history-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-md);
  object-fit: cover;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
  display: block;
  margin-bottom: 6px;
}

.history-card:hover img {
  border-color: var(--primary);
}

.history-meta {
  font-size: 12px;
  color: var(--foreground);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-date {
  font-size: 11px;
  color: var(--muted-foreground);
}

.history-download {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--primary);
  cursor: pointer;
  text-decoration: none;
  margin-top: 2px;
}

.history-download:hover {
  text-decoration: underline;
}

/* ----------------------------------------------------------------
   Utility Buttons
   ---------------------------------------------------------------- */

.btn-text {
  background: transparent;
  border: none;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  color: var(--muted-foreground);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.btn-text:hover {
  color: var(--foreground);
  background: var(--muted);
}

.btn-danger {
  color: var(--muted-foreground);
}

.btn-danger:hover {
  color: var(--destructive);
  background: #fef2f2;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  color: var(--foreground);
  transition: all 0.2s;
}

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

/* ----------------------------------------------------------------
   Responsive (basic – collapse config panel on narrow screens)
   ---------------------------------------------------------------- */

/* ----------------------------------------------------------------
   Overlay Section (Config Panel)
   ---------------------------------------------------------------- */

.overlay-section {
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.overlay-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.overlay-fields label {
  font-size: 12px;
  font-weight: 600;
  color: var(--foreground);
  margin-top: 4px;
}

.ov-input {
  width: 100%;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  resize: none;
}

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

.logo-upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-filename {
  font-size: 12px;
  color: var(--muted-foreground);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.place-btn {
  background: var(--secondary);
  color: var(--secondary-foreground);
  border: 1px solid var(--primary);
  border-radius: var(--radius-md);
  height: 42px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  transition: all 0.2s;
  width: 100%;
}

.place-btn:hover:not(:disabled) {
  background: var(--primary);
  color: var(--primary-foreground);
}

.place-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ----------------------------------------------------------------
   Editor Mode
   ---------------------------------------------------------------- */

.editor-container {
  margin-bottom: 24px;
}

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

.editor-header h3 {
  font-size: 16px;
  font-weight: 600;
}

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

.editor-canvas {
  position: relative;
  display: inline-block;
  width: 100%;
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  background: #000;
}

.editor-canvas img {
  display: block;
  width: 100%;
  height: auto;
}

/* Overlay Boxes */
.ov-box {
  position: absolute;
  cursor: grab;
  user-select: none;
  z-index: 10;
  max-width: 55%;
}

.ov-box.dragging {
  cursor: grabbing;
  opacity: 0.9;
  z-index: 20;
}

.ov-box-content {
  background: rgba(0, 0, 0, 0.45);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-family: 'Montserrat', sans-serif;
  line-height: 1.4;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.ov-name-box .ov-box-content {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.ov-subtitle-box .ov-box-content {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ov-desc-box .ov-box-content {
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
}

.ov-logo-box {
  width: 80px;
  height: 80px;
}

.ov-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.ov-box-delete {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--destructive);
  color: white;
  border: 2px solid white;
  font-size: 13px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 30;
}

.ov-box:hover .ov-box-delete {
  display: flex;
}

/* ----------------------------------------------------------------
   Responsive
   ---------------------------------------------------------------- */

@media (max-width: 900px) {
  .workspace {
    flex-direction: column;
  }

  .config-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
    overflow-y: auto;
  }

  .canvas-area {
    min-height: 60vh;
  }

  .image-grid {
    gap: 2px;
    padding: 2px;
  }

  .loading-grid {
    width: 280px;
  }
}
