/* styles.css — Ulysses App Clone */

/* === Theme Variables === */
:root {
  /* Light theme (default) */
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f7;
  --bg-tertiary: #e8e8ed;
  --bg-hover: #e0e0e5;
  --bg-active: #d4d4dc;
  --bg-editor: #ffffff;
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #aeaeb2;
  --border: #d2d2d7;
  --border-light: #e5e5ea;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-light: rgba(0, 113, 227, 0.1);
  --danger: #ff3b30;
  --danger-hover: #ff453a;
  --success: #34c759;
  --warning: #ff9f0a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Menlo', 'Monaco', monospace;
  --font-editor: 'iA Writer Duo', 'SF Mono', 'Menlo', monospace;
  --sidebar-width: 240px;
  --sheetlist-width: 280px;
  --toolbar-height: 40px;
  --transition: 0.25s ease;
}

[data-theme="dark"] {
  --bg-primary: #1c1c1e;
  --bg-secondary: #2c2c2e;
  --bg-tertiary: #3a3a3c;
  --bg-hover: #48484a;
  --bg-active: #545456;
  --bg-editor: #1c1c1e;
  --text-primary: #f5f5f7;
  --text-secondary: #98989d;
  --text-tertiary: #636366;
  --border: #38383a;
  --border-light: #2c2c2e;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-light: rgba(10, 132, 255, 0.15);
  --danger: #ff453a;
  --danger-hover: #ff6961;
  --success: #30d158;
  --warning: #ffd60a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* === App Layout === */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) var(--sheetlist-width) 1fr;
  grid-template-rows: 1fr;
  height: 100vh;
  transition: grid-template-columns var(--transition);
}

#app.library-hidden {
  grid-template-columns: 0px var(--sheetlist-width) 1fr;
}

#app.sheets-hidden {
  grid-template-columns: var(--sidebar-width) 0px 1fr;
}

#app.library-hidden.sheets-hidden {
  grid-template-columns: 0px 0px 1fr;
}

/* === Library Panel === */
#library-panel {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity var(--transition);
}

#app.library-hidden #library-panel {
  opacity: 0;
  pointer-events: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  height: var(--toolbar-height);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.panel-header-actions {
  display: flex;
  gap: 4px;
}

.library-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.group-item {
  display: flex;
  align-items: center;
  padding: 6px 16px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 13px;
  transition: background var(--transition);
  user-select: none;
  position: relative;
}

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

.group-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* Keyboard focus indicator for panel navigation */
.filter-item.kb-focus,
.group-item.kb-focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 6px;
}
.filter-item.kb-focus:not(.active),
.group-item.kb-focus:not(.active) {
  background: var(--bg-hover);
}

.group-item .group-icon {
  width: 16px;
  height: 16px;
  margin-right: 8px;
  opacity: 0.6;
  flex-shrink: 0;
}

.group-item.active .group-icon {
  opacity: 1;
}

.group-item .group-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-item .group-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 8px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 0 6px;
  min-width: 18px;
  text-align: center;
  line-height: 18px;
}

.group-item.depth-1 {
  padding-left: 32px;
}
.group-item.depth-2 {
  padding-left: 48px;
}
.group-item.depth-3 {
  padding-left: 64px;
}
.group-item.depth-4 {
  padding-left: 80px;
}

.section-header {
  display: flex;
  align-items: center;
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  cursor: pointer;
  user-select: none;
}
.section-header:hover {
  color: var(--text-secondary);
}
.section-header .section-chevron {
  width: 10px;
  height: 10px;
  margin-right: 4px;
  transition: transform 0.15s;
}
.section-header .section-chevron.open {
  transform: rotate(90deg);
}
.section-header .section-add {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0 2px;
  font-size: 16px;
  line-height: 1;
}
.section-header .section-add:hover {
  color: var(--accent);
}

