/* Markdown PWA - Complete Stylesheet */
/* Extracted from index.html for security and maintainability */
/* Removes 'unsafe-inline' from CSP, improves caching and organization */

:root {
  /* ── Lokai (default): editor white-on-black, everything else black-on-white ── */

  /* Editor pane */
  --ed-bg:          #000000;
  --ed-text:        #f0f0f0;
  --ed-placeholder: #555555;
  --ln-bg:          #0a0a0a;
  --ln-text:        #555555;
  --ln-border:      #1f1f1f;

  /* Preview / modal colors */
  --bg:       #ffffff;
  --bg2:      #f5f5f5;
  --bg3:      #ebebeb;
  --border:   #e0e0e0;
  --text:     #111111;
  --text2:    #666666;
  --accent:   #5f6f2e;
  --accent2:  #4a5723;
  --green:    #1a7f37;
  --red:      #cf222e;
  --yellow:   #9a6700;
  --font:     'Inter', 'Segoe UI', system-ui, sans-serif;
  --tb-w:     52px;
  --sb-w:     230px;
  --status-h: 28px;
}

/* ── Dark theme ── */
body.theme-dark {
  --ed-bg:          #000000;
  --ed-text:        #f0f0f0;
  --ed-placeholder: #555555;
  --ln-bg:          #0a0a0a;
  --ln-text:        #555555;
  --ln-border:      #1f1f1f;

  --bg:       #000000;
  --bg2:      #0f0f0f;
  --bg3:      #1a1a1a;
  --border:   #2a2a2a;
  --text:     #f0f0f0;
  --text2:    #999999;
  --accent:   #5f6f2e;
  --accent2:  #4a5723;
  --green:    #3fb950;
  --red:      #f85149;
  --yellow:   #d29922;
}

/* ── Light theme ── */
body.theme-light {
  --ed-bg:          #ffffff;
  --ed-text:        #111111;
  --ed-placeholder: #aaaaaa;
  --ln-bg:          #f5f5f5;
  --ln-text:        #999999;
  --ln-border:      #e0e0e0;

  --bg:       #ffffff;
  --bg2:      #f5f5f5;
  --bg3:      #ebebeb;
  --border:   #e0e0e0;
  --text:     #111111;
  --text2:    #666666;
  --accent:   #5f6f2e;
  --accent2:  #4a5723;
  --green:    #1a7f37;
  --red:      #cf222e;
  --yellow:   #9a6700;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Install banner ── */
#install-banner {
  display: none;
  background: linear-gradient(135deg, #5f6f2e, #4a5723);
  color: #fff;
  padding: 8px 16px;
  font-size: 12px;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#install-banner.show { display: flex; }
#install-banner button { background: rgba(255,255,255,.2); border: none; color: #fff; padding: 4px 12px; border-radius: 4px; cursor: pointer; font-size: 12px; }
#install-banner button:hover { background: rgba(255,255,255,.3); }
#install-close { margin-left: auto; background: none !important; padding: 2px 6px !important; }

/* ── Find & Replace Bar ── */
#find-replace-bar {
  display: none;
  padding: 6px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}
#find-replace-bar.visible { display: flex; }
#find-replace-bar input {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 14px;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  width: 180px;
  outline: none;
  transition: border-color .15s;
}
#find-replace-bar input:focus { border-color: var(--accent); }
#find-replace-bar input.no-match { border-color: var(--red); }
.fr-label  { font-size: 12px; color: var(--text2); min-width: 48px; }
#match-info { font-size: 12px; color: var(--text2); min-width: 64px; }
.fr-btn-group { display: flex; gap: 4px; }
#find-replace-bar button {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 3px 9px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
#find-replace-bar button:hover { background: var(--border); color: var(--text); }
.fr-divider { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; }

/* ── Header bar ── */
#header-bar {
  height: 44px;
  background: #ffffff;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 8px;
  flex-shrink: 0;
  user-select: none;
  position: relative;
  z-index: 20;
}

.hdr-left  { display: flex; align-items: center; gap: 2px; }
.hdr-right { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.hdr-center {
  position: absolute; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  max-width: 300px; overflow: hidden;
}
.hdr-doc-icon { color: #aaaaaa; flex-shrink: 0; }

#tb-title {
  font-size: 14px; font-weight: 500;
  color: #666666;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 220px;
  transition: color .15s;
}
#tb-title:hover { color: #111111; }

#title-input {
  display: none;
  background: #ffffff;
  border: 1px solid var(--accent);
  color: #111111;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 14px;
  width: 200px;
}
#title-input:focus { outline: none; }

