/**
 * uNotes Web - Core Application Styles & Apple-Notes Design System
 */

:root {
  /* Apple Notes "Paper" primitives (DESIGN.md §2) */
  --notes-cream: #FFFBED;
  --cream-surface-1: #FAF6E3;
  --cream-surface-2: #F2EDD6;
  --divider: #EDEAD8;
  --notes-orange: #F09A38;
  --notes-orange-pressed: #D87E1F;
  --notes-orange-tint: #FFF1DD;
  --folder-yellow: #F5D773;
  --folder-highlight: #FAE8A0;
  --highlight-yellow: #FFEB78;
  --ink: #1C1C1E;
  --slate: #8E8E93;
  --slate-text: #6E6E73;
  --orange-text: #B45309;
  --mute: #C7C7CC;
  --success: #34C759;
  --warning: #FFCC00;
  --error: #FF3B30;
  --info: #0A84FF;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-9: 36px;
  --space-10: 40px;
  --space-11: 44px;
  --space-12: 48px;
  --space-13: 52px;
  --space-14: 56px;
  --space-15: 60px;
  --space-16: 64px;

  --radius-badge: 4px;
  --radius-search: 10px;
  --radius-cta: 12px;
  --radius-sheet: 16px;

  --elev-1: rgba(0, 0, 0, 0.04) 0 1px 3px;
  --elev-fab: rgba(240, 154, 56, 0.30) 0 4px 12px;
  --elev-sheet: rgba(0, 0, 0, 0.16) 0 -8px 24px;

  --font-text: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', system-ui, 'Segoe UI', Roboto, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', system-ui, 'Segoe UI', Roboto, sans-serif;

  --bg-app: var(--notes-cream);
  --bg-sidebar: var(--notes-cream);
  --bg-list: var(--notes-cream);
  --bg-editor: var(--notes-cream);
  --bg-input: var(--cream-surface-1);
  --bg-hover: var(--cream-surface-1);
  --bg-pressed: var(--cream-surface-2);
  --bg-selected: var(--notes-orange-tint);
  --text-primary: var(--ink);
  --text-secondary: var(--slate-text);
  --text-tertiary: var(--slate);
  --accent: var(--notes-orange);
  --accent-pressed: var(--notes-orange-pressed);
  --accent-tint: var(--notes-orange-tint);
  --accent-text: #FFFFFF;
  --border-subtle: var(--divider);

  --bg-sidebar-hover: var(--bg-hover);
  --bg-sidebar-active: var(--bg-selected);
  --bg-card: transparent;
  --bg-card-hover: var(--bg-hover);
  --bg-card-active: var(--bg-selected);
  --bg-toolbar: var(--notes-cream);
  --bg-modal: var(--notes-cream);
  --bg-modal-overlay: rgba(0, 0, 0, 0.4);
  --accent-green: var(--success);
  --accent-red: var(--error);
  --border-card: var(--divider);
  --border-strong: var(--mute);
  --border-accent: rgba(240, 154, 56, 0.4);
  --error-tint: rgba(255, 59, 48, 0.12);
  --success-glow: rgba(52, 199, 89, 0.5);
  --warning-glow: rgba(255, 204, 0, 0.5);
  --error-glow: rgba(255, 59, 48, 0.45);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.16);

  --font-system: var(--font-text);
  --sidebar-width: 280px;
  --list-width: 316px;
  --radius-sm: var(--radius-badge);
  --radius-md: var(--radius-search);
  --radius-lg: var(--radius-sheet);
}

[data-theme="dark"] {
  /* Apple Notes "Paper" dark primitives (DESIGN.md §2 and §10) */
  --notes-cream: #1A1A1A;
  --cream-surface-1: #262626;
  --cream-surface-2: #333333;
  --divider: #2A2A2A;
  --notes-orange: #F09A38;
  --notes-orange-pressed: #D87E1F;
  --notes-orange-tint: rgba(240, 154, 56, 0.16);
  --folder-yellow: #D8B65C;
  --folder-highlight: #E8CE8A;
  --highlight-yellow: #5C4A1F;
  --ink: #F2F2F2;
  --slate: #8E8E93;
  --slate-text: #8E8E93;
  --orange-text: #F09A38;
  --mute: #48484A;
  --success: #34C759;
  --warning: #FFCC00;
  --error: #FF3B30;
  --info: #0A84FF;

  --bg-modal-overlay: rgba(0, 0, 0, 0.65);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-system);
  color: var(--text-primary);
  background: var(--bg-app);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Master 3-Pane App Container */
