@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Lora:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
  --bg-primary: #0a0a0c;
  --bg-secondary: #121215;
  --bg-tertiary: #19191e;
  
  --border-color: rgba(255, 255, 255, 0.05);
  --border-hover: rgba(197, 168, 128, 0.35);
  
  --text-primary: #f4f4f7;
  --text-secondary: #a1a1aa;
  --text-muted: #52525b;
  
  --accent-purple: #c5a880;
  --accent-cyan: #e5cfb3;
  --accent-blue: #9a8466;
  --accent-success: #10b981;
  --accent-danger: #ef4444;
  
  --gradient-purple: linear-gradient(135deg, #dfc8a5 0%, #c5a880 100%);
  --gradient-cyan: linear-gradient(135deg, #e5cfb3 0%, #d4b483 100%);
  --gradient-glow: linear-gradient(135deg, rgba(197, 168, 128, 0.05) 0%, rgba(212, 180, 131, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #c5a880 0%, #d4b483 100%);
  
  --radius-sm: 3px;
  --radius-md: 4px;
  --radius-lg: 6px;
  
  --transition-fast: 0.1s ease;
  --transition-normal: 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Reset and Globals */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Outfit', sans-serif;
  line-height: 1.5;
  background-image: 
    radial-gradient(at 0% 0%, rgba(197, 168, 128, 0.04) 0px, transparent 40%),
    radial-gradient(at 100% 100%, rgba(212, 180, 131, 0.04) 0px, transparent 40%);
}

a, button, input, select, textarea {
  font-family: inherit;
  color: inherit;
  line-height: normal;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-sm);
  min-height: 36px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.3);
}

/* Auth Layout */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  height: 100vh;
  overflow-y: auto;
  padding: 2rem;
  box-sizing: border-box;
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 3rem 2.5rem;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.auth-logo svg {
  width: 42px;
  height: 42px;
  stroke: url(#brand-gradient-auth);
}

.auth-header h2 {
  font-size: 1.8rem;
  font-weight: 700;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}

.auth-header p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

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

.form-input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: var(--transition-fast);
}

.form-input:focus {
  outline: none;
  border-color: var(--border-hover);
  box-shadow: 0 0 5px rgba(197, 168, 128, 0.2);
}

select.form-input {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 0.85rem;
  padding-right: 2.25rem !important;
}

select option {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
}

select option:disabled {
  color: var(--text-muted) !important;
}

html[data-theme="windows-9x"] select option {
  background-color: #ffffff !important;
  color: #000000 !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--border-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.7rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  text-decoration: none;
}

.btn:focus,
.form-input:focus,
select:focus,
textarea:focus {
  outline: none;
}

.btn:focus-visible {
  outline: 2px solid var(--border-hover) !important;
  outline-offset: 1px;
}

.btn-primary {
  background: var(--gradient-brand);
  border: none;
  color: var(--btn-primary-text, #fff);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.btn-primary:hover {
  opacity: 0.95;
  box-shadow: 0 4px 12px rgba(197, 168, 128, 0.2);
  transform: translateY(-1px);
}

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

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-hover);
}

.btn-danger {
  background: var(--accent-danger);
  border: none;
  color: #fff;
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-danger-outline {
  background: rgba(239, 68, 68, 0.03);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: rgba(239, 68, 68, 0.85);
  transition: var(--transition-fast);
}

.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--accent-danger);
  color: #fff;
  transform: translateY(-1px);
}

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.auth-footer a {
  color: var(--accent-cyan);
  text-decoration: none;
  font-weight: 600;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* Dashboard Core Layout */
.app-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  box-sizing: border-box;
}

/* Sidebar styling */
.sidebar {
  width: 260px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 50;
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
  padding: 0 0.5rem;
}

.brand svg {
  width: 32px;
  height: 32px;
  stroke: url(#brand-gradient-sidebar);
}

.brand h1 {
  font-size: 1.3rem;
  font-weight: 700;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-grow: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  margin-bottom: 1rem;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 500;
  transition: var(--transition-fast);
  border: 1px solid transparent;
  cursor: pointer;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.02);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.nav-item.active {
  background: var(--gradient-glow);
  color: var(--text-primary);
  border-color: rgba(197, 168, 128, 0.35);
}

.nav-icon {
  width: 18px;
  height: 18px;
}

.sidebar-footer {
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.user-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.5rem;
}

.logout-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.logout-link:hover {
  color: var(--accent-danger);
}

/* Main Content Wrapper */
.main-content {
  margin-left: 260px;
  flex-grow: 1;
  padding: 1.5rem 2rem;
  width: calc(100% - 260px);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  transition: var(--transition-normal);
}

/* Header styling */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  transition: max-height 0.3s ease, padding 0.3s ease, margin 0.3s ease;
}

.main-header.collapsed {
  display: none !important;
}

.header-title h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.header-title p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Content Sections */
.content-section {
  display: none;
}

.content-section.active {
  display: flex !important;
  flex-direction: column;
  flex-grow: 1;
  min-height: 0;
  overflow-y: auto;
  box-sizing: border-box;
  animation: fadeIn 0.3s ease-out;
}

/* Sections that should not scroll internally at the root level */
#editor-tab,
#reader-tab,
#logs-tab,
#world-facts-tab,
#illustrations-tab,
#project-settings-admin-tab {
  overflow: hidden !important;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* High Density Structured Tables - NO CARDS constraint */
.table-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  margin-bottom: 1.5rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  background: var(--bg-tertiary);
  padding: 1rem 1.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr {
  transition: var(--transition-fast);
}

.data-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.015);
}

/* Aligned details rows & status indicators */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-pill.online {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--accent-success);
}

.status-pill.offline {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--accent-danger);
}

.status-pill.system {
  background-color: rgba(59, 130, 246, 0.1);
  color: var(--accent-blue);
}

.status-pill.shared {
  background-color: rgba(197, 168, 128, 0.1);
  color: var(--accent-purple);
}

