/* ─────────────────────────────────────────
   Design tokens
   ───────────────────────────────────────── */
:root {
  --sidebar-width: 220px;
  --list-width: 280px;

  --sidebar-bg: #2b3a4a;
  --sidebar-text: #c9d4df;
  --sidebar-active-bg: #1a2733;
  --sidebar-active-text: #ffffff;
  --sidebar-hover-bg: #354657;
  --sidebar-border: #1e2d3a;
  --sidebar-accent: #4a9eda;

  --list-bg: #f4f4f4;
  --list-border: #e0e0e0;
  --list-item-hover: #eaeaea;
  --list-item-active-bg: #dceeff;
  --list-item-active-border: #4a9eda;

  --editor-bg: #ffffff;
  --editor-text: #1a1a1a;
  --title-color: #111111;
  --meta-text: #888888;

  --tag-bg: #e3f0fb;
  --tag-text: #2574a9;
  --tag-border: #b3d4ee;

  --status-ok: #888;
  --status-saving: #e8a020;

  --radius: 4px;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-editor: Georgia, 'Times New Roman', serif;
}

/* ─────────────────────────────────────────
   Reset & base
   ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--editor-text);
  overflow: hidden;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
}

input[type="text"],
input[type="search"] {
  font: inherit;
  border: none;
  outline: none;
  background: transparent;
}

ul { list-style: none; }

/* ─────────────────────────────────────────
   App shell — 3-column flex layout
   ───────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─────────────────────────────────────────
   Resize handles
   ───────────────────────────────────────── */
.resize-handle {
  width: 4px;
  flex-shrink: 0;
  cursor: col-resize;
  background: transparent;
  position: relative;
  z-index: 10;
}

/* Thin visible separator line */
.resize-handle::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 1.5px;
  width: 1px;
  background: var(--sidebar-border);
  transition: left 0.1s, width 0.1s, background 0.1s;
}

.resize-handle:hover::after,
.resize-handle.dragging::after {
  left: 0;
  width: 4px;
  background: var(--sidebar-accent);
}

/* ─────────────────────────────────────────
   Sidebar
   ───────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  /* border-right handled by resize handle */
}

#sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 12px 12px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

#app-title {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.3px;
}

#sidebar-header-actions {
  display: flex;
  gap: 6px;
}

#btn-new-note,
#btn-sidebar-new-task {
  flex: 1;
  background: var(--sidebar-accent);
  color: #fff;
  border-radius: var(--radius);
  padding: 5px 0;
  font-size: 12px;
  font-weight: 600;
  transition: opacity 0.15s;
}
#btn-new-note:hover { opacity: 0.85; }

/* Notebook list */
#notebook-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

#notebook-list ul { padding: 0; }

.notebook-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
  position: relative;
}
.notebook-item:hover { background: var(--sidebar-hover-bg); }
.notebook-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.notebook-icon { font-size: 14px; flex-shrink: 0; }

.notebook-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

.notebook-actions {
  display: none;
  gap: 2px;
}
.notebook-item:hover .notebook-actions { display: flex; }

.notebook-actions button {
  font-size: 11px;
  padding: 2px 4px;
  border-radius: var(--radius);
  opacity: 0.7;
  transition: opacity 0.1s;
  color: var(--sidebar-text);
}
.notebook-actions button:hover { opacity: 1; background: rgba(255,255,255,0.1); }

#sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#btn-new-notebook {
  color: var(--sidebar-text);
  font-size: 12px;
  padding: 6px 0;
  text-align: left;
  opacity: 0.75;
  transition: opacity 0.15s;
}
#btn-new-notebook:hover { opacity: 1; }

#sidebar-footer-icons {
  display: flex;
  gap: 2px;
}

#btn-theme,
#btn-settings {
  font-size: 15px;
  color: var(--sidebar-text);
  opacity: 0.55;
  padding: 4px 7px;
  border-radius: var(--radius);
  transition: opacity 0.15s;
  line-height: 1;
}
#btn-theme:hover,
#btn-settings:hover { opacity: 1; background: rgba(255,255,255,0.1); }

/* ─────────────────────────────────────────
   Note list panel
   ───────────────────────────────────────── */
#note-list-panel {
  width: var(--list-width);
  flex-shrink: 0;
  background: var(--list-bg);
  /* border-right handled by resize handle */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#note-list-header {
  flex-shrink: 0;
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--list-border);
}

#note-list-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

#note-list-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--meta-text);
}

#sort-select {
  font-size: 11px;
  color: var(--meta-text);
  border: 1px solid #d8d8d8;
  border-radius: var(--radius);
  background: #fff;
  padding: 2px 4px;
  cursor: pointer;
}
#sort-select:focus { outline: none; border-color: var(--sidebar-accent); }

