:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --sidebar-bg: #f0f2f5;
  --ink: #111318;
  --muted: #6b7280;
  --subtle: #9ca3af;
  --line: #e2e5ea;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-muted: #eff6ff;
  --hover: #e8eaed;
  --active: #dde1f0;
  --code-bg: #1e2128;
  --code-fg: #e8edf5;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 16px rgba(0,0,0,0.10), 0 1px 4px rgba(0,0,0,0.06);
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #111827;
  --sidebar-bg: #0b1220;
  --ink: #e5e7eb;
  --muted: #a1a8b5;
  --subtle: #7c8798;
  --line: #263244;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-muted: #172554;
  --hover: #1e293b;
  --active: #1d3157;
  --code-bg: #020617;
  --code-fg: #dbeafe;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.25);
  --shadow: 0 8px 28px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.25);
}

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  background: var(--bg);
  font-family: "Roboto", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* ── Layout ── */

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.sidebar-inner {
  overflow-y: auto;
  padding: 0 8px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.app-controls > .sidebar-inner {
  flex: 1;
  min-height: 0;
}

.content {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--surface);
}

.install-prompt {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 150;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 480px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.install-prompt strong {
  display: block;
  margin-bottom: 2px;
  font-size: 14px;
}

.install-prompt p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

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

/* ── Sidebar header ── */

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 12px;
  gap: 8px;
}

.brand-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}

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

.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.15s;
}

.icon-button.secondary {
  width: auto;
  padding: 0 9px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
}

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

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

.theme-toggle-button {
  height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
}

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

:root[data-theme="dark"] .folder-result,
:root[data-theme="dark"] .sidebar,
:root[data-theme="dark"] .brand,
:root[data-theme="dark"] .sidebar-tab,
:root[data-theme="dark"] .manage-folders-button,
:root[data-theme="dark"] .sort-btn,
:root[data-theme="dark"] .folder-combo-button,
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

:root[data-theme="dark"] .sidebar-tab.active,
:root[data-theme="dark"] .sort-btn.active,
:root[data-theme="dark"] .tree button.active {
  background: var(--active);
  color: var(--accent);
  border-color: var(--accent);
}

:root[data-theme="dark"] .folder-row,
:root[data-theme="dark"] .tree button,
:root[data-theme="dark"] .brand-title,
:root[data-theme="dark"] .note-list-meta,
:root[data-theme="dark"] .tree-note-date {
  color: var(--ink);
}

:root[data-theme="dark"] .panel-heading .btn-ghost {
  background: #3f3a1d;
  border-color: #8a7424;
  color: #fef3c7;
}

:root[data-theme="dark"] .form-status.working {
  background: #172554;
  border-color: #1d4ed8;
  color: #bfdbfe;
}

:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar {
  background: #182235;
  border-color: #334155;
}

:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar button,
:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar .ql-picker-label {
  color: #e5e7eb;
  border-radius: 5px;
}

:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar button:hover,
:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar button:focus,
:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar .ql-picker-label:hover {
  background: #334155;
  color: #ffffff;
}

:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar button.ql-active,
:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar .ql-picker-label.ql-active,
:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar .ql-picker-item.ql-selected {
  background: #1d4ed8;
  color: #ffffff;
}

:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar .ql-stroke {
  stroke: currentColor;
}

:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar .ql-fill {
  fill: currentColor;
}

:root[data-theme="dark"] .rich-editor-toolbar.ql-toolbar .ql-picker-options {
  background: #111827;
  border-color: #334155;
  color: #e5e7eb;
}

/* ── Search ── */

.search-wrap {
  padding: 0 4px 8px;
}

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

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--subtle);
  pointer-events: none;
  font-style: normal;
}

input[type="search"] {
  width: 100%;
  padding: 7px 10px 7px 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  outline: none;
  appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 91, 219, 0.12);
}

/* ── Search results ── */

.search-results {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 4px;
}

.result {
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}

.result:hover { background: var(--hover); }

.folder-result {
  background: #f8fafc;
}

.folder-result .result-title::before {
  content: 'Folder: ';
  color: var(--muted);
  font-weight: 500;
}

