/* =============================================================================
   SOLARA — Application Styles
   Dashboard, Writing Studio, Wizard, Settings
   ============================================================================= */

/* =============================================================================
   APP SHELL
   ============================================================================= */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-primary);
}

/* App-wide Top Bar */
.app-topbar {
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-4);
  flex-shrink: 0;
  z-index: var(--z-sticky);
}

.app-topbar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--text-primary);
  min-width: 180px;
}

.app-topbar-logo img {
  height: 28px;
  width: auto;
}

.app-topbar-logo-text {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.02em;
}

.app-topbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-topbar-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  border: none;
  background: transparent;
  text-align: center;
  max-width: 400px;
  width: 100%;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}

.app-topbar-title:hover,
.app-topbar-title:focus {
  background: var(--bg-surface-2);
  outline: none;
}

.app-topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 180px;
  justify-content: flex-end;
}

/* Token display */
.token-display {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.375rem var(--space-3);
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  cursor: default;
}

.token-icon {
  color: var(--accent-gold);
  width: 16px;
  height: 16px;
}

.token-count {
  transition: color var(--transition-base);
}

.token-count.low {
  color: var(--warning);
}

.token-count.critical {
  color: var(--error);
}

.token-count.infinite {
  color: var(--accent-secondary);
}

/* Model selector */
.model-selector {
  position: relative;
}

.model-selector-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.375rem var(--space-3);
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.model-selector-btn:hover {
  border-color: var(--accent-primary);
}

.model-selector-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-dropdown);
  min-width: 260px;
  overflow: hidden;
  animation: scaleIn var(--transition-base) ease-out both;
  transform-origin: top right;
}

.model-dropdown-item {
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: background var(--transition-fast);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.model-dropdown-item:last-child {
  border-bottom: none;
}

.model-dropdown-item:hover {
  background: var(--bg-surface-2);
}

.model-dropdown-item.active {
  background: rgba(108, 99, 255, 0.05);
}

.model-radio {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  transition: border-color var(--transition-fast);
}

.model-dropdown-item.active .model-radio {
  border-color: var(--accent-primary);
}

.model-radio::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-primary);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.model-dropdown-item.active .model-radio::after {
  opacity: 1;
}

.model-info-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.model-info-desc {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* =============================================================================
   MAIN CONTENT AREA
   ============================================================================= */
.app-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* View = each "page" in the SPA */
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  transition: opacity var(--transition-base), transform var(--transition-base);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

.view.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* =============================================================================
   DASHBOARD VIEW
   ============================================================================= */
.dashboard {
  padding: var(--space-8) var(--space-8);
  max-width: 1400px;
  margin: 0 auto;
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-8);
  flex-wrap: wrap;
  gap: var(--space-4);
}

.dashboard-title {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.dashboard-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrap svg {
  position: absolute;
  left: var(--space-3);
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-input {
  padding: 0.5rem var(--space-4) 0.5rem calc(var(--space-3) + 20px);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  color: var(--text-primary);
  width: 220px;
  transition: border-color var(--transition-fast), width var(--transition-base);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  width: 280px;
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

/* Filter chips */
.filter-bar {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

/* Projects grid */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-5);
}

/* Project card */
.project-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  flex-direction: column;
}

.project-card:hover {
  border-color: rgba(108, 99, 255, 0.3);
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
}

.project-card-cover {
  height: 140px;
  background: var(--bg-surface-2);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.project-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.project-card-cover-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-tertiary);
}

.project-card-cover-placeholder svg {
  width: 40px;
  height: 40px;
  opacity: 0.4;
}

.project-type-badge {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  padding: 0.25rem 0.625rem;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  color: #FFFFFF;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.project-card-menu {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.project-card:hover .project-card-menu {
  opacity: 1;
}