.hdr-btn {
  background: transparent; border: none;
  color: #666666;
  width: 30px; height: 30px;
  border-radius: 6px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
  flex-shrink: 0; padding: 0;
}
.hdr-btn:hover  { background: #f2f2f2; color: #111111; }
.hdr-btn:active { transform: translateY(0.5px); }
.hdr-btn.active { background: rgba(95,111,46,.2); color: #5f6f2e; }
.hdr-danger     { color: #e06c75; }
.hdr-danger:hover { background: rgba(224,108,117,.15) !important; }


/* More dropdown */
.hdr-more-wrap { position: relative; }
.hdr-dropdown {
  display: none; position: absolute;
  top: calc(100% + 4px); left: 0;
  background: #ffffff; border: 1px solid #e0e0e0;
  border-radius: 8px; padding: 4px;
  min-width: 180px; z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.hdr-dropdown.open { display: block; }
.hdr-dd-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; background: none; border: none;
  color: #444444; font-size: 12px; font-family: var(--font);
  padding: 7px 10px; border-radius: 5px; cursor: pointer;
  text-align: left; transition: background .1s, color .1s;
}
.hdr-dd-item:hover { background: #f2f2f2; color: #111111; }
.hdr-dd-item svg   { flex-shrink: 0; color: #aaaaaa; }
.hdr-dd-sep        { height: 1px; background: #e0e0e0; margin: 3px 6px; }
.hdr-dd-danger     { color: #e06c75; }
.hdr-dd-danger:hover { background: rgba(224,108,117,.15) !important; color: #e06c75; }
.hdr-dd-label      { font-size: 10px; font-weight: 600; color: #aaaaaa; padding: 6px 10px 3px; letter-spacing: .05em; text-transform: uppercase; }
.hdr-export-grid   { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 2px 4px 4px; }
.hdr-export-fmt    { justify-content: center; padding: 5px 4px; font-size: 11px; font-weight: 600; letter-spacing: .03em; border-radius: 4px; }

/* ── Format bar ── */
#format-bar {
  height: 38px;
  background: #ffffff;
  border-bottom: 1px solid #e0e0e0;
  display: flex; align-items: center;
  padding: 0 8px; gap: 1px;
  flex-shrink: 0; user-select: none;
  position: relative; z-index: 10;
}

.fmt-btn {
  background: transparent; border: none;
  color: #666666;
  min-width: 28px; height: 28px;
  border-radius: 5px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-family: var(--font);
  padding: 0 4px;
  transition: background .12s, color .12s;
  flex-shrink: 0;
}
.fmt-btn:hover  { background: #f2f2f2; color: #111111; }
.fmt-btn:active { transform: translateY(0.5px); }
.fmt-btn.active { background: rgba(95,111,46,.2); color: #5f6f2e; }
.fmt-bold   { font-weight: 700; }
.fmt-italic { font-style: italic; }
.fmt-strike s { text-decoration: line-through; }
.fmt-h-label   { font-size: 12px; font-weight: 600; padding: 0 5px; }
.fmt-code-text { font-family: monospace; font-size: 12px; letter-spacing: -.5px; }

.fmt-sep {
  width: 1px; height: 18px;
  background: #e0e0e0;
  margin: 0 4px; flex-shrink: 0;
}
.fmt-spacer { flex: 1; }

.fmt-split-btn {
  display: flex; align-items: center; position: relative;
}
.fmt-dd-arrow {
  min-width: 16px; padding: 0 2px;
  border-radius: 0 5px 5px 0;
  border-left: 1px solid #e0e0e0;
  height: 28px;
}
.fmt-split-btn .fmt-btn:first-child { border-radius: 5px 0 0 5px; }

.fmt-dropdown {
  display: none; position: absolute;
  top: calc(100% + 4px); left: 0;
  background: #ffffff; border: 1px solid #e0e0e0;
  border-radius: 7px; padding: 4px;
  min-width: 150px; z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.fmt-dropdown.open { display: block; }
.fmt-dd-item {
  display: block; width: 100%;
  background: none; border: none;
  color: #444444; font-size: 12px; font-family: var(--font);
  padding: 6px 10px; border-radius: 5px;
  cursor: pointer; text-align: left;
  transition: background .1s, color .1s;
}
.fmt-dd-item:hover { background: #f2f2f2; color: #111111; }

.fmt-table-picker-wrap { padding: 8px; min-width: unset; }
.fmt-table-grid { display: grid; grid-template-columns: repeat(5, 18px); gap: 3px; }
.fmt-table-cell { width: 18px; height: 18px; border: 1px solid var(--border); border-radius: 2px; cursor: pointer; transition: background .08s, border-color .08s; }
.fmt-table-cell.active { background: rgba(95,111,46,.2); border-color: var(--accent); }
.fmt-table-label { font-size: 11px; color: var(--text2); text-align: center; margin-top: 6px; }

/* View toggle group */
.fmt-view-group {
  display: flex; align-items: center;
  background: #ebebeb; border-radius: 6px;
  padding: 2px; gap: 1px; margin: 0 4px;
}
.fmt-view-group .fmt-btn {
  height: 24px; min-width: 26px; border-radius: 4px;
}
.fmt-view-group .fmt-btn.active {
  background: #5f6f2e; color: #fff;
}
.fmt-view-group .fmt-btn.active:hover { background: #4a5723; }

/* Drive status dot */
#toolbar-drive-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #aaaaaa;
  transition: background .2s;
  cursor: default; flex-shrink: 0;
}
#toolbar-drive-dot.connected { background: #2ea043; }
#toolbar-drive-dot.saving    { background: #d29922; }
#toolbar-drive-dot.error     { background: #f85149; }

/* Tooltip wrapper */
.tw { position: relative; display: inline-flex; z-index: 1; align-items: center; }
.tw-tip {
  position: absolute;
  top: calc(100% + 8px); left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: #111111;
  color: #ffffff;
  font-size: 11px; font-weight: 500;
  padding: 5px 8px; border-radius: 5px;
  border: 1px solid #333333;
  white-space: nowrap; pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease, transform 120ms ease;
  transition-delay: 0ms;
  z-index: 9998;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.tw:hover .tw-tip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  transition-delay: 500ms;
}

/* ── App shell (sidebar + main column) ── */
#app-shell {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sb-user-w, var(--sb-w));
  min-width: var(--sb-user-w, var(--sb-w));
  max-width: var(--sb-user-w, var(--sb-w));
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 200ms ease, min-width 200ms ease, opacity 200ms ease;
  flex-shrink: 0;
  z-index: 10;
}
#app-shell.sidebar-collapsed #sidebar {
  width: 0;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
}

#sidebar-inner {
  width: var(--sb-user-w, var(--sb-w));
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Sidebar drag-to-resize handle (desktop only) */
#sidebar-resizer {
  flex: 0 0 5px;
  width: 5px;
  margin-left: -3px;
  margin-right: -2px;
  cursor: col-resize;
  position: relative;
  z-index: 11;
  background: transparent;
  touch-action: none;
  transition: background 120ms ease;
}
#sidebar-resizer:hover,
#sidebar-resizer:focus-visible,
#app-shell.sb-resizing #sidebar-resizer {
  background: color-mix(in srgb, var(--accent) 55%, transparent);
  outline: none;
}
#app-shell.sidebar-collapsed #sidebar-resizer { display: none; }
/* No width animation while dragging, and no text selection or iframe stealing events */
#app-shell.sb-resizing #sidebar { transition: none; }
#app-shell.sb-resizing { cursor: col-resize; user-select: none; -webkit-user-select: none; }

/* Sidebar header */
#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 12px;
  height: 44px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
#sidebar-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text2);
  text-transform: uppercase;
  user-select: none;
}
#sidebar-collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--text2);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: .6;
  transition: opacity 120ms, background 120ms;
}
#sidebar-collapse-btn:hover { opacity: 1; background: var(--bg3); }

/* Sidebar search */
#sidebar-search-wrap {
  padding: 8px 10px 6px;
  flex-shrink: 0;
}
#sidebar-search {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text);
  font-family: var(--font);
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
#sidebar-search::placeholder { color: var(--text2); opacity: .7; }
#sidebar-search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent); }

/* Clear (x) button inside search boxes. Visible only while the box has text:
   :placeholder-shown also tracks values the app sets from code. */
.search-field { position: relative; display: block; }
.search-field-grow { flex: 1; min-width: 0; }
.search-field > input { padding-right: 26px; }
#sidebar-search { padding-right: 26px; }
.search-clear {
  position: absolute; top: 50%; right: 5px; transform: translateY(-50%);
  width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--text2);
  font-size: 11px; line-height: 18px; text-align: center; cursor: pointer;
}
.search-clear:hover { background: var(--bg3); color: var(--text); }
.search-field > input:placeholder-shown + .search-clear { display: none; }
body.theme-dark .search-clear:hover { background: #2a2a2a; color: #f0f0f0; }
.modal-search { box-sizing: border-box; }

/* Sort toggle */
#sidebar-sort-bar {
  display: flex;
  gap: 4px;
  padding: 4px 10px 6px;
  flex-shrink: 0;
}
.sb-sort-btn {
  flex: 1;
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 0;
  font-size: 11px;
  font-family: var(--font);
  color: var(--text2);
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.sb-sort-btn:hover { background: var(--bg3); color: var(--text); }
.sb-sort-btn.active { background: var(--bg3); color: var(--text); border-color: var(--accent); }

/* New doc button */
#sidebar-new-btn {
  margin: 4px 10px 6px;
  width: calc(100% - 20px);
  background: none;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-family: var(--font);
  color: var(--text2);
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 120ms, color 120ms, border-color 120ms;
  flex-shrink: 0;
}
#sidebar-new-btn:hover {
  background: var(--bg3);
  color: var(--text);
  border-color: var(--accent);
}
#sidebar-new-btn svg { flex-shrink: 0; }

/* Doc list */
#sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 6px;
}
#sidebar-list::-webkit-scrollbar { width: 4px; }
#sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 100ms;
  user-select: none;
}
.sidebar-item:hover { background: var(--bg3); }
.sidebar-item.active {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  font-weight: 500;
}
.sidebar-item svg { flex-shrink: 0; opacity: .5; }
.sidebar-item.active svg { opacity: 1; }
.sidebar-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.sidebar-empty {
  padding: 12px 8px;
  font-size: 12px;
  color: var(--text2);
  text-align: center;
  opacity: .7;
}

/* Sidebar footer */
#sidebar-footer {
  flex-shrink: 0;
  padding: 6px 10px 10px;
  border-top: 1px solid var(--border);
}
#sidebar-browse-all-btn {
  width: 100%;
  background: none;
  border: none;
  padding: 6px 8px;
  font-size: 12px;
  font-family: var(--font);
  color: var(--text2);
  cursor: pointer;
  text-align: left;
  border-radius: 5px;
  transition: background 120ms, color 120ms;
}
#sidebar-browse-all-btn:hover { background: var(--bg3); color: var(--text); }
#sidebar-trash-btn {
  width: 100%;
  background: none;
  border: none;
  padding: 6px 8px;
  font-size: 12px;
  font-family: var(--font);
  color: var(--text2);
  cursor: pointer;
  text-align: left;
  border-radius: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 120ms, color 120ms;
}
#sidebar-trash-btn:hover { background: var(--bg3); color: var(--text); }