/* Collapsible Row details */
.detail-row {
  display: none;
}

.detail-row.active {
  display: table-row;
}

.detail-content {
  background: rgba(0, 0, 0, 0.2);
  padding: 1.25rem !important;
  border-left: 3px solid var(--accent-purple);
}

.detail-meta-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.detail-meta-list li {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.detail-meta-list strong {
  color: var(--text-primary);
}

.editor-workspace {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  width: 100%;
  flex-grow: 1;
  min-height: 0;
  overflow: hidden;
  transition: var(--transition-normal);
}


.editor-header-toolbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  min-height: 50px;
  width: 100%;
  flex-shrink: 0 !important;
}

.editor-title-container {
  order: 1;
  flex-grow: 0;
  flex-shrink: 0;
  width: 280px;
  min-width: 280px;
  max-width: 280px;
  margin-right: 1rem;
}

.editor-nav-group {
  order: 2;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-shrink: 0;
}

.editor-toolbar-spacer {
  order: 3;
  flex-grow: 1;
}

#editor-add-section-select {
  order: 4;
  flex-shrink: 0;
}

.editor-toggles-group {
  order: 5;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-shrink: 0;
}

.editor-save-btn {
  order: 6;
  flex-shrink: 0;
}

/* Clean styling for editor header toolbar controls */
.editor-header-toolbar button {
  font-size: 0.75rem !important;
  padding: 0.25rem 0.6rem !important;
  height: 30px !important;
  box-sizing: border-box !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: normal !important;
  background: var(--bg-tertiary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-md) !important;
  color: var(--text-primary) !important;
  margin: 0 !important;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.editor-header-toolbar select {
  font-size: 0.75rem !important;
  height: 30px !important;
  box-sizing: border-box !important;
  line-height: normal !important;
  background: var(--bg-tertiary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-md) !important;
  color: var(--text-primary) !important;
  margin: 0 !important;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-block !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e") !important;
  background-repeat: no-repeat !important;
  background-position: right 0.4rem center !important;
  background-size: 0.65rem !important;
  padding: 0.25rem 1.4rem 0.25rem 0.5rem !important;
  vertical-align: middle;
  text-align: left !important;
  text-align-last: left !important;
}

.editor-header-toolbar button:hover,
.editor-header-toolbar select:hover {
  background: rgba(255, 255, 255, 0.04) !important;
  border-color: var(--border-hover) !important;
}

.editor-header-toolbar button.btn-primary {
  background: var(--gradient-brand) !important;
  border: none !important;
  color: var(--btn-primary-text, #fff) !important;
  font-weight: 600 !important;
}

.editor-header-toolbar button.btn-primary:hover {
  opacity: 0.95 !important;
  transform: translateY(-1px);
}

#editor-chapter-select {
  width: auto !important;
  min-width: 115px !important;
  max-width: 220px !important;
}

#editor-add-section-select {
  width: auto !important;
  min-width: 125px !important;
  max-width: 160px !important;
}

/* Premium Toggle Pills for Toolbar */
.toolbar-toggle-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition-fast);
  height: 30px;
  box-sizing: border-box;
  margin-right: 0.3rem;
}

.toolbar-toggle-label:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.toolbar-toggle-label:has(input[type="checkbox"]:checked) {
  background: rgba(168, 85, 247, 0.15) !important;
  border-color: var(--accent-purple) !important;
  color: var(--text-primary) !important;
  box-shadow: 0 0 8px rgba(168, 85, 247, 0.1);
}

.toolbar-toggle-label input[type="checkbox"] {
  display: none !important;
}

.pane {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

.pane-header {
  background: var(--bg-tertiary);
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 48px;
  min-height: 48px;
  box-sizing: border-box;
  overflow: hidden;
}

.pane-title {
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pane-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

#chapter-editor-textarea,
#manuscript-editor-highlight,
#editor-suggestion-textarea,
#editor-suggestion-highlight {
  font-family: 'JetBrains Mono', monospace !important;
  font-size: 0.9rem !important;
  line-height: 1.7 !important;
  box-sizing: border-box !important;
  white-space: pre-wrap !important;
  word-break: break-word !important;
  scrollbar-gutter: stable !important;
  padding: 1.5rem !important;
}

.editor-textarea {
  flex-grow: 1;
  background: transparent;
  border: none;
  padding: 1.5rem;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  line-height: 1.7;
  resize: none;
  outline: none;
}

.editor-view-pane {
  padding: 1.5rem;
  overflow-y: auto;
  flex-grow: 1;
  font-size: 0.95rem;
  line-height: 1.7;
}

/* Focused Mode Classes */
.app-container.focused .sidebar {
  transform: translateX(-260px);
}

.app-container.focused .main-content {
  margin-left: 0;
  width: 100%;
  padding-top: 10px !important;
}

/* Settings Form View */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.settings-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
}

.settings-card-header {
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.settings-card-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

/* Forum Discussion styling */
.forum-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.forum-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.thread-row {
  cursor: pointer;
}

.thread-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Detail sections / overlays */
.overlay-view {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

/* Form layouts */
.grid-form-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 650px) {
  .grid-form-2 {
    grid-template-columns: 1fr;
  }
}

/* Focused Mode Exit Button styling */
#exit-focus-btn {
  display: none;
  position: fixed;
  top: 10px;
  right: 1.25rem;
  z-index: 9999;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.8rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: var(--transition-fast);
  height: 32px;
  box-sizing: border-box;
}

#exit-focus-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-hover);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  transform: translateY(-1px);
}

#exit-focus-btn:focus {
  outline: none;
  border-color: var(--border-hover);
}

.app-container.focused #exit-focus-btn {
  display: flex !important;
}

/* Focused Mode Mobile adjustments to hide menu and brand title bar */
.app-container.focused .mobile-navbar {
  display: none !important;
}

