/* ============================================
   orOS Writer — Complete Stylesheet v1.4
   Fixes: Header/tabs layout, footnote area,
   single-row toolbar, page sizes, 
   word count arrow, session centering, 
   exit reading position, comments
   Author: Christos Koulaxizis | orOS Ecosystem
   ============================================ */

/* ===== LAYOUT — Body padding for fixed header ===== */
body.writer-page {
  min-height: 100vh;
  overflow: hidden;
  padding-top: 56px;
  box-sizing: border-box;
}

/* ===== TAB BAR ===== */
.tab-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 10px 0 10px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  flex-shrink: 0;
  position: relative;
  z-index: 999;
  min-height: 38px;
}

.tab-bar::-webkit-scrollbar { height: 3px; }
.tab-bar::-webkit-scrollbar-track { background: transparent; }
.tab-bar::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-primary);
  color: var(--text-muted);
  white-space: nowrap;
  max-width: 200px;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

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

.tab.active {
  background: var(--bg-surface);
  color: var(--accent-gold);
  border-color: var(--border-color);
  border-bottom: 1px solid var(--bg-surface);
  font-weight: 600;
  position: relative;
  z-index: 1;
}

.tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  max-width: 180px;
}

.tab-label-input,
.tab-label.editing {
  background: var(--bg-input);
  border: 1px solid var(--accent-gold);
  border-radius: 2px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-primary);
  padding: 0 4px;
  outline: none;
  max-width: 160px;
}

.tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 16px;
  line-height: 1;
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  background: transparent;
  border: none;
}

.tab-close:hover { background: rgba(255, 80, 80, 0.2); color: #ff5050; }

.tab-new {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 18px;
  font-weight: bold;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  margin-left: 4px;
  background: transparent;
  border: none;
}

.tab-new:hover { background: var(--accent-gold-dim); color: var(--accent-gold-light); }

/* ===== EDITOR WRAPPER & LAYOUT ===== */
#editor-wrapper {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 112px);
  margin-top: 0;
  background: var(--bg-dark);
  overflow: hidden;
}

.reading-progress-container {
  height: 3px;
  background: transparent;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

.reading-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent-gold);
  transition: width 0.1s ease;
  border-radius: 0 2px 2px 0;
}

/* ===== MAIN TOOLBAR ===== */
.main-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 4px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 998;
}

.toolbar-group,
.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 4px;
}

.toolbar-center { flex: 1; justify-content: center; }

.tb-separator {
  width: 1px;
  height: 24px;
  background: var(--border-color);
  margin: 0 4px;
  flex-shrink: 0;
}

.action-btn,
.fmt-text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 14px;
  font-family: var(--font-primary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.action-btn:hover,
.fmt-text-btn:hover { background: var(--bg-hover); color: var(--accent-gold-light); }
.action-btn:active,
.fmt-text-btn:active { background: var(--accent-gold-dim); }
.action-btn.active,
.fmt-text-btn.active {
  background: var(--accent-gold-dim);
  color: var(--accent-gold-light);
  border-color: var(--border-hover);
}

/* ===== DROPDOWN ===== */
.dropdown { position: relative; }
.dropdown-toggle { display: flex; align-items: center; gap: 2px; }
.dropdown-arrow-icon { font-size: 10px; margin-left: 2px; }

.dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 1100;
  min-width: 180px;
  overflow: hidden;
}

.dropdown-content.visible,
.dropdown-content.active { display: block; }

.dropdown-content button {
  display: block;
  width: 100%;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--font-primary);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.dropdown-content button:hover { background: var(--bg-hover); color: var(--accent-gold-light); }

/* ===== STYLES DROPDOWN ===== */
.styles-dropdown {
  height: 32px;
  padding: 0 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--font-primary);
  cursor: pointer;
  outline: none;
  max-width: 140px;
}

.styles-dropdown:hover,
.styles-dropdown:focus { border-color: var(--accent-gold); }
.styles-dropdown option { background: var(--bg-panel); color: var(--text-primary); }

/* ===== SECONDARY BARS ===== */
.goal-bar,
.find-replace-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: center;
}

.goal-bar select,
.goal-bar input[type="number"],
.session-bar input[type="number"] {
  height: 30px;
  padding: 0 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-primary);
  outline: none;
}

.goal-bar input[type="number"] { width: 80px; }

.goal-lock-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.find-replace-bar input[type="text"] {
  height: 30px;
  padding: 0 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-primary);
  outline: none;
  min-width: 120px;
}

.find-replace-bar input[type="text"]:focus { border-color: var(--accent-gold); }

.find-format-filter {
  height: 30px;
  padding: 0 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-primary);
  outline: none;
  cursor: pointer;
}

.find-format-filter option { background: var(--bg-panel); }

#fr-results {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 4px;
  white-space: nowrap;
}

/* ===== MINI BUTTONS ===== */
.mini-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  padding: 0 4px;
}

.mini-btn:hover { background: var(--bg-hover); color: var(--accent-gold-light); border-color: var(--border-hover); }

/* ===== RICH EDITOR ===== */
.rich-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
}

.rich-editor {
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 48px 64px 120px;
  outline: none;
  font-family: var(--font-primary);
  font-size: 16px;
  line-height: 1.8;
  color: var(--text-primary);
  background: var(--bg-dark);
  caret-color: var(--accent-gold);
  max-width: 900px;
  margin: 0 auto;
}

.rich-editor[data-page-size="full-width"] {
  max-width: none;
  padding: 48px 40px 120px;
}

.rich-editor[data-page-size="a5"] { max-width: 600px; }
.rich-editor[data-page-size="b5"] { max-width: 760px; }
.rich-editor[data-page-size="a3"] { max-width: 1000px; }

.rich-editor:empty::before,
.rich-editor.editor-empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
  font-style: italic;
  position: relative;
  display: block;
}

.rich-editor h1 { font-size: 2em; font-weight: 700; margin: 0.8em 0 0.4em; color: var(--accent-gold-light); line-height: 1.3; }
.rich-editor h2 { font-size: 1.6em; font-weight: 600; margin: 0.7em 0 0.35em; color: var(--accent-gold-light); line-height: 1.3; }
.rich-editor h3 { font-size: 1.3em; font-weight: 600; margin: 0.6em 0 0.3em; color: var(--text-primary); line-height: 1.3; }
.rich-editor h4 { font-size: 1.1em; font-weight: 600; margin: 0.5em 0 0.3em; color: var(--text-primary); line-height: 1.3; }
.rich-editor p { margin: 0.5em 0; }
.rich-editor ul, .rich-editor ol { margin: 0.5em 0; padding-left: 1.8em; }
.rich-editor li { margin: 0.2em 0; }