/* Drag: reorder bar above (no layout shift) */
.group-item.drop-above::before {
  content: '';
  position: absolute;
  top: -2px;
  left: 10px;
  right: 10px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  z-index: 5;
  box-shadow: 0 0 6px var(--accent);
}
.group-item.drop-above::after {
  content: '';
  position: absolute;
  top: -5px;
  left: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  z-index: 5;
}

/* Drag: reorder bar below (no layout shift) */
.group-item.drop-below::before {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 10px;
  right: 10px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  z-index: 5;
  box-shadow: 0 0 6px var(--accent);
}
.group-item.drop-below::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  z-index: 5;
}

/* Drag: nest inside */
.group-item.drop-nest {
  background: var(--accent-light);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 6px;
}

.group-item.dragging {
  opacity: 0.3;
}

/* Collapse chevron / spacer */
.group-chevron,
.group-chevron-spacer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-right: 2px;
  flex-shrink: 0;
}

.group-chevron {
  cursor: pointer;
  opacity: 0.5;
  transition: transform 0.2s ease, opacity 0.15s;
  transform: rotate(0deg);
}

.group-chevron.open {
  transform: rotate(90deg);
}

.group-chevron:hover {
  opacity: 1;
}

.group-children {
  transition: none;
}

/* Filter items (smart filters in sidebar) */
.filter-item {
  display: flex;
  align-items: center;
  padding: 6px 16px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 13px;
  transition: background var(--transition);
  user-select: none;
}

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

.filter-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

.filter-item .group-icon {
  width: 16px;
  height: 16px;
  margin-right: 8px;
  opacity: 0.6;
  flex-shrink: 0;
}

.filter-item.active .group-icon {
  opacity: 1;
}

.filter-item .group-name {
  flex: 1;
}

.filter-item .group-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 8px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 0 6px;
  min-width: 18px;
  text-align: center;
  line-height: 18px;
}

.library-divider {
  height: 1px;
  background: var(--border-light);
  margin: 6px 16px;
}

.library-section {
  padding: 4px 0;
}

/* Sheet card header with favorite star */
.sheet-card-header {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sheet-card-header .sheet-card-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-card-fav {
  color: var(--warning);
  font-size: 12px;
  flex-shrink: 0;
}

.sheet-card-indicator {
  font-size: 12px;
  margin-left: 6px;
  opacity: 0.85;
  flex-shrink: 0;
}

/* Active toggle button state */
.btn-icon.active-toggle {
  color: var(--accent);
  background: var(--accent-light);
}

.group-item .group-name-input {
  background: var(--bg-primary);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 1px 4px;
  font-size: 13px;
  color: var(--text-primary);
  width: 100%;
  outline: none;
}

/* === Sheet List Panel === */
#sheets-panel {
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity var(--transition);
}

#app.sheets-hidden #sheets-panel {
  opacity: 0;
  pointer-events: none;
}

.sheet-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.sheet-card {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}

.sheet-card:hover {
  background: var(--bg-secondary);
}

.sheet-card.active {
  background: var(--accent-light);
}

.sheet-card.selected {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}

.sheet-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-card-preview {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 4px;
}

.sheet-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
}

.sheet-card-tags {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
  color: #fff;
}

.sheet-card.dragging {
  opacity: 0.5;
}

.sheet-card.drop-above {
  border-top: 2px solid var(--accent);
}

.sheet-card.drop-below {
  border-bottom: 2px solid var(--accent);
}

/* === Sheet Group Separators (Ulysses-style sticky headers) === */
.sheet-group-separator {
  display: flex;
  align-items: center;
  padding: 7px 16px;
  gap: 8px;
  user-select: none;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
  margin-top: 2px;
}

.sheet-group-separator:first-child {
  margin-top: 0;
}

.sheet-group-separator-name {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.sheet-group-separator-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--border);
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
  line-height: 18px;
}

/* Sheet card group label */
.sheet-card-group {
  color: var(--accent);
  font-weight: 500;
}