.result-title {
  display: block;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-folder {
  display: block;
  font-size: 11px;
  color: var(--subtle);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-excerpt {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ── Tree ── */

.section-label {
  padding: 6px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--subtle);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

.tree > ul {
  padding-left: 0;
}

.tree li { margin: 1px 0; }

.folder-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}

.folder-row:hover { background: var(--hover); }

.folder-name {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-action-button {
  opacity: 0;
  flex: 0 0 auto;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.folder-row:hover .folder-action-button,
.folder-action-button:focus {
  opacity: 1;
}

.folder-action-button:hover {
  background: var(--hover);
  color: var(--ink);
}

.folder-delete-button {
  border-color: #fecaca;
  background: #fff1f2;
  color: #991b1b;
}

.folder-delete-button:hover {
  background: #ffe4e6;
  border-color: #fca5a5;
  color: #7f1d1d;
}

.folder-chevron {
  font-size: 10px;
  transition: transform 0.15s;
  flex-shrink: 0;
}

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

.folder-children.collapsed { display: none; }

.tree button {
  display: flex;
  align-items: baseline;
  gap: 6px;
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  padding: 5px 8px;
  text-align: left;
  font-size: 13px;
  overflow: hidden;
  transition: background 0.1s;
}

.tree button.tree-note-with-date {
  display: grid;
  gap: 1px;
  align-items: start;
}

.tree button:hover { background: var(--hover); }
.tree button.active { background: var(--active); color: var(--accent); font-weight: 500; }

.tree .folder-action-button {
  display: inline-flex;
  width: auto;
  padding: 2px 6px;
  font-size: 11px;
}

.tree-note-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.tree-note-date {
  display: block;
  margin: 0;
  padding: 0;
  font-size: 11px;
  color: #475569;
  font-weight: 500;
  line-height: 1.25;
}

/* ── Auth screen ── */

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 48px 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-eyebrow {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--subtle);
}

.auth-title {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.auth-sub {
  margin: 0 0 28px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.auth-card #googleSignIn {
  display: flex;
  justify-content: center;
}

/* ── App controls ── */

.app-controls {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Content area ── */

.content-inner {
  flex: 1;
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
  padding: 48px 40px 80px;
}

body.editing-note .content-inner {
  max-width: none;
  padding-left: 56px;
  padding-right: 56px;
}

/* ── Empty state ── */

.empty-state {
  padding-top: 15vh;
}

.empty-state h2 {
  margin: 8px 0 12px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.empty-state p {
  color: var(--muted);
  font-size: 14px;
  max-width: 400px;
  line-height: 1.6;
}

.label-small {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--subtle);
  margin-bottom: 6px;
}

/* ── Note view ── */

.note-view {
  max-width: 100%;
  padding-top: 0;
  overflow-wrap: break-word;
  word-break: keep-all;
  hyphens: none;
}

.note-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  font-size: 12px;
  color: var(--subtle);
}

.note-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.note-breadcrumb span { color: var(--subtle); }
.note-breadcrumb .sep { color: var(--line); }

.note-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 10px;
}

.note-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--ink);
}

.edit-title-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 4px 0 8px;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.edit-title-input:focus {
  border-color: var(--accent);
  box-shadow: none;
  background: transparent;
}

.note-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding-top: 1px;
}

.btn-danger {
  color: #991b1b;
  border-color: #fecaca;
  background: #fff1f2;
}

.btn-danger:hover {
  color: #7f1d1d;
  border-color: #fca5a5;
  background: #ffe4e6;
}

.note-edit-button {
  padding: 9px 18px;
  box-shadow: 0 6px 14px rgba(59, 91, 219, 0.18);
}

.note-edit-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(59, 91, 219, 0.22);
}

.note-dates {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-bottom: 26px;
  font-size: 12px;
  color: var(--subtle);
}

.note-dates strong {
  color: var(--muted);
  font-weight: 500;
}

.link-button {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  padding: 0;
}

.link-button:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.date-edit-form {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 26px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.date-edit-form label {
  min-width: 210px;
  flex: 1 1 210px;
}

.date-edit-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.edit-note-form {
  margin-top: 4px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 8px;
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--surface);
}

