:root {
  color-scheme: light dark;
  --bg: #1a1d23;
  --panel: #252930;
  --panel-light: #2d3139;
  --text: #e4e4e7;
  --text-secondary: #a1a1aa;
  --muted: #71717a;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.05);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --radius: 8px;
  --radius-lg: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8f9fa;
  --panel: #ffffff;
  --panel-light: #f1f3f5;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --muted: #9ca3af;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --border: rgba(0, 0, 0, 0.1);
  --border-light: rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.brand {
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

.search {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.search-filters {
  display: flex;
  gap: 8px;
}

.filter-select {
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary);
}

.search input[type="search"] {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  transition: all 0.15s ease;
}

.search input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--panel-light);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

button,
select {
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-light);
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s ease;
}

button:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.12);
}

button.primary {
  background: var(--primary);
  color: #ffffff;
  border: none;
}

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

button.danger {
  background: var(--danger);
  color: #fff;
  border: none;
}

button.danger:hover {
  background: #dc2626;
}

button.ghost {
  background: transparent;
  border: none;
}

button.ghost:hover {
  background: rgba(255, 255, 255, 0.08);
}

button.icon-btn {
  font-size: 1.2rem;
  padding: 4px 8px;
  line-height: 1;
  min-width: auto;
}

button.back-btn {
  font-size: 1.3rem;
  padding: 4px 8px;
}

#syncStatusIcon {
  color: var(--success);
  font-size: 1rem;
  transition: all 0.2s ease;
}

#syncStatusIcon.syncing {
  animation: rotate 1s linear infinite;
}

#syncStatusIcon.error {
  color: var(--danger);
  cursor: help;
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

select {
  font-size: 0.875rem;
}

.layout {
  display: grid;
  grid-template-columns: 240px 320px 1fr;
  flex: 1;
  min-height: 0;
}

.layout.masonry-mode {
  grid-template-columns: 240px 1fr;
}

.layout.masonry-mode .editor {
  display: none;
}

.layout.masonry-editing {
  grid-template-columns: 240px 1fr;
}

.layout.masonry-editing .list {
  display: none;
}

.layout.masonry-editing .editor {
  display: flex;
  border-left: 1px solid var(--border);
}

.panel-hidden {
  display: none !important;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar-header {
  font-weight: 600;
  margin-bottom: 16px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding-left: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.folder-tree {
  font-size: 0.95rem;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
}

.folder-tree button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.15s ease;
  flex: 1;
}

.folder-tree button.deleted {
  opacity: 0.5;
  text-decoration: line-through;
}

.folder-more-btn {
  opacity: 0;
  padding: 4px 6px !important;
  font-size: 1rem !important;
  min-width: auto !important;
  width: auto !important;
  flex: 0 0 auto !important;
}

.folder-item:hover .folder-more-btn {
  opacity: 0.7;
}

.folder-more-btn:hover {
  opacity: 1 !important;
}

.folder-dropdown {
  position: relative;
}

.folder-dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 140px;
  z-index: 1000;
  display: none;
  flex-direction: column;
  padding: 4px;
}

.folder-dropdown.open .folder-dropdown-menu {
  display: flex;
}

.folder-dropdown-menu button {
  width: 100% !important;
  text-align: left;
  border: none;
  padding: 8px 12px !important;
  background: transparent;
  border-radius: var(--radius);
  font-size: 0.875rem !important;
}

.folder-dropdown-menu button:hover {
  background: rgba(255, 255, 255, 0.05);
}

.folder-dropdown-menu button.danger {
  color: var(--danger);
}

.folder-dropdown-menu button.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.folder-tree button:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.folder-tree button.active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--primary);
}

.folder-tree ul {
  list-style: none;
  padding-left: 14px;
  margin: 4px 0;
}

.list {
  border-right: 1px solid var(--border);
  padding: 16px;
  background: var(--panel-light);
  overflow-y: auto;
}

.list-header {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.breadcrumb {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  flex: 1;
}

.note-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.note-list.masonry {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  align-items: start;
}

.note-card {
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  background: var(--panel);
  cursor: pointer;
  transition: all 0.15s ease;
}

.note-card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.note-list:not(.masonry) .note-card {
  box-shadow: var(--shadow-sm);
}

.note-list.masonry .note-card {
  break-inside: avoid;
}

.note-card.deleted {
  opacity: 0.5;
  text-decoration: line-through;
}

.note-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.note-card.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.note-card.drag-over {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}

.note-card {
  cursor: grab;
}

.note-card:active {
  cursor: grabbing;
}

.note-title {
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--text);
}