.rich-editor blockquote {
  border-left: 3px solid var(--accent-gold);
  padding: 0.3em 0 0.3em 1em;
  margin: 0.8em 0;
  color: inherit !important;
  font-style: normal !important;
  background: rgba(200, 169, 110, 0.05);
  border-radius: 0 4px 4px 0;
}

.rich-editor strong { color: var(--text-primary); font-weight: 700; }
.rich-editor em { font-style: italic; }
.rich-editor u { text-decoration-color: var(--accent-gold); }

.rich-editor code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.rich-editor pre {
  background: var(--bg-input);
  padding: 12px 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.8em 0;
  font-family: 'Courier New', monospace;
}

.rich-editor a {
  color: var(--accent-gold-light);
  text-decoration: underline;
  text-decoration-color: var(--accent-gold-dim);
}

.rich-editor img.editor-image { max-width: 100%; height: auto; border-radius: 6px; margin: 8px 0; }

.rich-editor table.custom-table { border-collapse: collapse; width: 100%; margin: 0.8em 0; }
.rich-editor table.custom-table td,
.rich-editor table.custom-table th { border: 1px solid var(--border-color); padding: 8px 12px; }
.rich-editor table.custom-table th { background: var(--accent-gold-dim); font-weight: 600; }

.rich-editor hr { border: none; border-top: 1px solid var(--border-color); margin: 1.5em 0; }

.rich-editor mark { background: rgba(200, 169, 110, 0.25); color: inherit; border-radius: 2px; padding: 0 2px; }
mark.find-match { background: rgba(255, 235, 59, 0.3); color: inherit; border-radius: 2px; padding: 0 1px; }
mark.find-match.current { background: rgba(255, 152, 0, 0.5); outline: 1px solid #ff9800; }

.outline-flash { animation: outlineFlash 1.2s ease; }

@keyframes outlineFlash {
  0%, 100% { background: transparent; }
  50% { background: var(--accent-gold-dim); }
}

.page-break-marker {
  width: 100%;
  height: 24px;
  margin: 12px 0;
  background: repeating-linear-gradient(135deg, transparent, transparent 4px, var(--accent-gold-dim) 4px, var(--accent-gold-dim) 8px);
  border-top: 1px dashed var(--border-color);
  border-bottom: 1px dashed var(--border-color);
  position: relative;
}

.page-break-marker::after {
  content: '— Page Break —';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-dark);
  padding: 0 8px;
}

/* ===== FOOTNOTE AREA ===== */
.footnote-area {
  border-top: 2px solid var(--border-color);
  padding: 12px 60px;
  background: var(--bg-panel);
  flex-shrink: 0;
  max-height: 200px;
  overflow-y: auto;
  margin: 0;
  position: relative;
  z-index: 1;
}