#search-input {
  width: 100%;
  background: #fff;
  border: 1px solid #d0d0d0;
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  color: var(--editor-text);
}
#search-input:focus { border-color: var(--sidebar-accent); }

#note-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.note-item {
  padding: 10px 12px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.note-item:hover { background: var(--list-item-hover); }
.note-item.active {
  background: var(--list-item-active-bg);
  border-left-color: var(--list-item-active-border);
}

.note-item-title-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 3px;
  min-width: 0;
}

.note-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--title-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.note-task-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.note-task-dot.now        { background: #e53935; }
.note-task-dot.next       { background: #f57c00; }
.note-task-dot.soon       { background: #1976d2; }
.note-task-dot.eventually { background: #9e9e9e; }

.note-item-preview {
  font-size: 12px;
  color: var(--meta-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.note-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.note-item-date {
  font-size: 11px;
  color: #aaa;
}

.btn-delete-note {
  font-size: 12px;
  opacity: 0;
  padding: 2px 4px;
  border-radius: var(--radius);
  transition: opacity 0.1s;
  color: #999;
}
.note-item:hover .btn-delete-note { opacity: 1; }
.btn-delete-note:hover { color: #c0392b; }

.note-list-empty {
  padding: 24px 12px;
  text-align: center;
  color: #bbb;
  font-size: 13px;
}

/* ─────────────────────────────────────────
   Editor panel
   ───────────────────────────────────────── */
#editor-panel {
  flex: 1;
  min-width: 0;
  background: var(--editor-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#editor-meta {
  flex-shrink: 0;
  padding: 20px 32px 12px;
  border-bottom: 1px solid #ebebeb;
}

#note-title {
  display: block;
  width: 100%;
  font-size: 22px;
  font-weight: 700;
  color: var(--title-color);
  margin-bottom: 10px;
  line-height: 1.2;
}
#note-title::placeholder { color: #ccc; }

/* Notebook selector + action buttons row */
#editor-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}

#note-notebook {
  font-size: 12px;
  color: var(--meta-text);
  border: 1px solid #e0e0e0;
  border-radius: var(--radius);
  background: #fafafa;
  padding: 3px 6px;
  max-width: 180px;
  cursor: pointer;
}
#note-notebook:focus { outline: none; border-color: var(--sidebar-accent); }

#editor-action-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#editor-action-buttons button {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius);
  border: 1px solid #d8d8d8;
  background: #fafafa;
  color: #555;
  transition: background 0.1s, border-color 0.1s;
}
#editor-action-buttons button:hover:not(:disabled) {
  background: #eef4fb;
  border-color: var(--sidebar-accent);
  color: var(--sidebar-accent);
}

.action-sep {
  width: 1px;
  height: 16px;
  background: #e0e0e0;
  margin: 0 2px;
}

/* AI buttons — dimmed when no API key */
.btn-ai { color: #7a6fb0 !important; border-color: #c5bfe8 !important; }
.btn-ai:hover:not(:disabled) {
  background: #f0eefb !important;
  border-color: #7a6fb0 !important;
  color: #5a4fa0 !important;
}
.btn-ai:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Tags */
#tag-area {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
}

#tags-display {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid var(--tag-border);
  border-radius: 12px;
  padding: 2px 8px 2px 10px;
  font-size: 11px;
  font-weight: 500;
}

.tag-remove {
  font-size: 14px;
  line-height: 1;
  color: var(--tag-text);
  opacity: 0.6;
  padding: 0;
}
.tag-remove:hover { opacity: 1; }

#tag-input {
  font-size: 12px;
  color: var(--meta-text);
  min-width: 100px;
}
#tag-input::placeholder { color: #ccc; }

/* Quill toolbar — override defaults to fit our layout */
.ql-toolbar.ql-snow {
  flex-shrink: 0;
  border: none;
  border-bottom: 1px solid #ebebeb;
  padding: 6px 28px;
}

/* Quill container — flex: 1 so it fills remaining height */
#editor-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#editor-container.ql-container {
  border: none;
  font-family: var(--font-editor);
  font-size: 15px;
  line-height: 1.7;
}

.ql-editor {
  flex: 1;
  overflow-y: auto;
  padding: 20px 32px 40px;
  height: 100%;
}

.ql-editor.ql-blank::before {
  color: #ccc;
  font-style: normal;
  left: 32px;
}

/* Empty state — shown when no note is selected */
#editor-empty {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 16px;
  color: #bbb;
}

#editor-empty p {
  font-size: 15px;
}

