/* ================================================================
   Notes — style.css
   Tokens → base → layout → components → utilities → responsive
   ================================================================ */

/* ── Fonts ──────────────────────────────────────────────────────── */

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

@font-face {
  font-family: 'Inter';
  src: url('fonts/InterVariable-Italic.woff2') format('woff2');
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/JetBrainsMono.ttf') format('ttf');
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/JetBrainsMonoItalic.ttf') format('ttf');
  font-weight: 100 800;
  font-style: italic;
  font-display: swap;
}

/* ── Reset ──────────────────────────────────────────────────────── */

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

[hidden] { display: none !important; }

/* ── Design tokens ──────────────────────────────────────────────── */

:root {

  /* Surfaces */
  --surface:        #ffffff;
  --surface-raised: #f7f7f5;
  --surface-subtle: #fafaf9;
  --surface-hover:  #ebebea;
  --surface-active: #fafaf9;

  /* Borders */
  --border: #e3e3e0;

  /* Text */
  --text:       #191918;
  --text-muted: #8f8e8a;
  --text-faint: #b8b6b0;

  /* Accent */
  --accent:        #54ab76;
  --accent-hover:  #3e8259;
  --accent-subtle: #eff6ff;

  /* Semantic */
  --danger:         #dc2626;
  --danger-hover:   #b91c1c;
  --danger-subtle:  #fef2f2;
  --success:        #16a34a;

  /* Typography */
  --font-sans:   -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono:   'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  /* Overridden by [data-font] attribute */
  --font-ui:     var(--font-sans);
  --font-editor: var(--font-sans);

  /* Type scale */
  --text-2xs:  .6875rem;  /* 11px — labels, badges       */
  --text-xs:   .75rem;    /* 12px — meta, status          */
  --text-sm:   .8125rem;  /* 13px — secondary UI          */
  --text-base: .875rem;   /* 14px — primary UI            */
  --text-md:   .9375rem;  /* 15px — editor, inputs        */
  --text-lg:   1rem;      /* 16px — titles, headings      */
  --text-xl:   1.125rem;  /* 18px                         */
  --text-2xl:  1.5rem;    /* 24px — page titles           */
  
  /* Type weight */
  --ft-weight-n: 400;
  --ft-weight-b: 600;

  /* Editor type — font-size overridden by JS via setProperty */
  --font-size-editor:   var(--text-md);
  --line-height-editor: 1.35;

  /* Spacing — 4 px grid */
  --sp-1:  .25rem;   /*  4px */
  --sp-2:  .5rem;    /*  8px */
  --sp-3:  .75rem;   /* 12px */
  --sp-4:  1rem;     /* 16px */
  --sp-5:  1.25rem;  /* 20px */
  --sp-6:  1.5rem;   /* 24px */
  --sp-8:  2rem;     /* 32px */
  --sp-10: 2.5rem;   /* 40px */

  /* Radii */
  --radius-sm: 4px;
  --radius:    6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;

  /* Shadows */
  --shadow-sm:      0 1px 4px rgba(0, 0, 0, .06);
  --shadow:         0 4px 24px rgba(0, 0, 0, .10), 0 1px 4px rgba(0, 0, 0, .06);
  --shadow-lg:      0 12px 48px rgba(0, 0, 0, .18);
  --shadow-card:    0 4px 32px rgba(0, 0, 0, .07);
  --shadow-sidebar: 6px 0 24px rgba(0, 0, 0, .20);

  /* Transitions — cubic-bezier(0.2,0,0,1) is a snappy but smooth "standard" curve */
  --t-fast:   .12s cubic-bezier(0.2, 0, 0, 1);
  --t:        .2s  cubic-bezier(0.2, 0, 0, 1);
  --t-slow:   .3s  cubic-bezier(0.2, 0, 0, 1);
  /* ease-out — for things entering the screen (dropdowns, modals) */
  --t-emerge: .18s cubic-bezier(0, 0, 0.2, 1);

  /* Z-index layers */
  --z-dropdown: 50;
  --z-overlay:  99;
  --z-sidebar:  100;
  --z-modal:    200;

  /* Layout */
  --sidebar-w: 210px;
  --panel-w:   270px;

  /* Focus ring */
  --focus-ring: 0 0 0 3px rgba(59, 130, 246, .15);
}