/* ===== FOOTNOTE LINK STYLING ===== */
.footnote-ref {
  color: var(--accent-gold, #c8a96e);
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s;
}
.footnote-ref:hover {
  text-decoration: underline;
  color: var(--accent-gold-light, #d4b876);
}

.footnote-back {
  color: var(--accent-gold, #c8a96e) !important;
  font-weight: 600;
  text-decoration: none;
  margin-right: 8px;
  transition: color 0.15s;
}
.footnote-back:hover {
  text-decoration: none;
  color: var(--accent-gold-light, #d4b876);
}

.footnote-entry a {
  color: var(--accent-gold, #c8a96e) !important;
}
.footnote-entry a:hover {
  color: var(--accent-gold-light, #d4b876) !important;
}

/* ===== SAVE INDICATOR & STATS ===== */
.save-indicator-overlay {
  position: absolute;
  bottom: 12px;
  left: 24px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
  pointer-events: none;
  font-family: var(--font-primary);
  letter-spacing: 0.3px;
  z-index: 10;
  transition: opacity 0.15s;
}

.stats-overlay {
  position: absolute;
  bottom: 12px;
  right: 24px;
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: auto;
  font-family: var(--font-primary);
  letter-spacing: 0.3px;
  z-index: 10;
  background: var(--bg-dark);
  border-radius: 4px;
  padding: 4px 8px;
}

.stats-default { 
  cursor: pointer; 
  opacity: 0.7; 
  transition: opacity 0.15s; 
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.stats-default:hover { opacity: 1; color: var(--accent-gold-light); }
.stats-up-arrow { 
  font-size: 10px; 
  color: var(--accent-gold); 
  transition: transform 0.2s;
}
.stats-default:hover .stats-up-arrow { 
  transform: translateY(-2px);
}
.stats-goal { color: var(--accent-gold); opacity: 0.8; }

.stats-detailed {
  display: none;
  flex-direction: column;
  gap: 4px;
  position: absolute;
  bottom: 100%;
  right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 6px;
  min-width: 240px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 12px;
  z-index: 1050;
}

.stats-detailed.visible { display: flex; }

.stat-row { display: flex; justify-content: space-between; gap: 12px; color: var(--text-secondary); }
.stat-row span:last-child { color: var(--text-primary); font-weight: 600; }

/* ===== SIDE PANELS ===== */
.side-panel {
  position: fixed;
  top: 112px;
  right: 0;
  width: 280px;
  max-height: calc(100vh - 172px);
  background: var(--bg-panel);
  border-left: 1px solid var(--border-color);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
  z-index: 1001;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  gap: 4px;
}

.panel-title { font-size: 13px; font-weight: 600; color: var(--accent-gold-light); text-transform: uppercase; letter-spacing: 0.5px; }
.panel-close { flex-shrink: 0; }
.panel-body { padding: 12px 14px; overflow-y: auto; flex: 1; }

/* ===== WORD FREQUENCY PANEL ===== */
.wordfreq-summary { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border-color); }
.wordfreq-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 4px; margin-bottom: 4px; }
.wf-word { min-width: 80px; font-size: 12px; color: var(--text-primary); text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.wordfreq-bar { flex: 1; height: 6px; background: var(--bg-input); border-radius: 3px; overflow: hidden; }
.wordfreq-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-gold), var(--accent-gold-light)); border-radius: 3px; transition: width 300ms ease; }
.wordfreq-count { min-width: 32px; text-align: right; font-size: 12px; color: var(--text-muted); font-weight: 600; }
.wordfreq-item.overused .wf-word { color: var(--accent-gold-light); }
.wordfreq-item:hover { background: var(--bg-hover); }
.wordfreq-empty { color: var(--text-muted); font-size: 12px; font-style: italic; padding: 8px; text-align: center; }
.word-row { display: flex; justify-content: space-between; padding: 4px 8px; border-bottom: 1px solid var(--border-color); }
.word-row .word { flex: 1; color: var(--text-primary); font-size: 12px; }
.word-row .count { color: var(--text-muted); font-size: 12px; min-width: 32px; text-align: right; }

/* ===== COMMENTS PANEL ===== */
#comments-list { display: flex; flex-direction: column; gap: 8px; }
.comment-item { background: var(--bg-dark); border: 1px solid var(--border-color); border-radius: 6px; padding: 10px 12px; position: relative; }
.comment-item.highlighted { border-color: var(--accent-gold); box-shadow: 0 0 0 1px var(--accent-gold); }
.comment-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.comment-author { font-size: 12px; font-weight: 600; color: var(--accent-gold); }
.comment-timestamp { font-size: 10px; color: var(--text-muted); }
.comment-text { font-size: 13px; color: var(--text-primary); line-height: 1.5; margin-bottom: 6px; }
.comment-quoted { font-size: 11px; color: var(--text-muted); font-style: italic; background: var(--bg-input); border-left: 2px solid var(--border-color); padding: 4px 8px; border-radius: 0 4px 4px 0; margin-bottom: 6px; max-height: 60px; overflow: hidden; }
.comment-actions { display: flex; gap: 4px; }
.comment-actions button { font-size: 11px; padding: 2px 8px; background: transparent; border: 1px solid var(--border-color); border-radius: 3px; color: var(--text-muted); cursor: pointer; transition: all 0.15s; }
.comment-actions button:hover { color: var(--danger); border-color: var(--danger); }
.comment-resolved { opacity: 0.5; }
.comment-resolved .comment-text { text-decoration: line-through; }
.comment-add-area { margin-top: 8px; }
.comment-add-area textarea { width: 100%; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-primary); font-size: 13px; font-family: var(--font-primary); padding: 8px; resize: vertical; outline: none; }
.comment-add-area textarea:focus { border-color: var(--accent-gold); }
.comment-highlight { background: rgba(255, 235, 59, 0.15); border-bottom: 1px dotted rgba(255, 235, 59, 0.4); cursor: pointer; }
.comment-highlight.active { background: rgba(255, 235, 59, 0.3); }

/* ===== TOC PANEL ===== */
.toc-item { display: flex; align-items: center; padding: 4px 8px; font-size: 13px; color: var(--text-secondary); cursor: pointer; border-radius: 4px; transition: background 0.15s; gap: 6px; }
.toc-item:hover { background: var(--bg-hover); color: var(--accent-gold); }
.toc-level-1 { font-weight: 600; }
.toc-level-2 { padding-left: 20px; }
.toc-level-3 { padding-left: 32px; font-size: 12px; }
.toc-level-4 { padding-left: 44px; font-size: 12px; }
.toc-level-5 { padding-left: 56px; font-size: 11px; }
.toc-level-6 { padding-left: 68px; font-size: 11px; }
.toc-num { color: var(--accent-gold); font-weight: 600; flex-shrink: 0; }

/* ===== VERSION HISTORY PANEL ===== */
.version-item { background: var(--bg-dark); border: 1px solid var(--border-color); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; transition: border-color 0.15s; }
.version-item:hover { border-color: var(--accent-gold); }
.version-item.current { border-color: var(--accent-gold); background: var(--accent-gold-dim); }
.version-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.version-time { font-size: 12px; font-weight: 600; color: var(--accent-gold); }
.version-badge { font-size: 10px; padding: 1px 6px; border-radius: 3px; background: var(--accent-gold-dim); color: var(--accent-gold-light); }
.version-words { font-size: 11px; color: var(--text-muted); }
.version-actions { display: flex; gap: 4px; margin-top: 6px; }
.version-actions button { font-size: 11px; padding: 2px 8px; background: transparent; border: 1px solid var(--border-color); border-radius: 3px; color: var(--text-secondary); cursor: pointer; transition: all 0.15s; }
.version-actions button:hover { border-color: var(--accent-gold); color: var(--accent-gold); }

.version-restore {
  padding: 4px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 11px;
  font-family: var(--font-primary);
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 6px;
  width: 100%;
}
.version-restore:hover {
  background: var(--accent-gold);
  border-color: var(--accent-gold);
  color: var(--bg-dark);
}

/* ===== METADATA PANEL ===== */
.meta-field { margin-bottom: 12px; }
.meta-field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.meta-field input[type="text"],
.meta-field select { width: 100%; height: 32px; padding: 0 8px; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-primary); font-size: 13px; font-family: var(--font-primary); outline: none; transition: border-color 0.15s; }
.meta-field input[type="text"]:focus,
.meta-field select:focus { border-color: var(--accent-gold); }
.meta-field-inline { display: inline-flex; align-items: center; gap: 4px; margin-right: 12px; margin-bottom: 8px; }
.meta-field-inline label { font-size: 12px; color: var(--text-muted); }
.meta-field-inline input[type="number"] { height: 28px; padding: 0 4px; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-primary); font-size: 12px; outline: none; }
.meta-dates { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border-color); }
.meta-date-row { font-size: 11px; color: var(--text-muted); padding: 2px 0; }
.settings-divider { height: 1px; background: var(--border-color); margin: 12px 0; }

/* ===== DIALOGS ===== */
.dialog-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.dialog {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 420px;
  max-width: 90vw;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.dialog-large { width: 680px; max-width: 92vw; }

.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border-color); }
.dialog-header h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--accent-gold); }
.dialog-close { background: transparent; border: none; color: var(--text-muted); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 4px; transition: background 0.15s, color 0.15s; }
.dialog-close:hover { background: rgba(255, 80, 80, 0.15); color: var(--danger); }