#btn-empty-new-note {
  padding: 9px 20px;
  background: var(--sidebar-accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s;
}
#btn-empty-new-note:hover { opacity: 0.85; }

/* When panel has .empty class: show placeholder, hide editor chrome */
#editor-panel.empty #editor-empty          { display: flex; }
#editor-panel.empty #editor-meta           { display: none; }
#editor-panel.empty .ql-toolbar            { display: none; }
#editor-panel.empty #editor-container      { display: none; }
#editor-panel.empty #editor-status         { display: none; }
#editor-panel.empty #editor-meta-row       { display: none; }

/* Images inside the editor */
.ql-editor img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  display: block;
  margin: 8px 0;
  cursor: default;
}

/* Selected image — blue outline (the resizer overlay sits on top) */
.ql-editor img.image-selected { outline: 2px solid var(--sidebar-accent); }

/* Resize overlay — positioned fixed over the selected image */
#image-resizer {
  display: none;
  position: fixed;
  border: 2px solid var(--sidebar-accent);
  pointer-events: none; /* clicks pass through except on the handles */
  z-index: 500;
  box-sizing: border-box;
}

/* Corner handles */
.img-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid var(--sidebar-accent);
  border-radius: 2px;
  pointer-events: all;
  z-index: 501;
}
.img-handle.nw { top: -5px;    left: -5px;   cursor: nw-resize; }
.img-handle.ne { top: -5px;    right: -5px;  cursor: ne-resize; }
.img-handle.se { bottom: -5px; right: -5px;  cursor: se-resize; }
.img-handle.sw { bottom: -5px; left: -5px;   cursor: sw-resize; }

/* Highlight the editor while dragging an image over it */
.ql-editor.drag-over {
  outline: 2px dashed var(--sidebar-accent);
  outline-offset: -4px;
  background: rgba(74, 158, 218, 0.05);
}

/* Status bar */
#editor-status {
  flex-shrink: 0;
  padding: 4px 32px;
  font-size: 11px;
  color: var(--status-ok);
  border-top: 1px solid #f0f0f0;
  height: 26px;
}

#editor-status.saving { color: var(--status-saving); }

/* ─────────────────────────────────────────
   Modal
   ───────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#modal-overlay.hidden { display: none; }

#modal {
  background: #fff;
  border-radius: 8px;
  padding: 24px 28px;
  min-width: 320px;
  max-width: 460px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

#modal-message {
  font-size: 14px;
  margin-bottom: 14px;
  color: var(--editor-text);
  line-height: 1.4;
}

#modal-body {
  font-size: 14px;
  color: var(--editor-text);
  line-height: 1.6;
  margin-bottom: 16px;
  white-space: pre-wrap;
}

#modal-input {
  display: block;
  width: 100%;
  border: 1px solid #d0d0d0;
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 14px;
  color: var(--editor-text);
  background: #fff;
  margin-bottom: 16px;
}
#modal-input:focus { border-color: var(--sidebar-accent); outline: none; }

#modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#modal-cancel {
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  color: #555;
  background: #f0f0f0;
  transition: background 0.1s;
}
#modal-cancel:hover { background: #e0e0e0; }

#modal-confirm {
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--sidebar-accent);
  transition: opacity 0.15s;
}
#modal-confirm:hover { opacity: 0.85; }

/* ─────────────────────────────────────────
   Settings modal
   ───────────────────────────────────────── */
#settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}
#settings-overlay.hidden { display: none; }

#settings-modal {
  background: #fff;
  border-radius: 8px;
  width: 440px;
  max-width: 92vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  overflow: hidden;
}

#settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 14px;
  border-bottom: 1px solid #eee;
}
#settings-header h2 { font-size: 16px; color: var(--title-color); }

#settings-close-x {
  font-size: 20px;
  color: #aaa;
  line-height: 1;
  padding: 0 4px;
  transition: color 0.1s;
}
#settings-close-x:hover { color: #444; }

.settings-section {
  padding: 20px 24px;
}
.settings-section h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--meta-text);
  margin-bottom: 8px;
}
.settings-section p {
  font-size: 13px;
  color: #666;
  line-height: 1.5;
  margin-bottom: 14px;
}
.settings-section label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #444;
  margin-bottom: 6px;
}

.settings-key-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.settings-key-row input {
  flex: 1;
  border: 1px solid #d0d0d0;
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  font-family: monospace;
  color: var(--editor-text);
  background: #fff;
  display: block;
}
.settings-key-row input:focus { border-color: var(--sidebar-accent); outline: none; }

#settings-key-toggle {
  padding: 0 10px;
  border: 1px solid #d0d0d0;
  border-radius: var(--radius);
  background: #fafafa;
  font-size: 16px;
  color: #888;
  transition: background 0.1s;
}
#settings-key-toggle:hover { background: #eee; }