.editor-toolbar button {
  min-width: 32px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.editor-toolbar button:hover {
  border-color: var(--line);
  background: var(--hover);
  color: var(--ink);
}

.edit-note-form textarea {
  min-height: 58vh;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.rich-editor {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  text-transform: none;
  letter-spacing: normal;
  color: var(--ink);
}

.rich-editor-toolbar.ql-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 0;
  border-color: var(--line);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--surface);
  font-family: "Roboto", Arial, sans-serif;
}

.rich-editor-toolbar.ql-toolbar .ql-formats {
  margin-right: 8px;
}

.rich-editor-toolbar .editor-text-button {
  width: auto !important;
  min-width: 48px;
  padding: 0 8px !important;
  color: var(--muted);
  font-family: "Roboto", Arial, sans-serif;
  font-size: 12px;
  font-weight: 500;
}

.rich-editor-toolbar .editor-text-button:hover {
  color: var(--ink);
}

.rich-editor .ql-container {
  max-width: 100%;
  border-color: var(--line);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--bg);
  font-family: "Roboto", Arial, sans-serif;
}

.rich-editor .ql-editor {
  font-family: "Roboto", Arial, sans-serif;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.65;
  color: var(--ink);
  min-height: 220px;
}

.edit-note-editor .ql-editor {
  min-height: 52vh;
}

body.editing-note .rich-editor-toolbar.ql-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border: 0;
  border-radius: 0;
  background: var(--surface);
}

body.editing-note .rich-editor-toolbar.ql-toolbar.ql-snow,
body.editing-note .edit-note-editor .ql-container.ql-snow {
  border-left: 0 !important;
  border-right: 0 !important;
  border-top: 0 !important;
  border-bottom: 0 !important;
}

body.editing-note .edit-note-editor .ql-container {
  border: 0;
  border-radius: 0;
  background: transparent;
}

body.editing-note .edit-note-editor .ql-editor {
  padding-left: 8px;
  padding-right: 8px;
}

.ai-command-row {
  display: flex;
  gap: 10px;
  flex: 0 1 460px;
  max-width: 460px;
  min-width: 260px;
}

.ai-command-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.ai-command-row button {
  flex: 0 0 auto;
}

.ai-run-button {
  flex: 0 0 50px;
  width: 50px;
  min-width: 50px;
  max-width: 50px;
  height: 50px;
  padding: 0;
  justify-content: center;
}

.ai-run-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

#runAiButton:disabled {
  opacity: 1;
  background: #1d4ed8;
  color: #ffffff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
  cursor: wait;
}

:root[data-theme="dark"] body.editing-note .rich-editor-toolbar.ql-toolbar {
  background: #182235;
}

.rich-editor .ql-editor p {
  margin: 0 0 10px;
}

.rich-editor .ql-editor .ql-soft-break {
  display: inline;
  margin: 0;
  line-height: inherit;
}

.rich-editor .ql-editor h1,
.rich-editor .ql-editor h2,
.rich-editor .ql-editor h3 {
  margin: 18px 0 10px;
}

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

.edit-action-toolbar {
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

.icon-action-button {
  width: 54px;
  min-width: 54px;
  height: 50px;
  padding: 0;
  justify-content: center;
}

.icon-action-button svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Markdown body ── */

.markdown-body {
  max-width: 100%;
  font-size: 15px;
  line-height: 1.75;
  color: var(--ink);
  overflow-wrap: break-word;
  word-break: keep-all;
  hyphens: none;
}

.markdown-body p,
.markdown-body li,
.markdown-body blockquote {
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: keep-all;
  hyphens: none;
  white-space: normal;
}

.markdown-body code,
.markdown-body pre,
.markdown-body a {
  overflow-wrap: anywhere;
}

.markdown-body h1 { font-size: 22px; font-weight: 700; margin: 32px 0 12px; letter-spacing: -0.02em; }
.markdown-body h2 { font-size: 18px; font-weight: 600; margin: 28px 0 10px; letter-spacing: -0.01em; }
.markdown-body h3 { font-size: 15px; font-weight: 600; margin: 22px 0 8px; }
.markdown-body h4, .markdown-body h5, .markdown-body h6 { font-size: 14px; font-weight: 600; margin: 18px 0 6px; }
.markdown-body h1 strong,
.markdown-body h2 strong,
.markdown-body h3 strong,
.markdown-body h4 strong,
.markdown-body h5 strong,
.markdown-body h6 strong { font-weight: inherit; }

.markdown-body p { margin: 0 0 14px; }
.markdown-body ul, .markdown-body ol { margin: 0 0 14px; padding-left: 22px; }
.markdown-body li { margin: 4px 0; }

.markdown-body blockquote {
  margin: 16px 0;
  padding: 10px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-muted);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--muted);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 24px 0;
}