/* ── Dark theme ─────────────────────────────────────────────────── */

[data-theme="dark"] {
  --surface:        #1c1c1e;
  --surface-raised: #232325;
  --surface-subtle: #1c1c1e;
  --surface-hover:  #2c2c2e;
  --surface-active: #1d3050;
  --border:         #38383a;
  --text:           #ebebeb;
  --text-muted:     #8d8d93;
  --text-faint:     #636366;
  --accent:         #4f8ef7;
  --accent-hover:   #3b7ce8;
  --accent-subtle:  #1d3050;
  --danger-subtle:  #2d1515;
}

/* ── Font themes ────────────────────────────────────────────────── */

[data-font="inter"] {
  --font-ui:     'Inter', -apple-system, sans-serif;
  --font-editor: 'Inter', -apple-system, sans-serif;
}

[data-font="jetbrains"] {
  --font-ui:          'JetBrains Mono', monospace;
  --font-editor:      'JetBrains Mono', monospace;
  --font-size-editor: var(--text-base); /* mono is comfortable slightly smaller */
}

[data-font="jetbrains"] #note-content {
  line-height: 1.65;
  letter-spacing: 0;
}

/* ── Base ───────────────────────────────────────────────────────── */

html, body {
  height: 100%;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--surface);
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Reusable: icon button ──────────────────────────────────────── */

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}

.icon-btn:hover  { background: var(--surface-hover); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }

/* ── Reusable: text input / select ─────────────────────────────── */

.field {
  display: block;
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-family: var(--font-ui);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--t), box-shadow var(--t);
}

.field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

/* ── Reusable: primary button ───────────────────────────────────── */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-2) var(--sp-4);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-family: var(--font-ui);
  font-weight: var(--ft-weight-b);
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}

.btn-primary:hover  { background: var(--accent-hover); box-shadow: 0 2px 8px rgba(0,0,0,.15); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0) scale(0.97); box-shadow: none; }

/* ── Auth page ──────────────────────────────────────────────────── */

body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--surface-raised);
  overflow: auto;
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--sp-10) var(--sp-8);
  width: 360px;
  max-width: 95vw;
  box-shadow: var(--shadow-card);
}

.auth-box h1 {
  font-size: var(--text-2xl);
  font-weight: var(--ft-weight-b);
  letter-spacing: -.02em;
  margin-bottom: var(--sp-1);
}

.auth-box h2 {
  font-size: var(--text-base);
  font-weight: var(--ft-weight-n);
  color: var(--text-muted);
  margin-bottom: var(--sp-6);
}

.auth-error {
  font-size: var(--text-sm);
  color: var(--danger);
  background: var(--danger-subtle);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-4);
}

.auth-box label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--ft-weight-b);
  margin-bottom: var(--sp-4);
}

.auth-box label small {
  font-weight: var(--ft-weight-n);
  color: var(--text-muted);
}

.auth-box input[type="text"],
.auth-box input[type="password"] {
  display: block;
  width: 100%;
  margin-top: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-md);
  font-family: var(--font-ui);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--t), box-shadow var(--t);
}

.auth-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  font-weight: var(--ft-weight-n) !important;
  color: var(--text-muted) !important;
  margin-bottom: var(--sp-5) !important;
}

.checkbox-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--accent);
}

.auth-box button[type="submit"] {
  width: 100%;
  padding: var(--sp-2) var(--sp-4);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: var(--text-md);
  font-weight: var(--ft-weight-b);
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background var(--t-fast);
}

.auth-box button[type="submit"]:hover { background: var(--accent-hover); }

/* ── App shell ──────────────────────────────────────────────────── */

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────── */

.app-title {
  font-size: var(--text-lg);
  font-weight: var(--ft-weight-b);
  letter-spacing: -.02em;
}

/* ── Folders dropdown ───────────────────────────────────────── */