.settings-hint {
  font-size: 11px !important;
  color: #aaa !important;
  margin-bottom: 0 !important;
}
#settings-key-status { min-height: 16px; }

.settings-section-border {
  border-top: 1px solid #eee;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.settings-row label {
  display: inline;
  margin-bottom: 0;
  font-size: 12px;
  font-weight: 600;
  color: #444;
}
.settings-row select {
  font-size: 12px;
  border: 1px solid #d0d0d0;
  border-radius: var(--radius);
  padding: 4px 8px;
  background: #fff;
  color: var(--editor-text);
  cursor: pointer;
}
.settings-row select:focus { outline: none; border-color: var(--sidebar-accent); }

[data-theme="dark"] .settings-row label  { color: #9aaabb; }
[data-theme="dark"] .settings-row select {
  background: #253040;
  border-color: #2e3d4e;
  color: var(--editor-text);
}

#backup-list {
  margin-bottom: 10px;
  border: 1px solid #eee;
  border-radius: var(--radius);
  overflow: hidden;
}
#backup-list:empty { display: none; }

.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid #f5f5f5;
  gap: 8px;
}
.backup-item:last-child { border-bottom: none; }

.backup-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.backup-item-date {
  font-size: 12px;
  font-weight: 600;
  color: var(--editor-text);
}
.backup-item-counts {
  font-size: 11px;
  color: var(--meta-text);
}
.backup-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.btn-backup-dl,
.btn-backup-restore {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius);
  border: 1px solid #d8d8d8;
  background: #fafafa;
  color: #555;
  transition: background 0.1s, border-color 0.1s;
}
.btn-backup-dl:hover,
.btn-backup-restore:hover {
  background: #eef4fb;
  border-color: var(--sidebar-accent);
  color: var(--sidebar-accent);
}
.backup-list-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: #aaa;
}

[data-theme="dark"] #backup-list          { border-color: #2e3d4e; }
[data-theme="dark"] .backup-item          { border-bottom-color: #2a3540; }
[data-theme="dark"] .backup-item-date     { color: var(--editor-text); }
[data-theme="dark"] .btn-backup-dl,
[data-theme="dark"] .btn-backup-restore   { background: #253040; border-color: #2e3d4e; color: #8a9ab0; }
[data-theme="dark"] .btn-backup-dl:hover,
[data-theme="dark"] .btn-backup-restore:hover {
  background: #1e3a55;
  border-color: var(--sidebar-accent);
  color: var(--sidebar-accent);
}
[data-theme="dark"] .backup-list-empty    { color: #3a4d5e; }

#settings-backup-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

#settings-backup-row button {
  flex: 1;
  padding: 7px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #d8d8d8;
  background: #fafafa;
  color: #555;
  transition: background 0.1s, border-color 0.1s;
}
#settings-backup-row button:hover {
  background: #eef4fb;
  border-color: var(--sidebar-accent);
  color: var(--sidebar-accent);
}

[data-theme="dark"] .settings-section-border { border-top-color: #2a3540; }
[data-theme="dark"] #settings-backup-row button {
  background: #253040;
  border-color: #2e3d4e;
  color: #8a9ab0;
}
[data-theme="dark"] #settings-backup-row button:hover {
  background: #1e3a55;
  border-color: var(--sidebar-accent);
  color: var(--sidebar-accent);
}

#settings-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 24px;
  border-top: 1px solid #eee;
  background: #fafafa;
}

#settings-cancel {
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  color: #555;
  background: #f0f0f0;
  transition: background 0.1s;
}
#settings-cancel:hover { background: #e0e0e0; }

#settings-save {
  padding: 7px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--sidebar-accent);
  transition: opacity 0.15s;
}
#settings-save:hover { opacity: 0.85; }

/* ─────────────────────────────────────────
   Dark mode
   All color overrides live here — toggled by
   setting data-theme="dark" on <html>.
   ───────────────────────────────────────── */

[data-theme="dark"] {
  --list-bg:                #1e2731;
  --list-border:            #28333f;
  --list-item-hover:        #242f3c;
  --list-item-active-bg:    #18304a;
  --list-item-active-border:#5aaae8;

  --editor-bg:    #1c2530;
  --editor-text:  #cdd3da;
  --title-color:  #dde2e8;
  --meta-text:    #6d7d8e;

  --tag-bg:     #1a2f44;
  --tag-text:   #6aabe0;
  --tag-border: #284560;

  --status-ok: #5a6a7a;
}