.markdown-body table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 14px;
  margin-bottom: 16px;
}

.markdown-body th, .markdown-body td {
  padding: 8px 12px;
  border: 1px solid var(--line);
  text-align: left;
}

.markdown-body th {
  background: var(--bg);
  font-weight: 600;
}

.markdown-body tr:nth-child(even) td { background: var(--bg); }

.markdown-body code {
  font-family: "Roboto", Arial, sans-serif;
  font-size: 0.88em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
}

.markdown-body pre {
  overflow-x: auto;
  padding: 16px 20px;
  border-radius: var(--radius);
  background: var(--code-bg);
  border: 1px solid #2e333d;
  margin-bottom: 16px;
}

.markdown-body pre code {
  padding: 0;
  border: none;
  background: transparent;
  color: var(--code-fg);
  font-size: 13px;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.markdown-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}

/* ── New note modal ── */

.new-note {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 20px;
  background: rgba(17, 19, 24, 0.45);
  backdrop-filter: blur(2px);
  overflow-y: auto;
}

.panel-card {
  width: 100%;
  max-width: 820px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

form { display: grid; gap: 16px; }

form label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

form label.inline-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.inline-checkbox input[type="checkbox"] {
  width: auto;
  margin: 0;
}

input:not([type="search"]), select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:not([type="search"]):focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 91, 219, 0.12);
  background: var(--surface);
}

.folder-combo {
  position: relative;
}

.folder-combo-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  text-align: left;
}

.folder-combo-button:hover,
.folder-combo-button:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 91, 219, 0.12);
  background: var(--surface);
}

.folder-combo-chevron {
  color: var(--muted);
  font-size: 12px;
}

.folder-combo-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.14);
}

.folder-combo-menu input[type="search"] {
  padding: 8px 10px;
  background: var(--bg);
}

.folder-combo-options {
  max-height: 260px;
  overflow-y: auto;
  margin-top: 8px;
}

.folder-combo-option {
  display: block;
  width: 100%;
  padding: 8px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  text-align: left;
}

.folder-combo-option:hover,
.folder-combo-option.active {
  background: var(--hover);
}

.folder-combo-empty {
  padding: 10px 9px;
  color: var(--muted);
  font-size: 13px;
}

textarea {
  min-height: 240px;
  resize: vertical;
  font-family: "Roboto", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.6;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
}

.form-status {
  font-size: 13px;
  color: var(--muted);
}

#editNoteStatus:not(:empty) {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--hover);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.form-status.working {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
}

.form-status.working::before {
  content: '';
  width: 13px;
  height: 13px;
  border: 2px solid #93c5fd;
  border-top-color: #1d4ed8;
  border-radius: 999px;
  animation: spin 0.75s linear infinite;
}

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