.dialog-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.dialog-field { margin-bottom: 12px; }
.dialog-field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.dialog-field input[type="text"],
.dialog-field input[type="url"],
.dialog-field input[type="number"],
.dialog-field textarea,
.dialog-field select { width: 100%; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-primary); font-size: 13px; font-family: var(--font-primary); padding: 8px; outline: none; transition: border-color 0.15s; }
.dialog-field input:focus,
.dialog-field textarea:focus,
.dialog-field select:focus { border-color: var(--accent-gold); }
.dialog-field textarea { resize: vertical; min-height: 60px; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border-color); }
.btn-primary, .btn-cancel { padding: 8px 16px; border-radius: 4px; font-size: 13px; font-family: var(--font-primary); font-weight: 600; cursor: pointer; border: 1px solid transparent; transition: all 0.15s; }
.btn-primary { background: var(--accent-gold); color: var(--bg-dark); border-color: var(--accent-gold); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-cancel { background: transparent; color: var(--text-secondary); border-color: var(--border-color); }
.btn-cancel:hover { border-color: var(--text-secondary); color: var(--text-primary); }

/* ===== TEMPLATES DIALOG ===== */
.templates-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.template-card { background: var(--bg-dark); border: 1px solid var(--border-color); border-radius: 6px; padding: 16px; cursor: pointer; transition: border-color 0.15s, transform 0.15s; text-align: center; }
.template-card:hover { border-color: var(--accent-gold); transform: translateY(-2px); }
.template-card > i { font-size: 28px; color: var(--accent-gold); margin-bottom: 8px; }
.template-card h4 { margin: 4px 0; font-size: 14px; color: var(--text-primary); }
.template-card p { margin: 0; font-size: 11px; color: var(--text-muted); }

.template-card.custom-template {
  border-color: var(--accent-gold);
  position: relative;
}
.template-card.custom-template::after {
  content: 'CUSTOM';
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 8px;
  background: var(--accent-gold);
  color: var(--bg-dark);
  padding: 2px 6px;
  border-radius: 3px;
}
.custom-template-actions {
  margin-top: 8px;
  display: flex;
  gap: 4px;
  justify-content: center;
}
.btn-delete-template {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--danger);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}
.btn-delete-template:hover {
  background: rgba(231, 76, 60, 0.15);
}

/* ===== SPECIAL CHARACTERS DIALOG ===== */
.special-chars-tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.sc-tab { padding: 6px 12px; background: transparent; border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-secondary); font-size: 12px; font-family: var(--font-primary); cursor: pointer; transition: all 0.15s; }
.sc-tab.active { background: var(--accent-gold-dim); border-color: var(--accent-gold); color: var(--accent-gold); }
.sc-tab:hover:not(.active) { border-color: var(--text-secondary); }

.special-chars-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px; max-height: 400px; overflow-y: auto; }
.sc-char { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; background: var(--bg-dark); border: 1px solid var(--border-color); border-radius: 4px; font-size: 18px; color: var(--text-primary); cursor: pointer; transition: all 0.15s; }
.sc-char:hover { background: var(--bg-hover); border-color: var(--accent-gold); color: var(--accent-gold); transform: scale(1.1); }

/* ===== SETTINGS MODAL ===== */
.settings-modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  z-index: 2100;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: var(--font-primary);
}

.settings-modal.active,
.settings-modal.visible { display: flex; }

.settings-modal-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); }

.settings-modal-content {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 560px;
  max-width: 92vw;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.settings-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border-color); }
.settings-header h2 { margin: 0; font-size: 18px; color: var(--accent-gold); }
.settings-close { background: transparent; border: none; color: var(--text-muted); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.settings-close:hover { background: rgba(255, 80, 80, 0.15); color: var(--danger); }

.settings-nav { display: flex; gap: 0; border-bottom: 1px solid var(--border-color); padding: 0 12px; }
.tab-btn { padding: 10px 16px; background: transparent; border: none; border-bottom: 2px solid transparent; color: var(--text-secondary); font-size: 13px; font-family: var(--font-primary); cursor: pointer; transition: color 0.15s, border-color 0.15s; }
.tab-btn.active { color: var(--accent-gold); border-bottom-color: var(--accent-gold); }

.settings-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.toggles-container { display: flex; flex-direction: column; gap: 4px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.toggle-label { font-size: 13px; color: var(--text-secondary); }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: var(--border-color); border-radius: 11px; transition: background 0.2s; }
.slider::before { content: ''; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px; background: var(--text-muted); border-radius: 50%; transition: transform 0.2s, background 0.2s; }
.switch input:checked + .slider { background: var(--accent-gold-dim); }
.switch input:checked + .slider::before { transform: translateX(18px); background: var(--accent-gold); }

.btn-install { padding: 4px 12px; background: var(--accent-gold); color: var(--bg-dark); border: none; border-radius: 4px; font-size: 12px; font-weight: 600; cursor: pointer; }
.btn-install:disabled { opacity: 0.4; cursor: not-allowed; }

#advanced-settings h4 { font-size: 14px; color: var(--accent-gold); margin: 0 0 8px; }
.autocorrect-rules-container { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.ac-rule-row { display: flex; align-items: center; gap: 6px; padding: 4px 0; }
.ac-rule-row input { background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-primary); font-size: 12px; padding: 4px 8px; outline: none; transition: border-color 0.15s; }
.ac-rule-row input:focus { border-color: var(--accent-gold); }
.autocorrect-add-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.autocorrect-add-row input { background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-primary); font-size: 12px; padding: 4px 8px; outline: none; transition: border-color 0.15s; }
.autocorrect-add-row input:focus { border-color: var(--accent-gold); }
#shortcuts-custom-container { display: flex; flex-direction: column; gap: 4px; }
.sc-custom-row { display: flex; align-items: center; gap: 6px; padding: 4px 0; font-size: 12px; color: var(--text-secondary); }
.sc-custom-row input { background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-primary); font-size: 12px; padding: 4px 8px; outline: none; width: 120px; transition: border-color 0.15s; }
.sc-custom-row input:focus { border-color: var(--accent-gold); }

/* ===== FOCUS MODE ===== */
body.focus-mode .rich-editor p,
body.focus-mode .rich-editor h1,
body.focus-mode .rich-editor h2,
body.focus-mode .rich-editor h3,
body.focus-mode .rich-editor h4,
body.focus-mode .rich-editor h5,
body.focus-mode .rich-editor h6,
body.focus-mode .rich-editor blockquote,
body.focus-mode .rich-editor pre,
body.focus-mode .rich-editor ul,
body.focus-mode .rich-editor ol,
body.focus-mode .rich-editor table {
  opacity: 0.25;
  transition: opacity 0.3s;
}

body.focus-mode .rich-editor p.is-focused,
body.focus-mode .rich-editor h1.is-focused,
body.focus-mode .rich-editor h2.is-focused,
body.focus-mode .rich-editor h3.is-focused,
body.focus-mode .rich-editor blockquote.is-focused,
body.focus-mode .rich-editor pre.is-focused,
body.focus-mode .rich-editor ul.is-focused,
body.focus-mode .rich-editor ol.is-focused {
  opacity: 1;
}