.app-container {
  display: flex;
  flex: 1;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Pane 1: Left Navigation Sidebar */
.app-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 20;
  user-select: none;
}

body.sidebar-collapsed .app-sidebar {
  margin-left: calc(-1 * var(--sidebar-width));
  opacity: 0;
  pointer-events: none;
  border-right: none;
}

.sidebar-header {
  padding: var(--space-2) var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: 1;
}

.sidebar-header .icon-btn {
  width: 44px;
  height: 44px;
  color: var(--slate-text);
}

.sidebar-header .icon-btn:hover {
  color: var(--ink);
}

.app-sidebar .sidebar-header .auth-avatar {
  width: 24px;
  height: 24px;
  font-size: 11px;
  font-weight: 700;
  background: var(--notes-orange);
  color: var(--accent-text);
  box-shadow: none;
}

.app-sidebar .sidebar-header-actions .auth-logout-btn {
  min-height: 44px;
  padding: 0 var(--space-2);
  border: none;
  border-radius: var(--radius-search);
  background: none;
  color: var(--orange-text);
  font-family: inherit;
  font-size: 17px;
  font-weight: 400;
}

.app-sidebar .sidebar-header-actions .auth-logout-btn:hover {
  background: var(--bg-hover);
}

.sidebar-scrollable {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) var(--space-3);
}

.nav-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--slate-text);
  text-transform: uppercase;
  letter-spacing: 1.6px;
  padding: var(--space-2) var(--space-2) var(--space-1);
}

.sidebar-tags-title {
  margin-top: var(--space-4);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-search);
  font-size: 17px;
  color: var(--ink);
  cursor: pointer;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-hover);
}

.nav-item:active {
  background: var(--bg-pressed);
}

.nav-item.active {
  background: var(--bg-selected);
  color: var(--ink);
}

.nav-icon {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.nav-item > .nav-icon,
.nav-item .folder-glyph {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.folder-glyph-body {
  fill: var(--folder-yellow);
  stroke: var(--notes-orange);
  stroke-width: 1;
  stroke-linejoin: round;
}

.folder-glyph-highlight {
  fill: none;
  stroke: var(--folder-highlight);
  stroke-width: 0.5;
  stroke-linecap: round;
}

.nav-item.active .nav-icon {
  color: var(--ink);
}

.nav-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-count {
  font-size: 17px;
  color: var(--slate-text);
  font-variant-numeric: tabular-nums;
}

.nav-group {
  margin-bottom: 2px;
}

.folder-arrow {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--slate-text);
  font: inherit;
  cursor: pointer;
}

/* Expand the 16px glyph to a 24px pointer target without moving it */
.folder-arrow::after {
  content: '';
  position: absolute;
  inset: -4px;
}

.nav-group.open .folder-arrow {
  transform: rotate(90deg);
}

.sub-nav-items {
  display: none;
}

.nav-group.open .sub-nav-items {
  display: block;
}

.sub-item {
  padding-left: 34px;
}

/* Tag chips in the note list header */
.tags-list-container {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-2);
  overflow-x: auto;
  padding: 2px 0;
  margin-top: var(--space-1);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tags-list-container::-webkit-scrollbar {
  display: none;
}

.tags-empty-hint {
  padding: 2px 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--slate-text);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-height: 32px;
  padding: 0 var(--space-3);
  border: none;
  border-radius: var(--radius-sheet);
  background: var(--accent-tint);
  color: var(--orange-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}

.tag-chip.active {
  background: var(--notes-orange);
  color: var(--accent-text);
}

/* Sidebar Footer (Sync Badge & Settings) */
.sidebar-footer {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  background: var(--bg-sidebar);
}

.sync-status-indicator {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 12px;
  color: var(--slate-text);
}

#vault-status-text {
  white-space: nowrap;
}