/* === Icon Picker === */
.icon-picker {
  position: fixed;
  z-index: 3000;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  width: 272px;
}

.icon-picker-colors {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.icon-picker-color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}

.icon-picker-color-swatch:hover {
  transform: scale(1.15);
}

.icon-picker-color-swatch.active {
  border-color: var(--text-primary);
  transform: scale(1.15);
}

.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.icon-picker-cell {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.icon-picker-cell:hover {
  background: var(--bg-hover);
}

.icon-picker-cell.active {
  background: var(--accent-light);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.icon-picker-actions {
  display: flex;
  justify-content: space-between;
}

/* Group icon colored */
.group-item .group-icon-custom svg {
  width: 16px;
  height: 16px;
}

/* === Editor Panel === */
#editor-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-editor);
  position: relative;
}

/* Editor toolbar */
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  height: var(--toolbar-height);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  background: var(--bg-primary);
}

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

.editor-toolbar-center {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  min-width: 0;
  flex: 1;
  justify-content: center;
}

/* Breadcrumb trail */
.breadcrumb-item {
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
  transition: color 0.15s;
}
.breadcrumb-item:hover {
  color: var(--accent);
}
.breadcrumb-sep {
  color: var(--text-tertiary);
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1;
}

/* Editor container */
.editor-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.editor-container .cm-editor {
  height: 100%;
}

.editor-container .cm-editor .cm-scroller {
  overflow: auto;
  font-family: var(--font-editor);
  font-size: 16px;
  line-height: 1.7;
  padding: 40px 60px;
}

.editor-container .cm-editor .cm-content {
  max-width: 720px;
  margin: 0 auto;
}

.editor-container .cm-editor .cm-focused {
  outline: none;
}

.editor-container .cm-editor .cm-gutters {
  background: transparent;
  border: none;
}

/* Fold placeholder (inline "..." when section is collapsed) */
.cm-editor .cm-foldPlaceholder {
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-tertiary);
  padding: 0 6px;
  border-radius: 3px;
  font-size: 0.85em;
  cursor: pointer;
  margin: 0 4px;
}
.cm-editor .cm-foldPlaceholder:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.editor-container .cm-editor .cm-activeLine {
  background: transparent;
}

.editor-container .cm-editor.cm-focused .cm-activeLine {
  background: var(--accent-light);
}

/* Checkbox widgets in editor */
.cm-checkbox-wrap {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  cursor: pointer;
  margin: 0 2px 0 0;
}
.cm-checkbox-wrap svg {
  display: block;
}
.cm-checkbox-wrap:hover svg rect {
  stroke: var(--accent);
}

.editor-container .cm-editor .cm-selectionBackground {
  background: rgba(0, 113, 227, 0.2) !important;
}

/* Typewriter mode */
.editor-container.typewriter .cm-editor .cm-scroller {
  padding-top: 45vh;
  padding-bottom: 45vh;
}

/* Focus mode — dims all lines except the active one */
.editor-container.focus-mode .cm-line {
  opacity: 0.25;
  transition: opacity 0.2s ease;
}

.editor-container.focus-mode .cm-editor.cm-focused .cm-activeLine {
  opacity: 1;
}

/* When editor loses focus in focus mode, keep all lines dimmed */
.editor-container.focus-mode .cm-editor:not(.cm-focused) .cm-line {
  opacity: 0.25;
}

/* Split view */
#app.split-view #editor-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: var(--toolbar-height) 1fr;
}

#app.split-view .editor-toolbar {
  grid-column: 1 / -1;
}

.split-divider {
  width: 1px;
  background: var(--border);
}

/* === Empty States === */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px;
  text-align: center;
  color: var(--text-tertiary);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.3;
}

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

.empty-state-text {
  font-size: 13px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all var(--transition);
  border-radius: var(--radius-sm);
}

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

.btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
}

.btn-icon svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-weight: 500;
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: #fff;
}

.btn-danger {
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(255, 59, 48, 0.1);
  color: var(--danger-hover);
}