.project-card-body {
  padding: var(--space-4);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.project-card-title {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.project-card-progress {
  margin-top: auto;
  padding-top: var(--space-3);
}

.project-progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

/* New Story Card */
.new-story-card {
  background: var(--bg-surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8);
  cursor: pointer;
  transition: all var(--transition-base);
  min-height: 200px;
  text-align: center;
  color: var(--text-tertiary);
}

.new-story-card:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: rgba(108, 99, 255, 0.03);
  transform: translateY(-2px);
}

.new-story-card-icon {
  width: 48px;
  height: 48px;
  background: var(--bg-surface-2);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.new-story-card:hover .new-story-card-icon {
  background: rgba(108, 99, 255, 0.1);
}

.new-story-card-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: inherit;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-20) var(--space-4);
  text-align: center;
  gap: var(--space-4);
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  background: var(--bg-surface-2);
  border-radius: var(--radius-2xl);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  margin-bottom: var(--space-4);
}

.empty-state-title {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.empty-state-desc {
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  max-width: 400px;
}

/* =============================================================================
   WIZARD
   ============================================================================= */
.wizard {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.wizard-header {
  padding: var(--space-6) var(--space-8);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  flex-shrink: 0;
}

.wizard-step-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.wizard-step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: all var(--transition-base);
}

.wizard-step-dot.active {
  width: 24px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
}

.wizard-step-dot.completed {
  background: var(--success);
}

.wizard-step-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.wizard-step-label strong {
  color: var(--text-primary);
}

.wizard-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-8);
}

.wizard-step {
  max-width: 720px;
  margin: 0 auto;
  display: none;
}

.wizard-step.active {
  display: block;
  animation: fadeInUp 0.3s ease-out both;
}

.wizard-step-title {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.wizard-step-subtitle {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin-bottom: var(--space-8);
  line-height: var(--leading-relaxed);
}

/* Story type selection cards */
.story-type-select-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.story-type-select-card {
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.story-type-select-card:hover {
  border-color: rgba(108, 99, 255, 0.4);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.story-type-select-card.selected {
  border-color: var(--accent-primary);
  background: rgba(108, 99, 255, 0.04);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.12);
}

.story-type-select-icon-wrap {
  width: 42px;
  height: 42px;
  background: var(--bg-surface-2);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-secondary);
  transition: background var(--transition-fast);
}

.story-type-select-card.selected .story-type-select-icon-wrap {
  background: rgba(108, 99, 255, 0.12);
  color: var(--accent-primary);
}

.story-type-select-name {
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
  color: var(--text-primary);
}

.story-type-select-desc {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

/* Writing style cards */
.writing-style-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

.writing-style-card {
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  cursor: pointer;
  transition: all var(--transition-base);
}

.writing-style-card:hover {
  border-color: rgba(108, 99, 255, 0.3);
}

.writing-style-card.selected {
  border-color: var(--accent-primary);
  background: rgba(108, 99, 255, 0.04);
}

.writing-style-name {
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.writing-style-desc {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* Model selection in wizard */
.model-select-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
}

.model-select-card {
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.model-select-card:hover {
  border-color: rgba(108, 99, 255, 0.3);
}

.model-select-card.selected {
  border-color: var(--accent-primary);
  background: rgba(108, 99, 255, 0.04);
}

.model-select-name {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.model-select-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

.model-select-cost {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: auto;
}

/* Slider input */
.range-slider {
  width: 100%;
  height: 4px;
  background: var(--bg-surface-2);
  border-radius: var(--radius-full);
  outline: none;
  appearance: none;
  cursor: pointer;
}

.range-slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent-primary);
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.range-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Wizard navigation */
.wizard-footer {
  padding: var(--space-4) var(--space-8);
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

/* Review step */
.review-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  margin-bottom: var(--space-4);
}

.review-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-2);
}

.review-section-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.review-section-body {
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.review-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 140px;
}

.review-item-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.review-item-value {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}

/* Story guide generation progress */
.story-guide-progress {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: var(--space-12);
  text-align: center;
  max-width: 560px;
  margin: var(--space-8) auto;
}

.guide-progress-title {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-3);
}

.guide-progress-steps {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: var(--space-8) 0;
  text-align: left;
}

.guide-progress-step {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.guide-progress-step.done {
  color: var(--success);
}

.guide-progress-step.active {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}

.guide-step-indicator {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--bg-surface-2);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.guide-progress-step.done .guide-step-indicator {
  background: var(--success);
  border-color: var(--success);
}

.guide-progress-step.active .guide-step-indicator {
  border-color: var(--accent-primary);
  background: none;
  animation: pulse 1s ease-in-out infinite;
}

/* =============================================================================
   WRITING STUDIO
   ============================================================================= */
.studio {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* Left Sidebar */
.studio-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition-slow), transform var(--transition-slow);
}

.studio-sidebar.collapsed {
  width: 0;
  overflow: hidden;
}

.studio-sidebar.collapsed .sidebar-inner {
  opacity: 0;
  pointer-events: none;
}

.sidebar-inner {
  width: 260px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  cursor: pointer;
  text-align: center;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.sidebar-tab:hover {
  color: var(--text-primary);
  background: var(--bg-surface-2);
}

.sidebar-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.sidebar-panel {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: none;
}

.sidebar-panel.active {
  display: block;
}

/* Story guide fields */
.guide-section {
  margin-bottom: var(--space-5);
}

.guide-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.guide-section-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}

.guide-field {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  min-height: 60px;
  cursor: text;
  transition: border-color var(--transition-fast);
  white-space: pre-wrap;
  outline: none;
}

.guide-field:focus,
.guide-field[contenteditable="true"]:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(108, 99, 255, 0.1);
}