.status-reconnect-btn {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 var(--space-2);
  border: none;
  border-radius: var(--radius-search);
  background: none;
  color: var(--orange-text);
  font-family: var(--font-text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.status-reconnect-btn:hover,
.status-reconnect-btn:active {
  background: var(--bg-pressed);
}

.status-reconnect-btn[hidden] {
  display: none;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.drive-reconnect-banner {
  display: none;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  background: var(--cream-surface-1);
  border-bottom: 1px solid var(--divider);
  color: var(--ink);
  font-size: 14px;
}

.drive-reconnect-banner[hidden] {
  display: none;
}

.drive-reconnect-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drive-reconnect-action {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 44px;
  padding: 0 var(--space-2);
  border: none;
  border-radius: var(--radius-search);
  background: none;
  color: var(--orange-text);
  font-family: var(--font-text);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.drive-reconnect-action:hover,
.drive-reconnect-action:active {
  background: var(--bg-pressed);
}

.dot-synced { background: var(--accent-green); box-shadow: 0 0 6px var(--success-glow); }
.dot-syncing { background: var(--accent); }
.dot-offline { background: var(--text-tertiary); }
.dot-conflict { background: var(--accent); box-shadow: 0 0 6px var(--warning-glow); }
.dot-auth { background: var(--accent-red); box-shadow: 0 0 6px var(--error-glow); }

.readonly-badge {
  display: none;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-tint);
  border-radius: 4px;
  padding: 2px 6px;
  white-space: nowrap;
}

@keyframes pulse {
  0% { opacity: 0.4; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1.1); }
}

.footer-actions {
  display: flex;
  align-items: center;
  gap: 0;
  margin-left: auto;
}

.sidebar-footer .icon-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-search);
  color: var(--slate-text);
}

.sidebar-footer .icon-btn:hover {
  background: var(--bg-hover);
  color: var(--ink);
}

.icon-btn {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

/* Pane 2: Middle Note List */
.app-note-list {
  width: clamp(260px, 26vw, 360px);
  min-width: 250px;
  background: var(--bg-list);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

body.sidebar-collapsed .app-note-list {
  width: clamp(290px, 29vw, 390px);
}

.note-list-header {
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.bulk-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-selected);
  border-bottom: 1px solid var(--border-subtle);
}

.bulk-action-bar[hidden] {
  display: none;
}

.bulk-action-count {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
  white-space: nowrap;
}

.bulk-action-buttons {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-1);
  margin-left: auto;
}

.bulk-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-list);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.bulk-action-btn:hover {
  background: var(--bg-hover);
}

.bulk-action-btn:active {
  background: var(--bg-pressed);
}

.bulk-action-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.bulk-action-danger {
  border-color: var(--error-tint);
  color: var(--accent-red);
}

.bulk-action-danger:hover {
  background: var(--error-tint);
}

.bulk-action-close {
  padding: 0;
}

.filter-badge-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.filter-title-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.current-filter-title {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notes-count-badge {
  font-size: 13px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--slate-text);
}

.note-list-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.new-note-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: var(--radius-search);
  background: none;
  color: var(--notes-orange);
  cursor: pointer;
}

.new-note-btn:hover {
  background: var(--bg-hover);
  color: var(--notes-orange-pressed);
}

.mobile-new-note-fab {
  display: none;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--notes-orange);
  color: var(--accent-text);
  cursor: pointer;
  box-shadow: var(--elev-fab);
}

.sidebar-new-note-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 8px 12px 2px;
  padding: 8px 10px;
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  background: var(--accent-tint);
  color: var(--accent);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.sidebar-new-note-btn[hidden] {
  display: none;
}

.sidebar-new-note-btn:hover {
  border-color: var(--accent);
}

.search-bar-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  height: 36px;
  background: var(--cream-surface-1);
  border: 2px solid transparent;
  border-radius: var(--radius-search);
  padding: 0 var(--space-3);
  margin-bottom: var(--space-2);
}

.search-bar-wrapper:focus-within {
  border-color: var(--notes-orange);
}

.search-icon {
  color: var(--slate-text);
  flex-shrink: 0;
  margin-right: var(--space-2);
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: none;
  border: none;
  outline: none;
  padding: 0;
  font-size: 17px;
  color: var(--text-primary);
  font-family: inherit;
}

