@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter-medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter-semibold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-tertiary: #efefef;
  --bg-hover: #e8e8ec;
  --border: #e0e0e4;
  --text-primary: #1a1a1e;
  --text-secondary: #6a6a76;
  --text-tertiary: #9a9aa6;
  --accent: #5e6ad2;
  --accent-hover: #4a56c0;
  --accent-subtle: rgba(94, 106, 210, 0.1);
  --danger: #e5484d;
  --danger-hover: #d33a3f;
  --success: #30a46c;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
  --bg-primary: #0a0a0b;
  --bg-secondary: #111113;
  --bg-tertiary: #1a1a1e;
  --bg-hover: #1e1e22;
  --border: #2a2a2e;
  --text-primary: #e8e8ec;
  --text-secondary: #8a8a96;
  --text-tertiary: #5a5a66;
  --accent: #5e6ad2;
  --accent-hover: #7078e0;
  --accent-subtle: rgba(94, 106, 210, 0.15);
  --danger: #e5484d;
  --danger-hover: #f26368;
  --success: #30a46c;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.2);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Setup screen */
.setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 12px;
  padding: 32px;
  background: var(--bg-primary);
}

.setup-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}

.setup-card h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.setup input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 150ms ease;
}

.setup input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

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

.setup button {
  width: 100%;
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  transition: background 150ms ease;
}

.setup button:hover {
  background: var(--accent-hover);
}

.setup-error {
  color: var(--danger);
  font-size: 0.8rem;
  text-align: center;
  max-width: 100%;
}

/* Main layout */
.main {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 240px;
  overflow-y: auto;
  flex-shrink: 0;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 8px;
}

.sidebar-footer {
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  font-size: 0.75rem;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-footer .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: 4px;
}

.sidebar-footer .status-dot.connected {
  background: var(--success);
}

.sidebar-footer .status-dot.error {
  background: var(--danger);
}

.new-folder-input {
  padding: 4px 12px 8px;
}

.new-folder-label {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.new-folder-input input {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 150ms ease;
}

.new-folder-input input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

.new-folder-input input::placeholder {
  color: var(--text-tertiary);
}

.note-list-panel {
  width: 280px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-width: 0;
}

/* Resizer handles */
.resizer {
  width: 1px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  transition: background 150ms ease;
  user-select: none;
}

.resizer:hover,
.resizer.active {
  background: var(--accent);
  width: 2px;
}

/* Folder tree */
.folder {
  padding: 6px 12px;
  margin: 1px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.875rem;
  border-radius: 6px;
  transition: background 150ms ease, color 150ms ease;
  user-select: none;
}

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

.folder.active {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.folder-children {
  padding-left: 16px;
}

.folder-toggle {
  display: inline-block;
  width: 1.2em;
  text-align: center;
  font-family: monospace;
  flex-shrink: 0;
  margin-right: 4px;
}

.folder {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

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

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: 6px;
  transition: background 150ms ease, color 150ms ease;
  white-space: nowrap;
}

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

.toolbar-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

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

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

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

.toolbar-btn-danger:hover {
  background: rgba(229, 72, 77, 0.1);
  color: var(--danger);
}

.toolbar-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.toolbar-btn:disabled:hover {
  background: transparent;
}

.toolbar-spacer {
  flex: 1;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Hamburger (mobile) */
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background 150ms ease, color 150ms ease;
}

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

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

/* Note list panel */
.note-list-header {
  padding: 12px 16px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.note-list {
  flex: 1;
  overflow-y: auto;
}

.note-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 150ms ease;
}

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

.note-item.active {
  background: var(--bg-tertiary);
}

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

.note-date {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.note-empty {
  padding: 32px 16px;
  color: var(--text-tertiary);
  text-align: center;
  font-size: 0.875rem;
}

/* Note view */
.note-view {
  padding: 32px;
  width: 100%;
}

.note-view h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
  line-height: 1.3;
}

.note-view h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--text-primary);
  line-height: 1.35;
}

.note-view h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 20px 0 6px;
  color: var(--text-primary);
  line-height: 1.4;
}

.note-view p {
  margin-bottom: 12px;
  line-height: 1.65;
  color: var(--text-secondary);
}

.note-view code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  color: var(--text-primary);
}