[data-theme="dark"] body { background: #1c2530; }

/* Sidebar — slightly deeper shade to separate from note list */
[data-theme="dark"] #sidebar {
  background: #1a2530;
  border-color: #111d27;
}
[data-theme="dark"] .notebook-item:hover        { background: #22303d; }
[data-theme="dark"] .notebook-item.active        { background: #111d28; }
[data-theme="dark"] #sidebar-header,
[data-theme="dark"] #sidebar-footer             { border-color: #111d27; }

/* Resize handles */
[data-theme="dark"] .resize-handle::after { background: #111d27; }

/* Note list header controls */
[data-theme="dark"] #search-input {
  background: #253040;
  border-color: #2e3d4e;
  color: var(--editor-text);
}
[data-theme="dark"] #sort-select {
  background: #253040;
  border-color: #2e3d4e;
  color: var(--editor-text);
}
[data-theme="dark"] .note-list-empty { color: #3a4d5e; }

/* Editor meta area */
[data-theme="dark"] #editor-meta        { border-color: #2a3540; }
[data-theme="dark"] #note-title         { color: var(--title-color); }
[data-theme="dark"] #note-title::placeholder { color: #3a4d5e; }
[data-theme="dark"] #note-notebook {
  background: #253040;
  border-color: #2e3d4e;
  color: var(--editor-text);
}
[data-theme="dark"] #editor-action-buttons button {
  background: #253040;
  border-color: #2e3d4e;
  color: #8a9ab0;
}
[data-theme="dark"] #editor-action-buttons button:hover:not(:disabled) {
  background: #1e3a55;
  border-color: var(--sidebar-accent);
  color: var(--sidebar-accent);
}
[data-theme="dark"] .action-sep { background: #2e3d4e; }

/* AI buttons */
[data-theme="dark"] .btn-ai              { color: #9e94d0 !important; border-color: #4a4478 !important; }
[data-theme="dark"] .btn-ai:hover:not(:disabled) {
  background: #252040 !important;
  border-color: #9e94d0 !important;
  color: #c0b8e8 !important;
}

/* Tag input placeholder */
[data-theme="dark"] #tag-input { color: var(--meta-text); }

/* Editor empty state */
[data-theme="dark"] #editor-empty { color: #3a4d5e; }

/* Quill toolbar */
[data-theme="dark"] .ql-toolbar.ql-snow {
  background: #1c2530;
  border-bottom-color: #2a3540;
}
[data-theme="dark"] .ql-toolbar.ql-snow .ql-stroke                    { stroke: #7a8a9a; }
[data-theme="dark"] .ql-toolbar.ql-snow .ql-fill                      { fill:   #7a8a9a; }
[data-theme="dark"] .ql-toolbar.ql-snow button:hover .ql-stroke,
[data-theme="dark"] .ql-toolbar.ql-snow .ql-active .ql-stroke         { stroke: #c8d4e0; }
[data-theme="dark"] .ql-toolbar.ql-snow button:hover .ql-fill,
[data-theme="dark"] .ql-toolbar.ql-snow .ql-active .ql-fill           { fill:   #c8d4e0; }
[data-theme="dark"] .ql-toolbar.ql-snow .ql-picker-label              { color:  #7a8a9a; }
[data-theme="dark"] .ql-toolbar.ql-snow .ql-picker-label:hover        { color:  #c8d4e0; }
[data-theme="dark"] .ql-toolbar.ql-snow .ql-picker-options {
  background: #253040;
  border-color: #2e3d4e;
  color: var(--editor-text);
}
[data-theme="dark"] .ql-toolbar.ql-snow .ql-picker-item:hover { color: var(--sidebar-accent); }

/* Quill editor */
[data-theme="dark"] .ql-editor                  { color: var(--editor-text); background: var(--editor-bg); }
[data-theme="dark"] .ql-editor.ql-blank::before { color: #3a4d5e; }
[data-theme="dark"] .ql-editor blockquote        { border-left-color: #3a4d5e; color: #8a9ab0; }
[data-theme="dark"] .ql-editor code,
[data-theme="dark"] .ql-editor pre              { background: #253040; color: #c8d4e0; }

/* Status bar */
[data-theme="dark"] #editor-status { border-top-color: #252f3a; }

/* Prompt / confirm modal */
[data-theme="dark"] #modal              { background: #1e2731; }
[data-theme="dark"] #modal-message,
[data-theme="dark"] #modal-body        { color: var(--editor-text); }
[data-theme="dark"] #modal-input {
  background: #253040;
  border-color: #2e3d4e;
  color: var(--editor-text);
}
[data-theme="dark"] #modal-cancel      { background: #253040; color: #8a9ab0; }
[data-theme="dark"] #modal-cancel:hover { background: #2e3d4e; }

/* Settings modal */
[data-theme="dark"] #settings-modal    { background: #1e2731; }
[data-theme="dark"] #settings-header   { border-bottom-color: #2a3540; }
[data-theme="dark"] #settings-header h2 { color: var(--title-color); }
[data-theme="dark"] #settings-close-x  { color: #5a6a7a; }
[data-theme="dark"] #settings-close-x:hover { color: #cdd3da; }
[data-theme="dark"] .settings-section p  { color: #7a8a9a; }
[data-theme="dark"] .settings-section label { color: #9aaabb; }
[data-theme="dark"] .settings-key-row input {
  background: #253040;
  border-color: #2e3d4e;
  color: var(--editor-text);
}
[data-theme="dark"] #settings-key-toggle {
  background: #253040;
  border-color: #2e3d4e;
  color: #7a8a9a;
}
[data-theme="dark"] #settings-key-toggle:hover { background: #2e3d4e; }
[data-theme="dark"] #settings-footer   { background: #18222c; border-top-color: #2a3540; }
[data-theme="dark"] #settings-cancel   { background: #253040; color: #8a9ab0; }
[data-theme="dark"] #settings-cancel:hover { background: #2e3d4e; }

/* ─────────────────────────────────────────
   Mode switching — notes vs tasks
   ───────────────────────────────────────── */

/* Default (notes mode): notes content visible, tasks content hidden */
#notes-list-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
#tasks-list-view { display: none; }
#task-editor     { display: none; }

/* Tasks mode */
#app[data-mode="tasks"] #notes-list-view { display: none; }
#app[data-mode="tasks"] #tasks-list-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
#app[data-mode="tasks"] #task-editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* Hide note editor chrome in tasks mode */
#app[data-mode="tasks"] #editor-empty     { display: none !important; }
#app[data-mode="tasks"] #editor-meta      { display: none !important; }
#app[data-mode="tasks"] .ql-toolbar       { display: none !important; }
#app[data-mode="tasks"] #editor-container { display: none !important; }
#app[data-mode="tasks"] #editor-status    { display: none !important; }

/* ─────────────────────────────────────────
   Sidebar Tasks button
   ───────────────────────────────────────── */
#sidebar-tasks {
  flex-shrink: 0;
  border-top: 1px solid var(--sidebar-border);
  padding: 4px 0;
}

#btn-tasks-mode {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  color: var(--sidebar-text);
  font-size: 13px;
  text-align: left;
  transition: background 0.1s;
}
#btn-tasks-mode:hover  { background: var(--sidebar-hover-bg); }
#btn-tasks-mode.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

/* ─────────────────────────────────────────
   Tasks list panel
   ───────────────────────────────────────── */
#tasks-list-header {
  flex-shrink: 0;
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--list-border);
}

#tasks-list-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

#tasks-list-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--meta-text);
}

#task-filter-select {
  font-size: 11px;
  color: var(--meta-text);
  border: 1px solid #d8d8d8;
  border-radius: var(--radius);
  background: #fff;
  padding: 2px 4px;
  cursor: pointer;
}
#task-filter-select:focus { outline: none; border-color: var(--sidebar-accent); }

#btn-new-task {
  width: 100%;
  padding: 6px 10px;
  background: var(--sidebar-accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  transition: opacity 0.15s;
}
#btn-new-task:hover { opacity: 0.85; }

#tasks-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

/* Task groups */
.task-group { margin-bottom: 4px; }

.task-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 4px;
}

.task-group-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--meta-text);
  flex: 1;
}

.task-group-count {
  font-size: 11px;
  color: var(--meta-text);
  background: var(--list-border);
  border-radius: 8px;
  padding: 0 6px;
  min-width: 18px;
  text-align: center;
}

/* Priority dots */
.priority-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.priority-dot.now        { background: #e53935; }
.priority-dot.next       { background: #f57c00; }
.priority-dot.soon       { background: #1976d2; }
.priority-dot.eventually { background: #9e9e9e; }

.task-group-list { padding: 0; }

/* Task items */
.task-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.task-item:hover { background: var(--list-item-hover); }
.task-item.active {
  background: var(--list-item-active-bg);
  border-left-color: var(--list-item-active-border);
}
.task-item.completed .task-item-title {
  text-decoration: line-through;
  color: var(--meta-text);
}

.task-checkbox-label {
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.task-checkbox {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--sidebar-accent);
}

.task-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.task-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--title-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-item-body .due-badge {
  align-self: flex-start;
}

/* Due date badges */
.due-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 8px;
  flex-shrink: 0;
  white-space: nowrap;
}
.due-overdue  { background: #fde8e8; color: #c62828; }
.due-today    { background: #fff3e0; color: #e65100; }
.due-upcoming { background: #e3f2fd; color: #1565c0; }

.btn-delete-task {
  font-size: 12px;
  opacity: 0;
  padding: 2px 4px;
  border-radius: var(--radius);
  transition: opacity 0.1s;
  color: #999;
  flex-shrink: 0;
}
.task-item:hover .btn-delete-task { opacity: 1; }
.btn-delete-task:hover { color: #c0392b; }

.task-list-empty {
  padding: 24px 12px;
  text-align: center;
  color: #bbb;
  font-size: 13px;
}

/* ─────────────────────────────────────────
   Task editor
   ───────────────────────────────────────── */
#task-editor-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 16px;
  color: #bbb;
}
#task-editor-empty p { font-size: 15px; }

#btn-task-editor-new {
  padding: 9px 20px;
  background: var(--sidebar-accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s;
}
#btn-task-editor-new:hover { opacity: 0.85; }

#task-editor-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
#task-editor-form.hidden { display: none; }

#task-form-header {
  flex-shrink: 0;
  padding: 20px 32px 12px;
  border-bottom: 1px solid #ebebeb;
}

#task-title {
  display: block;
  width: 100%;
  font-size: 22px;
  font-weight: 700;
  color: var(--title-color);
  line-height: 1.2;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-ui);
}
#task-title::placeholder { color: #ccc; }

#task-form-fields {
  flex-shrink: 0;
  padding: 12px 32px;
  border-bottom: 1px solid #ebebeb;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-field-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.task-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--meta-text);
  width: 80px;
  flex-shrink: 0;
}

#task-priority,
#task-due-date {
  font-size: 13px;
  color: var(--editor-text);
  border: 1px solid #e0e0e0;
  border-radius: var(--radius);
  background: #fafafa;
  padding: 4px 8px;
  cursor: pointer;
  font-family: var(--font-ui);
}
#task-priority:focus,
#task-due-date:focus { outline: none; border-color: var(--sidebar-accent); }

#task-note-link-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

#task-note-link {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--editor-text);
  border: 1px solid #e0e0e0;
  border-radius: var(--radius);
  background: #fafafa;
  padding: 4px 8px;
  cursor: pointer;
  font-family: var(--font-ui);
}
#task-note-link:focus { outline: none; border-color: var(--sidebar-accent); }

#btn-go-to-note {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 14px;
  border: 1px solid #e0e0e0;
  border-radius: var(--radius);
  background: #fafafa;
  color: var(--sidebar-accent);
  transition: background 0.1s, border-color 0.1s;
}
#btn-go-to-note:hover:not(:disabled) {
  background: #eef4fb;
  border-color: var(--sidebar-accent);
}
#btn-go-to-note:disabled { opacity: 0.4; cursor: default; }