.trash-item { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.trash-item:last-child { border-bottom: none; }
.trash-item-name { flex: 1; font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-item-date { font-size: 11px; color: var(--text2); white-space: nowrap; }
.trash-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

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

/* App content column */
#app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Sidebar toggle button (in header) */
#sidebar-toggle-btn { margin-right: 4px; }

/* ── Dark theme sidebar overrides ── */
body.theme-dark #sidebar {
  background: #111111;
  border-right-color: #2a2a2a;
}
body.theme-dark #sidebar-search {
  background: #1a1a1a;
  border-color: #2a2a2a;
  color: #f0f0f0;
}
body.theme-dark #sidebar-search::placeholder { color: #666; }
body.theme-dark .sidebar-item { color: #e0e0e0; }
body.theme-dark .sidebar-item:hover { background: #222222; }
body.theme-dark .sidebar-item.active { background: color-mix(in srgb, var(--accent) 20%, transparent); }
body.theme-dark #sidebar-footer { border-top-color: #2a2a2a; }
body.theme-dark #sidebar-browse-all-btn { color: #888; }
body.theme-dark #sidebar-browse-all-btn:hover { background: #222; color: #e0e0e0; }
body.theme-dark #sidebar-trash-btn { color: #888; }
body.theme-dark #sidebar-trash-btn:hover { background: #222; color: #e0e0e0; }
body.theme-dark #sidebar-header { border-bottom-color: #2a2a2a; }
body.theme-dark #sidebar-new-btn { border-color: #2a2a2a; color: #888; }
body.theme-dark #sidebar-new-btn:hover { background: #222; color: #e0e0e0; }

/* ── Light theme sidebar overrides ── */
body.theme-light #sidebar {
  background: #f8f8f8;
  border-right-color: #e0e0e0;
}

/* ── Mobile responsive ── */
@media (max-width: 600px) {
  #sidebar-resizer { display: none; }
  #sidebar-inner { width: var(--sb-w); }
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sb-w) !important;
    min-width: var(--sb-w) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: translateX(-100%);
    transition: transform 200ms ease, opacity 200ms ease;
    z-index: 100;
    box-shadow: 4px 0 20px rgba(0,0,0,.2);
  }
  #app-shell.sidebar-open #sidebar {
    transform: translateX(0);
  }
  #app-shell.sidebar-open #sidebar-backdrop {
    display: block;
  }
  #app-shell.sidebar-collapsed #sidebar {
    transform: translateX(-100%);
    opacity: 1;
    pointer-events: auto;
  }
}

/* ── Sidebar tree nodes ── */
.sb-node {
  position: relative;
}
.sb-node-row,
.sb-node .sidebar-item {
  display: flex;
  align-items: center;
  gap: 0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.12s;
  min-height: 30px;
}
.sb-node-row:hover,
.sb-node .sidebar-item:hover {
  background: var(--bg3);
}
.sb-chevron {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  transition: transform 0.15s;
  border-radius: 3px;
}
.sb-chevron:hover {
  background: var(--bg4, #d0d0d0);
  color: var(--text);
}
.sb-chevron.expanded {
  transform: rotate(90deg);
}
.sb-chevron-placeholder {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}
.sb-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  margin-right: 4px;
}
.sb-node-title {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 4px 2px;
  line-height: 1.3;
}
.sb-actions {
  flex-shrink: 0;
  display: none;
  align-items: center;
  gap: 1px;
  padding-right: 4px;
}
.sb-node-row:hover .sb-actions,
.sb-node .sidebar-item:hover .sb-actions {
  display: flex;
}
.sb-action-btn {
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  padding: 0;
  transition: background 0.12s, color 0.12s;
}
.sidebar-item .sb-action-btn svg { opacity: .8; }
.sb-action-btn:hover {
  background: var(--accent);
  color: #fff;
}
.sb-children {
  overflow: hidden;
}
.sb-children.sb-hidden {
  display: none;
}

