/* AI Image Studio - Dark Theme */
:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #222;
  --border: #2a2a2a;
  --border-hover: #3a3a3a;
  --text: #e0e0e0;
  --text-bright: #fff;
  --muted: #888;
  --accent: #4f8cff;
  --accent-hover: #6fa0ff;
  --danger: #ff4f6d;
  --success: #4fdf8b;
  --warning: #ffb84d;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-bright);
  white-space: nowrap;
}
.header-logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.config-select {
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  min-width: 180px;
  max-width: 300px;
}
.config-select:focus { outline: none; border-color: var(--accent); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-hover); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-icon {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 8px;
  border-radius: var(--radius);
  font-size: 18px;
  cursor: pointer;
}
.btn-icon:hover { color: var(--text); background: var(--surface2); }
.btn-small { padding: 6px 12px; font-size: 12px; }

/* ── Main Layout ── */
main {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.panel-left {
  width: 380px;
  min-width: 320px;
  padding: 20px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.result-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  min-height: 0;
}
.queue-area {
  border-top: 1px solid var(--border);
  max-height: 200px;
  overflow-y: auto;
  padding: 12px 20px;
}

/* ── Form Elements ── */
.field { display: flex; flex-direction: column; }
.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}
textarea, input[type="text"], input[type="number"], input[type="password"], select {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--accent); }
select { cursor: pointer; }

.row { display: flex; gap: 12px; }
.row .field { flex: 1; }

/* ── Drop Zone ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  position: relative;
  font-size: 13px;
  color: var(--muted);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(79,140,255,.06);
}
.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.preview-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.preview-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color .15s;
}
.preview-thumb:hover { border-color: var(--danger); }

/* ── Size Editor ── */
.size-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.size-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.size-preset-btn {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.size-preset-btn:hover {
  border-color: var(--border-hover);
  color: var(--text);
}
.size-preset-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.size-inputs {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}
.size-inputs .field { flex: 1; }
.size-inputs input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 14px;
  text-align: center;
}
.size-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
}
.size-row .size-inputs { flex: 1; }
.size-preview-box {
  width: 56px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  padding: 6px;
}
.size-preview-rect {
  border: 2px solid var(--accent);
  border-radius: 2px;
  background: rgba(79,140,255,.08);
  transition: width .2s, height .2s;
}
.size-dim-label {
  font-size: 11px !important;
  text-align: center;
}
.btn-link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all .15s;
  flex-shrink: 0;
}
.btn-link-icon:hover {
  background: var(--surface2);
  color: var(--text);
}
.btn-link-icon.locked {
  color: var(--accent);
}
.lock-icon-locked { display: none; }
.lock-icon-unlocked { display: block; }
.btn-link-icon.locked .lock-icon-locked { display: block; }
.btn-link-icon.locked .lock-icon-unlocked { display: none; }
.size-hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  min-height: 16px;
}

/* ── Advanced Section ── */
details.advanced-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
details.advanced-section summary {
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  background: var(--surface);
  user-select: none;
}
details.advanced-section summary:hover { color: var(--text); }
details.advanced-section[open] summary { border-bottom: 1px solid var(--border); }
.advanced-body { padding: 12px; display: flex; flex-direction: column; gap: 12px; }

/* ── Mode Indicator ── */
.mode-hint {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 4px 0;
}

/* ── Result Display ── */
.result-placeholder {
  text-align: center;
  color: var(--muted);
}
.result-placeholder .icon { font-size: 48px; margin-bottom: 12px; opacity: .3; }
.result-placeholder p { font-size: 14px; }
.result-img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.result-multi {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
}
.result-multi img {
  max-width: 300px;
  max-height: 400px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.result-nav {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: center;
}
.result-nav .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  cursor: pointer;
  transition: background .15s;
}
.result-nav .dot.active { background: var(--accent); }

/* ── Status ── */
.status { font-size: 13px; color: var(--muted); min-height: 20px; text-align: center; }
.status.error { color: var(--danger); }
.status.success { color: var(--success); }