#folders-menu {
  left: 0;
  right: auto;
  min-width: 240px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.dropdown-panel-header {
  display: flex;
  align-items: center;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.dropdown-search {
  padding: var(--sp-2) var(--sp-3);
  flex-shrink: 0;
}

.dropdown-search input {
  width: 100%;
  padding: var(--sp-1) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-family: var(--font-ui);
  color: var(--text);
  transition: border-color var(--t), box-shadow var(--t);
}

.dropdown-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.folder-section {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-1) 0 var(--sp-2);
  min-height: 0;
}

.folder-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-1) var(--sp-3);
  margin-bottom: var(--sp-1);
  font-size: var(--text-2xs);
  font-weight: var(--ft-weight-b);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
}

.folder-section-header button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--text-lg);
  color: var(--text-muted);
  line-height: 1;
  border-radius: var(--radius);
  flex-shrink: 0;
  transition: background var(--t-fast), color var(--t-fast);
}

.folder-section-header button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

#folder-list { list-style: none; }

.folder-item {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  margin: 1px var(--sp-1);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--text-base);
  transition: background var(--t-fast);
}

.folder-item:hover  { background: var(--surface-hover); }
.folder-item.active { background: var(--surface-active); color: var(--accent); font-weight: var(--ft-weight-b); }

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

.folder-count {
  font-size: var(--text-2xs);
  color: var(--text-faint);
  flex-shrink: 0;
}

.folder-actions {
  display: none;
  gap: var(--sp-1);
  flex-shrink: 0;
}

.folder-item:hover .folder-actions,
.folder-item.active .folder-actions { display: flex; }

.folder-actions button {
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--sp-1);
  font-size: var(--text-2xs);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: background var(--t-fast), color var(--t-fast);
}

.folder-actions button:hover {
  background: rgba(0, 0, 0, .08);
  color: var(--text);
}

.folder-actions .btn-delete-folder:hover {
  background: var(--danger-subtle);
  color: var(--danger);
}

.dropdown-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  flex-shrink: 0;
}

#btn-logout {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--t-fast);
}

#btn-logout:hover { color: var(--danger); }

/* ── Note list panel ────────────────────────────────────────────── */

#note-list-panel {
  width: var(--panel-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .35s cubic-bezier(0.4, 0, 0.2, 1), border-right-color .35s cubic-bezier(0.4, 0, 0.2, 1);
}

#app.focus-mode #note-list-panel {
  width: 0;
  border-right-color: transparent;
}

#btn-focus {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}

#btn-focus:hover          { background: var(--surface-hover); color: var(--text); }
#btn-focus[aria-pressed="true"] { background: var(--accent-subtle); color: var(--accent); border-color: var(--accent); }

.panel-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#panel-title {
  flex: 1;
  font-size: var(--text-lg);
  font-weight: var(--ft-weight-b);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#btn-new-note {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--text-xl);
  line-height: 1;
  flex-shrink: 0;
  transition: background var(--t-fast), transform var(--t-fast);
}

#btn-new-note:hover  { background: var(--accent-hover); transform: scale(1.08); }
#btn-new-note:active { transform: scale(0.95); }

#note-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
}

.note-item {
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  box-shadow: inset 3px 0 0 transparent;
  transition: background var(--t), box-shadow var(--t);
}

.note-item:hover  { background: var(--surface-hover); }
.note-item.active { background: var(--surface-active); box-shadow: inset 3px 0 0 var(--accent); }

.note-item .note-title {
  font-size: var(--text-base);
  font-weight: var(--ft-weight-b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  transition: color var(--t);
}

.note-item.active .note-title { color: var(--accent); }

.note-item .note-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
}

.note-item .note-preview {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state {
  padding: var(--sp-10) var(--sp-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-base);
  line-height: 1.8;
}

/* ── Editor panel ───────────────────────────────────────────────── */

#editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  background: var(--surface);
}

#editor-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-3) var(--sp-5);
  color: var(--text-muted);
  font-size: var(--text-md);
}

#editor-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  position: relative;
}

/* Spacer that pushes the ⋯ menu to the far right of the format toolbar */
.fmt-spacer { flex: 1; }