.note-view pre {
  background: var(--bg-tertiary);
  padding: 16px;
  border-radius: 6px;
  overflow-x: auto;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.note-view pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.note-view ul,
.note-view ol {
  padding-left: 24px;
  margin-bottom: 12px;
}

.note-view li {
  margin-bottom: 4px;
  line-height: 1.65;
  color: var(--text-secondary);
}

.note-view blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  margin-bottom: 12px;
  color: var(--text-tertiary);
}

.note-view a {
  color: var(--accent);
  text-decoration: none;
}

.note-view a:hover {
  text-decoration: underline;
}

.note-view hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.note-view strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Editor */
.editor {
  padding: 32px;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor-title {
  width: 100%;
  padding: 8px 0;
  background: none;
  border: none;
  border-bottom: none;
  color: var(--text-primary);
  font-size: 1.25rem;
  font-weight: 600;
  font-family: inherit;
  outline: none;
  margin-bottom: 16px;
}

.editor-title:focus {
  outline: none;
}

.editor-title::placeholder {
  color: var(--text-tertiary);
}

.editor textarea {
  width: 100%;
  flex: 1;
  background: none;
  color: var(--text-primary);
  border: none;
  padding: 0;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  resize: none;
  outline: none;
}

.editor textarea::placeholder {
  color: var(--text-tertiary);
}

.save-indicator {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  padding: 4px 0;
  flex-shrink: 0;
}

.save-indicator.saving {
  color: var(--accent);
}

/* Folder picker */
.folder-picker {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 12px;
  padding: 12px;
}

.folder-picker-header {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.folder-picker-tree {
  max-height: 200px;
  overflow-y: auto;
}

.folder-picker-item {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.875rem;
}

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

.folder-picker-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.folder-picker-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

/* Command palette */
.cmd-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
  animation: fadeIn 100ms ease;
}

.cmd-palette {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slideDown 150ms ease;
}

.cmd-input-wrap {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.cmd-input {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
}

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

.cmd-results {
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
}

.cmd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  transition: background 100ms ease, color 100ms ease;
}

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

.cmd-item-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-tertiary);
}

.cmd-item-label {
  flex: 1;
}

.cmd-item-shortcut {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-family: "SF Mono", "Cascadia Code", monospace;
}

.cmd-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.875rem;
}

.cmd-section-label {
  padding: 8px 12px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Search bar (inline in note list) */
.search-bar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.search-bar input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 150ms ease;
}

.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

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

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

/* Context menu */
.context-menu {
  position: fixed;
  z-index: 50;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 160px;
  box-shadow: var(--shadow-lg);
  animation: fadeIn 80ms ease;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  border-radius: 6px;
  transition: background 80ms ease, color 80ms ease;
  user-select: none;
}

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

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

.context-menu-item.danger:hover {
  background: rgba(229, 72, 77, 0.1);
  color: var(--danger);
}

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

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

/* Inline rename input in folder tree */
.folder-rename-input {
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  border-radius: 4px;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  width: 100%;
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

/* Mobile responsive */
@media (max-width: 640px) {
  .hamburger-btn {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 200ms ease-out;
  }

  .sidebar.open {
    transform: translateX(0);
    animation: slideInLeft 200ms ease-out;
  }

  .sidebar-overlay.open {
    display: block;
  }

  .note-list-panel {
    width: 100% !important;
  }

  .note-list-panel.hidden {
    display: none;
  }

  .resizer {
    display: none !important;
  }

  .content {
    width: 100% !important;
    min-width: 0;
  }

  .content.hidden {
    display: none;
  }

  .note-view {
    padding: 20px 16px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .editor {
    padding: 20px 16px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .editor-title {
    font-size: 16px;
    margin-bottom: 12px;
  }

  .editor textarea {
    font-size: 16px;
    line-height: 1.5;
  }

  .toolbar {
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px 8px;
  }

  .toolbar-btn {
    padding: 6px 8px;
    font-size: 0.75rem;
  }

  .toolbar-spacer {
    display: block;
  }

  .cmd-overlay {
    padding-top: 10vh;
    padding-left: 12px;
    padding-right: 12px;
  }

  .new-folder-input {
    padding: 4px 12px 8px;
  }

  .new-folder-input input {
    font-size: 16px;
  }

  .sidebar-header {
    padding: 10px 12px 6px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  .sidebar-header .toolbar-btn {
    padding: 4px 8px;
  }
}

/* Scrollbar styling */
::-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);
}