/* ── Queue ── */
.queue-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.queue-header h3 { font-size: 14px; font-weight: 600; }
.queue-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 13px;
}
.queue-item .prompt-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.queue-item .status-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}
.badge-waiting { background: var(--warning); color: #000; }
.badge-generating { background: var(--accent); color: #fff; }
.badge-done { background: var(--success); color: #000; }
.badge-failed { background: var(--danger); color: #fff; }
.queue-item .cancel-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
}
.queue-item .cancel-btn:hover { color: var(--danger); background: rgba(255,79,109,.1); }

/* ── History ── */
.history-area {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
}
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}
.history-header h3 { font-size: 14px; font-weight: 600; white-space: nowrap; }
.history-search {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
}
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}
.history-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: border-color .15s;
}
.history-grid img:hover { border-color: var(--accent); }

.history-item {
  position: relative;
}
.history-item-menu {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  background: rgba(0,0,0,.6);
  border: none;
  border-radius: 4px;
  color: #fff;
  font-size: 14px;
  line-height: 24px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
  padding: 0;
  z-index: 2;
}
.history-item:hover .history-item-menu { opacity: 1; }
.history-item-menu:hover { background: rgba(0,0,0,.8); }

.history-item-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 180px;
  padding: 4px;
  z-index: 10;
}
.history-item-dropdown .dropdown-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--text);
  white-space: nowrap;
}
.history-item-dropdown .dropdown-item:hover { background: var(--accent); color: #fff; }
.history-item-dropdown .dropdown-item.danger { color: var(--danger); }
.history-item-dropdown .dropdown-item.danger:hover { background: var(--danger); color: #fff; }

/* ── Overlays / Modals ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-wide { max-width: 800px; }
.modal h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text-bright);
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Wizard ── */
.wizard-steps {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}
.wizard-step {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.wizard-step.active { background: var(--accent); }
.wizard-step.done { background: var(--success); }
.wizard-body { display: flex; flex-direction: column; gap: 16px; }
.wizard-nav { display: flex; justify-content: space-between; margin-top: 20px; }

/* ── Settings ── */
.settings-layout { display: flex; gap: 20px; min-height: 300px; }
.settings-sidebar {
  width: 200px;
  border-right: 1px solid var(--border);
  padding-right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.settings-item {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  transition: all .15s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.settings-item:hover { color: var(--text); background: var(--surface2); }
.settings-item.active { color: var(--text-bright); background: var(--accent); }
.settings-content { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.settings-content .field-row { display: flex; gap: 12px; }
.settings-content .field-row .field { flex: 1; }

/* ── Context Menu ── */
.context-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 200;
  min-width: 160px;
  padding: 4px;
}
.context-menu-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--text);
}
.context-menu-item:hover { background: var(--accent); color: #fff; }
.context-menu-item.danger { color: var(--danger); }
.context-menu-item.danger:hover { background: var(--danger); color: #fff; }

/* ── Spinner ── */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Viewer ── */
.viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 150;
}
.viewer-overlay.hidden { display: none; }
.viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  z-index: 151;
}
.viewer-img {
  max-width: 90vw;
  max-height: 80vh;
  border-radius: var(--radius);
}
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,.5);
  border: none;
  color: #fff;
  font-size: 32px;
  padding: 16px 12px;
  cursor: pointer;
  border-radius: var(--radius);
}
.viewer-nav:hover { background: rgba(0,0,0,.8); }
.viewer-prev { left: 16px; }
.viewer-next { right: 16px; }
.viewer-info {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.7);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  text-align: center;
  max-width: 80%;
}
.viewer-actions {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  main { flex-direction: column; }
  .panel-left { width: 100%; min-width: unset; border-right: none; border-bottom: 1px solid var(--border); }
  .settings-layout { flex-direction: column; }
  .settings-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); padding-right: 0; padding-bottom: 12px; flex-direction: row; flex-wrap: wrap; }
}

.hidden { display: none !important; }