#note-title {
  display: block;
  width: 100%;
  font-size: var(--text-lg);
  font-weight: var(--ft-weight-b);
  font-family: var(--font-editor);
  line-height: 1.2;
  letter-spacing: -.02em;
  border: none;
  background: transparent;
  color: var(--text);
  padding: var(--sp-6) var(--sp-8) var(--sp-3);
  transition: color var(--t);
}

#note-title:focus        { outline: none; }
#note-title::placeholder { color: var(--text-faint); font-weight: 400; }

/* ── Navigation buttons ─────────────────────────────────────────── */

#btn-menu,
#btn-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast);
}

#btn-menu:hover,
#btn-back:hover {
  background: var(--surface-hover);
  color: var(--text);
}

#btn-menu        { display: flex; }  /* always visible */
#btn-menu.open   { background: var(--surface-hover); color: var(--text); }
#btn-back        { display: none; }  /* shown on mobile only */

/* ── Dropdown ───────────────────────────────────────────────────── */

.dropdown { position: relative; flex-shrink: 0; }

#btn-note-menu {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}

#btn-note-menu:hover,
#btn-note-menu.open {
  background: var(--surface-hover);
  border-color: var(--border);
  color: var(--text);
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + var(--sp-1));
  right: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  z-index: var(--z-dropdown);
  padding: var(--sp-1) 0;
  /* appear animation */
  transition: opacity var(--t-emerge), transform var(--t-emerge);
}

@starting-style {
  .dropdown-panel:not([hidden]) {
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
  }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-base);
  font-family: var(--font-ui);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  transition: background var(--t-fast);
}

.dropdown-item:hover { background: var(--surface-hover); }

.dropdown-item-icon {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.dropdown-item-select {
  justify-content: space-between;
  cursor: default;
  color: var(--text-muted);
}

.dropdown-item-select:hover { background: none; }

.dropdown-item-select select {
  font-size: var(--text-xs);
  font-family: var(--font-ui);
  padding: var(--sp-1) var(--sp-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  max-width: 115px;
}

.dropdown-item-danger               { color: var(--danger); }
.dropdown-item-danger .dropdown-item-icon { color: var(--danger); }
.dropdown-item-danger:hover         { background: var(--danger-subtle); }

.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-1) 0;
}

/* ── Format toolbar ─────────────────────────────────────────────── */

#format-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  background: var(--surface);
}

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

.fmt-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 var(--sp-1);
  flex-shrink: 0;
}

.fmt-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
  flex-shrink: 0;
}

.fmt-btn:hover  { background: var(--surface-hover); color: var(--text); border-color: var(--border); }
.fmt-btn:active { transform: scale(0.88); }

.fmt-btn.active {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: transparent;
}

[data-theme="dark"] .fmt-btn.active {
  background: var(--surface-active);
}

.fmt-btn-danger       { color: var(--danger) !important; }
.fmt-btn-danger:hover { background: var(--danger-subtle) !important; }

#fmt-block {
  height: 28px;
  padding: 0 var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-family: var(--font-ui);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--t-fast);
}

#fmt-block:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Note content (rich text editor) ────────────────────────────── */

#scroll-wrap {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

#note-content {
  border: none;
  padding: var(--sp-3) var(--sp-8) var(--sp-10);
  font-size: var(--font-size-editor);
  font-family: var(--font-editor);
  line-height: var(--line-height-editor);
  color: var(--text);
  background: var(--surface);
  word-break: break-word;
  overflow-wrap: break-word;
  min-height: 100%;
}

#note-content:focus { outline: none; }

/* Placeholder */
#note-content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
  pointer-events: none;
}

/* Rich text element styles */
#note-content :first-child { margin-top: 0; }

#note-content h1,
#note-content h2,
#note-content h3,
#note-content h4,
#note-content h5,
#note-content h6 {
  font-weight: var(--ft-weight-b);
  line-height: 1.3;
  margin: var(--sp-6) 0 var(--sp-2);
  letter-spacing: -.01em;
}