.note-title.editable {
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  outline: none;
  transition: all 0.15s ease;
  cursor: text;
}

.note-title.editable:hover {
  border-color: var(--border-light);
}

.note-tags, .note-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  margin-bottom: 4px;
}

.note-tag, .note-category {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  font-weight: 500;
}

.note-category {
  background: var(--success);
}

.note-star {
  display: inline-block;
  margin-left: 6px;
  color: #fbbf24;
}

.note-card[data-color] {
  border-left: 4px solid;
}


.note-title.editable:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.02);
}

.note-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 8px;
}

.note-preview {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-top: 8px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.note-ellipsis {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
  text-align: center;
}

.empty-message {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.note-content-editable {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.6;
  margin-top: 12px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  outline: none;
  min-height: 80px;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  transition: all 0.15s ease;
}

.note-content-editable:focus {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.note-card.editing {
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.close-editor {
  font-size: 1.5rem;
  line-height: 1;
  padding: 4px 8px;
  display: none;
}

.editor-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-light);
  justify-content: space-between;
  align-items: center;
}

.editor-toolbar-left {
  display: flex;
  gap: 8px;
}

.editor-toolbar-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.editor-toolbar button {
  padding: 6px 10px;
  font-size: 0.9rem;
}

.editor-title-container {
  padding: 16px 32px 0;
  background: var(--bg);
}

.editor-title-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 2rem;
  font-weight: 700;
  padding: 8px 0;
  outline: none;
  font-family: inherit;
}

.editor-title-input::placeholder {
  color: var(--muted);
  opacity: 0.5;
}

.editor-title-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.inline-metadata {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 12px;
}

.inline-metadata input[type="text"] {
  padding: 5px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-light);
  color: var(--text);
  font-size: 0.8rem;
  width: 120px;
  transition: all 0.2s ease;
}

.inline-metadata input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  width: 160px;
}

.inline-metadata input[type="text"]::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

.color-btn {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 2px solid var(--border);
  cursor: pointer;
  background: var(--primary);
  transition: all 0.15s ease;
  padding: 0;
}

.color-btn:hover {
  transform: scale(1.1);
  border-color: var(--text-secondary);
}

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

#noteStarBtn {
  font-size: 1.1rem;
  transition: all 0.15s ease;
}

#noteStarBtn.starred {
  color: #fbbf24;
}

#noteStarBtn:not(.starred) {
  opacity: 0.4;
}

#noteStarBtn:hover {
  opacity: 1;
  transform: scale(1.15);
}

.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  z-index: 1000;
  display: none;
  flex-direction: column;
  padding: 4px;
}

.dropdown.open .dropdown-menu {
  display: flex;
}

.dropdown-menu button {
  width: 100%;
  text-align: left;
  border: none;
  padding: 8px 12px;
  background: transparent;
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.dropdown-menu button:hover {
  background: rgba(255, 255, 255, 0.05);
}

.dropdown-menu button.danger {
  color: var(--danger);
}

.dropdown-menu button.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.current-file {
  font-weight: 600;
}

.editor-surface {
  flex: 1;
  padding: 24px 32px;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.7;
  overflow-y: auto;
}

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

.editor-surface .ProseMirror {
  min-height: 100%;
  outline: none;
}

.editor-surface .ProseMirror p.is-editor-empty:first-child::before {
  content: "Start writing...";
  color: var(--muted);
  opacity: 0.5;
  float: left;
  height: 0;
  pointer-events: none;
}

.editor-surface .ProseMirror ul[data-type="taskList"] {
  list-style: none;
  padding-left: 0;
}

.editor-surface .ProseMirror ul[data-type="taskList"] li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 0;
}

.editor-surface .ProseMirror ul[data-type="taskList"] li > label {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.editor-surface .ProseMirror ul[data-type="taskList"] li > label > input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  margin: 0;
}

.editor-surface .ProseMirror ul[data-type="taskList"] li > div {
  flex: 1;
  min-width: 0;
}

.editor-surface .ProseMirror ul[data-type="taskList"] li > div > p {
  margin: 0;
  line-height: inherit;
}