/* Character cards in sidebar */
.character-card-mini {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.character-card-mini:hover {
  border-color: rgba(108, 99, 255, 0.3);
}

.character-mini-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.character-mini-role {
  font-size: var(--text-xs);
  color: var(--accent-secondary);
  text-transform: capitalize;
}

/* Chapter list in sidebar */
.chapter-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.chapter-list-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

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

.chapter-list-item.active {
  background: rgba(108, 99, 255, 0.08);
}

.chapter-list-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--accent-primary);
  border-radius: 0 2px 2px 0;
}

.chapter-num {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--text-tertiary);
  width: 20px;
  text-align: right;
  flex-shrink: 0;
}

.chapter-list-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chapter-status-dot.not_started { background: var(--border-strong); }
.chapter-status-dot.writing     { background: var(--accent-gold); animation: pulse 1s infinite; }
.chapter-status-dot.complete    { background: var(--success); }
.chapter-status-dot.edited      { background: var(--accent-secondary); }

/* Add chapter btn */
.add-chapter-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: none;
  border: 1px dashed var(--border);
  width: 100%;
  margin-top: var(--space-2);
}

.add-chapter-btn:hover {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
  background: rgba(108, 99, 255, 0.04);
}

/* Main writing area */
.studio-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

.studio-chapter-header {
  padding: var(--space-6) var(--space-8) var(--space-4);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.chapter-header-left {
  flex: 1;
}

.chapter-number-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-secondary);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chapter-title-input {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  background: none;
  border: none;
  outline: none;
  width: 100%;
  padding: 0;
  line-height: 1.3;
}

.chapter-title-input::placeholder {
  color: var(--text-tertiary);
}

.chapter-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Writing area */
.writing-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-8);
  position: relative;
}

.chapter-content {
  max-width: 720px;
  margin: 0 auto;
  font-family: var(--font-reading);
  font-size: 1.0625rem;
  line-height: var(--leading-reading);
  color: var(--text-primary);
  outline: none;
  min-height: 400px;
}

.chapter-content p {
  margin-bottom: 1.25em;
  text-indent: 2em;
}

.chapter-content p:first-child {
  text-indent: 0;
}

