/* === CSS Variables (dark theme) === */
:root {
  --bg:           #0f0f13;
  --surface:      #1a1a23;
  --surface2:     #22222e;
  --border:       #2e2e3e;
  --accent:       #7c6af7;
  --accent-hover: #9183f8;
  --danger:       #e05a5a;
  --danger-hover: #e87070;
  --text:         #e8e8f0;
  --text-muted:   #8888a8;
  --radius:       10px;
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
}

/* === Bootstrap overrides === */
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* Bootstrap Modal — apply dark theme */
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header .modal-title { font-size: 1rem; font-weight: 700; }

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  gap: 0.75rem;
}

.modal-backdrop { --bs-backdrop-opacity: 0.7; }

/* === Layout === */
.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.page-header h1 span { color: var(--accent); }

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: none;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; }

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); background: transparent; }

.btn-icon {
  padding: 0.35rem 0.5rem;
  background: rgba(224,90,90,0.15);
  color: var(--danger);
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-icon:hover { background: rgba(224,90,90,0.3); }

/* === Prompt Gallery Grid === */
.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.gallery-toolbar h2 {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 400;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

/* === Prompt Card === */
.prompt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}

.prompt-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.card-thumb {
  width: 100%;
  background: var(--surface2);
}

.card-thumb img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  display: block;
}

.card-thumb-placeholder {
  width: 100%;
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 2rem;
}

.card-body {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  margin-top: auto;
  padding-top: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.card-meta-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.card-image-count {
  display: flex;
  align-items: center;
  gap: 0.3em;
}

.card-copy-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.15rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.card-copy-btn:hover { color: var(--text); background: var(--surface2); }

/* === Empty State === */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { font-size: 1rem; }

/* === Form Controls === */
label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.875rem;
  padding: 0.6rem 0.75rem;
  font-family: inherit;
  transition: border-color 0.15s;
  cursor: pointer;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: none;
}

select option { background: var(--surface2); }

input[type="text"],
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.875rem;
  padding: 0.6rem 0.75rem;
  width: 100%;
  font-family: inherit;
  transition: border-color 0.15s;
  resize: vertical;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: none;
}

textarea { min-height: 120px; }

/* === Detail Page === */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
  transition: color 0.15s;
}
.back-link:hover { color: var(--text); text-decoration: none; }

.prompt-detail-header {
  margin-bottom: 2rem;
}

.prompt-detail-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.edit-title-input {
  font-size: 1.5rem;
  font-weight: 700;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  margin: 0 -0.4rem 0.25rem;
  width: calc(100% + 0.8rem);
  color: var(--text);
  letter-spacing: -0.02em;
  transition: border-color 0.15s, background 0.15s;
}
.edit-title-input:hover { border-color: var(--border); background: var(--surface); }
.edit-title-input:focus { border-color: var(--accent); background: var(--surface); outline: none; box-shadow: none; }

.edit-prompt-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.7;
  padding: 1rem 1.25rem;
  width: 100%;
  font-family: inherit;
  min-height: 240px;
  resize: vertical;
  transition: border-color 0.15s;
}
.edit-prompt-input:focus { outline: none; border-color: var(--accent); box-shadow: none; }

.section-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
  margin-top: 2rem;
}

/* === Upload Area === */
.upload-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.upload-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  transition: border-color 0.15s, background 0.15s;
  cursor: default;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(124,106,247,0.08);
  color: var(--accent);
}

.drop-zone p { pointer-events: none; }

.llm-input-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.llm-input-row input {
  flex: 1;
  min-width: 0;
}

/* === Image Grid === */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.image-tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.image-tile img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  transition: opacity 0.2s;
  cursor: zoom-in;
}

.image-tile:hover img { opacity: 0.85; }

.tile-delete {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(0,0,0,0.6);
  border: none;
  border-radius: 6px;
  color: #fff;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.image-tile:hover .tile-delete { opacity: 1; }
.tile-delete:hover { background: var(--danger); }

.tile-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.3rem 0.5rem;
  border-top: 1px solid var(--border);
}

.tile-date {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.tile-llm-select {
  font-size: 0.7rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  min-width: 0;
  flex: 1;
  max-width: 120px;
  background: var(--surface2);
  border-color: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.tile-llm-select:hover { border-color: var(--border); }
.tile-llm-select:focus { outline: none; border-color: var(--accent); color: var(--text); box-shadow: none; }
.tile-llm-select option { background: var(--surface2); }

/* === Prompt actions bar === */
.prompt-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* === Toast === */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease, toast-out 0.3s ease 2.7s forwards;
  max-width: 320px;
  pointer-events: auto;
  opacity: 1;
}

.toast.toast-error {
  border-color: var(--danger);
  color: #ffaaaa;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* === Loading spinner === */
.spinner {
  display: inline-block;
  width: 1.2em;
  height: 1.2em;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

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

/* === Dialog upload section (inside Bootstrap modal) === */
.dialog-upload-area {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.dialog-upload-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.6rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.dialog-drop-zone {
  padding: 0.9rem;
  font-size: 0.8rem;
}

.dialog-image-preview {
  display: none;
  position: relative;
  background: var(--bg);
}

.dialog-image-preview.has-image {
  display: block;
}

.dialog-image-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  display: block;
}

.dialog-image-preview .remove-preview {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: rgba(0,0,0,0.65);
  border: none;
  border-radius: 6px;
  color: #fff;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.85rem;
}
.dialog-image-preview .remove-preview:hover { background: var(--danger); }

/* === LLM select in upload controls === */
.llm-select {
  flex: 1;
  min-width: 140px;
}

/* === Lightbox === */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox[hidden] { display: none; }

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(6px);
}

.lightbox img {
  position: relative;
  max-width: min(92vw, 1400px);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 6px;
  display: block;
  box-shadow: 0 8px 48px rgba(0,0,0,0.6);
}

.lightbox-close {
  position: absolute;
  top: 1.2rem;
  right: 1.4rem;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  font-size: 1.3rem;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.25); }

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  font-size: 2.2rem;
  line-height: 1;
  width: 48px;
  height: 64px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.lightbox-nav:hover { background: rgba(255,255,255,0.22); }
.lightbox-nav:disabled { opacity: 0.2; cursor: default; }
.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }

.lightbox-caption {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.8rem;
  padding: 0.3rem 0.9rem;
  border-radius: 20px;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  pointer-events: none;
}

/* === Responsive === */
@media (max-width: 600px) {
  main { padding: 1rem; }
  .page-header { padding: 0 1rem; }
  .upload-controls { flex-direction: column; align-items: stretch; }
}