.search-input::placeholder {
  color: var(--slate-text);
}

.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.search-clear-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--slate-text);
  display: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
}

.search-clear-btn:hover {
  color: var(--text-primary);
}

.sort-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  margin-bottom: var(--space-1);
  font-size: 12px;
  color: var(--slate-text);
}

.sort-select {
  background: none;
  border: none;
  color: var(--slate-text);
  font-size: 12px;
  font-family: inherit;
  padding: 4px 0;
  min-height: 24px;
  outline: none;
  cursor: pointer;
}

.note-list-scrollable {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 var(--space-6);
}

.notes-section-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-4) var(--space-1);
  font-size: 13px;
  font-weight: 600;
  color: var(--slate-text);
  text-transform: uppercase;
  letter-spacing: 1.6px;
}

.notes-section-header:not(:first-child) {
  margin-top: var(--space-2);
}

/* Apple Notes three-line note row */
.note-row {
  position: relative;
  min-height: 84px;
  padding: var(--space-4) var(--space-4) var(--space-2);
  border-bottom: 1px solid var(--divider);
  background: transparent;
  cursor: pointer;
  user-select: none;
}

.note-row:last-child {
  border-bottom: none;
}

.note-row:hover {
  background: var(--bg-hover);
}

.note-row.pinned {
  background: var(--cream-surface-1);
}

.note-row.active {
  background: var(--bg-selected);
}

.note-row.selected {
  background: var(--bg-selected);
}

.note-row-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
}

.note-row-check.checked {
  color: var(--orange-text);
}

.note-row-heading {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.note-row-pin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--notes-orange);
}

.note-row-title {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.1px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-row-preview {
  margin-top: var(--space-1);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.35;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-row-meta {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: 2px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--slate-text);
  white-space: nowrap;
  overflow: hidden;
}

.note-row-date {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.note-row-folder {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-row-flag {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--slate-text);
}

.note-row-flag svg {
  width: 12px;
  height: 12px;
}

.empty-search-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 260px;
  color: var(--slate-text);
  text-align: center;
  padding: var(--space-5);
}

.empty-search-state svg {
  margin-bottom: var(--space-3);
  color: var(--slate-text);
  opacity: 0.6;
}

.empty-search-state p {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.empty-search-state span {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Pane 3: Right WYSIWYG Editor View */
.app-editor-pane {
  flex: 1;
  background: var(--bg-editor);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Mobile Overlay */
.mobile-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-modal-overlay);
  z-index: 15;
}

.mobile-drawer-overlay.open {
  display: block;
}

/* Responsive adjustments */
@media (max-width: 860px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: -270px;
    width: 260px;
    box-shadow: var(--shadow-lg);
  }

  .app-sidebar.drawer-open {
    transform: translateX(270px);
  }

  .app-note-list {
    width: 280px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .sidebar-header {
    padding: 10px;
    gap: 6px;
  }

  .modal-close-btn {
    width: 44px;
    height: 44px;
  }

  .note-pin-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    opacity: 0.7;
  }

  .note-list-actions {
    display: none;
  }
}

/* Force Mobile View Rule for screenshots */
body.force-mobile-view .app-sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 280px;
  transform: translateX(0);
  box-shadow: var(--shadow-lg);
  z-index: 30;
}

body.force-mobile-view .mobile-drawer-overlay {
  display: block;
  z-index: 25;
}

/* PWA edge-to-edge safe areas & mobile refinements */
body {
  height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.app-sidebar,
.note-list-header,
.editor-header-bar {
  padding-top: max(12px, env(safe-area-inset-top));
}

.sidebar-footer,
.note-list-scrollable,
.editor-scroll-area {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.app-container {
  height: 100%;
  min-height: 0;
}

@media (max-width: 860px) {
  .mobile-drawer-overlay.open {
    background: var(--bg-modal-overlay);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }

  .mobile-new-note-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--notes-orange);
    color: var(--accent-text);
    box-shadow: var(--elev-fab);
    border: none;
    cursor: pointer;
    z-index: 12;
  }

  .drive-reconnect-banner {
    display: flex;
  }
}