#note-content h1 { font-size: 1.75em; padding-bottom: var(--sp-1); }
#note-content h2 { font-size: 1.35em; padding-bottom: var(--sp-1); }
#note-content h3 { font-size: 1.15em; }
#note-content h4 { font-size: 1em; }
#note-content h5 { font-size: .9em;  color: var(--text-muted); }
#note-content h6 { font-size: .85em; color: var(--text-muted); }

#note-content p            { margin: 0 0 var(--sp-3); }
#note-content p:last-child { margin-bottom: 0; }

#note-content a             { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
#note-content a:hover       { opacity: .8; }

#note-content strong, #note-content b  { font-weight: var(--ft-weight-b); }
#note-content em      { font-style: italic; }
#note-content del,
#note-content s       { text-decoration: line-through; color: var(--text-muted); }

#note-content ul,
#note-content ol    { margin: 0 0 var(--sp-3) var(--sp-6); }
#note-content li    { margin-bottom: var(--sp-1); }

#note-content li > ul,
#note-content li > ol { margin-bottom: 0; margin-top: var(--sp-1); }

/* Checklist */
#note-content ul.checklist {
  list-style: none;
  margin-left: var(--sp-2);
}

#note-content ul.checklist li {
  position: relative;
  padding-left: 1.75rem;
  min-height: 1.4em;
}

#note-content ul.checklist li::before {
  content: '';
  position: absolute;
  left: 0;
  top: .4em;
  width: 1em;
  height: 1em;
  border: 1.5px solid var(--text-muted);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: background var(--t), border-color var(--t), transform var(--t);
}

#note-content ul.checklist li:hover::before {
  border-color: var(--accent);
}

#note-content ul.checklist li.checked::before {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 10 10' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1.5 5l2.5 2.5 4.5-4.5' stroke='white' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 75%;
  background-repeat: no-repeat;
  background-position: center;
  transform: scale(1.1);
}

#note-content ul.checklist li.checked {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: var(--text-faint);
}

#note-content code {
  font-family: var(--font-mono);
  font-size: .875em;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  padding: .15em .4em;
  border-radius: var(--radius-sm);
  color: var(--accent);
}

#note-content pre {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  margin: 0 0 var(--sp-3);
  overflow-x: auto;
}

#note-content pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font-size: var(--text-base);
  border-radius: 0;
}

#note-content blockquote {
  border-left: 3px solid var(--accent);
  padding: var(--sp-1) var(--sp-4);
  margin: 0 0 var(--sp-3);
  color: var(--text-muted);
}

#note-content blockquote p { margin-bottom: var(--sp-1); }

#note-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-5) 0;
}

#note-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 var(--sp-3);
  font-size: .9em;
}

#note-content th,
#note-content td {
  border: 1px solid var(--border);
  padding: var(--sp-1) var(--sp-3);
  text-align: left;
}

#note-content th                    { background: var(--surface-raised); font-weight: var(--ft-weight-b); }
#note-content tr:nth-child(even) td { background: var(--surface-subtle); }

#note-content img {
  max-width: 100%;
  border-radius: var(--radius);
  display: block;
  margin: var(--sp-2) 0;
  cursor: pointer;
  transition: opacity var(--t-fast);
}

#note-content img:hover   { opacity: .85; }
#note-content img.img-selected { outline: 2px solid var(--accent); outline-offset: 2px; opacity: 1; }

/* ── Drag-and-drop feedback ─────────────────────────────────────── */

#note-content.drag-over {
  box-shadow: inset 0 0 0 3px var(--accent);
  border-radius: var(--radius);
  background: var(--accent-subtle) !important;
}

/* ── Image resize overlay ───────────────────────────────────────── */

#img-resize-handle {
  position: fixed;
  display: none;
  z-index: var(--z-overlay);
  width: 14px;
  height: 14px;
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 2px;
  cursor: se-resize;
  touch-action: none;
  transform: translate(-50%, -50%);
}

/* ── Image delete button (floating, position:fixed) ─────────────── */

#img-delete-btn {
  position: fixed;
  z-index: var(--z-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background var(--t-fast), transform var(--t-fast);
}

#img-delete-btn:hover { background: var(--danger-hover); transform: scale(1.1); }