.app-container.focused .content-section {
  padding-top: 0 !important;
}
/* Prevent floating Exit Focus Mode button from overlapping save/close and tab controls */
@media (min-width: 1024px) {
  .app-container.focused .overlay-header,
  .app-container.focused .main-header {
    padding-right: 6.5rem !important;
  }
  .app-container.focused .editor-header-toolbar {
    padding-right: 7rem !important;
  }
  .app-container.focused #exit-focus-btn {
    top: 10px !important;
    right: 2rem !important;
    height: 26px !important;
    padding: 0.2rem 0.6rem !important;
    font-size: 0.72rem !important;
    line-height: normal !important;
  }
}

@media (max-width: 1023px) {
  .app-container.focused .overlay-header,
  .app-container.focused .main-header {
    padding-right: 6rem !important;
  }
  .app-container.focused .editor-header-toolbar {
    padding-right: 5rem !important;
  }

  #editor-split-container .pane-header {
    height: auto !important;
    min-height: 72px !important;
    flex-wrap: wrap !important;
    padding: 0.35rem 0.5rem !important;
    gap: 0.25rem !important;
    align-content: center !important;
  }

  #editor-split-container .pane-header > div:first-child {
    flex: 0 0 100% !important;
    display: flex !important;
    align-items: center !important;
  }

  #editor-approve-all-btn {
    width: 100% !important;
    justify-content: center !important;
    height: 26px !important;
    font-size: 0.72rem !important;
  }

  #editor-split-container .pane-header > div:last-child {
    width: 100% !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
  }
}

.app-container.focused .editor-title-container {
  display: none !important;
}

.app-container.focused .editor-header-toolbar button {
  font-size: 0.72rem !important;
  padding: 0.2rem 0.6rem !important;
  height: 26px !important;
  box-sizing: border-box !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: normal !important;
}

.app-container.focused .editor-header-toolbar select {
  font-size: 0.72rem !important;
  height: 26px !important;
  box-sizing: border-box !important;
  line-height: normal !important;
  display: inline-block !important;
  padding: 0.2rem 1.2rem 0.2rem 0.4rem !important;
  background-position: right 0.35rem center !important;
  background-size: 0.55rem !important;
}

.app-container.focused .toolbar-toggle-label {
  font-size: 0.72rem !important;
  padding: 0 0.5rem !important;
  height: 26px !important;
}

.app-container.focused #editor-chapter-select {
  width: auto !important;
  min-width: 100px !important;
  max-width: 180px !important;
}

.app-container.focused #editor-add-section-select {
  width: auto !important;
  min-width: 115px !important;
  max-width: 140px !important;
}

/* Sidebar Nav Submenus and Collapsible Groups */
.nav-group {
  display: flex;
  flex-direction: column;
}

.nav-item .chevron {
  margin-left: auto;
  font-size: 0.65rem;
  padding: 0.25rem;
  opacity: 0.5;
  transition: transform var(--transition-fast);
}

.nav-item .chevron:hover {
  opacity: 1;
}

.nav-group.expanded .chevron {
  transform: rotate(180deg);
}

.nav-sub-items {
  display: flex;
  flex-direction: column;
  padding-left: 1.5rem;
  margin-top: 0.25rem;
  border-left: 1px solid var(--border-color);
  margin-left: 1.5rem;
  gap: 0.25rem;
}

.nav-sub-item {
  display: block;
  padding: 0.4rem 0.5rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.nav-sub-item:hover, .nav-sub-item.active {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.05);
}

/* Project Nested Sidebar Groups */
.project-sub-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.25rem;
}

.project-sub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.project-sub-header .nav-sub-item-header {
  flex-grow: 1;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-sub-header .nav-sub-item-header:hover, .project-sub-header .nav-sub-item-header.active {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.05);
}

.project-sub-header .sub-chevron {
  font-size: 0.55rem;
  padding: 0.25rem;
  opacity: 0.5;
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.project-sub-group.expanded .sub-chevron {
  transform: rotate(180deg);
}

.project-sub-links {
  display: flex;
  flex-direction: column;
  padding-left: 1rem;
  border-left: 1px dashed var(--border-color);
  margin-left: 0.75rem;
  margin-top: 0.15rem;
  gap: 0.15rem;
}

.nav-sub-link {
  display: block;
  padding: 0.3rem 0.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.nav-sub-link:hover, .nav-sub-link.active {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.05);
}

/* Contributor Selection and Ordering */
.contributor-ordering-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem;
  background-color: rgba(0, 0, 0, 0.15);
}

.contributor-order-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.contributor-order-item:hover {
  border-color: var(--border-hover);
}

.contributor-order-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.contributor-order-info input[type="checkbox"] {
  width: auto;
  margin-right: 0.5rem;
}

.contributor-order-actions {
  display: flex;
  gap: 0.25rem;
}

.order-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.order-btn:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

/* Diff Highlighting & Spellcheck overlay */
.diff-added {
  background-color: rgba(16, 185, 129, 0.22) !important;
  color: #10b981 !important;
  text-decoration: none !important;
  padding: 0 !important;
  border-radius: 0 !important;
  font-weight: inherit !important;
}

.diff-removed {
  background-color: rgba(239, 68, 68, 0.22) !important;
  color: #ef4444 !important;
  text-decoration: none !important;
  padding: 0 !important;
  border-radius: 0 !important;
  font-weight: inherit !important;
}

.editor-typo {
  text-decoration: underline wavy #ef4444 !important;
  text-decoration-color: #ef4444 !important;
  -webkit-text-decoration-color: #ef4444 !important;
  color: transparent !important;
}

/* --- THEME STYLING OVERRIDES --- */

/* Dark Memories */
html[data-theme="dark-memories"] {
  --bg-primary: #0f0913;
  --bg-secondary: #0c0610;
  --bg-tertiary: #1a1020;
  --border-color: rgba(50, 27, 68, 0.4);
  --border-hover: #ec4899;
  --text-primary: #f1eef5;
  --text-secondary: #9b8ea9;
  --text-muted: #685a75;
  --accent-purple: #8b5cf6;
  --accent-cyan: #ec4899;
  --accent-blue: #a78bfa;
  --gradient-purple: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --gradient-cyan: linear-gradient(135deg, #ec4899 0%, #a78bfa 100%);
  --gradient-glow: linear-gradient(135deg, rgba(139, 92, 246, 0.05) 0%, rgba(236, 72, 153, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --btn-primary-text: #ffffff;
}

/* Mint Chocolate Chip */
html[data-theme="mint-chocolate-chip"] {
  --bg-primary: #2f1f17;
  --bg-secondary: #1f140e;
  --bg-tertiary: #3e2a1e;
  --border-color: rgba(74, 53, 37, 0.4);
  --border-hover: #aaf0d1;
  --text-primary: #f5f5f5;
  --text-secondary: #b09b8f;
  --text-muted: #827269;
  --accent-purple: #aaf0d1;
  --accent-cyan: #ffd1b3;
  --accent-blue: #ff7878;
  --gradient-purple: linear-gradient(135deg, #aaf0d1 0%, #ffd1b3 100%);
  --gradient-cyan: linear-gradient(135deg, #ffd1b3 0%, #ff7878 100%);
  --gradient-glow: linear-gradient(135deg, rgba(170, 240, 209, 0.05) 0%, rgba(255, 209, 179, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #aaf0d1 0%, #ffd1b3 100%);
  --btn-primary-text: #1f140e;
}

/* Lunar Del Soul */
html[data-theme="lunar-del-soul"] {
  --bg-primary: #191730;
  --bg-secondary: #100e21;
  --bg-tertiary: #26234a;
  --border-color: rgba(51, 47, 99, 0.4);
  --border-hover: #fde047;
  --text-primary: #f0f0f5;
  --text-secondary: #8c89a8;
  --text-muted: #5f5c78;
  --accent-purple: #c471ed;
  --accent-cyan: #fde047;
  --accent-blue: #fb7185;
  --gradient-purple: linear-gradient(135deg, #c471ed 0%, #fb7185 100%);
  --gradient-cyan: linear-gradient(135deg, #fde047 0%, #c471ed 100%);
  --gradient-glow: linear-gradient(135deg, rgba(196, 113, 237, 0.05) 0%, rgba(253, 224, 71, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #c471ed 0%, #fde047 100%);
  --btn-primary-text: #100e21;
}

/* Sunshine Freedom */
html[data-theme="sunshine-freedom"] {
  --bg-primary: #2d1e0f;
  --bg-secondary: #1c1209;
  --bg-tertiary: #402b15;
  --border-color: rgba(82, 55, 27, 0.4);
  --border-hover: #fbbf24;
  --text-primary: #fffaf0;
  --text-secondary: #c29972;
  --text-muted: #8c6a49;
  --accent-purple: #fbbf24;
  --accent-cyan: #f97316;
  --accent-blue: #4ade80;
  --gradient-purple: linear-gradient(135deg, #fbbf24 0%, #f97316 100%);
  --gradient-cyan: linear-gradient(135deg, #f97316 0%, #4ade80 100%);
  --gradient-glow: linear-gradient(135deg, rgba(251, 191, 36, 0.05) 0%, rgba(249, 115, 22, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #fbbf24 0%, #f97316 100%);
  --btn-primary-text: #1c1209;
}

/* Event Horizon */
html[data-theme="event-horizon"] {
  --bg-primary: #0a0a0c;
  --bg-secondary: #0e0e10;
  --bg-tertiary: #18181c;
  --border-color: rgba(45, 45, 50, 0.4);
  --border-hover: #ef4444;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent-purple: #ef4444;
  --accent-cyan: #dc2626;
  --accent-blue: #10b981;
  --gradient-purple: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  --gradient-cyan: linear-gradient(135deg, #dc2626 0%, #10b981 100%);
  --gradient-glow: linear-gradient(135deg, rgba(239, 68, 68, 0.05) 0%, rgba(220, 38, 38, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  --btn-primary-text: #ffffff;
}

/* Windows Modern */
html[data-theme="windows-modern"] {
  --bg-primary: #202020;
  --bg-secondary: #181818;
  --bg-tertiary: #2d2d2d;
  --border-color: rgba(60, 60, 60, 0.4);
  --border-hover: #0078d7;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent-purple: #0078d7;
  --accent-cyan: #8a2be2;
  --accent-blue: #22c55e;
  --gradient-purple: linear-gradient(135deg, #0078d7 0%, #8a2be2 100%);
  --gradient-cyan: linear-gradient(135deg, #8a2be2 0%, #22c55e 100%);
  --gradient-glow: linear-gradient(135deg, rgba(0, 120, 215, 0.05) 0%, rgba(138, 43, 226, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #0078d7 0%, #8a2be2 100%);
  --btn-primary-text: #ffffff;
}

/* Colorblind Safe */
html[data-theme="colorblind-safe"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --border-color: rgba(71, 85, 105, 0.4);
  --border-hover: #f97316;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-purple: #f97316;
  --accent-cyan: #38bdf8;
  --accent-blue: #eab308;
  --gradient-purple: linear-gradient(135deg, #f97316 0%, #38bdf8 100%);
  --gradient-cyan: linear-gradient(135deg, #38bdf8 0%, #eab308 100%);
  --gradient-glow: linear-gradient(135deg, rgba(249, 115, 22, 0.05) 0%, rgba(56, 189, 248, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #f97316 0%, #38bdf8 100%);
  --btn-primary-text: #0f172a;
}

/* Antigravity */
html[data-theme="antigravity"] {
  --bg-primary: #0a0c18;
  --bg-secondary: #141930;
  --bg-tertiary: #1b213a;
  --border-color: rgba(45, 55, 90, 0.4);
  --border-hover: #00f5ff;
  --text-primary: #f0f4ff;
  --text-secondary: #96a0c8;
  --text-muted: #4e567e;
  --accent-purple: #00f5ff;
  --accent-cyan: #af5aff;
  --accent-blue: #facc15;
  --gradient-purple: linear-gradient(135deg, #00f5ff 0%, #af5aff 100%);
  --gradient-cyan: linear-gradient(135deg, #af5aff 0%, #facc15 100%);
  --gradient-glow: linear-gradient(135deg, rgba(0, 245, 255, 0.05) 0%, rgba(175, 90, 255, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #00f5ff 0%, #af5aff 100%);
  --btn-primary-text: #0a0c18;
}

/* High Contrast Dark */
html[data-theme="high-contrast-dark"] {
  --bg-primary: #000000;
  --bg-secondary: #000000;
  --bg-tertiary: #141414;
  --border-color: #ffffff;
  --border-hover: #ffff00;
  --text-primary: #ffffff;
  --text-secondary: #b4b4b4;
  --text-muted: #888888;
  --accent-purple: #ffff00;
  --accent-cyan: #ff00ff;
  --accent-blue: #00ff00;
  --gradient-purple: linear-gradient(135deg, #ffff00 0%, #ff00ff 100%);
  --gradient-cyan: linear-gradient(135deg, #ff00ff 0%, #00ff00 100%);
  --gradient-glow: linear-gradient(135deg, rgba(255, 255, 0, 0.05) 0%, rgba(255, 0, 255, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #ffff00 0%, #ff00ff 100%);
  --btn-primary-text: #000000;
}

/* High Contrast Light */
html[data-theme="high-contrast-light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #ffffff;
  --bg-tertiary: #ebebeb;
  --border-color: #000000;
  --border-hover: #0000ff;
  --text-primary: #000000;
  --text-secondary: #464646;
  --text-muted: #767676;
  --accent-purple: #0000ff;
  --accent-cyan: #800080;
  --accent-blue: #ff0000;
  --gradient-purple: linear-gradient(135deg, #0000ff 0%, #800080 100%);
  --gradient-cyan: linear-gradient(135deg, #800080 0%, #ff0000 100%);
  --gradient-glow: linear-gradient(135deg, rgba(0, 0, 255, 0.05) 0%, rgba(128, 0, 128, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #0000ff 0%, #800080 100%);
  --btn-primary-text: #ffffff;
}

/* Windows 9x */
html[data-theme="windows-9x"] {
  --bg-primary: #105e5e;
  --bg-secondary: #d4d0c8;
  --bg-tertiary: #c0c0c0;
  --border-color: #808080;
  --border-hover: #000080;
  --text-primary: #000000;
  --text-secondary: #404040;
  --text-muted: #777777;
  --accent-purple: #000080;
  --accent-cyan: #800080;
  --accent-blue: #800000;
  --gradient-purple: linear-gradient(135deg, #000080 0%, #800080 100%);
  --gradient-cyan: linear-gradient(135deg, #800080 0%, #800000 100%);
  --gradient-glow: linear-gradient(135deg, rgba(0, 0, 128, 0.05) 0%, rgba(128, 0, 128, 0.05) 100%);
  --gradient-brand: linear-gradient(135deg, #000080 0%, #800080 100%);
  --radius-sm: 0px !important;
  --radius-md: 0px !important;
  --radius-lg: 0px !important;
}

html[data-theme="windows-9x"] * {
  border-radius: 0px !important;
  font-family: 'MS Sans Serif', 'Arial', sans-serif !important;
}

html[data-theme="windows-9x"] .loading-spinner {
  border-radius: 50% !important;
}

html[data-theme="windows-9x"] button, 
html[data-theme="windows-9x"] .btn {
  background: #d4d0c8 !important;
  color: #000000 !important;
  border: 2px solid !important;
  border-color: #ffffff #808080 #808080 #ffffff !important;
  box-shadow: inset 1px 1px 0 0 #dfdfdf !important;
}

html[data-theme="windows-9x"] button:active, 
html[data-theme="windows-9x"] .btn:active {
  border-color: #808080 #ffffff #ffffff #808080 !important;
}

html[data-theme="windows-9x"] input, 
html[data-theme="windows-9x"] select, 
html[data-theme="windows-9x"] textarea {
  background-color: #ffffff !important;
  color: #000000 !important;
  border: 2px solid !important;
  border-color: #808080 #ffffff #ffffff #808080 !important;
}

html[data-theme="windows-9x"] #editor-suggestion-highlight {
  background-color: #ffffff !important;
  color: #000000 !important;
}

/* Windows 9x Workspace Layout & Contrast Settings */
html[data-theme="windows-9x"] .main-content {
  background-color: var(--bg-secondary) !important;
}

html[data-theme="windows-9x"] .main-content,
html[data-theme="windows-9x"] .overlay-view,
html[data-theme="windows-9x"] .modal-content {
  color: var(--text-secondary) !important;
}

html[data-theme="windows-9x"] .main-content h1,
html[data-theme="windows-9x"] .main-content h2,
html[data-theme="windows-9x"] .main-content h3,
html[data-theme="windows-9x"] .main-content h4,
html[data-theme="windows-9x"] .main-content h5,
html[data-theme="windows-9x"] .main-content h6,
html[data-theme="windows-9x"] .main-content strong,
html[data-theme="windows-9x"] .main-content th,
html[data-theme="windows-9x"] .main-content td,
html[data-theme="windows-9x"] .overlay-view h1,
html[data-theme="windows-9x"] .overlay-view h2,
html[data-theme="windows-9x"] .overlay-view h3,
html[data-theme="windows-9x"] .overlay-view h4,
html[data-theme="windows-9x"] .overlay-view h5,
html[data-theme="windows-9x"] .overlay-view h6,
html[data-theme="windows-9x"] .overlay-view strong,
html[data-theme="windows-9x"] .overlay-view th,
html[data-theme="windows-9x"] .modal-content h1,
html[data-theme="windows-9x"] .modal-content h2,
html[data-theme="windows-9x"] .modal-content h3,
html[data-theme="windows-9x"] .modal-content h4,
html[data-theme="windows-9x"] .modal-content h5,
html[data-theme="windows-9x"] .modal-content h6,
html[data-theme="windows-9x"] .modal-content strong,
html[data-theme="windows-9x"] .modal-content th {
  color: var(--text-primary) !important;
}

/* Segmented Pill Tabs for Agents Workspace */
.agent-sub-tabs {
  display: inline-flex;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.25rem;
  margin-bottom: 1.5rem;
  box-sizing: border-box;
}

.agent-sub-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  outline: none;
}

.agent-sub-tab-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.agent-sub-tab-btn.active {
  background: var(--gradient-brand);
  color: #121215 !important;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(197, 168, 128, 0.25);
}

/* Scrollable subtab container for Continuity Workspace */
.facts-tabs-container {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none; /* Hide scrollbar for Firefox */
  -ms-overflow-style: none; /* Hide scrollbar for IE/Edge */
  -webkit-overflow-scrolling: touch; /* Smooth scroll for iOS */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.facts-tabs-container::-webkit-scrollbar {
  display: none;
}

.facts-subtab-btn {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  white-space: nowrap;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: normal; /* Fix vertical clipping */
}

.wizard-option-card:hover {
  border-color: var(--accent-light) !important;
  background: rgba(6, 182, 212, 0.05) !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}



/* Remove extra border around editor textareas to avoid double borders next to scrollbars under windows-9x */
html[data-theme="windows-9x"] textarea.editor-textarea, 
html[data-theme="windows-9x"] #editor-suggestion-textarea {
  border: none !important;
  box-shadow: none !important;
}

/* Premium Book Reader Styling */
.reader-volume-header {
  text-align: center;
  margin-bottom: 3.5rem;
}

.reader-volume-title {
  font-family: 'Lora', Georgia, serif;
  font-weight: 500;
  color: #8b5a2b;
  font-size: 2.2rem;
  margin: 0 0 1rem 0;
  letter-spacing: -0.01em;
}

.reader-volume-divider-line {
  border-bottom: 1px solid #e3dec9;
  margin: 1.5rem 0 0.75rem 0;
}

.reader-volume-divider-glyph {
  text-align: center;
  color: #8b5a2b;
  font-family: 'Lora', Georgia, serif;
  font-size: 1rem;
  line-height: 1;
}

.reader-chapter-title-container {
  text-align: center;
  margin-bottom: 2.5rem;
}

.reader-chapter-subtitle {
  font-family: 'Lora', Georgia, serif;
  font-size: 1rem;
  font-weight: 500;
  color: #8b5a2b;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 0.75rem;
}

.reader-chapter-title {
  font-family: 'Lora', Georgia, serif;
  font-weight: 600;
  color: #8b5a2b;
  font-size: 1.8rem;
  margin: 0 0 1.5rem 0;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.reader-chapter-divider {
  border-bottom: 1px solid #e3dec9;
  margin-bottom: 2.5rem;
}

.reader-chapter-body {
  font-family: 'Lora', Georgia, serif;
  font-size: 1.15rem;
  line-height: 1.8;
  color: #2d2620;
}

/* Paragraph spacing & alignment */
.reader-chapter-body p {
  margin: 0 0 1rem 0;
  text-align: justify;
  text-indent: 2rem;
}

/* First paragraph has no indent and features the drop cap */
.reader-chapter-body p:first-of-type {
  text-indent: 0;
}

.reader-chapter-body p:first-of-type::first-letter {
  font-family: 'Lora', Georgia, serif;
  font-size: 3.5rem;
  font-weight: bold;
  float: left;
  line-height: 0.85;
  margin: 0.1rem 0.5rem 0 0;
  color: #8b5a2b;
}

/* ==========================================================================
   Mobile & Tablet Responsiveness (Including Galaxy Z Fold 7 Support)
   ========================================================================== */

/* Mobile Navigation Header & Controls */
.mobile-navbar {
  display: none; /* Hidden on desktop */
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  min-height: 56px;
  box-sizing: border-box;
}

.mobile-menu-toggle {
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.mobile-menu-toggle:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.mobile-brand-title {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.5px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Sidebar Backdrop overlay */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(5px);
  z-index: 99; /* Just below sidebar on mobile (which is 100) */
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

/* Form inputs line height rule to satisfy AGENTS.md constraint */
a, button, input, select, textarea:not(.editor-textarea):not(#editor-suggestion-textarea) {
  line-height: normal !important;
}

@media (max-width: 1023px) {
  /* Hide the sidebar menu off-screen to act as a popup drawer */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: -300px !important; /* Hide left of the viewport */
    width: 280px !important;
    z-index: 100 !important; /* Float above content and backdrop */
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s !important;
    box-shadow: none !important; /* No shadow when hidden */
    visibility: hidden !important;
  }

  .sidebar.mobile-active {
    left: 0 !important; /* Slide in drawer menu */
    box-shadow: 15px 0 45px rgba(0, 0, 0, 0.5) !important;
    visibility: visible !important;
  }

  /* Expand main workspace layout to cover 100% of viewport width */
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 0 !important; /* Reset padding to fit mobile navbar layout */
  }

  .mobile-navbar {
    display: flex;
  }

  .main-header {
    padding: 1rem 1.25rem 0.75rem !important;
    margin-bottom: 1rem !important;
  }

  .content-section,
  #logs-tab,
  #world-facts-tab,
  #illustrations-tab,
  #project-settings-admin-tab {
    padding: 0 1.25rem 1.25rem !important;
    flex-grow: 1;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Specific override for editor-tab and reader-tab to occupy exact window height without page scroll */
  #editor-tab,
  #reader-tab {
    padding: 0 1.25rem 1.25rem !important;
    flex-grow: 1;
    flex-shrink: 1;
    min-height: 0 !important;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
  }

  .editor-header-toolbar {
    flex-wrap: wrap !important;
  }

  .editor-title-container {
    flex: 0 0 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    margin-bottom: 0.5rem !important;
  }
  .app-container.focused .editor-title-container {
    display: none !important;
  }

  /* Make containers scrollable horizontally rather than shrinking columns */
  .table-responsive, 
  .table-container,
  .admin-table-container,
  #projects-list-container,
  #users-table-container,
  .activity-log-container,
  .forum-thread-view,
  .network-map-wrapper {
    overflow-x: auto !important;
    width: 100% !important;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
  }

  .table-responsive table,
  .table-container table:not(.no-mobile-stack),
  #projects-list-container table,
  #users-table-container table,
  .admin-table-container table {
    min-width: 600px !important; /* Ensure table keeps dynamic visual data readable */
  }

  /* AI remains side-by-side-by-side on wide open mode (width 768px-1023px) */

  /* Compact toolbar controls in open mode to keep all controls and AI on the top row left of 'Exit' button */
  .editor-header-toolbar button,
  .editor-header-toolbar .toolbar-toggle-label,
  .app-container.focused .editor-header-toolbar button,
  .app-container.focused .toolbar-toggle-label {
    font-size: 0.72rem !important;
    padding: 0.22rem 0.5rem !important;
    height: 28px !important;
  }
  .editor-header-toolbar select,
  .app-container.focused .editor-header-toolbar select {
    font-size: 0.72rem !important;
    padding: 0.22rem 1.2rem 0.22rem 0.4rem !important;
    height: 28px !important;
    background-position: right 0.35rem center !important;
    background-size: 0.55rem !important;
  }
  #editor-chapter-select {
    width: auto !important;
    min-width: 100px !important;
    max-width: 180px !important;
  }
  #editor-add-section-select {
    width: auto !important;
    min-width: 115px !important;
    max-width: 140px !important;
  }
}

@media (max-width: 650px) {
  /* Compact layout rules for header title on small phone screens */
  .main-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
  }

  .header-controls {
    width: 100% !important;
  }

  .header-controls button {
    width: 100% !important;
    justify-content: center;
  }

  /* Form columns grid fallback */
  .grid-form-2, .grid-form-3, .stats-grid, .dashboard-stats {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  #editor-split-container {
    flex-direction: row !important;
    width: 100% !important;
    min-height: 0 !important;
    flex-shrink: 0 !important;
    gap: 0.4rem !important;
  }

  /* Responsive column/pane height splits for mobile views (Closed Mode: side-by-side on top of AI) */
  .editor-workspace {
    flex-direction: column !important;
    flex-grow: 1 !important;
    min-height: 0 !important;
    overflow: hidden !important;
    gap: 0.5rem !important;
  }

  .pane {
    height: 100% !important;
    min-height: 0 !important;
  }

  /* When Assistant (AI) is open in closed mode, divide available workspace height 55/45 */
  .editor-workspace:not(.full-focused) #editor-split-container {
    flex: 55 1 0% !important;
  }

  .editor-workspace:not(.full-focused) #editor-suggestions-pane {
    flex: 45 1 0% !important;
    width: 100% !important;
    min-height: 0 !important;
    flex-shrink: 0 !important;
    border-top: 1px solid var(--border-color) !important;
  }

  /* When Assistant (AI) is closed, split takes 100% of workspace height */
  .editor-workspace.full-focused #editor-split-container {
    height: 100% !important;
    flex-grow: 1 !important;
  }

  /* Compact controls on narrow screens to fit on exactly 2 rows */
  .editor-header-toolbar button,
  .editor-header-toolbar .toolbar-toggle-label,
  .app-container.focused .editor-header-toolbar button,
  .app-container.focused .toolbar-toggle-label {
    font-size: 0.68rem !important;
    padding: 0.2rem 0.35rem !important;
    height: 26px !important;
  }
  .editor-header-toolbar select,
  .app-container.focused .editor-header-toolbar select {
    font-size: 0.68rem !important;
    padding: 0.2rem 1.1rem 0.2rem 0.35rem !important;
    height: 26px !important;
    background-position: right 0.3rem center !important;
    background-size: 0.5rem !important;
  }
  #editor-chapter-select {
    width: auto !important;
    min-width: 95px !important;
    max-width: 140px !important;
  }
  #editor-add-section-select {
    width: auto !important;
    min-width: 105px !important;
    max-width: 130px !important;
  }

  /* Structure toolbar to fit on exactly 2 rows on mobile */
  .editor-header-toolbar {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.35rem !important;
    justify-content: flex-start !important;
  }

  .editor-title-container {
    flex: 0 0 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    order: 1 !important;
    margin-bottom: 0.35rem !important;
  }

  .editor-nav-group {
    order: 2 !important;
    flex: 0 0 auto !important;
  }

  .editor-toolbar-spacer {
    display: none !important;
  }

  #editor-add-section-select {
    order: 3 !important;
    flex: 0 0 auto !important;
  }

  .editor-toggles-group {
    order: 4 !important;
    flex: 0 0 auto !important;
  }

  .editor-save-btn {
    order: 5 !important;
    flex: 0 0 auto !important;
  }

  /* Focused mode mobile optimizations to fit on Row 1 and prevent overlap with Exit button */
  .app-container.focused #editor-chapter-select {
    width: auto !important;
    min-width: 80px !important;
    max-width: 120px !important;
  }

  .app-container.focused #editor-add-section-select {
    width: auto !important;
    min-width: 90px !important;
    max-width: 110px !important;
  }

  .app-container.focused #editor-tab {
    padding: 0 0.5rem 0.5rem !important;
  }

  .app-container.focused .editor-save-btn {
    margin-right: 0 !important;
  }

  .app-container.focused #exit-focus-btn {
    top: 8px !important;
    right: 0.5rem !important;
    height: 26px !important;
    padding: 0.2rem 0.5rem !important;
  }

  /* Make tables responsive and stack cells vertically on phones */
  table.data-table:not(.no-mobile-stack),
  table.data-table:not(.no-mobile-stack) thead,
  table.data-table:not(.no-mobile-stack) tbody,
  table.data-table:not(.no-mobile-stack) tr,
  table.data-table:not(.no-mobile-stack) th,
  table.data-table:not(.no-mobile-stack) td {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  table.data-table:not(.no-mobile-stack) thead {
    display: none !important; /* Hide standard headers on mobile */
  }

  table.data-table:not(.no-mobile-stack) tr {
    margin-bottom: 1rem !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-lg) !important;
    background: var(--bg-secondary) !important;
    padding: 0.75rem 1rem !important;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15) !important;
  }

  table.data-table:not(.no-mobile-stack) td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 0.5rem 0 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
    text-align: right !important;
    white-space: normal !important;
    word-break: break-word !important;
  }

  table.data-table:not(.no-mobile-stack) td:last-child {
    border-bottom: none !important;
  }

  table.data-table:not(.no-mobile-stack) td::before {
    content: attr(data-label);
    font-weight: 600 !important;
    color: var(--text-secondary) !important;
    font-size: 0.78rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    margin-right: 1.5rem !important;
    text-align: left !important;
    flex-shrink: 0 !important;
  }
}

@media (max-width: 1200px) {
  .editor-btn-text {
    display: none;
  }
}

/* Book Reader Sidebar */
.reader-sidebar {
  width: 240px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
}

@media (max-width: 1023px) {
  .reader-sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: -300px !important;
    width: 280px !important;
    height: 100% !important;
    z-index: 1000 !important;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s !important;
    box-shadow: none !important;
    background: var(--bg-secondary) !important;
    visibility: hidden !important;
  }

  .reader-sidebar.mobile-active {
    left: 0 !important;
    box-shadow: 15px 0 45px rgba(0, 0, 0, 0.5) !important;
    visibility: visible !important;
  }

  #reader-sidebar-toggle {
    display: inline-block !important;
  }
}

/* Custom scrollbar for the Book Reader paper container */
.reader-paper-container::-webkit-scrollbar {
  width: 10px !important;
}
.reader-paper-container::-webkit-scrollbar-track {
  background: #f7f4eb !important;
}
.reader-paper-container::-webkit-scrollbar-thumb {
  background: #8b5a2b !important; /* Rich brown matching book chapter titles for high contrast */
  min-height: 45px !important;     /* Prevents thumb from shrinking to a pixel on huge manuscripts */
  border-radius: var(--radius-sm);
  border: 2px solid #f7f4eb !important; /* Adds breathing space around the thumb */
}
.reader-paper-container::-webkit-scrollbar-thumb:hover {
  background: #5c3d1d !important; /* Darker brown on hover */
}

/* Illustrations Layout responsiveness */
.illustrations-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 1.5rem;
}

@media (max-width: 800px) {
  .illustrations-layout {
    flex-direction: column;
    overflow-y: auto !important;
  }
  .illustrations-queue-sidebar {
    max-width: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border-color);
    padding-right: 0 !important;
    padding-bottom: 1rem !important;
  }
}

/* New Art Gallery Grid Layout */
.illustration-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 165px);
  gap: 1rem;
  justify-content: start;
}

@media (max-width: 650px) {
  .illustration-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.75rem;
    justify-content: center;
  }
}

/* Writing Pipeline Dashboard Grid */
.pipeline-dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 1.5rem;
}

@media (max-width: 1023px) {
  .pipeline-dashboard-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
}

/* Cover Page Visual Editor Responsive Overrides */
@media (max-width: 768px) {
  #cover-page-visual-editor {
    flex-direction: column !important;
    overflow-y: auto !important;
  }
  #cover-page-visual-editor > div:first-child {
    width: 100% !important;
    height: auto !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border-color) !important;
    overflow-y: visible !important;
    flex-shrink: 0 !important;
  }
  #cover-page-visual-editor > div:last-child {
    width: 100% !important;
    height: auto !important;
    padding: 2rem 1rem !important;
    box-sizing: border-box !important;
  }
  #cover-page-preview-canvas {
    width: 320px !important;
    height: 480px !important;
    padding: 1.5rem 0 !important;
  }
  #cover-preview-header-group, #cover-preview-footer-group {
    padding: 0 1rem !important;
  }
  #cover-preview-title {
    font-size: 1.8rem !important;
  }

  /* In closed mode mobile, turn the visual controls panel into a popup modal/drawer */
  #editor-layout.full-focused #cover-properties-sidebar {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 90% !important;
    max-width: 380px !important;
    height: auto !important;
    max-height: 80vh !important;
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-hover) !important;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6) !important;
    border-radius: 8px !important;
    z-index: 200 !important;
    display: none !important; /* Managed dynamically via class .mobile-open */
    border-right: none !important;
    border-bottom: none !important;
  }

  /* Show the popup when it has the .mobile-open class */
  #editor-layout.full-focused #cover-properties-sidebar.mobile-open {
    display: flex !important;
  }

  /* Show the close button only in closed mode mobile */
  #editor-layout.full-focused #cover-properties-sidebar .mobile-only-header {
    display: flex !important;
  }

  /* Show the floating toggle button in closed mode mobile */
  #editor-layout.full-focused #cover-properties-toggle-btn {
    display: flex !important;
  }
}

/* Center and remove indent from Cover Page elements in reader */
.cover-page-container p {
  text-indent: 0 !important;
  text-align: center !important;
}

/* Disable drop caps for cover page elements */
.cover-page-container p::first-letter {
  font-size: inherit !important;
  font-weight: inherit !important;
  float: none !important;
  margin: 0 !important;
  color: inherit !important;
  line-height: inherit !important;
}

/* Image pointer and hover feedback in in-app reader */
#reader-story-content img {
  cursor: pointer;
  transition: opacity 0.2s ease;
}
#reader-story-content img:hover {
  opacity: 0.9;
}