/* Typewriter streaming cursor */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent-primary);
  border-radius: 1px;
  vertical-align: text-bottom;
  animation: blink-cursor 0.8s ease-in-out infinite;
  margin-left: 1px;
}

/* Selection for AI edit */
.chapter-content ::selection {
  background: rgba(108, 99, 255, 0.2);
}

/* AI context popup on selection */
.selection-popup {
  position: fixed;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--space-2);
  display: flex;
  gap: var(--space-1);
  z-index: var(--z-tooltip);
  animation: scaleIn 0.15s ease-out both;
  transform-origin: top center;
}

/* Direction input below chapter */
.chapter-direction {
  border-top: 1px solid var(--border);
  padding: var(--space-4) var(--space-8);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.direction-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

.direction-input-wrap {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
}

.direction-input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-primary);
  resize: none;
  height: 60px;
  transition: border-color var(--transition-fast);
  font-family: var(--font-sans);
}

.direction-input:focus {
  border-color: var(--accent-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.1);
}

.direction-input::placeholder {
  color: var(--text-tertiary);
}

/* Studio bottom bar */
.studio-bottombar {
  height: 36px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-6);
  flex-shrink: 0;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.bottombar-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.bottombar-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
}

.save-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  margin-left: auto;
}

.save-status.saving {
  color: var(--accent-secondary);
}

.save-status.saved {
  color: var(--success);
}

/* Right panel */
.studio-right {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition-slow);
}

.studio-right.collapsed {
  width: 0;
}

.right-panel-inner {
  width: 300px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.right-panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.right-tab {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  cursor: pointer;
  text-align: center;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.right-tab:hover {
  color: var(--text-primary);
}

.right-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.right-panel {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: none;
}

.right-panel.active {
  display: flex;
  flex-direction: column;
}

/* AI Chat */
.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow-y: auto;
  padding-bottom: var(--space-4);
}

.chat-message {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}

.chat-message-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--text-secondary);
}

.chat-message.ai .chat-message-avatar {
  background: rgba(108, 99, 255, 0.12);
  color: var(--accent-primary);
}

.chat-message-content {
  flex: 1;
  background: var(--bg-surface-2);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-primary);
  line-height: var(--leading-relaxed);
}

.chat-message.user .chat-message-content {
  background: rgba(108, 99, 255, 0.08);
}

.chat-input-area {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
}

.chat-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-primary);
  resize: none;
  height: 72px;
  font-family: var(--font-sans);
  line-height: var(--leading-relaxed);
  transition: border-color var(--transition-fast);
}

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

.chat-input::placeholder {
  color: var(--text-tertiary);
}

/* Toggle sidebar buttons */
.sidebar-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 44px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all var(--transition-fast);
  z-index: var(--z-raised);
}

.sidebar-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-surface-2);
}

.sidebar-toggle-left {
  right: -20px;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  border-left: none;
}

.sidebar-toggle-right {
  left: -20px;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  border-right: none;
}

/* Image display in chapter */
.chapter-image {
  max-width: 100%;
  margin: var(--space-8) auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.chapter-image img {
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-height: 500px;
  width: 100%;
  object-fit: cover;
}

.chapter-image-caption {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-style: italic;
  text-align: center;
}

/* =============================================================================
   IMAGE GENERATION MODAL
   ============================================================================= */
.image-gen-modal {
  max-width: 640px;
}

.image-model-tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.image-model-tab {
  flex: 1;
  padding: var(--space-3);
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-fast);
}

.image-model-tab:hover {
  border-color: rgba(108, 99, 255, 0.3);
}

.image-model-tab.active {
  border-color: var(--accent-primary);
  background: rgba(108, 99, 255, 0.05);
}