/* ===== TOAST ===== */
.zentool-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: var(--bg-panel);
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  padding: 14px 28px;
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-primary);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 9999;
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  text-align: center;
  max-width: 90vw;
}

.zentool-toast.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Centered welcome toast */
.zentool-toast.welcome-toast {
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) scale(0.9);
  font-size: 1.25rem;
  padding: 22px 40px;
  border-radius: 12px;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.zentool-toast.welcome-toast.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ===== ZEN MODE ===== */
body.zen-mode .header,
body.zen-mode #oros-header,
body.zen-mode #oros-footer,
body.zen-mode .main-toolbar,
body.zen-mode .quick-format-toolbar,
body.zen-mode .reading-progress-container,
body.zen-mode .tab-bar,
body.zen-mode .stats-overlay,
body.zen-mode .save-indicator-overlay,
body.zen-mode .goal-bar,
body.zen-mode .session-bar,
body[data-zen="true"] .footnote-area,
body.zen-mode .find-replace-bar {
  display: none !important;
}

body.zen-mode #editor-wrapper {
  height: 100vh;
  margin-top: 0;
}

body.zen-mode .rich-editor {
  padding-top: 15vh;
  padding-bottom: 30vh;
  max-width: 720px;
  margin: 0 auto;
}

body.zen-mode .side-panel {
  display: none;
}

/* Support for data-zen attribute from main.js */
body[data-zen="true"] .header,
body[data-zen="true"] #oros-header,
body[data-zen="true"] #oros-footer,
body[data-zen="true"] .main-toolbar,
body[data-zen="true"] .quick-format-toolbar,
body[data-zen="true"] .reading-progress-container,
body[data-zen="true"] .tab-bar,
body[data-zen="true"] .stats-overlay,
body[data-zen="true"] .save-indicator-overlay,
body[data-zen="true"] .goal-bar,
body[data-zen="true"] .session-bar,
body[data-zen="true"] .footnote-area,
body[data-zen="true"] .find-replace-bar {
  display: none !important;
}

body[data-zen="true"] #editor-wrapper {
  height: 100vh;
  margin-top: 0;
}

body[data-zen="true"] .rich-editor {
  padding-top: 15vh;
  padding-bottom: 30vh;
  max-width: 720px;
  margin: 0 auto;
}

body[data-zen="true"] .side-panel {
  display: none;
}

/* ===== SCROLLBAR ===== */
.rich-wrapper::-webkit-scrollbar,
.panel-body::-webkit-scrollbar,
.dialog-body::-webkit-scrollbar,
.settings-body::-webkit-scrollbar,
.footnote-area::-webkit-scrollbar {
  width: 8px;
}

.rich-wrapper::-webkit-scrollbar-track,
.panel-body::-webkit-scrollbar-track,
.dialog-body::-webkit-scrollbar-track,
.settings-body::-webkit-scrollbar-track,
.footnote-area::-webkit-scrollbar-track {
  background: transparent;
}

.rich-wrapper::-webkit-scrollbar-thumb,
.panel-body::-webkit-scrollbar-thumb,
.dialog-body::-webkit-scrollbar-thumb,
.settings-body::-webkit-scrollbar-thumb,
.footnote-area::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.rich-wrapper::-webkit-scrollbar-thumb:hover,
.panel-body::-webkit-scrollbar-thumb:hover,
.dialog-body::-webkit-scrollbar-thumb:hover,
.settings-body::-webkit-scrollbar-thumb:hover,
.footnote-area::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

/* ===== HELP DIALOG CONTENT ===== */
.help-section {
  margin-bottom: 16px;
}

.help-section h4 {
  font-size: 14px;
  color: var(--accent-gold);
  margin: 0 0 8px;
}

.shortcut-table {
  width: 100%;
  border-collapse: collapse;
}

.shortcut-table td {
  padding: 4px 8px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.shortcut-table td:first-child {
  width: 120px;
}

.shortcut-table kbd {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: 'Courier New', monospace;
  color: var(--accent-gold-light);
}

.help-list {
  list-style: disc;
  padding-left: 20px;
  margin: 0;
}

.help-list li {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 2px 0;
}

/* ===== PRINT STYLES ===== */
@media print {
  .header,
  #oros-header,
  #oros-footer,
  #tab-bar,
  #main-toolbar,
  .goal-bar,
  .session-bar,
  .find-replace-bar,
  .stats-overlay,
  .save-indicator-overlay,
  .reading-progress-container,
  .footnote-area,
  .side-panel,
  .dialog-overlay,
  .settings-modal,
  .zentool-toast,
  #btn-exit-reading-mode {
    display: none !important;
  }

  #editor-wrapper {
    height: auto;
    margin-top: 0;
  }

  .rich-wrapper {
    overflow: visible;
  }

  .rich-editor {
    max-width: none;
    padding: 0;
    color: black;
    background: white;
  }

  .page-break-marker {
    page-break-after: always;
    display: block;
    height: 0;
    margin: 0;
    border: none;
    background: none;
  }

  .page-break-marker::after {
    display: none;
  }
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  #editor-wrapper {
    height: calc(100vh - 96px);
    margin-top: 0;
  }

  .main-toolbar {
    padding: 4px 6px;
    gap: 2px;
  }

  .toolbar-group {
    gap: 1px;
  }

  .action-btn,
  .fmt-text-btn {
    min-width: 28px;
    height: 28px;
    font-size: 12px;
    padding: 0 4px;
  }

  .tb-separator {
    margin: 0 2px;
  }

  .rich-editor {
    padding: 20px 16px;
    font-size: 15px;
  }

  .side-panel {
    width: 100vw;
    top: 48px;
    height: calc(100vh - 96px);
  }

  .dialog {
    width: 94vw;
  }

  .styles-dropdown {
    max-width: 100px;
    font-size: 12px;
  }

  .session-bar,
  .find-replace-bar {
    flex-wrap: wrap;
  }

  .find-replace-bar input[type="text"] {
    min-width: 80px;
  }

  .goal-bar {
    flex-wrap: wrap;
  }

  .tab {
    max-width: 140px;
    padding: 6px 8px;
  }

  .tab-label {
    max-width: 100px;
  }
}