/* ── Table picker ───────────────────────────────────────────────── */

#fmt-table-wrap { position: relative; }

#table-picker {
  position: absolute;
  top: calc(100% + var(--sp-1));
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-2);
  z-index: var(--z-dropdown);
  user-select: none;
  transition: opacity var(--t-emerge), transform var(--t-emerge);
}

@starting-style {
  #table-picker:not([hidden]) {
    opacity: 0;
    transform: translateY(-5px) scale(0.97);
  }
}

#table-grid {
  display: grid;
  grid-template-columns: repeat(8, 16px);
  gap: 3px;
}

.tp-cell {
  width: 16px;
  height: 16px;
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
  background: var(--surface);
  transition: background var(--t-fast), border-color var(--t-fast);
}

.tp-cell.active {
  background: var(--accent-subtle);
  border-color: var(--accent);
}

#table-picker-label {
  margin-top: var(--sp-2);
  font-size: var(--text-xs);
  font-family: var(--font-ui);
  color: var(--text-muted);
  text-align: center;
  min-height: 1em;
}

/* ── Editor status bar ──────────────────────────────────────────── */

#editor-status {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-2) var(--sp-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
  pointer-events: none;
}

#save-status,
#note-meta {
  pointer-events: auto;
  padding: 2px var(--sp-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  /* border: 1px solid var(--border); */
  transition: color var(--t-slow), opacity var(--t-slow);
}

#note-meta { margin-left: auto; }

#save-status:empty,
#note-meta:empty { display: none; }

#save-status.saving { color: var(--accent); }
#save-status.saved  { color: var(--success); }
#save-status.err    { color: var(--danger); }

/* ── Plain text modal ───────────────────────────────────────────── */

.plaintext-box {
  width: 560px;
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}

#plaintext-area {
  flex: 1;
  min-height: 260px;
  max-height: 50vh;
  resize: none;
  border: none;
  border-top: 1px solid var(--border);
  padding: var(--sp-4) var(--sp-6);
  font-size: var(--text-base);
  font-family: var(--font-mono);
  line-height: 1.65;
  color: var(--text);
  background: var(--surface-raised);
  outline: none;
}

.plaintext-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-6);
  border-top: 1px solid var(--border);
}

.plaintext-hint {
  font-size: var(--text-xs);
  color: var(--text-faint);
}

/* ── Modal ──────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--sp-4);
  transition: opacity var(--t-emerge);
}

@starting-style {
  .modal:not([hidden]) {
    opacity: 0;
  }
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 480px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transition: opacity var(--t-emerge), transform var(--t-emerge);
}

@starting-style {
  .modal:not([hidden]) .modal-box {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-header h2 {
  font-size: var(--text-lg);
  font-weight: var(--ft-weight-b);
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--text-xl);
  color: var(--text-muted);
  line-height: 1;
  transition: background var(--t-fast), color var(--t-fast);
}

.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* ── Dialog ─────────────────────────────────────────────────────── */

.dlg-box { width: 380px; }

.dlg-body {
  padding: var(--sp-4) var(--sp-6) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

#dlg-msg {
  font-size: var(--text-base);
  color: var(--text-muted);
  line-height: 1.55;
  margin: 0;
}

.dlg-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-6) var(--sp-4);
}

.dlg-btn,
.dlg-btn-ghost,
.dlg-btn-danger {
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-family: var(--font-ui);
  font-weight: var(--ft-weight-b);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}

.dlg-btn:active,
.dlg-btn-ghost:active,
.dlg-btn-danger:active { transform: scale(0.96); }

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

.dlg-btn-ghost        { background: none; color: var(--text-muted); border-color: var(--border); }
.dlg-btn-ghost:hover  { background: var(--surface-hover); color: var(--text); }