/* Move-to modal list */
.move-option {
  padding: 7px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.1s;
}
.move-option:hover {
  background: var(--bg3);
}
.move-option.move-option-selected {
  background: var(--accent);
  color: #fff;
}
.move-option.move-option-current {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

/* Dark theme overrides for tree and move modal */
body.theme-dark .sb-node-row:hover,
body.theme-dark .sb-node .sidebar-item:hover { background: #2a2a2a; }
body.theme-dark .sb-chevron { color: #666; }
body.theme-dark .sb-chevron:hover { background: #333; color: #ccc; }
body.theme-dark .sb-icon { color: #666; }
body.theme-dark .sb-node-title { color: #ccc; }
body.theme-dark .sb-action-btn { color: #666; }
body.theme-dark .move-option { color: #ccc; }
body.theme-dark .move-option:hover { background: #2a2a2a; }

/* Light theme overrides */
body.theme-light .sb-chevron { color: #999; }
body.theme-light .sb-chevron:hover { background: #e0e0e0; color: #444; }
body.theme-light .sb-icon { color: #999; }
body.theme-light .sb-node-title { color: #1a1a1a; }
body.theme-light .sb-action-btn { color: #999; }

/* ── Main content row ── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

/* Open-in-Drive link in statusbar */
#drive-open-link {
  color: var(--text2);
  opacity: .6;
  margin-left: 4px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
#drive-open-link:hover { opacity: 1; }

/* ── Editor pane ── */
#editor-pane {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-width: 200px;
  overflow: hidden;
}

#divider {
  width: 5px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s;
}
#divider:hover, #divider.dragging { background: var(--accent); }

#line-numbers {
  width: 44px;
  padding: 20px 6px 20px 0;
  text-align: right;
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 16px;
  line-height: 1.7;
  color: var(--ln-text);
  background: var(--ln-bg);
  border-right: 1px solid var(--ln-border);
  user-select: none;
  overflow: hidden;
  flex-shrink: 0;
}

#editor {
  flex: 1;
  background: var(--ed-bg);
  color: var(--ed-text);
  border: none;
  outline: none;
  resize: none;
  padding: 20px 24px;
  will-change: scroll-position;
  -webkit-overflow-scrolling: touch;
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 16px;
  line-height: 1.7;
  tab-size: 2;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow-x: hidden;
}
#editor::placeholder { color: var(--ed-placeholder); }

/* ── Preview wrapper & zoom controls ── */
#preview-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 200px;
}

#preview-pane {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 32px;
  background: var(--bg);
  word-wrap: break-word;
  overflow-wrap: break-word;
  will-change: scroll-position;
  -webkit-overflow-scrolling: touch;
}

#preview-inner {
  transform-origin: top left;
}
#preview-inner:focus { outline: none; }

#preview-pane h1,h2,h3,h4,h5,h6 { color: var(--text); margin: 1.5em 0 .5em; line-height: 1.3; }
#preview-pane h1 { font-size: 1.8em; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
#preview-pane h2 { font-size: 1.4em; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
#preview-pane p  { color: var(--text); line-height: 1.7; margin-bottom: 1em; }
#preview-pane a  { color: var(--accent); }
#preview-pane code { background: #f2f2f2; color: #c0392b; padding: 2px 6px; border-radius: 4px; font-family: 'Cascadia Code', monospace; font-size: .9em; }
#preview-pane pre { background: #f5f5f5; border: 1px solid var(--border); border-radius: 8px; padding: 16px; overflow-x: auto; margin-bottom: 1em; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; }
#preview-pane pre code { background: none; color: inherit; padding: 0; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; }

/* Mermaid diagrams */
.mermaid-diagram { text-align: center; margin: 1em 0; overflow-x: auto; }
.mermaid-diagram svg { max-width: 100%; height: auto; }
.mermaid-pending { display: none; }
.mermaid-error { background: #fff0f0; border: 1px solid #f5c2c2; border-radius: 8px; padding: 12px 16px; color: var(--red); font-size: 13px; margin: 1em 0; white-space: pre-wrap; font-family: monospace; }

/* Copy button on fenced code blocks */
.code-block { position: relative; }
.copy-code-btn {
  position: absolute; top: 10px; right: 10px;
  width: 26px; height: 26px; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg2); border: 1px solid var(--border); color: var(--text2);
  cursor: pointer; opacity: .7; transition: opacity .15s, background .15s, color .15s;
}
.code-block:hover .copy-code-btn { opacity: 1; }
.copy-code-btn:hover  { background: var(--bg3); color: var(--text); }
.copy-code-btn.copied { opacity: 1; color: var(--green); border-color: var(--green); }
#preview-pane blockquote { border-left: 3px solid var(--accent); color: var(--text2); padding: 4px 16px; margin: 0 0 1em; }
#preview-pane table { border-collapse: collapse; width: 100%; margin-bottom: 1em; }
#preview-pane th,td { border: 1px solid var(--border); padding: 8px 12px; }
#preview-pane th { background: var(--bg2); }
#preview-pane tr:nth-child(even) { background: var(--bg2); }
#preview-pane img { max-width: 100%; border-radius: 6px; }
#preview-pane hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
#preview-pane ul,ol { padding-left: 1.5em; margin-bottom: 1em; }
#preview-pane li { margin-bottom: .25em; line-height: 1.7; }
#preview-pane ul li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.5em; }

/* Zoom controls overlay */
.zoom-controls {
  position: absolute;
  bottom: 10px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 2px;
  z-index: 10;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 5px;
}
.zoom-controls button {
  background: transparent;
  border: none;
  color: var(--text2);
  width: 24px; height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
  padding: 0;
}
.zoom-controls button:hover { background: var(--bg3); color: var(--text); }
#zoom-pct {
  font-size: 11px;
  color: var(--text2);
  min-width: 36px;
  text-align: center;
  padding: 0 3px;
}

/* ── Status bar ── */
#statusbar {
  height: var(--status-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  font-size: 11px;
  color: var(--text2);
  flex-shrink: 0;
}
#statusbar span { white-space: nowrap; }
#word-count { cursor: pointer; }
#word-count:hover { color: var(--text); }
#word-count.goal-met { color: var(--accent); font-weight: 600; }

.goal-popover { position: fixed; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: none; align-items: center; gap: 8px; z-index: 9000; box-shadow: 0 4px 16px rgba(0,0,0,.2); font-size: 13px; color: var(--text2); }
.goal-popover.open { display: flex; }
.goal-popover label { white-space: nowrap; }
.goal-popover input { width: 80px; padding: 4px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; color: var(--text); font-size: 13px; }
.goal-popover input:focus { outline: none; border-color: var(--accent); }
.goal-popover button { padding: 4px 10px; background: var(--bg2); border: 1px solid var(--border); border-radius: 4px; color: var(--text2); font-size: 12px; cursor: pointer; }
.goal-popover button:hover { color: var(--text); }

#tb-title {
  font-size: 11px;
  color: var(--text2);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background .15s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}
#tb-title:hover { background: var(--bg3); color: var(--text); }

#title-input {
  display: none;
  background: var(--bg3);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  width: 200px;
}
#title-input:focus { outline: none; }

/* ── Kanban ── */
.kanban-panel { display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 800; background: var(--bg); }
.kanban-panel.hidden { display: none; }
.kanban-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; }
.kanban-title { font-size: 15px; font-weight: 600; color: var(--text); }
.kanban-board { display: flex; gap: 16px; padding: 20px; overflow-x: auto; flex: 1; align-items: flex-start; }
.kb-col { display: flex; flex-direction: column; width: 280px; min-width: 280px; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.kb-col-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg3); }
.kb-col-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); }
.kb-col-count { font-size: 11px; font-weight: 600; background: var(--border); color: var(--text2); border-radius: 10px; padding: 1px 7px; }
.kb-col-cards { display: flex; flex-direction: column; gap: 8px; padding: 10px; min-height: 80px; flex: 1; }
.kb-col-cards.drag-over { background: rgba(95,111,46,.08); outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: 6px; }
.kb-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: grab; position: relative; transition: box-shadow .15s, opacity .15s; }
.kb-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.kb-card.dragging { opacity: .4; cursor: grabbing; }
.kb-card-title { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 6px; line-height: 1.4; word-break: break-word; padding-right: 18px; }
.kb-card-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kb-card-words { font-size: 11px; color: var(--text2); }
.kb-card-tag { background: rgba(95,111,46,.12); color: var(--accent); border: 1px solid rgba(95,111,46,.2); border-radius: 10px; padding: 1px 6px; font-size: 9px; font-weight: 500; white-space: nowrap; }
.kb-card-remove { position: absolute; top: 6px; right: 6px; background: none; border: none; color: var(--text2); cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 4px; border-radius: 4px; opacity: 0; transition: opacity .12s; }
.kb-card:hover .kb-card-remove { opacity: 1; }
.kb-card-remove:hover { color: #cf222e; background: rgba(207,34,46,.08); }
.kb-add-btn { margin: 0 10px 10px; padding: 7px; background: none; border: 1px dashed var(--border); border-radius: 6px; color: var(--text2); font-size: 12px; cursor: pointer; text-align: left; transition: border-color .12s, color .12s; }
.kb-add-btn:hover { border-color: var(--accent); color: var(--accent); }
.kb-empty { color: var(--text2); font-size: 12px; text-align: center; padding: 16px 0; }

/* ── Modals ── */
.modal-backdrop { display: none; position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,.4); align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: 560px; max-width: 95vw; max-height: 80vh; display: flex; flex-direction: column; gap: 16px; box-shadow: 0 24px 64px rgba(0,0,0,.15); position: relative; }
.modal-resize-grip { position: absolute; bottom: 4px; right: 4px; width: 14px; height: 14px; cursor: nwse-resize; opacity: 0.25; background-image: repeating-linear-gradient(-45deg, var(--text2) 0, var(--text2) 1px, transparent 0, transparent 4px); border-radius: 0 0 8px 0; }
.modal-resize-grip:hover { opacity: 0.55; }
.modal-title { font-size: 17px; font-weight: 600; color: var(--text); }
.modal-search { padding: 8px 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 15px; width: 100%; }
.modal-search:focus { outline: none; border-color: var(--accent); }
.doc-browser-controls { display: flex; gap: 8px; align-items: center; }
.doc-browser-controls .modal-search { width: 100%; }
.doc-browser-sort { padding: 8px 10px; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 14px; cursor: pointer; white-space: nowrap; }
.doc-browser-sort:focus { outline: none; border-color: var(--accent); }

