:root {
  --bg-primary: #1a1b26;
  --bg-secondary: #24283b;
  --bg-tertiary: #2f334d;
  --text-primary: #c0caf5;
  --text-secondary: #7dcfff;
  --text-muted: #565f89;
  --border-color: #414868;
  --hover-color: #3b4261;
  --accent-color: #7aa2f7;
  --error-color: #f7768e;
  --success-color: #9ece6a;
  --cell-padding: 12px;
  --border-radius: 8px;
}

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

body {
  margin: 0;
  padding: 24px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}

/* Toolbar Styles */
.toolbar {
  padding: 16px;
  background-color: var(--bg-secondary);
  border-radius: var(--border-radius);
  margin-bottom: 24px;
  display: flex;
  gap: 12px;
  align-items: center;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.toolbar-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toolbar-button:hover {
  background: var(--hover-color);
  border-color: var(--accent-color);
}

.toolbar-button.primary {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #ffffff;
}

.toolbar-button.primary:hover {
  background: var(--text-secondary);
  border-color: var(--text-secondary);
}

.toolbar-button.icon-only {
  padding: 8px;
  width: 36px;
  height: 36px;
  justify-content: center;
}

.button-icon {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.toolbar-button.icon-only .button-icon {
  margin: 0;
}

/* Grid Container */
#grid-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Story Input */
#story-input {
  min-height: 200px;
  padding: 16px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s ease;
  resize: vertical;
  box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

#story-input:focus {
  border-color: var(--accent-color);
}

#story-input[placeholder]:empty:before {
  content: attr(placeholder);
  color: var(--text-muted);
}

/* Grid Table */
#grid-table {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.grid-headers {
  display: flex;
  background-color: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  padding: 12px;
}

.grid-header {
  position: relative;
  padding: 8px 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

/* Grid Rows and Cells */
.row-group {
  border-bottom: 1px solid var(--border-color);
}

.grid-row {
  display: flex;
  background-color: var(--bg-secondary);
  transition: background-color 0.2s ease;
}

.grid-row:hover {
  background-color: var(--hover-color);
}

.grid-cell {
  padding: var(--cell-padding);
  border-right: 1px solid var(--border-color);
  min-height: 24px;
  outline: none;
  position: relative;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  min-width: 0;
}

.grid-cell[contenteditable="true"] {
  transition: background-color 0.2s ease;
}

.grid-cell[contenteditable="true"]:hover {
  background-color: var(--hover-color);
}

.grid-cell[contenteditable="true"]:focus {
  background-color: var(--bg-tertiary);
  border-color: var(--accent-color);
}

/* Delete Button */
.delete-cell {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
}

.grid-row:hover .delete-cell {
  opacity: 1;
}

.delete-cell:hover {
  color: var(--error-color);
}

/* Image Cells */
.images-cell {
  padding: var(--cell-padding);
  min-height: 280px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-color) var(--bg-tertiary);
}

.images-cell::-webkit-scrollbar {
  height: 8px;
}

.images-cell::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.images-cell::-webkit-scrollbar-thumb {
  background: var(--accent-color);
  border-radius: 4px;
}

.image-container {
  display: flex;
  gap: 12px;
  min-height: 256px;
  padding: 4px;
}

.image-placeholder {
  flex: 0 0 256px;
  height: 256px;
  background: var(--bg-tertiary);
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  padding: 16px;
  position: relative;
  border: 1px solid var(--border-color);
  transition: border-color 0.2s ease;
}

.image-placeholder[data-loading="true"] {
  border-color: var(--accent-color);
}

.generated-image {
  width: 256px;
  height: 256px;
  object-fit: cover;
  border-radius: var(--border-radius);
  transition: transform 0.2s ease;
}

.generated-image:hover {
  transform: scale(1.02);
}

/* Loading Indicator */
.loading::after,
.image-placeholder[data-loading="true"]::after {
  content: '';
  position: absolute;
  top: 12px;
  right: 12px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(17, 24, 39, 0.7);
  backdrop-filter: blur(4px);
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  overflow-y: auto; /* Enable scrolling */
}

.modal-content {
  background: var(--bg-primary);
  padding: 32px;
  border-radius: var(--border-radius);
  width: 90%;
  max-width: 600px;
  max-height: 90vh; /* Set maximum height */
  overflow-y: auto; /* Enable scrolling within the modal content */
  margin: auto;
  border: 1px solid var(--border-color);
}

