/* Modern Minimalist "Zen" Theme */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:root {
  /* Light Theme (Clean Paper) */
  --bg-app: #ffffff;
  --bg-panel: #f7f7f8;
  --bg-hover: #f0f0f1;
  --bg-tertiary: #f0f0f1;
  --text-primary: #111111;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --border-subtle: #eaeaea;
  --border-color: #eaeaea;
  --accent: #00A995;
  --accent-text: #ffffff;
  --danger: #ef4444;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Geist Mono', 'SF Mono', Consolas, monospace;
}

[data-theme="dark"] {
  /* Dark Theme (Midnight/Obsidian) */
  --bg-app: #050505; /* Deep black/grey */
  --bg-panel: #111111;
  --bg-hover: #1a1a1a;
  --bg-tertiary: #1a1a1a;
  --text-primary: #ffffff;
  --text-secondary: #888888;
  --text-tertiary: #666666;
  --border-subtle: #222222;
  --border-color: #222222;
  --accent: #00A995;
  --accent-text: #ffffff;
  --danger: #ef4444;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.7;
  height: 100vh;
  overflow: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

button {
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  cursor: pointer;
}

/* Zen Container */
.zen-container {
  max-width: 1000px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 2rem;
  padding-left: max(2rem, env(safe-area-inset-left));
  padding-right: max(2rem, env(safe-area-inset-right));
  position: relative;
}

/* Header & Nav */
.zen-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3rem 0 2rem;
}

.mode-switcher {
  display: flex;
  gap: 2rem;
}

.mode-btn {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-tertiary);
  transition: color 0.2s ease;
}

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

.mode-btn:active {
  transform: scale(0.95);
}

.mode-btn.active {
  color: var(--text-primary);
  font-weight: 600;
}

.header-actions .btn-text {
  font-size: 0.875rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.header-actions .btn-text:hover {
  color: var(--text-primary);
}

/* Main Views */
.zen-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* Enable shrinking for scroll */
  opacity: 0;
  transform: translateY(10px);
  animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.zen-view.hidden {
  display: none;
}

@keyframes slideUpFade {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Input Styles (Universal) */
input[type="text"], textarea {
  background: transparent;
  border: none;
  color: var(--text-primary);
  caret-color: var(--accent);
  outline: none;
}

input::placeholder, textarea::placeholder {
  color: var(--text-tertiary);
  opacity: 1;
}

/* Notes View */
.notes-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

#notesInput {
  flex: 1;
  width: 100%;
  resize: none;
  font-size: 1.125rem;
  line-height: 1.75;
  font-family: var(--font-mono);
  padding: 0;
}

.zen-controls {
  padding: 1.5rem 0;
  display: flex;
  gap: 1.5rem;
  justify-content: flex-end;
}

.zen-controls button {
  font-size: 0.825rem;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.zen-controls button:hover {
  color: var(--text-primary);
}

/* Tasks View */
.task-form {
  margin-bottom: 2rem;
}

#taskInput {
  width: 100%;
  font-size: 1.25rem;
  padding: 1rem 0;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

#taskInput:focus {
  border-bottom-color: var(--border-subtle);
}

.tasks-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.filter-tabs {
  display: flex;
  gap: 1.5rem;
}

.filter-tab {
  font-size: 0.875rem;
  color: var(--text-tertiary);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-tab.active {
  color: var(--text-primary);
}

.filter-tab:active {
  transform: scale(0.95);
}

.filter-count {
  font-size: 0.75rem;
  background: var(--bg-hover);
  color: var(--text-secondary);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
}

.search-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-tertiary);
}

.search-icon {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

#taskSearch {
  font-size: 0.875rem;
  width: 120px;
}

/* Task List */
.tasks-container {
  flex: 1;
  overflow-y: auto;
  margin: 0 -1rem;
  padding: 0 1rem;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0.5rem;
  border-radius: 6px;
  margin-bottom: 2px;
  transition: background-color 0.2s;
}

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

.task-item:active {
  transform: scale(0.98);
  background-color: var(--bg-hover);
}

.task-checkbox {
  width: 1.125rem;
  height: 1.125rem;
  border: 1.5px solid var(--text-tertiary);
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: all 0.2s;
}

.task-item:hover .task-checkbox {
  border-color: var(--text-secondary);
}

.task-item.completed .task-checkbox {
  background: var(--text-tertiary);
  border-color: transparent;
}

.task-text {
  flex: 1;
  font-size: 1rem;
  transition: color 0.2s;
}

.task-item.completed .task-text {
  color: var(--text-tertiary);
  text-decoration: line-through;
}

.task-delete {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
  opacity: 0.5;
  transition: all 0.2s ease;
}

.task-item:hover .task-delete {
  opacity: 1;
}