/* Finder-style column list */
.file-list-header { display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 44px; border: 1px solid var(--border); border-bottom: none; border-radius: 6px 6px 0 0; background: var(--bg3); }
.file-col-name, .file-col-tags, .file-col-words, .file-col-modified { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text2); }
.file-col-sortable { cursor: pointer; user-select: none; }
.file-col-sortable:hover { color: var(--text); }
.file-col-sortable.active { color: var(--accent); }
.sort-arrow { font-size: 9px; margin-left: 2px; }
.file-list-header .file-col-name { flex: 1; min-width: 0; }
.file-list-header .file-col-tags { width: 160px; flex-shrink: 0; }
.file-list-header .file-col-words { width: 64px; text-align: right; flex-shrink: 0; }
.file-list-header .file-col-modified { width: 110px; text-align: right; flex-shrink: 0; }

.file-list { flex: 1; overflow-y: auto; border: 1px solid var(--border); border-radius: 0 0 6px 6px; }
.file-item { display: flex; align-items: center; gap: 10px; padding: 6px 14px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .1s; }
.file-item:last-child { border-bottom: none; }
.file-item:hover { background: var(--bg3); }
.file-item.selected { background: rgba(95,111,46,.1); }
.file-type-badge { flex-shrink: 0; width: 20px; height: 20px; background: var(--accent); color: #fff; border-radius: 5px; font-size: 7px; font-weight: 700; letter-spacing: .05em; display: flex; align-items: center; justify-content: center; }
.file-col-name { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.file-name-row { display: flex; align-items: center; gap: 8px; width: 100%; min-width: 0; }
.file-snippet { font-size: 11px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; margin-top: 1px; }
.file-snippet mark { background: rgba(255,220,0,.25); color: inherit; border-radius: 2px; padding: 0 1px; }
.file-name { flex-shrink: 1; min-width: 40px; color: var(--text); font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-col-tags { width: 160px; flex-shrink: 0; overflow: hidden; }
.file-tags-wrap { display: flex; align-items: center; gap: 4px; overflow: hidden; }
.file-tag { background: rgba(95,111,46,.12); color: var(--accent); border: 1px solid rgba(95,111,46,.2); border-radius: 10px; padding: 1px 6px; font-size: 9px; font-weight: 500; white-space: nowrap; }
.file-tag-btn { background: none; border: 1px dashed var(--border); border-radius: 10px; color: var(--text2); font-size: 10px; padding: 1px 6px; cursor: pointer; white-space: nowrap; transition: opacity .12s, border-color .12s, color .12s; display: inline-flex; align-items: center; gap: 3px; font-family: var(--font); opacity: 0; }
.file-item:hover .file-tag-btn, .file-tags-wrap:focus-within .file-tag-btn { opacity: 1; }
.file-tag-btn:hover { border-color: var(--accent); color: var(--accent); }
.file-tag-input { border: 1px solid var(--accent); border-radius: 10px; background: var(--bg); color: var(--text); font-size: 11px; padding: 2px 8px; outline: none; width: 180px; font-family: var(--font); }
.file-col-words { width: 64px; flex-shrink: 0; text-align: right; color: var(--text2); font-size: 12px; }
.file-col-modified { width: 110px; flex-shrink: 0; text-align: right; color: var(--text2); font-size: 12px; white-space: nowrap; }
.file-date { color: var(--text2); font-size: 11px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.doc-browser-count { margin-right: auto; font-size: 13px; color: var(--text2); }
.btn { padding: 7px 16px; border: none; border-radius: 6px; cursor: pointer; font-size: 15px; }
.btn-secondary { background: var(--bg3); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-primary { background: var(--accent2); color: #fff; }
.btn-primary:hover { background: var(--accent); }
.btn-danger { background: #cf222e; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a40e26; }
.btn-danger:disabled { background: var(--bg3); color: var(--text2); cursor: not-allowed; opacity: .6; }
.modal-input { padding: 8px 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 15px; width: 100%; }
.modal-input:focus { outline: none; border-color: var(--accent); }
.modal-label { font-size: 13px; color: var(--text2); margin-bottom: 4px; display: block; }

/* ── Toast ── */
#toast { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 10px 20px; border-radius: 8px; font-size: 14px; z-index: 9999; opacity: 0; pointer-events: none; transition: opacity .2s; white-space: nowrap; }
#toast.show { opacity: 1; pointer-events: auto; }
#toast button { background: none; border: none; color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer; margin-left: 14px; padding: 0; }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ── Focus Mode Overlay ── */
#focus-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  overflow-y: auto;
  padding: 80px 0 120px;
}
body.focus-mode #focus-overlay { display: block; }

#focus-wysiwyg {
  width: 75%;
  margin: 0 auto;
  padding: 0 32px;
  font-size: 18px;
  line-height: 1.8;
  color: var(--text);
  outline: none;
  min-height: 60vh;
  font-family: Georgia, 'Times New Roman', serif;
}
#focus-wysiwyg:focus { caret-color: var(--accent); }

/* WYSIWYG content — mirrors #preview-pane */
#focus-wysiwyg h1,#focus-wysiwyg h2,#focus-wysiwyg h3,
#focus-wysiwyg h4,#focus-wysiwyg h5,#focus-wysiwyg h6 { color: var(--text); margin: 1.5em 0 .5em; line-height: 1.3; }
#focus-wysiwyg h1 { font-size: 1.8em; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
#focus-wysiwyg h2 { font-size: 1.4em; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
#focus-wysiwyg p  { color: var(--text); line-height: 1.7; margin-bottom: 1em; }
#focus-wysiwyg a  { color: var(--accent); }
#focus-wysiwyg code { background: #f2f2f2; color: #c0392b; padding: 2px 6px; border-radius: 4px; font-family: 'Cascadia Code', monospace; font-size: .9em; }
#focus-wysiwyg pre { background: #f5f5f5; border: 1px solid var(--border); border-radius: 8px; padding: 16px; overflow-x: auto; margin-bottom: 1em; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; }
#focus-wysiwyg pre code { background: none; color: inherit; padding: 0; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; }
#focus-wysiwyg blockquote { border-left: 3px solid var(--accent); color: var(--text2); padding: 4px 16px; margin: 0 0 1em; }
#focus-wysiwyg table { border-collapse: collapse; width: 100%; margin-bottom: 1em; }
#focus-wysiwyg th,#focus-wysiwyg td { border: 1px solid var(--border); padding: 8px 12px; }
#focus-wysiwyg th { background: var(--bg2); }
#focus-wysiwyg tr:nth-child(even) { background: var(--bg2); }
#focus-wysiwyg img { max-width: 100%; border-radius: 6px; }
#focus-wysiwyg hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
#focus-wysiwyg ul,#focus-wysiwyg ol { padding-left: 1.5em; margin-bottom: 1em; }
#focus-wysiwyg li { margin-bottom: .25em; line-height: 1.7; }
#focus-wysiwyg ul li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.5em; }

/* Focus mode: hide all chrome */
body.focus-mode #header-bar  { display: none; }
body.focus-mode #format-bar  { display: none; }
body.focus-mode #statusbar   { display: none; }
body.focus-mode #divider          { display: none; }
body.focus-mode #preview-wrapper  { display: none; }
body.focus-mode #find-replace-bar { display: none; }
body.focus-mode #editor-pane { display: none; }

/* Exit button */
#focus-exit-btn {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 210;
  background: rgba(0,0,0,.55);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background .15s;
}
#focus-exit-btn:hover { background: rgba(0,0,0,.8); }
body.focus-mode #focus-exit-btn { display: block; }

/* ── Dark theme: preview + toolbar overrides ── */
body.theme-dark #preview-pane code { background: var(--bg3); color: #ff7b72; }
body.theme-dark #preview-pane pre  { background: var(--bg2); border-color: var(--border); }
body.theme-dark #preview-pane th   { background: var(--bg2); }
body.theme-dark #preview-pane tr:nth-child(even) { background: var(--bg2); }
body.theme-dark #focus-wysiwyg code { background: var(--bg3); color: #ff7b72; }
body.theme-dark #focus-wysiwyg pre  { background: var(--bg2); border-color: var(--border); }
body.theme-dark #zoom-pct { color: var(--text2); }
body.theme-dark .zoom-controls { background: var(--bg2); border-color: var(--border); }
body.theme-dark .zoom-controls button { color: var(--text2); }
body.theme-dark .zoom-controls button:hover { background: var(--bg3); color: var(--text); }

body.theme-dark #header-bar   { background: #231f1b; border-bottom-color: #3d3630; }
body.theme-dark #format-bar   { background: #231f1b; border-bottom-color: #3d3630; }
body.theme-dark .hdr-btn      { color: #9e9089; }
body.theme-dark .hdr-btn:hover { background: #2e2a26; color: #e8e2d9; }
body.theme-dark .hdr-btn.active { background: rgba(95,111,46,.2); color: #5f6f2e; }
body.theme-dark .hdr-doc-icon { color: #9e9089; }
body.theme-dark .hdr-dropdown { background: #1a1714; border-color: #3d3630; box-shadow: 0 8px 24px rgba(0,0,0,.6); }
body.theme-dark .hdr-dd-item  { color: #c5bdb4; }
body.theme-dark .hdr-dd-item:hover { background: #2e2a26; color: #e8e2d9; }
body.theme-dark .hdr-dd-item svg { color: #9e9089; }
body.theme-dark .hdr-dd-sep   { background: #3d3630; }
body.theme-dark .hdr-dd-label { color: #9e9089; }
body.theme-dark .fmt-btn      { color: #9e9089; }
body.theme-dark .fmt-btn:hover { background: #2e2a26; color: #e8e2d9; }
body.theme-dark .fmt-btn.active { background: rgba(95,111,46,.2); color: #5f6f2e; }
body.theme-dark .fmt-sep      { background: #3d3630; }
body.theme-dark .fmt-dd-arrow { border-left-color: #3d3630; }
body.theme-dark .fmt-dropdown { background: #1a1714; border-color: #3d3630; box-shadow: 0 8px 24px rgba(0,0,0,.6); }
body.theme-dark .fmt-dd-item  { color: #c5bdb4; }
body.theme-dark .fmt-dd-item:hover { background: #2e2a26; color: #e8e2d9; }
body.theme-dark .fmt-view-group { background: #0f0d0b; }
body.theme-dark .fmt-view-group .fmt-btn.active { background: #5f6f2e; color: #fff; }
body.theme-dark .fmt-view-group .fmt-btn.active:hover { background: #4a5723; }
body.theme-dark .tw-tip { background: #e8e2d9; color: #1a1714; border-color: #9e9089; }
body.theme-dark #title-input { background: #2e2a26; border-color: #5f6f2e; color: #e8e2d9; }
body.theme-dark #tb-title { color: #9e9089; }
body.theme-dark #tb-title:hover { color: #e8e2d9; }
body.theme-dark #statusbar { background: #231f1b; border-top-color: #3d3630; color: #9e9089; }
body.theme-dark #find-replace-bar { background: #231f1b; border-bottom-color: #3d3630; }
body.theme-dark #find-replace-bar input { background: #2e2a26; border-color: #3d3630; color: #e8e2d9; }
body.theme-dark #find-replace-bar button { background: #2e2a26; border-color: #3d3630; color: #9e9089; }

/* ── Light theme: toolbar overrides ── */
body.theme-light #header-bar   { background: #ffffff; border-bottom-color: #e5e5e5; }
body.theme-light #format-bar   { background: #ffffff; border-bottom-color: #e5e5e5; }
body.theme-light .hdr-btn      { color: #666666; }
body.theme-light .hdr-btn:hover { background: #f2f2f2; color: #1a1a1a; }
body.theme-light .hdr-btn.active { background: rgba(95,111,46,.2); color: #5f6f2e; }
body.theme-light .hdr-doc-icon { color: #aaaaaa; }
body.theme-light .hdr-dropdown { background: #ffffff; border-color: #e5e5e5; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
body.theme-light .hdr-dd-item  { color: #444444; }
body.theme-light .hdr-dd-item:hover { background: #f2f2f2; color: #1a1a1a; }
body.theme-light .hdr-dd-sep   { background: #e5e5e5; }
body.theme-light .hdr-dd-label { color: #aaaaaa; }
body.theme-light .fmt-btn      { color: #666666; }
body.theme-light .fmt-btn:hover { background: #f2f2f2; color: #1a1a1a; }
body.theme-light .fmt-btn.active { background: rgba(95,111,46,.15); color: #5f6f2e; }
body.theme-light .fmt-sep      { background: #e5e5e5; }
body.theme-light .fmt-view-group { background: #ebebeb; }
body.theme-light .fmt-view-group .fmt-btn.active { background: #5f6f2e; color: #fff; }
body.theme-light .fmt-view-group .fmt-btn.active:hover { background: #4a5723; }
body.theme-light .fmt-dropdown { background: #ffffff; border-color: #e5e5e5; }
body.theme-light .fmt-dd-item  { color: #444444; }
body.theme-light .fmt-dd-item:hover { background: #f2f2f2; color: #1a1a1a; }
body.theme-light .fmt-dd-arrow { border-left-color: #e5e5e5; }
body.theme-light #toolbar-drive-dot { background: #aaaaaa; }
body.theme-light .tw-tip { background: #1a1a1a; color: #ffffff; border-color: #444444; }
body.theme-light #title-input { background: #ffffff; border-color: #5f6f2e; color: #1a1a1a; }
body.theme-light #tb-title { color: #666666; }
body.theme-light #tb-title:hover { color: #1a1a1a; }
body.theme-light #divider         { background: #e5e5e5; }
body.theme-light #statusbar { background: #ffffff; border-top-color: #e5e5e5; color: #666666; }
body.theme-light #find-replace-bar { background: #ffffff; border-bottom-color: #e5e5e5; }
body.theme-light #find-replace-bar input { background: #ffffff; border-color: #e5e5e5; color: #1a1a1a; }
body.theme-light #find-replace-bar button { background: #f2f2f2; border-color: #e5e5e5; color: #666666; }
body.theme-light #preview-pane code { background: #f2f2f2; }
body.theme-light #preview-pane pre  { background: #f5f5f5; }
body.theme-light #focus-wysiwyg code { background: #f2f2f2; }
body.theme-light #focus-wysiwyg pre  { background: #f5f5f5; }
body.theme-light .hdr-dd-item svg { color: #aaaaaa; }
body.theme-light .modal-search { background: #ffffff; }
body.theme-light .modal-input  { background: #ffffff; }
body.theme-light .btn-secondary { background: #efefef; }

/* ── iPad / tablet (portrait, Split View, Slide Over) ── */
@media (max-width: 1024px) {
  /* Safe areas for iPadOS — always apply on touch devices */
  #header-bar { padding-top: env(safe-area-inset-top); }
  #statusbar  { padding-bottom: env(safe-area-inset-bottom); }
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  /* Touch-friendly targets on tablet (Apple HIG: 44pt minimum) */
  .hdr-btn { width: 44px; height: 44px; font-size: 16px; }
  .hdr-btn svg { width: 18px; height: 18px; }
  #header-bar { height: 48px; gap: 2px; }

  .fmt-btn { min-width: 44px; height: 40px; font-size: 15px; }
  .fmt-btn svg { width: 16px; height: 16px; }
  .fmt-dd-arrow { height: 40px; min-width: 20px; }
  #format-bar { height: 44px; gap: 2px; }

  .hdr-dd-item { padding: 10px 14px; font-size: 14px; }
  .fmt-dd-item { padding: 8px 12px; font-size: 14px; }

  /* Prevent text selection lag on touch */
  #editor { -webkit-user-select: text; }
}

/* ── Phone / narrow windows (iPad Slide Over, Split View 1/3) ── */
@media (max-width: 700px) {

  #header-bar {
    padding-top: env(safe-area-inset-top);
    height: calc(44px + env(safe-area-inset-top));
    padding: 0 8px;
    gap: 4px;
  }
  #statusbar {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--status-h) + env(safe-area-inset-bottom));
  }


  /* Shrink the filename area and center it */
  .hdr-center {
    position: static;
    transform: none;
    flex: 1;
    min-width: 0;
    max-width: none;
    justify-content: center;
  }
  #tb-title { max-width: 40vw; font-size: 12px; }
  #title-input { max-width: 40vw; font-size: 12px; }
  .hdr-doc-icon { display: none; }

  /* Header icon buttons: 36px touch targets */
  .hdr-btn { width: 36px; height: 36px; }

  /* Format bar: scroll horizontally, no wrapping, good touch targets */
  #format-bar {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    gap: 2px;
    padding: 0 6px;
  }
  #format-bar::-webkit-scrollbar { display: none; }
  .fmt-btn { min-width: 38px; height: 36px; }
  .fmt-dd-arrow { height: 36px; }
  .fmt-sep { margin: 0 3px; }
  .fmt-view-group .fmt-btn { height: 30px; min-width: 32px; }

  /* Divider: no drag-resize on touch */
  #divider { display: none !important; }

  /* Editor / preview: full width each when shown */
  #editor-pane, #preview-wrapper { min-width: 0; }
  #line-numbers { display: none; }
  #editor { padding: 14px 16px; font-size: 15px; }
  #preview-pane { padding: 14px 16px; }

  .zoom-controls { bottom: 8px; right: 8px; }

  /* Status bar */
  #statusbar { gap: 10px; padding: 0 10px; font-size: 10px; }
  #cursor-pos { display: none; }

  /* Find & Replace bar */
  #find-replace-bar.visible { flex-wrap: wrap; row-gap: 6px; }
  #find-replace-bar input { width: 120px; flex: 1; min-width: 90px; }
}

/* Extra-narrow phones (iPhone SE) */
@media (max-width: 380px) {
  .hdr-center { display: none; }
}

/* Mobile-specific improvements: tap targets, keyboard handling, editor/preview toggle */
@media (max-width: 768px) {
  /* Show editor/preview toggle button on mobile */
  #editor-preview-toggle { display: inline-flex !important; }

  /* Focus mode: use the full width on phones, 75% is too cramped there */
  #focus-wysiwyg { width: 100%; padding: 0 20px; }

  /* Focus mode exit button: make it larger and more prominent on mobile */
  #focus-exit-btn {
    width: 56px;
    height: 56px;
    bottom: 20px;
    right: 20px;
    font-size: 28px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  /* Handle on-screen keyboard by adjusting layout */
  body.keyboard-visible #header-bar {
    position: sticky;
    z-index: 100;
  }

  /* Prevent layout shift when keyboard opens */
  body.keyboard-visible {
    height: 100vh;
    overflow: hidden;
  }

  /* Editor/preview toggle: ensure button is touch-friendly */
  #editor-preview-toggle {
    min-width: 44px;
    min-height: 44px;
  }

  /* Mobile pane hiding via class .mobile-hide-preview or .mobile-hide-editor */
  body.mobile-editor-only #preview-wrapper {
    display: none;
  }

  body.mobile-editor-only #editor-pane {
    width: 100%;
  }

  body.mobile-preview-only #editor-pane {
    display: none;
  }

  body.mobile-preview-only #preview-wrapper {
    width: 100%;
  }
}

/* ── Auth overlay — blocks UI until signed in ── */
#auth-overlay {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,.55);
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#auth-overlay.hidden { display: none; }

.auth-card {
  background: #ffffff;
  border-radius: 14px;
  padding: 36px 32px 28px;
  width: 380px;
  max-width: 94vw;
  box-shadow: 0 24px 64px rgba(0,0,0,.28);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-logo {
  font-size: 22px;
  font-weight: 700;
  color: #111111;
  letter-spacing: -.5px;
  text-align: center;
}

.auth-tagline {
  font-size: 13px;
  color: #666666;
  text-align: center;
  margin-top: -4px;
}

.auth-error {
  background: rgba(207,34,46,.08);
  color: #cf222e;
  border: 1px solid rgba(207,34,46,.2);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #aaaaaa;
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e0e0e0;
}

.auth-google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 9px 16px;
  background: #ffffff;
  border: 1px solid #dadce0;
  border-radius: 6px;
  color: #3c4043;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
.auth-google-btn:hover { background: #f8f9fa; box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.auth-google-btn:disabled { opacity: .6; cursor: default; }

.auth-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.auth-link {
  background: none;
  border: none;
  color: #5f6f2e;
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  padding: 0;
  line-height: 1.4;
}
.auth-link:hover { text-decoration: underline; }

/* ── v3.27.0: folders, context menu, command palette ─────────────────────── */
.sb-head-actions { display: flex; align-items: center; gap: 2px; }
.sb-head-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--text2);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: .6;
  transition: opacity 120ms, background 120ms;
}
.sb-head-btn:hover { opacity: 1; background: var(--bg3); }

.sidebar-item[data-type="folder"] .sb-icon { color: var(--accent); }
.sidebar-item[data-type="folder"] .sidebar-item-title { font-weight: 500; }
.sb-empty-folder {
  font-size: 11.5px;
  color: var(--text2);
  opacity: .7;
  padding: 3px 8px;
  user-select: none;
}
.sb-rename-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 2px 4px;
  margin: 2px 4px 2px 0;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.sidebar-item.ctx-target { outline: 1px solid var(--accent); outline-offset: -1px; }

.move-option-path {
  margin-left: auto;
  padding-left: 10px;
  font-size: 11px;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 45%;
}
.trash-item-count { margin-left: 6px; font-size: 11px; color: var(--text2); }
.trash-item-name svg { vertical-align: -2px; color: var(--accent); }

/* Context menu */
.ctx-menu {
  position: fixed;
  z-index: 1100;
  min-width: 190px;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .28);
}
.ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 6px 10px;
  border-radius: 5px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.ctx-item:hover,
.ctx-item:focus { background: var(--bg3); outline: none; }
.ctx-item:disabled { opacity: .4; cursor: default; }
.ctx-danger { color: var(--red); }
.ctx-sep { height: 1px; margin: 4px 2px; background: var(--border); }

/* Command palette */
.palette-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, .35);
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 12px 0;
}
.palette-backdrop.open { display: flex; }
.palette {
  width: min(640px, 100%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .35);
  overflow: hidden;
}
#palette-input {
  width: 100%;
  box-sizing: border-box;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  padding: 14px 16px;
  outline: none;
}
#palette-list { overflow-y: auto; padding: 4px; }
.palette-section {
  padding: 8px 10px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text2);
  user-select: none;
}
.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
}
.palette-item.selected { background: var(--accent); color: #fff; }
.palette-icon { width: 16px; text-align: center; flex-shrink: 0; opacity: .75; display: flex; align-items: center; justify-content: center; }
.palette-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-meta { font-size: 11.5px; opacity: .65; white-space: nowrap; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
.palette-empty { padding: 18px 12px; text-align: center; font-size: 13px; color: var(--text2); }
.palette-foot {
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text2);
  user-select: none;
}
@media (max-width: 600px) {
  .palette-backdrop { padding-top: 6vh; }
  .palette-foot { display: none; }
}