/* Hide scrollbar for webkit browsers */
.modal-content::-webkit-scrollbar {
  width: 0px; /* Remove scrollbar space */
  background: transparent; /* Optional: just to avoid a white background */
}

/* For Firefox */
.modal-content {
  scrollbar-width: none; /* Hide scrollbar for Firefox */
}

/* Optional sticky header/footer if needed */
.modal h2 {
  position: sticky;
  top: -32px;
  background: var(--bg-secondary);
  padding: 32px 32px 16px 32px;
  margin: -32px -32px 24px -32px;
  border-bottom: 1px solid var(--border-color);
}

.modal-buttons {
  position: sticky;
  bottom: -32px;
  background: var(--bg-secondary);
  margin: 32px -32px -32px -32px;
  padding: 24px 32px;
  border-top: 1px solid var(--border-color);
}

.settings-group {
  margin-bottom: 24px;
}

.settings-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-weight: 500;
}

.setting-item {
  margin-top: 16px;
}

.setting-item input,
.setting-item textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s ease;
}

.setting-item input:focus,
.setting-item textarea:focus {
  border-color: var(--accent-color);
}

/* Toast Notifications */
#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 24px;
  border-radius: var(--border-radius);
  color: white;
  opacity: 0;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.toast.success {
  background-color: var(--success-color);
}

.toast.error {
  background-color: var(--error-color);
}

/* Add to styles.css */
.toast.info {
  background-color: #3b82f6;
  max-width: 600px;
  white-space: pre-wrap;
}

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

.toolbar button {
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: white;
  cursor: pointer;
}

.toolbar button:hover {
  background: #f8fafc;
}

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

/* Auto-sizing text fields */
[contenteditable="true"] {
  overflow: hidden;
  min-height: 24px;
  height: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Add to styles.css */
.modal {
  background: rgba(17, 24, 39, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  background: #1a1f2e;
  color: #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  padding: 32px;
  width: 90%;
  max-width: 600px;
}

.modal h2 {
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 24px 0;
  color: #f1f5f9;
}

.settings-group {
  margin-bottom: 32px;
}

.settings-group > label {
  display: block;
  font-size: 16px;
  font-weight: 500;
  color: #94a3b8;
  margin-bottom: 12px;
}

.setting-item {
  margin-bottom: 16px;
}

.setting-item label {
  display: block;
  font-size: 14px;
  color: #cbd5e1;
  margin-bottom: 8px;
}

.modal input[type="number"],
.modal textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #2d3748;
  border-radius: 6px;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 14px;
  transition: all 0.2s;
}

.modal input[type="number"]:focus,
.modal textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.modal textarea {
  min-height: 100px;
  resize: vertical;
}

.modal input[type="file"] {
  display: none;
}

.file-upload-button {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  background: #2d3748;
  border: 1px solid #4a5568;
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.file-upload-button:hover {
  background: #374151;
}

.file-upload-button svg {
  margin-right: 8px;
  width: 16px;
  height: 16px;
}

.key-count {
  display: inline-block;
  margin-left: 12px;
  padding: 4px 8px;
  background: #1e293b;
  border-radius: 4px;
  font-size: 12px;
  color: #94a3b8;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid #2d3748;
}

.modal-buttons button {
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.modal-buttons button:first-child {
  background: #3b82f6;
  color: white;
  border: none;
}

.modal-buttons button:first-child:hover {
  background: #2563eb;
}

.modal-buttons button:last-child {
  background: transparent;
  color: #94a3b8;
  border: 1px solid #2d3748;
}

.modal-buttons button:last-child:hover {
  background: #1e293b;
}

/* Add these styles to your styles.css */

/* Style for the regenerate button */
.regenerate-button {
  display: none;
  position: absolute;
  bottom: 12px;
  right: 12px;
  padding: 6px 12px;
  background-color: var(--accent-color);
  color: #fff;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 12px;
}

.regenerate-button:hover {
  background-color: var(--text-secondary);
}

/* Show regenerate button on hover */
.image-placeholder:hover .regenerate-button {
  display: block;
}

/* Ensure generated images are positioned correctly */
.image-placeholder {
  position: relative; /* Ensure buttons are positioned relative to the container */
}

.generated-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.progress-info {
  margin-left: auto;
  display: flex;
  gap: 16px;
  align-items: center;
  color: var(--text-primary);
}

#progress-text,
#time-remaining {
  font-size: 14px;
}