@media (max-width: 430px) {
  .app-note-list {
    width: 100%;
    flex: 1;
    min-width: 0;
  }

  .note-list-header {
    padding: var(--space-3) var(--space-4);
  }

  .note-list-scrollable {
    padding: 0 0 var(--space-6);
  }

  .notes-count-badge {
    white-space: nowrap;
  }

  .sidebar-footer {
    padding: 10px 12px;
  }
}

/* Note list pinning and notebook management */
.note-pin-btn {
  margin-left: auto;
  background: none;
  border: none;
  padding: 3px;
  min-width: 24px;
  min-height: 24px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  opacity: 0;
  cursor: pointer;
}

.note-row:hover .note-pin-btn,
.note-row:focus-within .note-pin-btn,
.note-pin-btn:focus-visible {
  opacity: 0.7;
}

.note-pin-btn:hover {
  opacity: 1;
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.note-pin-btn.pinned {
  color: var(--accent);
}

.note-row:hover .note-pin-btn.pinned,
.note-row:focus-within .note-pin-btn.pinned,
.note-pin-btn.pinned:hover {
  opacity: 1;
}

@media (max-width: 860px) {
  .note-pin-btn {
    opacity: 0.7;
  }
}

.folder-actions-btn {
  margin-left: auto;
  background: none;
  border: none;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  line-height: 1;
  cursor: pointer;
  opacity: 0;
}

.nav-item:hover .folder-actions-btn,
.nav-item:focus-within .folder-actions-btn {
  opacity: 1;
}

.folder-actions-btn:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.folder-actions-btn:focus-visible {
  opacity: 1;
}

.sidebar-new-folder-btn {
  margin: var(--space-1) 0 var(--space-2);
  padding: var(--space-2);
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: none;
  border: none;
  border-radius: var(--radius-search);
  color: var(--orange-text);
  font-family: inherit;
  font-size: 17px;
  font-weight: 400;
  cursor: pointer;
}

.sidebar-new-folder-btn:hover {
  color: var(--orange-text);
  background: var(--bg-hover);
}

@media (max-width: 860px) {
  .folder-actions-btn {
    position: absolute;
    right: var(--space-1);
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    margin-left: 0;
    opacity: 0;
    pointer-events: none;
    background: inherit;
  }

  .nav-item:hover .folder-actions-btn {
    opacity: 0;
    pointer-events: none;
  }

  .nav-item:focus-within .folder-actions-btn,
  .nav-item.active .folder-actions-btn {
    opacity: 0.75;
    pointer-events: auto;
  }

  .nav-item:focus-within .nav-label,
  .nav-item.active .nav-label {
    padding-right: var(--space-11);
  }

  .nav-item:focus-within .nav-count,
  .nav-item.active .nav-count {
    visibility: hidden;
  }

  .sidebar-footer {
    padding: var(--space-2);
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    flex-wrap: wrap;
  }

  .footer-actions {
    flex-shrink: 0;
  }

  body.sidebar-collapsed .app-sidebar {
    margin-left: 0;
    opacity: 1;
    pointer-events: auto;
  }

  .desktop-sidebar-toggle,
  .sidebar-collapse-btn {
    display: none !important;
  }
}

/* Sidebar Toggle Buttons & Fluid Responsive Layout */
.desktop-sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.desktop-sidebar-toggle:hover {
  color: var(--accent);
}

.sidebar-collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  margin-left: auto;
}

.sidebar-collapse-btn:hover {
  color: var(--text-primary);
}

/* macOS Sequoia Floating Context Menu */
.app-context-menu {
  position: fixed;
  z-index: 9999;
  min-width: 210px;
  max-width: 280px;
  background: var(--cream-surface-1);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--divider);
  border-radius: var(--radius-search);
  padding: 5px;
  box-shadow: var(--shadow-lg);
  user-select: none;
}

@keyframes contextMenuFadeIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-2px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.context-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  min-height: 24px;
  font-size: 13px;
  color: var(--text-primary);
  border-radius: 6px;
  cursor: pointer;
}

.context-menu-item:hover,
.context-menu-item:focus {
  background: var(--accent-tint);
  color: var(--ink);
}

.context-menu-item.item-danger {
  color: var(--error);
  font-weight: 500;
}