.editor-surface .ProseMirror li {
  position: relative;
  cursor: grab;
}

.editor-surface .ProseMirror li:active {
  cursor: grabbing;
}

.editor-surface .ProseMirror li::before {
  content: "⋮⋮";
  position: absolute;
  left: -20px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.2s;
  font-size: 0.9rem;
  line-height: 1.5;
  cursor: grab;
}

.editor-surface .ProseMirror li:hover::before {
  opacity: 0.6;
}

/* Grip handles for all draggable block elements */
.editor-surface .ProseMirror p,
.editor-surface .ProseMirror h1,
.editor-surface .ProseMirror h2,
.editor-surface .ProseMirror h3,
.editor-surface .ProseMirror h4,
.editor-surface .ProseMirror h5,
.editor-surface .ProseMirror h6,
.editor-surface .ProseMirror pre,
.editor-surface .ProseMirror blockquote {
  position: relative;
  cursor: grab;
}

.editor-surface .ProseMirror p:active,
.editor-surface .ProseMirror h1:active,
.editor-surface .ProseMirror h2:active,
.editor-surface .ProseMirror h3:active,
.editor-surface .ProseMirror h4:active,
.editor-surface .ProseMirror h5:active,
.editor-surface .ProseMirror h6:active,
.editor-surface .ProseMirror pre:active,
.editor-surface .ProseMirror blockquote:active {
  cursor: grabbing;
}

.editor-surface .ProseMirror p::before,
.editor-surface .ProseMirror h1::before,
.editor-surface .ProseMirror h2::before,
.editor-surface .ProseMirror h3::before,
.editor-surface .ProseMirror h4::before,
.editor-surface .ProseMirror h5::before,
.editor-surface .ProseMirror h6::before,
.editor-surface .ProseMirror pre::before,
.editor-surface .ProseMirror blockquote::before {
  content: "⋮⋮";
  position: absolute;
  left: -20px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.2s;
  font-size: 0.9rem;
  cursor: grab;
}

.editor-surface .ProseMirror p:hover::before,
.editor-surface .ProseMirror h1:hover::before,
.editor-surface .ProseMirror h2:hover::before,
.editor-surface .ProseMirror h3:hover::before,
.editor-surface .ProseMirror h4:hover::before,
.editor-surface .ProseMirror h5:hover::before,
.editor-surface .ProseMirror h6:hover::before,
.editor-surface .ProseMirror pre:hover::before,
.editor-surface .ProseMirror blockquote:hover::before {
  opacity: 0.6;
}

.editor-surface .ProseMirror .ProseMirror-selectednode {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

.editor-surface .ProseMirror mark {
  background-color: #fef08a;
  color: inherit;
  padding: 2px 0;
  border-radius: 2px;
}

.editor-surface .ProseMirror u {
  text-decoration: underline;
}

.editor-surface .ProseMirror s {
  text-decoration: line-through;
}

.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.token-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.token-dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  max-width: 640px;
  width: 90vw;
  color: var(--text);
  background: var(--panel);
}

.token-form {
  padding: 20px;
  display: grid;
  gap: 12px;
}

.token-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.token-title {
  margin: 0;
  font-size: 1.2rem;
}

.token-intro {
  margin: 0;
  color: var(--muted);
}

.token-steps {
  margin: 0;
  padding-left: 18px;
  color: var(--text);
}

.token-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.token-links a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.95rem;
}

.token-links a:hover {
  text-decoration: underline;
}

.token-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.token-input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-light);
  color: var(--text);
}

.token-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.settings-dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  max-width: 720px;
  width: 90vw;
  color: var(--text);
  background: var(--panel);
}

.settings-form {
  padding: 20px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-sync-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.current-adapter {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  background: var(--panel-light);
  border: 1px solid var(--border);
}

.current-adapter label {
  font-weight: 500;
  color: var(--text-secondary);
}

.current-adapter span {
  font-weight: 600;
  color: var(--text);
}

.settings-sync-controls select {
  width: 100%;
}

.settings-list {
  display: grid;
  gap: 8px;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-light);
}

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

.file-upload {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  cursor: pointer;
  color: var(--muted);
}

.file-upload input {
  display: none;
}

.banner {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--panel-light);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  max-width: 320px;
}