.image-model-tab-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.image-model-tab-cost {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* Aspect ratio picker */
.aspect-ratio-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.aspect-ratio-btn {
  padding: 0.375rem var(--space-3);
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.aspect-ratio-btn:hover,
.aspect-ratio-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #FFFFFF;
}

/* Image preview in modal */
.image-preview-area {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.image-preview-area img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-preview-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* =============================================================================
   SETTINGS VIEW
   ============================================================================= */
.settings-view {
  padding: var(--space-8);
  max-width: 720px;
  margin: 0 auto;
}

.settings-title {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-8);
}

.settings-section {
  margin-bottom: var(--space-8);
}

.settings-section-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row-info h4 {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.settings-row-info p {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* =============================================================================
   ADMIN PANEL
   ============================================================================= */
.admin-modal {
  max-width: 800px;
  max-height: 85vh;
}

.admin-panel-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.admin-tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.admin-tab:hover {
  color: var(--text-primary);
}

.admin-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.admin-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}

.admin-panel-content {
  display: none;
}

.admin-panel-content.active {
  display: block;
}

.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.admin-stat-card {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  text-align: center;
}

.admin-stat-value {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--accent-primary);
  margin-bottom: var(--space-1);
}

.admin-stat-label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.admin-indicator-dot {
  position: fixed;
  bottom: var(--space-4);
  left: var(--space-4);
  width: 8px;
  height: 8px;
  background: var(--accent-gold);
  border-radius: 50%;
  cursor: pointer;
  z-index: var(--z-toast);
  box-shadow: 0 0 8px var(--accent-gold);
  animation: pulse 2s ease-in-out infinite;
}

/* Plan simulator */
.plan-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.plan-card {
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  cursor: pointer;
  transition: all var(--transition-base);
}

.plan-card:hover {
  border-color: rgba(108, 99, 255, 0.4);
}

.plan-card.active {
  border-color: var(--accent-primary);
  background: rgba(108, 99, 255, 0.04);
}

.plan-card-name {
  font-weight: var(--weight-bold);
  font-size: var(--text-base);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.plan-card-features {
  list-style: none;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* Model sandbox */
.sandbox-response {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-primary);
  line-height: var(--leading-relaxed);
  min-height: 100px;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  margin-top: var(--space-4);
}

/* =============================================================================
   BOOK EXTRAS
   ============================================================================= */
.extras-page {
  max-width: 680px;
  margin: var(--space-8) auto;
  padding: var(--space-8);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  min-height: 600px;
}

.extras-title-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  text-align: center;
  gap: var(--space-6);
}

.extras-title-page h1 {
  font-family: var(--font-serif);
  font-size: var(--text-5xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  line-height: 1.1;
}

.extras-title-page .author-name {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  color: var(--text-secondary);
  font-style: italic;
}

.extras-copyright-page {
  padding: var(--space-8);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

.extras-dedication {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  font-family: var(--font-reading);
  font-style: italic;
  font-size: var(--text-xl);
  color: var(--text-secondary);
  text-align: center;
  padding: var(--space-8);
}

/* =============================================================================
   RESPONSIVE STUDIO
   ============================================================================= */
@media (max-width: 768px) {
  .studio-sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: var(--z-overlay);
    transform: translateX(-100%);
    width: 280px !important;
    box-shadow: var(--shadow-2xl);
  }

  .studio-sidebar.open {
    transform: translateX(0);
  }

  .studio-right {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: var(--z-overlay);
    transform: translateX(100%);
    width: 280px !important;
    box-shadow: var(--shadow-2xl);
  }

  .studio-right.open {
    transform: translateX(0);
  }

  .writing-area {
    padding: var(--space-4);
  }

  .chapter-content {
    font-size: 1rem;
  }

  .story-type-select-grid {
    grid-template-columns: 1fr;
  }

  .model-select-grid {
    grid-template-columns: 1fr;
  }

  .admin-stat-grid,
  .plan-cards {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 769px) and (max-width: 1199px) {
  .studio-sidebar {
    width: 220px;
  }

  .studio-right {
    width: 260px;
  }

  .story-type-select-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