.task-delete:hover {
  color: var(--danger, #ef4444);
}


/* COMMAND PALETTE - REBUILT */
.command-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  padding-top: 20vh;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.command-palette-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.command-palette {
  width: 100%;
  max-width: 600px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 500px;
}

.command-palette-input-wrapper {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.command-palette-icon {
  color: var(--text-tertiary);
  font-size: 1.25rem;
}

#commandInput {
  font-size: 1.125rem;
  width: 100%;
  height: 100%;
}

.command-list {
  padding: 0.5rem;
  overflow-y: auto;
}

.command-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  color: var(--text-secondary);
  transition: all 0.1s ease;
  margin-bottom: 1px;
}

/* Explicitly override agent styles */
button.command-item {
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.command-item:hover, 
.command-item.selected {
  background-color: var(--bg-hover) !important;
  color: var(--text-primary);
}

.command-label {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.command-text {
  font-weight: 500;
}

.command-shortcut {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  background: var(--bg-app);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
}

.command-item.selected .command-shortcut {
  color: var(--text-secondary);
  border-color: transparent;
  background: rgba(255,255,255,0.1);
}

/* Quick Switcher (Cmd+O) */
.quick-switcher-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  padding-top: 20vh;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.quick-switcher-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.quick-switcher {
  width: 100%;
  max-width: 600px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 500px;
}

.quick-switcher-input-wrapper {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.quick-switcher-icon {
  font-size: 1.25rem;
  opacity: 0.5;
}

#switcherInput {
  font-size: 1.125rem;
  width: 100%;
  height: 100%;
}

.switcher-results {
  padding: 0.5rem;
  overflow-y: auto;
  max-height: 400px;
}

.switcher-item {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.1s ease;
  margin-bottom: 2px;
}

.switcher-item:hover,
.switcher-item.selected {
  background-color: var(--bg-hover);
}

.switcher-item-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.switcher-item-preview {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switcher-item-meta {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 0.25rem;
  display: flex;
  gap: 1rem;
}

.switcher-empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.875rem;
}

/* Highlight matched text in switcher */
.switcher-match {
  background: var(--accent);
  color: var(--accent-text);
  padding: 0.1rem 0.2rem;
  border-radius: 3px;
  font-weight: 600;
}


/* Multi-Note Layout */
.notes-layout {
  display: flex;
  flex: 1;
  gap: 2rem;
  overflow: hidden;
  min-height: 0; /* Enable shrinking for scroll */
  transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
}

.notes-layout.collapsed .notes-sidebar {
  width: 0;
  display: none;
  opacity: 0;
}

.notes-layout.collapsed .notes-container {
  max-width: 720px;
  margin: 0 auto;
}

.notes-sidebar {
  width: 240px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex-shrink: 0;
  min-height: 0; /* Enable shrinking for scroll */
}

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

.sidebar-header h3 {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.btn-icon {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  color: var(--text-secondary);
  border-radius: 6px;
  transition: all 0.2s;
  background: transparent;
}

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

.btn-icon:active {
  transform: scale(0.9);
}

.btn-sidebar-toggle {
  opacity: 0.5;
  transition: opacity 0.2s;
  cursor: pointer;
  padding: 4px;
}

.btn-sidebar-toggle:hover {
  opacity: 1;
}

/* Delete Note Button */
.btn-delete-note {
  color: var(--text-tertiary);
  transition: color 0.2s;
}

.btn-delete-note:hover {
  color: var(--danger, #ef4444);
}

.sidebar-search {
  position: relative;
}

.sidebar-search input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  background: var(--bg-hover);
  border: 1px solid transparent;
  border-radius: 6px;
  transition: all 0.2s;
}

.sidebar-search input:focus {
  background: var(--bg-app);
  border-color: var(--border-subtle);
}

.notes-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: none;
}

.note-item {
  padding: 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  margin-bottom: 0.5rem;
}

.note-item:hover {
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.note-item:active {
  transform: scale(0.98);
}

.note-item.active {
  background: var(--bg-hover);
  border-color: var(--border-subtle);
  border-left: 3px solid var(--accent);
}

.note-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.note-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pin-icon {
  font-size: 0.75rem;
  opacity: 0.6;
}

.note-preview {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Note Title Input (in editor) */
.note-title-input {
  width: 100%;
  font-size: 1.5rem;
  font-weight: 600;
  padding: 0.5rem 0 1rem 0;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border-subtle);
  letter-spacing: -0.02em;
}

.note-title-input:focus {
  border-bottom-color: var(--text-secondary);
}

/* Update notes container for new layout */
.notes-layout .notes-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Utilities */
.hidden { display: none !important; }

/* Markdown Preview Override */
.markdown-preview {
  flex: 1;
  min-height: 0;
  background: var(--bg-app);
  overflow-y: auto;
  padding: 0 0 3rem 0;
  padding-bottom: 3rem;
}

/* Markdown Toolbar */
.markdown-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.md-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s ease;
}

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

.md-btn:active {
  transform: scale(0.9);
}

.md-sep {
  width: 1px;
  height: 16px;
  background: var(--border-subtle);
  margin: 0 4px;
}

/* History Modal Styles */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: none; /* Hidden by default */
  justify-content: center;
  align-items: center; /* Center vertically */
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.show {
  display: flex !important;
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.3);
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  color: var(--text-primary); /* Ensure text is visible */
}

.history-item {
  padding: 0.75rem;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-panel);
}