/* === Context Menu === */
.context-menu {
  position: fixed;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 180px;
  z-index: 1000;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.context-menu-item:hover {
  background: var(--accent);
  color: #fff;
}

.context-menu-item.danger {
  color: var(--danger);
}

.context-menu-item.danger:hover {
  background: var(--danger);
  color: #fff;
}

.context-menu-divider {
  height: 1px;
  background: var(--border-light);
  margin: 4px 0;
}

.context-menu-item svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.context-menu-item .shortcut {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  min-width: 400px;
  max-width: 520px;
  width: 90%;
}

.modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* === Form Elements === */
.input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

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

.input-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

select.input {
  cursor: pointer;
}

/* === Search === */
.search-bar {
  position: relative;
  margin: 8px 12px;
}

.search-bar input {
  width: 100%;
  padding: 6px 30px 6px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: all var(--transition);
}

.search-bar input:focus {
  background: var(--bg-primary);
  border-color: var(--accent);
}

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

.search-bar .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-tertiary);
}

.search-tag-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all var(--transition);
}
.search-tag-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}
.search-tag-toggle.active {
  color: var(--accent);
  background: rgba(0,122,255,0.12);
}

.tag-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 12px 8px;
  align-items: center;
}

.tag-filter-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  transition: all var(--transition);
  border: 1.5px solid transparent;
}
.tag-filter-chip:hover {
  color: #fff;
  filter: brightness(1.1);
}
.tag-filter-chip.selected {
  color: #fff;
  border-color: #fff;
  box-shadow: 0 0 6px rgba(255,255,255,0.25);
}

.tag-filter-mode {
  font-size: 10px;
  color: var(--accent);
  cursor: pointer;
  margin-left: auto;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.tag-filter-mode:hover {
  background: var(--bg-tertiary);
}

/* === Goals === */
/* === Keywords / Tags Sidebar === */
.tags-section {
  padding: 8px 16px;
  border-top: 1px solid var(--border-light);
}

.tags-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.tags-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tag-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
  color: var(--text-primary);
}

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

.tag-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

.tag-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tag-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-count {
  font-size: 11px;
  color: var(--text-tertiary);
}

/* === Keywords in Attachments Panel === */
.keywords-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.keyword-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  cursor: default;
}

.keyword-remove {
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
  margin-left: 2px;
}

.keyword-remove:hover {
  opacity: 1;
}

.keyword-input-wrap {
  position: relative;
}

.keyword-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
}

.keyword-input:focus {
  border-color: var(--accent);
}

.keyword-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 160px;
  overflow-y: auto;
  z-index: 200;
}

.keyword-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-primary);
}

.keyword-option:hover {
  background: var(--bg-hover);
}

.keyword-create {
  color: var(--accent);
  font-style: italic;
}

/* === Global Search Overlay === */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  z-index: 3000;
  backdrop-filter: blur(4px);
}

.search-modal {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
}

.search-modal-input {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
}

.search-modal-input input {
  width: 100%;
  border: none;
  background: none;
  font-size: 18px;
  color: var(--text-primary);
  outline: none;
}

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

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.search-result-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
}

.search-result-item:hover,
.search-result-item.selected {
  background: var(--bg-secondary);
}