.context-menu-item.item-danger:hover,
.context-menu-item.item-danger:focus {
  background: var(--error-tint);
  color: var(--error);
}

.context-menu-item.item-disabled,
.context-menu-item.item-disabled:hover,
.context-menu-item.item-disabled:focus {
  opacity: 0.45;
  color: var(--text-primary);
  background: transparent;
  cursor: default;
}

.context-menu-label {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-menu-label svg {
  flex-shrink: 0;
}

.context-menu-shortcut {
  font-size: 11px;
  opacity: 0.6;
  margin-left: 14px;
  font-family: inherit;
  white-space: nowrap;
}

.context-menu-item:hover .context-menu-shortcut,
.context-menu-item:focus .context-menu-shortcut {
  opacity: 0.9;
  color: inherit;
}

.context-menu-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 6px;
}

/* Toast action button (Undo) */
.toast-action {
  flex-shrink: 0;
  margin-left: var(--space-1);
  min-height: 32px;
  padding: 0 var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--orange-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  pointer-events: auto;
}

.toast-action:hover,
.toast-action:active {
  background: var(--bg-pressed);
}

/* Toast dismiss button (errors) */
.toast-dismiss {
  flex-shrink: 0;
  min-width: 32px;
  min-height: 32px;
  padding: 0 var(--space-1);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--slate-text);
  font-family: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}

.toast-dismiss:hover,
.toast-dismiss:active {
  background: var(--bg-pressed);
  color: var(--ink);
}

/* Keyboard focus ring (DESIGN.md §10) */
:focus-visible {
  outline: 2px solid var(--notes-orange);
  outline-offset: 2px;
}

/* Keep the ring visible inside the scrolling list and the sidebar rows */
.note-row:focus-visible,
.nav-item:focus-visible,
.tag-chip:focus-visible {
  outline-offset: -2px;
}

/* Motion (DESIGN.md §6), enabled only when the reader allows it */
@media (prefers-reduced-motion: no-preference) {
  .app-sidebar {
    transition: margin-left 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.18s ease;
  }

  .app-note-list {
    transition: width 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .nav-item {
    transition: background-color 0.12s ease;
  }

  .folder-arrow {
    transition: transform 0.15s ease;
  }

  .tag-chip {
    transition: background-color 0.12s ease;
  }

  .dot-syncing {
    animation: pulse 1s infinite alternate;
  }

  .icon-btn {
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .new-note-btn {
    transition: background-color 0.12s ease, color 0.12s ease;
  }

  .sidebar-new-note-btn {
    transition: background-color 0.12s ease, border-color 0.12s ease;
  }

  .note-row {
    transition: background-color 0.12s ease, transform 0.12s ease;
  }

  .note-row:active {
    transform: scale(0.99);
  }

  .mobile-new-note-fab {
    transition: transform 250ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .mobile-new-note-fab:active {
    transform: scale(0.95);
  }

  .note-pin-btn {
    transition: opacity 0.12s ease, background-color 0.12s ease, color 0.12s ease;
  }

  .folder-actions-btn {
    transition: opacity 0.12s ease, background-color 0.12s ease, color 0.12s ease;
  }

  .sidebar-new-folder-btn {
    transition: background-color 0.12s ease;
  }

  .search-bar-wrapper {
    transition: border-color 0.15s ease;
  }

  .app-context-menu {
    animation: contextMenuFadeIn 0.12s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .context-menu-item {
    transition: background-color 0.08s ease, color 0.08s ease;
  }

  @media (max-width: 860px) {
    .app-sidebar {
      transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    }
  }
}

/* Narrow-screen pointer targets (A20). */
@media (max-width: 860px) {
  .search-bar-wrapper {
    height: 48px;
  }

  .search-input {
    height: 44px;
  }

  .sort-select {
    min-height: 44px;
    height: 44px;
  }

  .search-clear-btn {
    width: 44px;
    height: 44px;
  }

  .tag-chip {
    min-height: 44px;
  }

  .context-menu-item {
    min-height: 44px;
  }

  .toast-action {
    min-height: 44px;
    min-width: 44px;
  }

  .toast-dismiss {
    min-width: 44px;
    min-height: 44px;
  }

  .folder-arrow::after {
    inset: -14px;
  }
}