@media (max-width: 480px) {
  .hero {
    padding: calc(2.5rem + 48px) 0 2.5rem;
  }

  .hero h1 {
    font-size: 2.5rem;
  }

  .hero p {
    font-size: 1rem;
  }

  .tools-grid {
    gap: 1rem;
    padding: 1rem 0 calc(1rem + 48px);
  }

  .tool-card {
    min-width: 0;
    max-width: none;
    padding: 1.25rem;
  }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== AUTO-CORRECT RULES UI ===== */
.autocorrect-rules-container {
  margin-top: 16px;
}
.autocorrect-rules-list {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 12px;
}
.autocorrect-empty {
  text-align: center;
  padding: 16px;
  color: var(--text-muted, #888);
  font-size: 0.85rem;
}
.autocorrect-rule-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 6px;
  transition: background 0.15s;
}
.autocorrect-rule-row:hover {
  background: rgba(109,74,255,0.08);
}
.ac-trigger, .ac-replacement {
  flex: 1;
  background: var(--bg-input, rgba(0,0,0,0.3));
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-primary, #eee);
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 0.82rem;
  min-width: 0;
}
.ac-trigger:focus, .ac-replacement:focus {
  border-color: var(--accent, #6d4aff);
  outline: none;
}
.ac-arrow {
  color: var(--text-muted, #888);
  font-size: 0.8rem;
  flex-shrink: 0;
}
.ac-delete {
  background: none;
  border: none;
  color: var(--danger, #e74c3c);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: background 0.15s;
}
.ac-delete:hover {
  background: rgba(231,76,60,0.15);
}
.ac-badge {
  font-size: 0.65rem;
  color: var(--text-muted, #888);
  background: rgba(255,255,255,0.06);
  padding: 2px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}
.autocorrect-add-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.autocorrect-add-row input {
  flex: 1;
  background: var(--bg-input, rgba(0,0,0,0.3));
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-primary, #eee);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
}
.autocorrect-add-row input:focus {
  border-color: var(--accent, #6d4aff);
  outline: none;
}
.autocorrect-actions {
  display: flex;
  gap: 8px;
}

/* ===== QUICK FORMAT MENU ===== */
.quick-format-menu {
  display: none;
  position: fixed;
  z-index: 8000;
  background: var(--bg-panel, #1e1e2e);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.quick-format-menu.visible {
  display: flex;
  opacity: 1;
  transform: scale(1);
}
.qfm-group {
  display: flex;
  gap: 2px;
}
.qfm-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 3px 4px;
}
.qfm-btn {
  background: none;
  border: none;
  color: var(--text-primary, #eee);
  cursor: pointer;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  min-width: 34px;
  transition: background 0.12s;
}
.qfm-btn:hover {
  background: rgba(109,74,255,0.2);
}
.qfm-btn.qfm-action {
  color: var(--accent, #6d4aff);
}

/* ===== SINGLE-ROW TOOLBAR (1200px+) ===== */
@media (min-width: 1200px) {
  .main-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 8px;
    gap: 0;
    scrollbar-width: none;
  }
  .main-toolbar::-webkit-scrollbar { display: none; }
  .toolbar-group,
  .toolbar-left,
  .toolbar-center,
  .toolbar-right {
    gap: 1px;
    padding: 0 1px;
    flex-shrink: 0;
  }
  .toolbar-center {
    flex: 1;
    justify-content: center;
  }
  .action-btn,
  .fmt-text-btn {
    min-width: 26px;
    height: 26px;
    padding: 0 3px;
    font-size: 12px;
    flex-shrink: 0;
  }
  .tb-separator {
    width: 1px;
    height: 16px;
    margin: 0 1px;
    flex-shrink: 0;
  }
  .styles-dropdown {
    height: 26px;
    padding: 0 4px 0 6px;
    font-size: 11px;
    max-width: 96px;
    flex-shrink: 0;
  }
  .dropdown { flex-shrink: 0; }
}

@media (min-width: 1400px) {
  .main-toolbar { overflow: visible; }
  .action-btn, .fmt-text-btn {
    min-width: 28px;
    height: 28px;
    padding: 0 4px;
    font-size: 13px;
  }
  .styles-dropdown {
    height: 28px;
    font-size: 12px;
    max-width: 110px;
  }
}

/* ===== DB EXPORT & TEMPLATE ACTIONS ===== */
.db-export-btn {
  display: block;
  width: 100%;
  padding: 10px 16px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--font-primary);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 16px;
}
.db-export-btn:hover {
  background: var(--bg-hover);
  color: var(--accent-gold-light);
  border-color: var(--accent-gold);
}
.templates-dialog-actions {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-color);
  justify-content: space-between;
}
.templates-actions-left,
.templates-actions-right {
  display: flex;
  gap: 8px;
}

.btn-reset-autocorrect,
#btn-reset-autocorrect {
  background: var(--bg-hover, #f5f5f5);
  color: var(--text-primary, #333);
  border: 1px solid var(--border-color, #ddd);
  border-radius: 4px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  margin-top: 8px;
  transition: all 0.15s;
}

#btn-reset-autocorrect,
#btn-add-autocorrect,
.autocorrect-actions button {
  background: var(--bg-secondary, #2a2a3a);
  color: var(--text-primary, #eee);
  border: 1px solid var(--border-color, #444);
  border-radius: 4px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.85rem;
  margin: 4px 0;
  transition: all 0.15s;
}

#btn-reset-autocorrect:hover,
#btn-add-autocorrect:hover,
.autocorrect-actions button:hover {
  background: var(--bg-hover, #3a3a4a);
  border-color: var(--accent, #6d4aff);
}

/* ===== FOOTER ===== */
#oros-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--bg-dark);
  border-top: 1px solid var(--border-color);
  height: 56px;
}

#oros-footer > * {
  z-index: 9999;
}

/* ===== TEMPLATE CARDS (DETAILED) ===== */
.template-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border-color, #333);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
  min-height: 60px;
  background: var(--bg-dark);
}
.template-card:hover {
  border-color: var(--accent-gold, #c8a96e);
  background: rgba(200, 169, 110, 0.05);
}
.template-card .template-icon {
  font-size: 20px;
  color: var(--accent-gold, #c8a96e);
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}
.template-card .template-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}
.template-card .template-info strong {
  font-size: 0.9rem;
  line-height: 1.2;
}
.template-card .template-info small {
  font-size: 0.75rem;
  color: var(--text-muted, #888);
  line-height: 1.2;
}

.template-delete-btn,
.template-edit-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-panel, #1e1e2e);
  border: 1px solid var(--border-color, #333);
  border-radius: 4px;
  color: var(--text-muted, #888);
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  margin: 0;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s, border-color 0.2s;
  z-index: 3;
}
.template-delete-btn { right: 8px; }
.template-edit-btn { right: 38px; }
.template-delete-btn i,
.template-edit-btn i {
  font-size: 14px;
  line-height: 1;
  display: inline-block;
  margin: 0;
  vertical-align: middle;
}
.template-card:hover .template-delete-btn,
.template-card:hover .template-edit-btn {
  opacity: 1;
}
.template-delete-btn:hover { color: #e74c3c; border-color: #e74c3c; opacity: 1; }
.template-delete-btn:hover i { color: #e74c3c; }
.template-edit-btn:hover { color: var(--accent-gold, #c8a96e); border-color: var(--accent-gold, #c8a96e); opacity: 1; }
.template-edit-btn:hover i { color: var(--accent-gold, #c8a96e); }

.template-section-divider {
  grid-column: 1 / -1;
  text-align: center;
  margin: 16px 0 8px;
  padding-top: 16px;
  border-top: 2px solid var(--border-color, #333);
}
.template-section-divider span {
  font-size: 0.75rem;
  color: var(--text-muted, #888);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  background: var(--bg-panel, #1e1e2e);
  padding: 0 12px;
  position: relative;
  top: -10px;
}

/* ===== FOOTNOTE ENTRY HIGHLIGHT ===== */
.footnote-entry.flash-highlight {
  animation: footnote-flash 1.5s ease-out;
}

@keyframes footnote-flash {
  0%, 100% { background-color: transparent; }
  50% { background-color: rgba(109, 76, 255, 0.2); }
}

.footnote-back {
  min-width: 28px;
  text-align: center;
}

.rich-editor a {
  cursor: pointer;
}

/* ===== COMMENT STYLES ===== */
.comment-highlight {
  background-color: rgba(255, 235, 59, 0.4);
  border-radius: 2px;
  cursor: pointer;
}

.comment-highlight:hover {
  background-color: rgba(255, 235, 59, 0.6);
}

.comment-flash {
  animation: flash-comment 1.5s ease-out;
}

@keyframes flash-comment {
  0% { background-color: rgba(255, 235, 59, 0.8); }
  50% { background-color: rgba(255, 235, 59, 0.4); }
  100% { background-color: transparent; }
}

.comment-item {
  padding: 10px;
  border-bottom: 1px solid var(--border-color, #333);
}

.comment-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted, #888);
  margin-bottom: 4px;
}

.comment-date {
  font-size: 0.75rem;
}

.comment-delete {
  background: none;
  border: none;
  color: var(--danger, #ff4444);
  cursor: pointer;
  padding: 4px;
  opacity: 0.6;
}

.comment-delete:hover {
  opacity: 1;
}

.comment-text {
  font-size: 0.9rem;
  color: var(--text-primary, #e0e0e0);
  margin-bottom: 6px;
}

.comment-quoted {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--text-muted, #888);
  background: rgba(109, 76, 255, 0.1);
  padding: 6px 8px;
  border-radius: 4px;
  margin-top: 6px;
  border-left: 3px solid var(--primary, #6d4aff);
  cursor: pointer;
}

.comment-quoted:hover {
  background: rgba(109, 76, 255, 0.2);
}

.comments-empty {
  text-align: center;
  color: var(--text-muted, #888);
  padding: 20px;
  font-size: 0.9rem;
}

.comment-active {
  background-color: rgba(109, 76, 255, 0.35) !important;
  border-radius: 2px;
  transition: background-color 0.2s ease;
}

.comment-item.card-active {
  background-color: rgba(109, 76, 255, 0.15) !important;
  border-left: 3px solid var(--primary, #6d4aff);
  transition: background-color 0.2s ease;
}

/* ===== VERSION HISTORY ENHANCED ===== */
.version-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.version-item-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.version-item.manual-version {
  border-color: var(--accent-gold);
  background: var(--accent-gold-dim);
}

.manual-badge {
  background: var(--accent-gold);
  color: var(--bg-dark);
}

.auto-badge {
  background: var(--bg-input);
  color: var(--text-muted);
}

.version-delete {
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--danger, #e74c3c);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.version-delete:hover {
  background: rgba(231, 76, 60, 0.15);
  border-color: var(--danger, #e74c3c);
}

/* ===== FILE INPUT STYLING ===== */
#image-file-input {
  width: 100%;
  padding: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--font-primary);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

#image-file-input:hover {
  border-color: var(--accent-gold);
}

#image-file-input::-webkit-file-upload-button {
  background: var(--accent-gold);
  color: var(--bg-dark);
  border: none;
  border-radius: 4px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-primary);
  cursor: pointer;
  margin-right: 8px;
  transition: filter 0.15s;
}

#image-file-input::-webkit-file-upload-button:hover {
  filter: brightness(1.1);
}

#image-file-input::-moz-file-upload-button {
  background: var(--accent-gold);
  color: var(--bg-dark);
  border: none;
  border-radius: 4px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-primary);
  cursor: pointer;
  margin-right: 8px;
}

/* ===== SESSION TIMER CENTERING ===== */
.session-bar {
  justify-content: center !important;
}

.session-display-container {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 0 8px;
  min-width: 160px;
  justify-content: center;
}

.session-words-display {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== GOAL TRACKER PROGRESS ===== */
.goal-bar {
  justify-content: center;
}

.goal-bar-progress {
  font-size: 13px;
  color: var(--accent-gold);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-left: 8px;
  white-space: nowrap;
}

.goal-time-label {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0 2px;
}

.goal-bar-label {
  font-size: 13px;
  color: var(--text-secondary);
}

#goal-time-input {
  height: 30px;
  padding: 0 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-primary);
  outline: none;
  width: 50px;
}

#goal-time-input:focus {
  border-color: var(--accent-gold);
}

/* ===== PAGE SIZE (visual preview in editor) ===== */
.rich-editor[data-page-size="a4"]         { max-width: 210mm; margin: 0 auto; }
.rich-editor[data-page-size="letter"]     { max-width: 216mm; margin: 0 auto; }
.rich-editor[data-page-size="legal"]      { max-width: 216mm; margin: 0 auto; }
.rich-editor[data-page-size="a3"]         { max-width: 297mm; margin: 0 auto; }
.rich-editor[data-page-size="a5"]         { max-width: 148mm; margin: 0 auto; }
.rich-editor[data-page-size="b5"]         { max-width: 176mm; margin: 0 auto; }
.rich-editor[data-page-size="full-width"] { max-width: none; padding: 48px 40px 120px; }

/* ===== PRINT HEADER / FOOTER ===== */
@media print {
  body * { visibility: hidden; }
  .rich-editor, .rich-editor * { visibility: visible; }
  .rich-editor {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
  .toolbar-group, .tab-bar, .find-replace-bar, .goal-bar,
  .side-panel, .dialog-overlay, .stats-overlay,
  .reading-progress-container, .save-indicator-overlay,
  .footnote-area, #oros-header, #oros-footer {
    display: none !important;
  }
}

/* ===== HEADER / FOOTER PREVIEW (VISUAL) ===== */
/* ΜΕΤΑ */
.header-preview {
  position: relative;
  background: rgba(109, 76, 255, 0.08);
  border-bottom: 1px solid var(--accent-gold);
  font-size: 11px;
  color: var(--accent-gold);
  text-align: center;
  padding: 6px 12px;
  flex-shrink: 0;
  display: none;
  font-weight: 600;
}

.footer-preview {
  position: relative;
  background: rgba(109, 76, 255, 0.08);
  border-top: 1px solid var(--accent-gold);
  font-size: 11px;
  color: var(--accent-gold);
  text-align: center;
  padding: 6px 12px;
  flex-shrink: 0;
  display: none;
  font-weight: 600;
}

.page-dimensions-info {
  font-size: 11px;
  color: var(--accent-gold);
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--bg-input);
  border-radius: 4px;
  text-align: center;
  font-family: var(--font-primary);
  border: 1px solid var(--border-color);
}

/* ===== WORD FREQUENCY — ENHANCED SUMMARY ===== */
.wordfreq-summary-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.wordfreq-summary-icon {
  font-size: 18px;
  color: var(--accent-gold);
  flex-shrink: 0;
}

.wordfreq-summary-text {
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.3px;
}

.wordfreq-summary-text a,
.wordfreq-summary-text span {
  font-weight: 700;
  color: var(--accent-gold-light);
}

/* ===== TOOLBAR SIZE ADJUSTMENT ===== */
.main-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap !important;
  padding: 6px 12px;
  min-height: 48px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.action-btn,
.fmt-text-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  flex-shrink: 0;
}

.action-btn i,
.fmt-text-btn i {
  font-size: 15px;
  line-height: 1;
}

.tb-separator {
  width: 1px;
  height: 24px;
  background: var(--border-color, #333);
  margin: 0 4px;
  flex-shrink: 0;
}

.styles-dropdown {
  font-size: 14px;
  padding: 6px 10px;
  height: 36px;
  flex-shrink: 0;
}

/* Mobile fallback */
@media (max-width: 768px) {
  .main-toolbar {
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }
}

/* ===== TOOLBAR CENTERING — FINAL OVERRIDE ===== */
.toolbar-center {
  flex: 1 1 0% !important;
  justify-content: center !important;
  flex-shrink: 1 !important;
}

/* ===== CLOUD SYNC PANEL ===== */
.cloud-sync-section {
  max-width: 480px;
}

.sync-status-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-primary);
  letter-spacing: 0.3px;
}

.sync-status.sync-synced {
  background: rgba(46, 204, 113, 0.15);
  color: #2ecc71;
  border: 1px solid rgba(46, 204, 113, 0.3);
}

.sync-status.sync-syncing {
  background: rgba(241, 196, 15, 0.15);
  color: #f1c40f;
  border: 1px solid rgba(241, 196, 15, 0.3);
}

.sync-status.sync-error {
  background: rgba(231, 76, 60, 0.15);
  color: #e74c3c;
  border: 1px solid rgba(231, 76, 60, 0.3);
}

.sync-status.sync-idle {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.sync-status.sync-unsupported {
  background: rgba(230, 126, 34, 0.15);
  color: #e67e22;
  border: 1px solid rgba(230, 126, 34, 0.3);
}

.sync-dir-display {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.82rem;
}

.sync-actions .db-export-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.sync-restore-section .db-export-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* ===== FOOTER FIX ===== */
#oros-footer {
  height: auto;
  min-height: 56px;
  padding: 8px 16px;
  box-sizing: border-box;
  overflow: hidden;
}

#oros-footer .footer-inner,
#oros-footer > div {
  flex-wrap: wrap;
  gap: 4px;
}

.save-indicator-overlay {
  margin-bottom: 0;
  bottom: 8px;
}

.stats-overlay {
  bottom: 8px;
}

/* ===== MOBILE TOOLBAR WRAP ===== */
@media (max-width: 768px) {
  .main-toolbar {
    flex-wrap: wrap !important;
    justify-content: center;
    gap: 2px;
    padding: 4px 6px;
    min-height: 48px;
  }

  .toolbar-group,
  .toolbar-left,
  .toolbar-center,
  .toolbar-right {
    flex-wrap: wrap;
    gap: 2px;
    justify-content: center;
  }

  .toolbar-center {
    flex: 1 1 100%;
    order: 2;
  }

  .toolbar-right {
    order: 3;
    flex: 1 1 100%;
    justify-content: center;
  }

  #oros-footer {
    height: auto;
    min-height: 48px;
    padding: 6px 8px;
  }

  #oros-footer .footer-inner {
    font-size: 11px;
    line-height: 1.4;
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .action-btn,
  .fmt-text-btn {
    min-width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .styles-dropdown {
    max-width: 100px;
    font-size: 11px;
    height: 32px;
  }

  #oros-footer {
    padding: 4px 6px;
  }
}

.sync-help {
  margin-top: 20px;
  padding: 14px 16px;
  background: var(--bg-panel, #1a1a2e);
  border: 1px solid var(--border-color, #333);
  border-radius: 8px;
}

.sync-help h4 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary, #aaa);
  margin: 0 0 10px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sync-help h4:not(:first-child) {
  margin-top: 18px;
}

.sync-help h4 i {
  color: var(--accent, #6d4aff);
}

.sync-help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.sync-help-table th {
  text-align: left;
  padding: 5px 8px;
  color: var(--text-muted, #888);
  border-bottom: 1px solid var(--border-color, #333);
  font-weight: 500;
}

.sync-help-table td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.sync-help-table td.ok {
  color: #4caf50;
  font-weight: 600;
}

.sync-help-table td.no {
  color: #ef5350;
  font-weight: 600;
}

.sync-help-list {
  margin: 6px 0 0 0;
  padding-left: 20px;
  font-size: 0.78rem;
  line-height: 1.7;
}

.sync-help-list li {
  margin-bottom: 4px;
}

.sync-help-list strong {
  color: var(--accent, #6d4aff);
}

/* ===== FOOTER PREVIEW VS FOOTNOTES ===== */
.rich-wrapper {
  position: relative;
}

.footer-preview {
  z-index: 5;
  pointer-events: none;
  flex-shrink: 0;
}

.footnote-area {
  position: relative;
  z-index: 4;
}