.search-result-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.search-result-preview {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.search-result-group {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* === Export Modal === */
.export-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.export-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
}

.export-option:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.export-option svg {
  width: 28px;
  height: 28px;
  color: var(--text-secondary);
}

.export-option:hover svg {
  color: var(--accent);
}

.export-option span {
  font-size: 13px;
  font-weight: 500;
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* === Transitions === */
.fade-in {
  animation: fadeIn 0.2s ease;
}

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

/* === Goals Modal === */
.goal-setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.goal-setup-grid .input {
  width: 100%;
}

.goal-setup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.goal-setup .input {
  width: 100px;
}

.goal-setup select {
  width: 120px;
}


/* === Markup Bar (Formatting Toolbar) === */
.markup-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  height: 36px;
  border-top: 1px solid var(--border-light);
  background: var(--bg-secondary);
  overflow: hidden;
}

.markup-bar-inner {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 12px;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.markup-bar-inner::-webkit-scrollbar {
  display: none;
}

/* Individual markup button */
.markup-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}

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

.markup-btn:active {
  background: var(--bg-active);
}

.markup-btn svg {
  width: 15px;
  height: 15px;
}

/* Text-label buttons (H1, H2, H3) */
.markup-btn-text {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.02em;
  width: auto;
  padding: 0 6px;
  min-width: 28px;
}

/* Separator between button groups */
.markup-bar-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
  opacity: 0.6;
}

/* === Markdown Preview === */
.preview-pane {
  flex: 1;
  overflow-y: auto;
  padding: 40px 60px;
}

.preview-pane .preview-content {
  max-width: 720px;
  margin: 0 auto;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-primary);
}

.preview-content h1 { font-size: 28px; margin: 24px 0 12px; }
.preview-content h2 { font-size: 22px; margin: 20px 0 10px; }
.preview-content h3 { font-size: 18px; margin: 16px 0 8px; }
.preview-content p { margin: 0 0 12px; }
.preview-content a { color: var(--accent); text-decoration: none; }
.preview-content a:hover { text-decoration: underline; }
.preview-content code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 14px;
}
.preview-content pre {
  background: var(--bg-tertiary);
  padding: 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 12px 0;
}
.preview-content pre code {
  background: none;
  padding: 0;
}
.preview-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  color: var(--text-secondary);
  margin: 12px 0;
}
.preview-content ul, .preview-content ol { margin: 0 0 12px; padding-left: 24px; }
.preview-content li { margin: 4px 0; }
.preview-content img { max-width: 100%; border-radius: var(--radius-md); }
.preview-content hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 24px 0;
}
.preview-content table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.preview-content th, .preview-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.preview-content th { background: var(--bg-secondary); font-weight: 600; }

/* === Checkbox list === */
.preview-content .task-list-item {
  list-style: none;
  margin-left: -24px;
}
.preview-content .task-list-item input[type="checkbox"] {
  margin-right: 6px;
}

/* === Attachments Panel === */
.attachments-panel {
  position: absolute;
  right: 0;
  top: var(--toolbar-height);
  bottom: 0;
  width: 280px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform var(--transition);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.attachments-panel.open {
  transform: translateX(0);
}

.attachments-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.attach-section {
  margin-bottom: 16px;
}

.attach-section textarea {
  resize: vertical;
  min-height: 80px;
  font-family: var(--font-sans);
  font-size: 13px;
}

.image-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.image-thumb {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--bg-tertiary);
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}

.image-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition);
}

.image-thumb:hover .image-remove {
  opacity: 1;
}

/* === Outline Panel === */
.outline-panel {
  position: absolute;
  right: 0;
  top: var(--toolbar-height);
  bottom: 0;
  width: 260px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform var(--transition);
  z-index: 101;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.outline-panel.open {
  transform: translateX(0);
}

/* Outline search/filter */
.outline-search {
  position: relative;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.outline-search input {
  width: 100%;
  padding: 5px 8px 5px 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition);
}
.outline-search input:focus {
  border-color: var(--accent);
}
.outline-search input::placeholder {
  color: var(--text-tertiary);
}
.outline-search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.outline-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.outline-item {
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--transition), color var(--transition);
}

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

.outline-item.h1 {
  font-weight: 600;
  color: var(--text-primary);
}

.outline-item.h2 {
  padding-left: 28px;
}

.outline-item.h3 {
  padding-left: 40px;
}

.outline-item.h4 {
  padding-left: 52px;
}

.outline-empty {
  padding: 20px 16px;
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
}