.history-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.history-preview {
  font-size: 0.85rem;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-small {
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
}

/* Editor Header */
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.note-title-input {
  border-bottom: none !important; /* Override previous */
  margin-bottom: 0 !important;
  flex: 1;
}

.saved-status {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  opacity: 0;
  transition: opacity 0.5s ease;
}

.saved-status.visible {
  opacity: 1;
}

.btn-text-small {
  background: transparent;
  border: none;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

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

/* Backlinks Panel */
.backlinks-panel {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

.backlinks-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.backlinks-header h4 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}

.backlinks-count {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 12px;
}

.backlinks-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.backlinks-empty {
  font-size: 0.875rem;
  color: var(--text-tertiary);
  font-style: italic;
}

.backlink-item {
  padding: 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.backlink-item:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.backlink-title {
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.backlink-preview {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Link Suggester */
.link-suggester {
  position: absolute;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 10001;
  width: 280px;
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 4px;
}

.suggester-item {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: all 0.1s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  background: transparent;
  border: none;
  width: 100%;
}

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

.suggester-item .match-highlight {
  color: var(--accent);
  font-weight: 600;
}

/* Position helper element (mirror div) */
#textarea-mirror {
  position: absolute;
  visibility: hidden;
  white-space: pre-wrap;
  word-wrap: break-word;
  z-index: -1;
}

/* Custom Dialog Styles */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 11000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.dialog-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.dialog-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.3);
  padding: 2rem;
  width: 90%;
  max-width: 400px;
  transform: scale(0.95);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.dialog-overlay.show .dialog-box {
  transform: scale(1);
}

.dialog-box h3 {
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--text-primary);
}

.dialog-box p {
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.5;
  margin-bottom: 2rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
}

.btn-dialog {
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-dialog.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

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

.btn-dialog.btn-destructive {
  background: var(--danger, #ef4444);
  color: white;
}

.btn-dialog:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* ── Settings / Sync Panel ────────────────────────────────── */

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.settings-overlay.show {
  opacity: 1;
}

.settings-panel {
  background: var(--bg-primary, #1a1a2e);
  color: var(--text-primary, #e0e0e0);
  border-radius: 12px;
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
}

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

.settings-body {
  padding: 24px;
}

.settings-description {
  margin: 0 0 20px 0;
  font-size: 0.85rem;
  color: var(--text-muted, #888);
  line-height: 1.5;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-field label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary, #aaa);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-field input {
  background: var(--bg-secondary, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text-primary, #e0e0e0);
  font-size: 0.9rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  outline: none;
  transition: border-color 0.2s;
}

.settings-field input:focus {
  border-color: var(--accent, #6c63ff);
}

.settings-field input::placeholder {
  color: var(--text-muted, #555);
}

.settings-hint {
  font-size: 0.75rem;
  color: var(--text-muted, #666);
  line-height: 1.4;
}

.settings-hint a {
  color: var(--accent, #6c63ff);
  text-decoration: none;
}

.settings-hint a:hover {
  text-decoration: underline;
}

.settings-hint code {
  background: var(--bg-secondary, rgba(255, 255, 255, 0.08));
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.7rem;
}

.settings-actions {
  display: flex;
  gap: 10px;
  padding-top: 8px;
  flex-wrap: wrap;
}

.settings-actions .btn-primary {
  background: var(--accent, #6c63ff);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: opacity 0.2s;
}

.settings-actions .btn-primary:hover {
  opacity: 0.9;
}

.settings-actions .btn-danger {
  color: var(--danger, #ef4444);
}

.sync-status {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.sync-status.hidden {
  display: none;
}

.sync-status.connected {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.sync-status.error {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.sync-status.info {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.settings-advanced {
  margin-top: 20px;
}

.settings-advanced summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted, #666);
  padding: 8px 0;
  user-select: none;
}

.settings-advanced summary:hover {
  color: var(--text-secondary, #aaa);
}

.settings-explanation {
  padding: 12px 0;
  font-size: 0.8rem;
  color: var(--text-muted, #888);
  line-height: 1.6;
}

.settings-explanation pre {
  background: var(--bg-secondary, rgba(0, 0, 0, 0.3));
  padding: 12px;
  border-radius: 8px;
  font-size: 0.75rem;
  overflow-x: auto;
  margin: 8px 0;
  line-height: 1.4;
}

/* ── Sync Status Indicator ──────────────────────────────── */

.sync-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--bg-secondary, rgba(255, 255, 255, 0.05));
  cursor: default;
  transition: opacity 0.3s ease;
  user-select: none;
}

.sync-indicator.hidden {
  display: none;
}

.sync-label {
  color: var(--text-muted, #888);
  letter-spacing: 0.2px;
}

.sync-dot.dot-idle {
  color: var(--text-muted, #888);
}

.sync-dot.dot-pending {
  color: #f59e0b;
}

.sync-dot.dot-pending .sync-label,
.sync-indicator:has(.dot-pending) .sync-label {
  color: #f59e0b;
}

.sync-dot.dot-synced {
  color: #22c55e;
}

.sync-indicator:has(.dot-synced) .sync-label {
  color: #22c55e;
}

.sync-dot.dot-error {
  color: #ef4444;
}

.sync-indicator:has(.dot-error) .sync-label {
  color: #ef4444;
}

@keyframes sync-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sync-indicator:has(.dot-pending) .sync-dot {
  animation: sync-pulse 1.5s ease-in-out infinite;
}

/* ── Mobile / PWA Responsive ────────────────────────────── */

@media (max-width: 768px) {
  .zen-header {
    padding: calc(0.75rem + env(safe-area-inset-top)) 1rem 0.75rem;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
  }

  .mode-switcher {
    gap: 2rem;
    width: 100%;
    justify-content: center;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.5rem;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
    display: flex;
    align-items: center;
    gap: 1rem;
  }

  .zen-container {
    padding: 0 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: env(safe-area-inset-bottom);
  }

  .sync-indicator {
    order: -1;
    margin-bottom: 4px;
  }

  /* Two-panel mobile layout: sidebar is full-screen overlay */
  .notes-layout {
    flex-direction: column;
    gap: 0;
    position: relative;
  }

  .notes-sidebar {
    width: 100%;
    height: calc(100vh - 80px);
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0;
    position: relative;
    z-index: 10;
    background: var(--bg-app);
    transition: transform 0.3s ease;
  }

  .notes-layout.collapsed .notes-sidebar {
    display: block;
    transform: translateX(-100%);
    position: absolute;
    left: 0;
    top: 0;
  }

  /* Sidebar backdrop */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .notes-layout:not(.collapsed) .sidebar-backdrop {
    display: block;
  }

  .notes-layout:not(.collapsed) .sidebar-backdrop.show {
    opacity: 1;
  }

  /* Editor takes full width when collapsed */
  .notes-layout.collapsed .notes-container {
    max-width: none;
    margin: 0;
    width: 100%;
    padding: 0;
  }

  /* Back button - visible only on mobile */
  .btn-back-mobile {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.875rem;
    color: var(--accent);
    font-weight: 500;
    padding: 8px 12px;
    min-height: 44px;
    border-radius: 6px;
    transition: background 0.2s;
  }

  .btn-back-mobile:hover {
    background: var(--bg-hover);
  }

  .btn-back-mobile:active {
    transform: scale(0.95);
  }

  .btn-back-mobile svg {
    width: 20px;
    height: 20px;
  }

  /* Hide desktop sidebar toggle on mobile */
  .btn-sidebar-toggle {
    display: none;
  }

  /* Compact editor header */
  .editor-header {
    padding: 0.5rem 0;
  }

  .note-title-input {
    font-size: 1.125rem;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
  }

  #notesInput {
    font-size: 1rem;
    line-height: 1.6;
    flex: 1;
    min-height: 200px;
  }

  /* Compact markdown toolbar */
  .markdown-toolbar {
    padding: 4px 0;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-bottom: 4px;
  }

  .md-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    font-size: 13px;
  }

  /* Hide backlinks panel when empty on mobile */
  .backlinks-panel.backlinks-empty {
    display: none;
  }

  /* Compact note list items - titles only */
  .note-preview {
    display: none;
  }

  .note-item {
    padding: 0.875rem 0.5rem;
    min-height: 44px;
  }

  .note-item-header {
    gap: 0.5rem;
  }

  /* Task form */
  .task-form input {
    font-size: 1.125rem;
    padding: 1rem;
  }

  /* Modals and dialogs */
  .settings-panel,
  .modal,
  .command-palette,
  .quick-switcher {
    width: 95%;
    max-width: none;
    margin: 10px;
  }

  /* Improve tap targets */
  .btn-icon, .btn-text, .filter-tab, .btn-text-small {
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Theme button as icon on mobile */
  #themeToggle.btn-icon-mobile {
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
  }

  /* Hide header Preview button on mobile (toolbar has one) */
  #noteViewToggle {
    display: none;
  }
}