#task-tag-area {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-height: 24px;
}

#task-tags-display {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

#task-tag-input {
  font-size: 12px;
  font-family: var(--font-ui);
  color: var(--meta-text);
  min-width: 80px;
  border: none;
  outline: none;
  background: transparent;
}
#task-tag-input::placeholder { color: #ccc; }

#task-description-wrap {
  flex: 1;
  padding: 16px 32px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#task-description {
  flex: 1;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  font: 15px/1.7 var(--font-editor);
  color: var(--editor-text);
  overflow-y: auto;
}
#task-description::placeholder { color: #ccc; }

#task-editor-status {
  flex-shrink: 0;
  padding: 4px 32px;
  font-size: 11px;
  color: var(--status-ok);
  border-top: 1px solid #f0f0f0;
  height: 26px;
}

/* ─────────────────────────────────────────
   Linked tasks panel (in note view)
   ───────────────────────────────────────── */
#note-linked-tasks {
  flex-shrink: 0;
  border-top: 1px solid #ebebeb;
  max-height: 220px;
  display: flex;
  flex-direction: column;
}

#linked-tasks-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 32px;
  flex-shrink: 0;
}

#linked-tasks-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--meta-text);
}

#linked-tasks-count {
  background: var(--list-border);
  color: var(--meta-text);
  border-radius: 8px;
  padding: 0 5px;
  font-size: 10px;
  min-width: 16px;
  text-align: center;
}
#linked-tasks-count:empty { display: none; }