/* Outline drag-and-drop */
.outline-item.dragging {
  opacity: 0.3;
}
.outline-item.drop-above {
  box-shadow: 0 -2px 0 0 var(--accent);
}
.outline-item.drop-below {
  box-shadow: 0 2px 0 0 var(--accent);
}

/* Narrowed (focused) section indicator */
.outline-item.narrowed {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
  border-left: 2px solid var(--accent);
}

/* Narrow-to-subtree banner */
.narrow-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 16px;
  background: var(--accent-light);
  border-bottom: 1px solid var(--accent);
  flex-shrink: 0;
  animation: fadeIn 0.15s ease;
}
.narrow-breadcrumb {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.narrow-exit {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  padding: 2px 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  margin-left: 12px;
}
.narrow-exit:hover {
  background: var(--accent);
  color: #fff;
}

/* === Floating Stats Indicator (Ulysses-style) === */
.stats-float {
  position: absolute;
  top: 12px;
  right: 20px;
  z-index: 50;
  user-select: none;
}

.stats-float-trigger {
  position: relative;
  width: 40px;
  height: 40px;
  cursor: pointer;
}

.stats-badge-ring {
  position: absolute;
  inset: 0;
  width: 40px;
  height: 40px;
  transform: rotate(-90deg);
}

.stats-badge-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 2;
}

.stats-badge-progress {
  fill: none;
  stroke: transparent;
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s ease, stroke 0.3s ease;
}

.stats-float-badge {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  font-family: var(--font-sans);
  line-height: 1;
}

.stats-float-trigger:hover .stats-float-badge {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.stats-float.open .stats-float-badge {
  background: var(--accent);
  color: #fff;
}

.stats-float.open .stats-badge-track {
  stroke: transparent;
}

.stats-float.open .stats-badge-progress {
  stroke: transparent;
}

.stats-float-popover {
  display: none;
  position: absolute;
  top: 48px;
  right: -8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px 24px;
  width: 240px;
  font-family: var(--font-sans);
  text-align: center;
}

.stats-float.open .stats-float-popover {
  display: block;
  animation: fadeIn 0.15s ease;
}

/* Progress ring */
.stats-ring-section {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto 8px;
}

.stats-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.stats-ring-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}

.stats-ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 0.6s ease, stroke 0.3s ease;
}

.stats-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.stats-ring-subtitle {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stats-ring-count {
  font-size: 36px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

.stats-ring-unit {
  font-size: 13px;
  color: var(--text-secondary);
}

.stats-goal-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  min-height: 16px;
}

.stats-goal-label strong {
  font-weight: 700;
  color: var(--text-primary);
}

.stats-popover-divider {
  height: 1px;
  background: var(--border-light);
  margin: 8px 0;
}

.stats-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  text-align: center;
}

.stats-detail-item {
  display: flex;
  flex-direction: column;
}

.stats-detail-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stats-detail-label {
  font-size: 10px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* === Undo Toast === */
.undo-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  font-family: var(--font-sans);
  z-index: 10000;
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
}

.undo-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.undo-toast-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
}

.undo-toast-btn:hover {
  background: rgba(0, 113, 227, 0.2);
}

/* === CodeMirror Search Panel === */
.cm-search {
  background: var(--bg-secondary) !important;
  border-bottom: 1px solid var(--border) !important;
  padding: 8px 12px !important;
  font-family: var(--font-sans) !important;
  font-size: 13px !important;
  color: var(--text-primary) !important;
}

.cm-search input,
.cm-search button {
  font-family: var(--font-sans) !important;
  font-size: 13px !important;
  border-radius: var(--radius-sm) !important;
}

.cm-search input {
  background: var(--bg-primary) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
  padding: 4px 8px !important;
  outline: none !important;
}

.cm-search input:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px var(--accent-light) !important;
}

.cm-search button {
  background: var(--bg-tertiary) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
  padding: 4px 10px !important;
  cursor: pointer !important;
}

.cm-search button:hover {
  background: var(--bg-hover) !important;
}

