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

/* Prompt history */
.prompt-history { margin-top: 6px; border: 1px solid var(--border); border-radius: var(--radius); overflow: visible; }
.prompt-history-inner.scrollable { max-height: 196px; overflow-y: auto; }
.history-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.history-item:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom: none; }
.history-item:only-child { border-radius: var(--radius); }
.prompt-history.hidden { display: none; }
.history-item { position: relative; display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.history-item:last-child { border-bottom: none; }
.history-item:hover { background: var(--bg); }
.history-text { flex: 1; font-size: 13px; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-del { flex-shrink: 0; background: none; border: none; cursor: pointer; color: var(--muted); font-size: 11px; padding: 2px 4px; border-radius: 4px; line-height: 1; }
.history-del:hover { color: var(--danger); background: #fdecea; }
.history-tooltip { display: none; position: fixed; background: #1a1a1a; color: #fff; padding: 8px 12px; border-radius: 8px; font-size: 12px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; max-width: 320px; z-index: 1000; pointer-events: none; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.history-item:hover .history-tooltip { display: block; }

:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --border: #e0e0e0;
  --border-hover: #bbb;
  --accent: #1a1a1a;
  --accent-hover: #333;
  --muted: #888;
  --danger: #e53935;
  --success: #2e7d32;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--accent);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.tagline {
  font-size: 13px;
  color: var(--muted);
}

/* Main layout */
main {
  display: grid;
  grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  flex: 1;
  align-items: start;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  min-width: 0;
}

.panel { min-width: 0; }

@media (max-width: 900px) {
  main { grid-template-columns: minmax(0, 1fr); padding: 12px; gap: 12px; }
}

@media (max-width: 480px) {
  main { padding: 8px; gap: 8px; }
  .panel { padding: 14px; }
}

/* Panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; }
.btn-optimize { font-size: 12px; font-weight: 600; padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--accent); cursor: pointer; transition: border-color 0.15s, background 0.15s; font-family: var(--font); white-space: nowrap; }
.btn-optimize:hover:not(:disabled) { border-color: var(--accent); background: var(--bg); }
.btn-optimize:disabled { opacity: 0.5; cursor: not-allowed; }

/* 프롬프트 추출 히스토리 */
.extract-history { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.extract-history.hidden { display: none; }
.extract-thumb { position: relative; width: 48px; height: 48px; border-radius: 6px; overflow: visible; border: 1px solid var(--border); flex-shrink: 0; cursor: pointer; }
.extract-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 5px; }
.extract-thumb:hover { border-color: var(--accent); }

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.required { color: var(--danger); margin-left: 2px; }
.optional { font-weight: 400; color: var(--muted); }

textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 14px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
  background: var(--surface);
  color: var(--accent);
  line-height: 1.5;
}

textarea:focus { border-color: var(--accent); }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-height: 100px;
  position: relative;
  overflow: hidden;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: #fafafa;
}

.dropzone-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  min-height: 100px;
}

.dropzone-placeholder svg { opacity: 0.4; }
.dropzone-placeholder p { font-size: 13px; line-height: 1.5; }
.dropzone-placeholder span { font-size: 12px; color: var(--accent); text-decoration: underline; }

/* Product preview */
.dropzone-preview {
  position: relative;
  width: 100%;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f8f8;
}

.dropzone-preview img {
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
  border-radius: 4px;
}

.remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: rgba(0,0,0,0.5);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.remove-btn:hover { background: rgba(0,0,0,0.7); }

/* Reference thumbs */
.dropzone-multi { min-height: 100px; }

.ref-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
}

.product-history {
  margin-top: 8px;
  padding: 0;
}

.ref-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.ref-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ref-thumb .remove-btn {
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  font-size: 9px;
}

.ref-add {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}

.ref-add:hover { border-color: var(--accent); color: var(--accent); }

/* Count control */
.field-count { flex-direction: row; align-items: center; justify-content: space-between; }

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

.count-control button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: border-color 0.15s;
}

.count-control button:hover { border-color: var(--accent); }

.count-control input {
  width: 56px;
  height: 32px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  outline: none;
}

.count-control input:focus { border-color: var(--accent); }
.count-control input::-webkit-inner-spin-button,
.count-control input::-webkit-outer-spin-button { -webkit-appearance: none; }

/* Generate button */
.btn-generate {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  letter-spacing: 0.2px;
}

.btn-generate:hover:not(:disabled) { background: var(--accent-hover); }
.btn-generate:disabled { opacity: 0.45; cursor: not-allowed; }

/* Results panel */
.results-panel { min-height: 500px; }

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-bar {
  font-size: 13px;
  color: var(--muted);
}

.status-bar.running { color: var(--accent); font-weight: 500; }
.status-bar.done { color: var(--success); font-weight: 500; }
.status-bar.error { color: var(--danger); }

.btn-download {
  padding: 8px 16px;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
}

.btn-download:hover { border-color: var(--accent); background: #f8f8f8; }

/* Image grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.grid-empty {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  color: var(--muted);
  font-size: 14px;
}

/* Image card */
.img-card {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  background: #f0f0f0;
  border: 1px solid var(--border);
}

.img-card.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

.img-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.img-card .card-download {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  background: rgba(255,255,255,0.9);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  color: var(--accent);
  text-decoration: none;
}

.img-card:hover .card-download { opacity: 1; }
.img-card .card-download:hover { background: white; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.lightbox.hidden { display: none; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.85); }
.lightbox-content { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 16px; max-width: 90vw; max-height: 90vh; }
.lightbox-content img { max-width: 100%; max-height: calc(90vh - 70px); object-fit: contain; border-radius: 8px; display: block; }
.lightbox-actions { display: flex; gap: 12px; }
.lightbox-download { display: flex; align-items: center; gap: 8px; padding: 10px 20px; background: var(--accent); color: #fff; text-decoration: none; border-radius: 8px; font-size: 14px; font-weight: 600; }
.lightbox-download:hover { background: var(--accent-hover); }
.lightbox-close { display: flex; align-items: center; gap: 6px; padding: 10px 20px; background: rgba(255,255,255,0.15); color: #fff; border: 1px solid rgba(255,255,255,0.3); border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.lightbox-close:hover { background: rgba(255,255,255,0.25); }

.img-card.failed {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fef2f2;
  border-color: #fecaca;
}

.img-card.failed span {
  font-size: 12px;
  color: var(--danger);
  text-align: center;
  padding: 8px;
}

.img-card .card-index {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 11px;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  opacity: 0.8;
}

/* Image history */
.img-history-section { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 16px; }
.img-history-section.hidden { display: none; }
.img-history-header { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.img-history-group { margin-bottom: 20px; }
.img-history-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; min-width: 0; }
.img-history-date { font-size: 11px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.img-history-prompt { font-size: 12px; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.img-history-dl { flex-shrink: 0; display: flex; align-items: center; padding: 4px; color: var(--muted); border-radius: 4px; }
.img-history-dl:hover { color: var(--accent); background: var(--bg); }
.img-history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 6px; }
.img-history-thumb { position: relative; aspect-ratio: 1/1; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.img-history-thumb img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; display: block; }
.img-history-thumb .card-download { position: absolute; bottom: 4px; right: 4px; width: 24px; height: 24px; background: rgba(255,255,255,0.9); border-radius: 4px; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.15s; color: var(--accent); text-decoration: none; }
.img-history-thumb:hover .card-download { opacity: 1; }

.hidden { display: none !important; }