#btn-add-linked-task {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius);
  border: 1px solid #d8d8d8;
  background: #fafafa;
  color: #555;
  transition: background 0.1s, border-color 0.1s;
}
#btn-add-linked-task:hover {
  background: #eef4fb;
  border-color: var(--sidebar-accent);
  color: var(--sidebar-accent);
}

#linked-tasks-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 32px 8px;
  list-style: none;
}

.linked-task-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 0;
  border-bottom: 1px solid #f5f5f5;
}
.linked-task-item:last-child { border-bottom: none; }
.linked-task-item.completed .linked-task-title {
  text-decoration: line-through;
  color: var(--meta-text);
}

.linked-task-title {
  flex: 1;
  font-size: 13px;
  color: var(--editor-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-open-task {
  font-size: 13px;
  padding: 1px 6px;
  border-radius: var(--radius);
  border: 1px solid #e0e0e0;
  background: transparent;
  color: var(--sidebar-accent);
  opacity: 0;
  transition: opacity 0.1s;
  flex-shrink: 0;
}
.linked-task-item:hover .btn-open-task { opacity: 1; }
.btn-open-task:hover { background: #eef4fb; }

.linked-task-empty {
  padding: 6px 0;
  font-size: 12px;
  color: #bbb;
}

.linked-task-nodate {
  font-size: 10px;
  color: #ccc;
  flex-shrink: 0;
  white-space: nowrap;
}
[data-theme="dark"] .linked-task-nodate { color: #3a4d5e; }

/* Hide linked tasks panel in empty state and tasks mode */
#editor-panel.empty #note-linked-tasks    { display: none; }
#app[data-mode="tasks"] #note-linked-tasks { display: none; }

/* ─────────────────────────────────────────
   Dark mode — tasks
   ───────────────────────────────────────── */
[data-theme="dark"] #sidebar-tasks { border-top-color: #111d27; }
[data-theme="dark"] #btn-tasks-mode:hover  { background: #22303d; }
[data-theme="dark"] #btn-tasks-mode.active { background: #111d28; }

[data-theme="dark"] #tasks-list-header { border-bottom-color: #28333f; }
[data-theme="dark"] #task-filter-select {
  background: #253040;
  border-color: #2e3d4e;
  color: var(--editor-text);
}
[data-theme="dark"] .task-group-count { background: #2a3540; }

[data-theme="dark"] .due-overdue  { background: #3a1a1a; color: #ef9a9a; }
[data-theme="dark"] .due-today    { background: #3a2a10; color: #ffb74d; }
[data-theme="dark"] .due-upcoming { background: #0d2a40; color: #64b5f6; }
[data-theme="dark"] .task-list-empty { color: #3a4d5e; }

[data-theme="dark"] #task-editor-empty { color: #3a4d5e; }
[data-theme="dark"] #task-form-header  { border-bottom-color: #2a3540; }
[data-theme="dark"] #task-title        { color: var(--title-color); }
[data-theme="dark"] #task-title::placeholder { color: #3a4d5e; }
[data-theme="dark"] #task-form-fields  { border-bottom-color: #2a3540; }

[data-theme="dark"] #task-priority,
[data-theme="dark"] #task-due-date,
[data-theme="dark"] #task-note-link {
  background: #253040;
  border-color: #2e3d4e;
  color: var(--editor-text);
}
[data-theme="dark"] #btn-go-to-note {
  background: #253040;
  border-color: #2e3d4e;
  color: var(--sidebar-accent);
}
[data-theme="dark"] #btn-go-to-note:hover:not(:disabled) {
  background: #1e3a55;
  border-color: var(--sidebar-accent);
}
[data-theme="dark"] #task-tag-input { color: var(--meta-text); }
[data-theme="dark"] #task-description { color: var(--editor-text); }
[data-theme="dark"] #task-description::placeholder { color: #3a4d5e; }
[data-theme="dark"] #task-editor-status { border-top-color: #252f3a; }

/* Linked tasks panel */
[data-theme="dark"] #note-linked-tasks      { border-top-color: #2a3540; }
[data-theme="dark"] #linked-tasks-count     { background: #2a3540; }
[data-theme="dark"] #btn-add-linked-task {
  background: #253040;
  border-color: #2e3d4e;
  color: #8a9ab0;
}
[data-theme="dark"] #btn-add-linked-task:hover {
  background: #1e3a55;
  border-color: var(--sidebar-accent);
  color: var(--sidebar-accent);
}
[data-theme="dark"] .linked-task-item    { border-bottom-color: #252f3a; }
[data-theme="dark"] .linked-task-title   { color: var(--editor-text); }
[data-theme="dark"] .linked-task-empty   { color: #3a4d5e; }
[data-theme="dark"] .btn-open-task       { border-color: #2e3d4e; }
[data-theme="dark"] .btn-open-task:hover { background: #1e3a55; }

/* ─────────────────────────────────────────
   Scrollbar tweaks (WebKit / Edge)
   ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }