/* WrytaEngine — Shared Component Styles */

/* ============================================ */
/* FORM ELEMENTS                                */
/* ============================================ */

.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: border-color var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--accent-primary);
  outline: none;
  box-shadow: 0 0 0 2px rgba(91, 155, 213, 0.15);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

.form-textarea {
  min-height: 80px;
  line-height: 1.5;
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a0c0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

/* ============================================ */
/* BUTTONS                                      */
/* ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
  border: 1px solid var(--accent-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.btn-success {
  background: var(--success);
  color: #fff;
  border: 1px solid var(--success);
}

.btn-success:hover:not(:disabled) {
  background: #5cc497;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border: 1px solid var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #e05565;
}

.btn-warning {
  background: var(--warning);
  color: #1a1a2e;
  border: 1px solid var(--warning);
}

.btn-warning:hover:not(:disabled) {
  background: #deb85a;
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 0.9375rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 6px;
  min-width: 32px;
  min-height: 32px;
  border-radius: var(--radius-sm);
}

/* ============================================ */
/* CHAPTER INPUT SECTION (Main Panel)           */
/* ============================================ */

.chapter-input-area {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  flex-shrink: 0;
}

.chapter-input-area .chapter-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.chapter-input-area .chapter-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.chapter-input-area textarea {
  width: 100%;
  min-height: 80px;
  max-height: 200px;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  line-height: 1.6;
  resize: vertical;
  font-family: var(--font-sans);
}

.chapter-input-area textarea:focus {
  border-color: var(--accent-primary);
  outline: none;
}

.chapter-input-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}

/* ============================================ */
/* CHAPTER OUTPUT (contentEditable)             */
/* ============================================ */

.chapter-output-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 300px;
}

.chapter-output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.chapter-output-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.chapter-output-actions {
  display: flex;
  gap: 6px;
}

.chapter-output-editor {
  flex: 1;
  padding: 24px 28px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.85;
  overflow-y: auto;
  min-height: 400px;
  outline: none;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chapter-output-editor:focus {
  border-color: var(--accent-primary);
}

.chapter-output-editor:empty::before {
  content: 'Your generated chapter will appear here...';
  color: var(--text-muted);
  font-style: italic;
  font-family: var(--font-sans);
}

.chapter-output-editor p {
  margin-bottom: 1em;
}

.chapter-output-editor h2,
.chapter-output-editor h3 {
  margin: 1.2em 0 0.6em;
  color: var(--accent-primary);
}

/* Selection styling for chapter output */
.chapter-output-editor ::selection {
  background: rgba(91, 155, 213, 0.3);
  color: inherit;
}

/* ============================================ */
/* CHAPTER HISTORY LIST                         */
/* ============================================ */

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chapter-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: 0.8125rem;
}

.chapter-list-item:hover {
  background: var(--bg-hover);
}

.chapter-list-item.active {
  background: var(--bg-active);
  border-left: 2px solid var(--accent-primary);
}

.chapter-list-item .chapter-num {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 28px;
}

.chapter-list-item .chapter-info {
  flex: 1;
  min-width: 0;
}

.chapter-list-item .chapter-name {
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-list-item .chapter-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.chapter-list-item .chapter-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.chapter-badge.approved {
  background: rgba(76, 175, 132, 0.15);
  color: var(--success);
}

.chapter-badge.draft {
  background: rgba(212, 168, 67, 0.15);
  color: var(--warning);
}

/* ============================================ */
/* REWRITE TOOLS (Right Sidebar)                */
/* ============================================ */

.rewrite-section {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.rewrite-section:last-child {
  border-bottom: none;
}

.rewrite-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.rewrite-action-btn {
  padding: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  transition: all var(--transition-fast);
}

.rewrite-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

.rewrite-action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.rewrite-action-btn .icon {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 2px;
}

/* Tone selector */
.tone-selector {
  margin-top: 10px;
}

.tone-selector .form-select {
  margin-top: 4px;
}

/* Selection info */
.selection-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 8px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  font-family: var(--font-mono);
  word-break: break-all;
  max-height: 60px;
  overflow-y: auto;
}

.selection-info.empty {
  font-style: italic;
  color: var(--text-muted);
}

/* ============================================ */
/* CONTINUITY & CHARACTER STATES               */
/* ============================================ */

.notes-editor {
  width: 100%;
  min-height: 100px;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8125rem;
  line-height: 1.6;
  resize: vertical;
  font-family: var(--font-sans);
}

.notes-editor:focus {
  border-color: var(--accent-primary);
  outline: none;
}

.notes-editor.small {
  min-height: 60px;
}

/* ============================================ */
/* LOADING / GENERATING INDICATOR              */
/* ============================================ */

.generating-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius-md);
  color: var(--accent-primary);
  font-size: 0.875rem;
  font-weight: 500;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--accent-dim);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============================================ */
/* SETTINGS PANEL                               */
/* ============================================ */

.settings-group {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.settings-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.settings-group h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* API key input with show/hide */
.api-key-wrapper {
  display: flex;
  gap: 4px;
}

.api-key-wrapper .form-input {
  flex: 1;
}

.api-key-wrapper .btn-icon {
  flex-shrink: 0;
}

/* ============================================ */
/* EMPTY STATE                                 */
/* ============================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state .title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-state .desc {
  font-size: 0.8125rem;
  max-width: 280px;
}