.dlg-btn-danger       { background: var(--danger); color: #fff; }
.dlg-btn-danger:hover { background: var(--danger-hover); }

/* ── Settings ───────────────────────────────────────────────────── */

.settings-section {
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child { border-bottom: none; }

.settings-section h3 {
  font-size: var(--text-2xs);
  font-weight: var(--ft-weight-b);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: var(--sp-4);
}

.settings-section label {
  display: block;
  font-size: var(--text-base);
  font-weight: var(--ft-weight-b);
  margin-bottom: var(--sp-3);
}

.settings-section label small {
  font-weight: var(--ft-weight-n);
  color: var(--text-muted);
}

.settings-section input[type="password"],
.settings-section select {
  display: block;
  width: 100%;
  margin-top: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-family: var(--font-ui);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--t), box-shadow var(--t);
}

.settings-section input:focus,
.settings-section select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.settings-section button[type="submit"],
#btn-save-prefs {
  padding: var(--sp-2) var(--sp-4);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-family: var(--font-ui);
  font-weight: var(--ft-weight-b);
  cursor: pointer;
  transition: background var(--t-fast);
}

.settings-section button[type="submit"]:hover,
#btn-save-prefs:hover { background: var(--accent-hover); }

.form-msg {
  margin-top: var(--sp-2);
  font-size: var(--text-sm);
  min-height: 1.2em;
}

.form-msg.ok  { color: var(--success); }
.form-msg.err { color: var(--danger); }

/* ── Scrollbars ─────────────────────────────────────────────────── */

::-webkit-scrollbar              { width: 5px; height: 5px; }
::-webkit-scrollbar-track        { background: transparent; }
::-webkit-scrollbar-thumb        { background: var(--border); border-radius: var(--radius-sm); }
::-webkit-scrollbar-thumb:hover  { background: var(--text-faint); }


/* ── Responsive — tablet / mobile ───────────────────────────────── */

@media (max-width: 768px) {

  /* Use dynamic viewport to fix iOS Safari 100vh bug */
  html, body { height: 100%; height: 100dvh; }
  #app        { height: 100vh; height: 100dvh; }

  :root {
    --panel-w: 100vw;
  }

  #btn-back  { display: flex; }
  #btn-focus { display: none; }

  /* Note list: full screen */
  #note-list-panel { width: 100vw; }

  /* Editor: hidden until a note is opened */
  #editor-panel { display: none; width: 100vw; }

  #app.show-editor #note-list-panel { display: none; }
  #app.show-editor #editor-panel    { display: flex; }

  /* Safe-area insets for panel header */
  .panel-header {
    padding-top:   max(var(--sp-3), calc(var(--sp-1) + env(safe-area-inset-top)));
    padding-left:  max(var(--sp-4), env(safe-area-inset-left));
    padding-right: max(var(--sp-4), env(safe-area-inset-right));
  }

  /* Safe-area insets for the combined format/nav toolbar */
  #format-toolbar {
    padding-top:   max(var(--sp-1), calc(var(--sp-1) + env(safe-area-inset-top)));
    padding-left:  max(var(--sp-4), env(safe-area-inset-left));
    padding-right: max(var(--sp-4), env(safe-area-inset-right));
  }

  /* Home-indicator safe area */
  #editor-status {
    padding-bottom: calc(var(--sp-2) + env(safe-area-inset-bottom));
    padding-left:   max(var(--sp-4), env(safe-area-inset-left));
    padding-right:  max(var(--sp-4), env(safe-area-inset-right));
  }

  /* Prevent iOS zoom on focus — all editable elements must be ≥ 16px */
  input[type="text"],
  input[type="search"],
  input[type="password"],
  textarea,
  select,
  [contenteditable] { font-size: 16px !important; }

  /* Minimum 44px touch targets */
  .folder-item      { min-height: 44px; }
  .note-item        { min-height: 60px; padding: var(--sp-3) var(--sp-4); }
  .panel-header button { width: 40px; height: 40px; }
}

@media (max-width: 480px) {
  .auth-box        { padding: var(--sp-8) var(--sp-6); }
  #note-title      { font-size: 1.35rem; padding: var(--sp-4) var(--sp-4) var(--sp-2); }
  #note-content    { padding: var(--sp-2) var(--sp-4) var(--sp-10); }
  #format-toolbar  { gap: 2px; }
  .fmt-sep         { display: none; }
  .plaintext-box   { width: 100%; }
  #plaintext-area  { font-size: 13px; }
}