.cm-search label {
  color: var(--text-secondary) !important;
}

.cm-searchMatch {
  background: rgba(255, 204, 0, 0.3) !important;
}

.cm-searchMatch-selected {
  background: rgba(255, 204, 0, 0.6) !important;
}

/* === Login Screen === */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  text-align: center;
  padding: 48px 40px;
  max-width: 360px;
  width: 100%;
}

.login-icon {
  color: var(--accent);
  margin-bottom: 16px;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  font-family: var(--font-sans);
}


/* Logout bar */
.logout-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.logout-user {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 500;
}
.logout-btn {
  font-size: 11px;
  color: var(--text-tertiary);
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  cursor: pointer;
  transition: all var(--transition);
}
.logout-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}


/* === Mobile Layout === */
@media (max-width: 768px) {
  #app {
    display: block;
    position: relative;
    overflow: hidden;
  }

  #library-panel,
  #sheets-panel,
  #editor-panel {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 100%;
    transition: transform 0.25s ease;
    border-right: none;
  }

  #library-panel { z-index: 3; transform: translateX(0); }
  #sheets-panel { z-index: 2; transform: translateX(100%); }
  #editor-panel { z-index: 1; transform: translateX(100%); }

  /* States */
  #app.mobile-sheets #library-panel { transform: translateX(-100%); }
  #app.mobile-sheets #sheets-panel { transform: translateX(0); }
  #app.mobile-sheets #editor-panel { transform: translateX(100%); }

  #app.mobile-editor #library-panel { transform: translateX(-100%); }
  #app.mobile-editor #sheets-panel { transform: translateX(-100%); }
  #app.mobile-editor #editor-panel { transform: translateX(0); }

  /* Override desktop hidden states */
  #app.library-hidden #library-panel,
  #app.sheets-hidden #sheets-panel {
    opacity: 1;
    pointer-events: auto;
  }
  #app.library-hidden,
  #app.sheets-hidden,
  #app.library-hidden.sheets-hidden {
    grid-template-columns: unset;
  }

  /* Mobile back buttons */
  .mobile-back {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 14px;
    cursor: pointer;
    padding: 4px 8px;
    margin-right: 4px;
    border-radius: var(--radius-sm);
  }
  .mobile-back:hover {
    background: var(--accent-light);
  }
  .mobile-back svg {
    width: 16px;
    height: 16px;
  }

  /* Full width panels */
  .panel-header {
    padding: 12px 12px;
  }

  /* Editor toolbar adjustments */
  .editor-toolbar {
    padding: 6px 8px;
  }

  /* Larger touch targets */
  .group-item, .filter-item {
    padding: 10px 12px;
    min-height: 40px;
  }
  .sheet-card {
    padding: 12px;
  }

  /* Hide sidebar toggle on mobile */
  #toggle-library,
  #toggle-sheets {
    display: none;
  }

  /* Compact logout on mobile */
  .logout-bar {
    padding: 4px 12px;
    margin-top: 2px;
  }
  .logout-user, .logout-btn {
    font-size: 10px;
  }

  /* Compact filters and groups */
  .filter-item {
    padding: 6px 12px;
    min-height: 32px;
  }
  .group-item {
    padding: 6px 12px;
    min-height: 32px;
  }
  .section-header {
    padding: 4px 12px;
    margin-top: 4px;
  }
  .panel-header {
    padding: 8px 12px;
    height: auto;
    min-height: 36px;
  }

  /* Make sheet list search full width */
  .search-bar {
    padding: 8px 12px;
  }
}

/* Desktop: hide mobile-only elements */
@media (min-width: 769px) {
  .mobile-back {
    display: none;
  }
}

.logout-header-btn {
  display: none;
}
.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Library scroll wrapper */
.library-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.library-scroll .library-tree {
  flex: none;
}
.version-badge {
  padding: 6px 12px;
  font-size: 10px;
  color: var(--text-tertiary);
  text-align: center;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .logout-header-btn {
    display: none;
  }
  .mobile-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    margin-top: 8px;
  }
  .mobile-logout button {
    font-size: 12px;
    color: var(--text-tertiary);
    background: none;
    border: none;
    cursor: pointer;
  }
}
@media (min-width: 769px) {
  .mobile-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    margin-top: 4px;
  }
  .mobile-logout button {
    font-size: 11px;
    color: var(--text-tertiary);
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.5;
  }
  .mobile-logout button:hover {
    opacity: 1;
  }
}


/* === Native App Feel === */
html, body {
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  position: fixed;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  touch-action: manipulation;
}

#app {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  overflow: hidden;
}

@media (max-width: 768px) {
  /* Compact editor toolbar */
  .editor-toolbar {
    flex-wrap: nowrap;
    gap: 2px;
    padding: 4px 8px;
    min-height: 36px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .editor-toolbar .btn-icon {
    padding: 4px;
    min-width: 28px;
    flex-shrink: 0;
  }

  /* Hide word count on mobile - access via button */
  .editor-toolbar-center {
    display: none;
  }

  /* Compact toolbar sections */
  .editor-toolbar-left,
  .editor-toolbar-right {
    gap: 2px;
  }

  /* Editor fills available space */
  #editor-panel {
    display: flex;
    flex-direction: column;
  }
  .editor-container {
    flex: 1;
    overflow-y: auto;
  }

  /* Prevent text selection causing scroll issues */
  .library-scroll {
    -webkit-overflow-scrolling: touch;
  }

  /* Sheet list smooth scroll */
  .sheet-list {
    -webkit-overflow-scrolling: touch;
  }
}


@media (max-width: 768px) {
  /* Top toolbar icons */
  .editor-toolbar .btn-icon {
    padding: 6px;
    min-width: 34px;
  }
  .editor-toolbar .btn-icon svg {
    width: 18px;
    height: 18px;
  }
  .editor-toolbar {
    overflow: visible;
    justify-content: space-between;
  }
  .editor-toolbar-left,
  .editor-toolbar-right {
    gap: 6px;
  }

  /* Markup bar: fixed at bottom */
  .markup-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 42px;
    z-index: 200;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
  }
  .markup-btn {
    width: 38px;
    height: 36px;
  }
  .markup-btn svg {
    width: 20px;
    height: 20px;
  }
  .markup-btn-text {
    font-size: 14px;
    min-width: 34px;
  }
  .markup-bar-inner {
    gap: 4px;
    padding: 0 8px;
    -webkit-overflow-scrolling: touch;
  }

  /* When virtual keyboard is open, keep markup bar visible */
  #editor-panel {
    height: 100%;
  }
  .editor-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 50px;
  }
}

/* Stats float: hide on mobile, show in markup bar instead */
@media (max-width: 768px) {
  .stats-float {
    display: none;
  }
}

/* Mobile stats in markup bar */
.markup-stats {
  display: none;
}

@media (max-width: 768px) {
  .markup-stats {
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: auto;
    height: 100%;
    border-left: 1px solid var(--border);
    font-family: var(--font-sans);
    position: relative;
  }
  .markup-stats:hover,
  .markup-stats.open {
    color: var(--accent);
    background: var(--accent-light);
  }
  .markup-stats-popover {
    display: none;
    position: absolute;
    bottom: 48px;
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 16px 20px;
    min-width: 220px;
    font-family: var(--font-sans);
  }
  .markup-stats.open .markup-stats-popover {
    display: block;
    animation: fadeIn 0.15s ease;
  }
}

/* Editor disabled state */
.editor-container.editor-disabled .cm-editor {
  cursor: default;
}
.editor-container.editor-disabled .cm-cursor {
  display: none !important;
}
.editor-container.editor-disabled .cm-selectionBackground {
  display: none !important;
}
.editor-container.editor-disabled .cm-activeLine {
  background: none !important;
}
