/* Reset & Base */
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #F7F5EF;
  color: #2D2A26;
  min-height: 100vh;
}

/* Three-Pane Layout */
#app {
  display: grid;
  grid-template-columns: 240px 320px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
#sidebar {
  background: #1B2A4A;
  color: white;
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-header h1 {
  margin: 0;
  font-size: 1.2rem;
  font-family: Georgia, serif;
}
#categoryList {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}
.category-item {
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.2s;
  border-left: 4px solid transparent;
}
.category-item:hover {
  background: rgba(255,255,255,0.05);
}
.category-item.active {
  background: rgba(201, 122, 11, 0.2);
  border-left-color: #C97A0B;
}
.category-count {
  background: rgba(255,255,255,0.2);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
}
.btn-sidebar-action {
  background: transparent;
  color: rgba(255,255,255,0.8);
  border: none;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding: 15px 20px;
  text-align: left;
  cursor: pointer;
  font-weight: bold;
}
.btn-sidebar-action:hover {
  background: rgba(255,255,255,0.05);
  color: white;
}

/* Prompt Pane */
#promptPane {
  background: #F7F5EF;
  border-right: 1px solid #E0DACE;
  display: flex;
  flex-direction: column;
}
.pane-header {
  padding: 20px;
  border-bottom: 1px solid #E0DACE;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pane-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-family: Georgia, serif;
}
#promptList {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.prompt-card {
  background: white;
  border: 1px solid #E0DACE;
  border-radius: 8px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
}
.prompt-card:hover {
  border-color: #C97A0B;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.prompt-card.active {
  border-color: #C97A0B;
  box-shadow: 0 0 0 1px #C97A0B;
}
.prompt-card-name {
  margin: 0 0 8px 0;
  font-weight: 700;
  color: #1B2A4A;
}
.prompt-tag {
  display: inline-block;
  background: #C97A0B;
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
}
.btn-new-prompt {
  margin: 16px;
  padding: 12px;
  background: #1B2A4A;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
}
.btn-new-prompt:hover {
  background: #2a4175;
}

/* Editor Pane */
#editorPane {
  background: white;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#editorContent {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.placeholder-message {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8B8680;
  font-style: italic;
}

/* Viewer Mode */
.editor-heading {
  font-family: Georgia, serif;
  color: #1B2A4A;
  margin-top: 0;
  margin-bottom: 12px;
}
.editor-tag-display {
  display: inline-block;
  background: #C97A0B;
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: bold;
  margin-bottom: 20px;
}

/* Image Gallery */
.image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.image-gallery-item {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1;
  background: #F0EDE6;
}
.image-gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}
.image-gallery-item:hover img {
  transform: scale(1.05);
}
.image-gallery-item .img-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 12px;
  cursor: pointer;
  display: none;
}
.image-gallery-item:hover .img-delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Prompt Body Preview */
.prompt-body-preview {
  background: #FFFDF7;
  border: 1px solid #E8E4DC;
  border-radius: 6px;
  padding: 16px 20px;
  white-space: pre-wrap;
  font-size: 0.92rem;
  line-height: 1.6;
  color: #2D2A26;
  min-height: 80px;
  margin-bottom: 24px;
  font-family: Consolas, monospace;
}
.prompt-body-preview a {
  color: #C97A0B;
  text-decoration: underline;
  word-break: break-all;
}
.prompt-body-preview a:hover {
  color: #B06A00;
}
.editor-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

/* Editor Edit Mode */
.edit-form-group {
  margin-bottom: 16px;
}
.edit-form-group label {
  display: block;
  font-weight: bold;
  margin-bottom: 6px;
  color: #1B2A4A;
}
.edit-form-group input, .edit-form-group textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #E0DACE;
  border-radius: 6px;
  font-family: inherit;
}
.edit-form-group textarea {
  min-height: 150px;
  resize: vertical;
  font-family: Consolas, monospace;
}
.edit-token-hint {
  font-size: 0.85rem;
  color: #8B8680;
  margin-top: 4px;
}
.image-upload-area {
  border: 2px dashed #D0CBC0;
  border-radius: 6px;
  padding: 16px;
  text-align: center;
  margin-bottom: 12px;
  background: #FAFAF7;
}
.image-upload-area:hover {
  border-color: #C97A0B;
}
.image-upload-btn {
  display: inline-block;
  background: #C97A0B;
  color: white;
  padding: 6px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
.image-upload-hint {
  color: #8B8680;
  font-size: 0.8rem;
  margin-top: 6px;
}
.existing-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.existing-image-thumb {
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  aspect-ratio: 1;
}
.existing-image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.existing-image-thumb .remove-img {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(192,57,43,0.85);
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Lightbox */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  cursor: pointer;
}
.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  color: white;
  font-size: 2rem;
  cursor: pointer;
  z-index: 2001;
}

/* Buttons, Modal, Scrollbar */
.btn-primary {
  background: #C97A0B;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}
.btn-primary:hover { background: #B06A00; }
.btn-secondary {
  background: #E0DACE;
  color: #2D2A26;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
}
.btn-secondary:hover { background: #D0CBC0; }
.btn-danger {
  color: #c0392b;
}
.btn-danger:hover {
  color: #E74C3C;
}
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  opacity: 0.7;
}
.btn-icon:hover { opacity: 1; }
.btn-copy {
  background: #1B2A4A;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}
.btn-copy:hover { background: #2a4175; }
.btn-copy.copied {
  background: #27ae60;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: white;
  padding: 24px;
  border-radius: 8px;
  width: 400px;
  max-width: 90%;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.modal-box h3 { margin-top: 0; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: bold; }
.form-group input { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D0CBC0; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #A09B90; }