.banner.hidden {
  display: none;
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 220px 280px 1fr;
  }
  
  .layout.masonry-mode {
    grid-template-columns: 220px 1fr;
  }
  
  .layout.masonry-editing {
    grid-template-columns: 220px 1fr;
  }
  
  .note-list.masonry {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
  }
}

@media (max-width: 1024px) {
  /* Tablet: Show sidebar + list OR full-screen editor */
  .layout {
    grid-template-columns: 200px 1fr;
  }
  
  .layout.masonry-mode {
    grid-template-columns: 200px 1fr;
  }
  
  .layout.responsive-tablet {
    grid-template-columns: 200px 1fr;
  }
  
  /* When editor is shown on tablet, make it full width */
  .layout.responsive-tablet:not(.masonry-editing) .editor:not(.panel-hidden) {
    grid-column: 1 / -1;
  }

  .list {
    border-right: none;
  }

  .editor {
    border-left: 1px solid var(--border);
  }
  
  .note-list.masonry {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

@media (max-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
  }

  .search {
    order: 3;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-filters {
    width: 100%;
    gap: 8px;
  }
  
  .filter-select {
    flex: 1;
  }
  
  .brand {
    order: 1;
  }
  
  .actions {
    order: 2;
    flex-wrap: wrap;
    gap: 6px;
    margin-left: auto;
  }

  .actions button,
  .actions select {
    font-size: 0.8rem;
    padding: 6px 10px;
  }

  .layout {
    grid-template-columns: 180px 1fr;
  }

  .sidebar {
    padding: 12px 8px;
  }
  
  .note-list.masonry {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
  }
  
  .inline-metadata {
    flex-wrap: wrap;
  }
  
  .inline-metadata input[type="text"] {
    width: 100px;
  }
  
  .inline-metadata input[type="text"]:focus {
    width: 130px;
  }
}

@media (max-width: 640px) {
  /* Phone: Show one panel at a time */
  .layout {
    grid-template-columns: 1fr;
  }
  
  .editor-toolbar {
    flex-wrap: wrap;
  }
  
  .editor-toolbar-left {
    order: 2;
    width: 100%;
    margin-top: 8px;
  }
  
  .editor-toolbar-right {
    order: 1;
    width: 100%;
    justify-content: space-between;
  }
  
  .inline-metadata {
    order: 1;
    flex: 1;
  }
  
  .inline-metadata input[type="text"] {
    width: 80px;
    font-size: 0.75rem;
  }
  
  .inline-metadata input[type="text"]:focus {
    width: 100px;
  }
  
  .layout.responsive-phone {
    grid-template-columns: 1fr;
  }
  
  .layout.responsive-phone .sidebar,
  .layout.responsive-phone .list,
  .layout.responsive-phone .editor {
    grid-column: 1;
    border: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
  }

  .sidebar,
  .list {
    border-right: none;
  }

  .editor {
    grid-column: 1;
    border-left: none;
  }

  .topbar .brand {
    font-size: 1rem;
  }
  
  .note-list.masonry {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  
  .editor-surface {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .note-list.masonry {
    grid-template-columns: 1fr;
  }
  
  .note-card {
    padding: 12px;
  }
}

/* Welcome Dialog */
.welcome-dialog {
  border: none;
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: 600px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-lg);
}

.welcome-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.welcome-content {
  padding: 40px;
  text-align: center;
}

.welcome-content h1 {
  margin: 0 0 12px 0;
  font-size: 2rem;
  font-weight: 600;
}

.welcome-content > p {
  margin: 0 0 32px 0;
  color: var(--text-secondary);
  font-size: 1.1rem;
}

.storage-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.storage-option {
  background: var(--panel-light);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.storage-option:hover {
  border-color: var(--primary);
  background: var(--bg);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.storage-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.storage-name {
  font-weight: 600;
  font-size: 1.1rem;
}

.storage-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.welcome-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  text-align: center;
  min-height: 300px;
}

.welcome-loading h2 {
  margin: 24px 0 12px 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.welcome-loading p {
  margin: 0 0 24px 0;
  color: var(--text-secondary);
  font-size: 1rem;
}

.progress-info {
  min-height: 24px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.welcome-footer-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
}

.welcome-footer-buttons button {
  flex: 0 1 auto;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
  .welcome-content {
    padding: 24px;
  }
  
  .welcome-content h1 {
    font-size: 1.5rem;
  }
  
  .storage-options {
    grid-template-columns: 1fr;
  }
}