.spellcheck-review {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.spellcheck-review strong {
  font-size: 13px;
}

.spellcheck-review ul {
  display: grid;
  gap: 6px;
  max-height: 180px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.spellcheck-review li {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.spellcheck-review li span {
  text-decoration: line-through;
}

.spellcheck-review li span::after {
  content: '→';
  display: inline-block;
  margin-left: 8px;
  text-decoration: none;
}

.spellcheck-review li strong {
  color: var(--ink);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

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

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

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.btn-ghost:hover { background: var(--hover); color: var(--ink); }

.panel-heading .btn-ghost {
  background: #fef9c3;
  color: var(--ink);
  border-color: #fde68a;
  box-shadow: var(--shadow-sm);
}

.panel-heading .btn-ghost:hover {
  background: #fef08a;
  color: var(--ink);
  border-color: #facc15;
}

/* ── Sidebar tabs ── */

.sidebar-tabs {
  display: flex;
  gap: 2px;
  padding: 4px 0 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.sidebar-tab {
  flex: 1;
  padding: 5px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  transition: background 0.1s, color 0.1s;
}

.sidebar-tab:hover { background: var(--hover); color: var(--ink); }
.sidebar-tab.active { background: var(--active); color: var(--accent); font-weight: 600; }

.folder-toolbar {
  display: block;
  margin: 0 0 8px;
}

.manage-folders-button {
  width: 100%;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}

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

.floating-collapse-button {
  position: fixed;
  left: 10px;
  bottom: 18px;
  z-index: 60;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow-sm);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.floating-collapse-button:hover {
  background: var(--hover);
  color: var(--ink);
}

.scroll-top-button {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 65;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  box-shadow: var(--shadow);
}

.scroll-top-button svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.manage-folder-details {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.manage-action-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.manage-action-tab {
  padding: 7px 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.manage-action-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.manage-action-panel {
  display: grid;
  gap: 8px;
}

.manage-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

/* ── Sort bar ── */

.sort-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px;
  align-items: center;
  gap: 6px;
  padding: 8px 2px 6px;
}

.sort-label {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  color: var(--subtle);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.sort-buttons {
  grid-column: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  flex: 1 1 0;
  min-width: 0;
}

.sort-btn {
  width: 100%;
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.sort-btn:hover { background: var(--hover); color: var(--ink); }
.sort-btn.active { background: var(--accent-muted); color: var(--accent); border-color: var(--accent); font-weight: 600; }

.sort-order-btn {
  grid-column: 2;
  width: 24px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
}

.sort-order-btn:hover { background: var(--hover); color: var(--ink); }

/* ── Note list ── */

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

.note-list-item {
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  padding: 7px 10px;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}

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

.note-list-title {
  display: block;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-list-meta {
  display: block;
  font-size: 11px;
  color: #475569;
  font-weight: 500;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Utilities ── */

.hidden { display: none !important; }

@media (max-width: 760px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  body {
    overflow-x: hidden;
    font-size: 16px;
  }

  .shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    min-height: 0;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
  }

  body:not(.has-note) .sidebar {
    min-height: 100vh;
  }

  body:not(.has-note) .sidebar-inner {
    max-height: calc(100vh - 132px);
  }

  .brand {
    position: sticky;
    top: 0;
    z-index: 8;
    padding: 12px;
    background: #f8fafc;
  }

  .brand-title {
    color: #0f172a;
  }

  .brand-title {
    font-size: 14px;
  }

  .icon-button {
    min-width: 36px;
    height: 36px;
  }

  .icon-button.secondary {
    padding: 0 10px;
  }

  .app-controls {
    min-height: 0;
  }

  .search-wrap {
    padding: 0 12px 10px;
  }

  input[type="search"],
  input:not([type="search"]),
  select,
  textarea {
    font-size: 16px;
  }

  .sidebar-inner {
    padding: 0 12px 14px;
  }

  .sidebar-tab {
    padding: 9px 10px;
    font-size: 15px;
    color: #334155;
    background: #ffffff;
    border: 1px solid #dbe3ef;
  }

  .sidebar-tab.active {
    background: #dbeafe;
    color: #1d4ed8;
    border-color: #93c5fd;
  }

  .manage-folders-button {
    padding: 10px 12px;
    font-size: 15px;
    background: #ffffff;
    color: #1e293b;
    border-color: #cbd5e1;
  }

  .sort-bar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .sort-label {
    width: 100%;
  }

  .sort-buttons {
    flex: 1 1 auto;
  }

  .sort-label {
    font-size: 12px;
    color: #64748b;
  }

  .sort-btn {
    padding: 8px 7px;
    font-size: 14px;
    color: #334155;
    background: #ffffff;
    border-color: #cbd5e1;
  }

  .sort-btn.active {
    background: #dbeafe;
    color: #1d4ed8;
    border-color: #3b82f6;
  }

  .sort-order-btn {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }

  .sort-btn,
  .sort-order-btn,
  .sidebar-tab,
  .tree button,
  .folder-row {
    min-height: 42px;
  }

  .folder-row {
    font-size: 16px;
    padding: 9px 10px;
    color: #334155;
  }

  .folder-chevron {
    font-size: 12px;
  }

  .tree button {
    font-size: 16px;
    padding: 10px 10px;
    color: #0f172a;
  }

  .tree button.active {
    background: #dbeafe;
    color: #1d4ed8;
  }

  .tree-note-date,
  .tree-note-date {
    font-size: 13px;
  }

  .note-list-title {
    font-size: 16px;
  }

  .note-list-meta {
    font-size: 13px;
  }

  .content {
    width: 100%;
    max-width: 100vw;
    min-height: 52vh;
    overflow-x: hidden;
    overflow-y: visible;
  }

  body:not(.has-note) .content {
    display: none;
  }

  .content-inner {
    width: 100%;
    max-width: none;
    padding: 24px 16px 96px;
  }

  .note-view,
  .markdown-body {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .empty-state {
    display: none;
  }

  .empty-state h2,
  .note-title {
    font-size: 24px;
  }

  .note-meta,
  .note-header,
  .note-dates,
  .form-actions,
  .edit-actions,
  .date-edit-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .note-actions {
    width: 100%;
    justify-content: stretch;
  }

  .note-actions .btn,
  .edit-actions .btn,
  .date-edit-actions .btn,
  .form-actions .btn {
    justify-content: center;
    width: 100%;
  }

  .edit-actions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .edit-actions .icon-action-button {
    width: 54px;
    min-width: 54px;
  }

  body.editing-note .content-inner {
    padding-left: 20px;
    padding-right: 20px;
  }

  .ai-command-row {
    flex: 1 1 100%;
    max-width: none;
    min-width: 0;
  }

  .ai-command-row input {
    flex: 1 1 auto;
    min-width: 180px;
  }

  .ai-command-row .ai-run-button {
    flex: 0 0 50px;
    width: 50px;
    min-width: 50px;
    max-width: 50px;
    justify-content: center;
  }

  .date-edit-form {
    align-items: stretch;
  }

  .date-edit-form label {
    min-width: 0;
  }

  .rich-editor-toolbar.ql-toolbar {
    position: sticky;
    top: 0;
    z-index: 7;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  }

  .rich-editor .ql-editor {
    min-height: 52vh;
    font-size: 16px;
  }

  .new-note {
    align-items: stretch;
    padding: 12px;
    overflow-y: auto;
  }

  .panel-card,
  .panel-card-sm {
    max-width: none;
    padding: 18px;
    border-radius: var(--radius-lg);
  }

  .panel-heading {
    align-items: stretch;
    gap: 12px;
    flex-direction: column;
  }

  .install-prompt {
    left: 12px;
    right: 12px;
    bottom: 12px;
    align-items: stretch;
    flex-direction: column;
  }

  .install-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .install-actions .btn {
    justify-content: center;
  }
}

@media (max-width: 420px) {
  .brand {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-actions {
    justify-content: space-between;
  }

  .brand-actions .icon-button.secondary {
    flex: 1;
  }
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 6px 10px;
}

/* ── Scrollbar ── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--subtle); }

body.editing-note #editNoteContent + .rich-editor-toolbar.ql-toolbar,
body.editing-note #editNoteContent + .rich-editor-toolbar.ql-toolbar + .edit-note-editor,
body.editing-note #editNoteContent + .rich-editor-toolbar.ql-toolbar + .edit-note-editor .ql-container,
body.editing-note #editNoteContent + .rich-editor-toolbar.ql-toolbar + .edit-note-editor .ql-editor {
  border: 0 !important;
  outline: 0 !important;
  box-shadow: none !important;
}

body.editing-note #editNoteContent + .rich-editor-toolbar.ql-toolbar + .edit-note-editor,
body.editing-note #editNoteContent + .rich-editor-toolbar.ql-toolbar + .edit-note-editor .ql-container,
body.editing-note #editNoteContent + .rich-editor-toolbar.ql-toolbar + .edit-note-editor .ql-editor {
  background: transparent !important;
}
