/* ═══════════════════════════════════════════════════════════
   VERBO v0.5 — STYLESHEET
   Aesthetic: warm dark editorial, typewriter-inspired
   ═══════════════════════════════════════════════════════════ */

/* ── Design tokens ──────────────────────────────────────── */
:root {
  --kbd-h:       0px;    /* updated by JS when mobile keyboard opens */
  --bg:          #111010;
  --surface:     #1a1918;
  --surface2:    #242220;
  --surface3:    #2e2c2a;
  --border:      #2e2c2a;
  --text:        #f0ece4;
  --text-muted:  #7a7570;
  --text-dim:    #3c3a38;
  --accent:      #e8a020;
  --accent-hov:  #f4b030;
  --accent-dim:  rgba(232, 160, 32, 0.12);
  --blue:        #5aabff;
  --green:       #8fb97a;
  --purple:      #b48ef2;
  --red:         #e85520;

  --header-h:    44px;
  --tabbar-h:    32px;
  --status-h:    26px;
  --sidebar-w:   240px;

  --font-editor: ui-monospace, 'Cascadia Code', 'Source Code Pro',
                 Menlo, Consolas, 'Courier New', monospace;
  --font-prose:  Georgia, 'Book Antiqua', Palatino, 'Times New Roman', serif;
  --font-ui:     system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --radius:      6px;
  --ease:        0.15s ease;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html { height: 100%; height: 100dvh; overflow: hidden; }

body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ── App shell ───────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

/* ── Header ──────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: var(--header-h);
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 20;
}

@supports (padding: env(safe-area-inset-top)) {
  #header {
    padding-top: env(safe-area-inset-top);
    padding-left: calc(10px + env(safe-area-inset-left));
    padding-right: calc(10px + env(safe-area-inset-right));
    height: calc(var(--header-h) + env(safe-area-inset-top));
  }
}

.header-left   { display: flex; align-items: center; gap: 2px; min-width: 0; flex: 1 1 0; }
.header-center { display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.header-right  { display: flex; align-items: center; justify-content: flex-end; flex: 1 1 0; }

.header-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

/* On very narrow screens, drop the centred view-toggle — the FAB takes over. */
@media (max-width: 520px) {
  .header-center { display: none; }
}

/* ── Icon buttons ────────────────────────────────────────── */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: none;
  border: none;
  color: var(--text-muted);
  border-radius: var(--radius);
  transition: color var(--ease), background var(--ease);
  flex-shrink: 0;
}
.icon-btn:hover  { color: var(--text); background: var(--surface2); }
.icon-btn:active { background: var(--surface3); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.icon-btn-sm {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: none;
  border: none;
  color: var(--text-muted);
  border-radius: 4px;
  transition: color var(--ease), background var(--ease);
  flex-shrink: 0;
}
.icon-btn-sm:hover { color: var(--text); background: var(--surface2); }

/* ── View toggle ─────────────────────────────────────────── */
.view-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 1px;
}

.view-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 9px;
  border-radius: 4px;
  transition: color var(--ease), background var(--ease);
  font-family: var(--font-editor);
}
.view-btn:hover { color: var(--text); }
.view-btn.active {
  background: var(--accent);
  color: #111010;
}

/* ── Tab bar ─────────────────────────────────────────────── */
#tabbar {
  display: flex;
  align-items: stretch;
  height: var(--tabbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  scrollbar-width: none;
}
#tabbar::-webkit-scrollbar { display: none; }
#tabbar:empty { display: none; }

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px 0 12px;
  max-width: 220px;
  min-width: 90px;
  height: 100%;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-editor);
  font-size: 12px;
  border: none;
  border-right: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
  transition: color var(--ease), background var(--ease);
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--surface2); }
.tab.active {
  color: var(--text);
  background: var(--bg);
}
.tab.active::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
}

.tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  text-align: left;
}

.tab-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.tab-close {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--ease), background var(--ease);
}
.tab:hover .tab-close,
.tab.active .tab-close { opacity: 1; }
.tab-close:hover { background: var(--surface3); color: var(--text); }

/* ── Main (sidebar + workspace) ──────────────────────────── */
#main {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-root {
  font-family: var(--font-editor);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.file-tree::-webkit-scrollbar { width: 6px; }
.file-tree::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.tree-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 0;
  color: var(--text-muted);
  font-family: var(--font-editor);
  font-size: 12px;
  cursor: pointer;
  transition: color var(--ease), background var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
  -webkit-user-select: none;
}
.tree-item:hover { color: var(--text); background: var(--surface2); }
.tree-item.active {
  color: var(--accent);
  background: var(--surface2);
}

.tree-item .tree-caret {
  width: 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 10px;
  flex-shrink: 0;
}
.tree-item .tree-icon {
  width: 14px;
  font-size: 12px;
  flex-shrink: 0;
  color: var(--text-dim);
}
.tree-item.dir .tree-icon { color: var(--accent); }
.tree-item.file .tree-icon { color: var(--text-muted); }

.tree-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Hide sidebar on narrow screens (< 720px) — toggle via JS */
@media (max-width: 720px) {
  #sidebar {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    z-index: 30;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
}

/* ── Workspace ───────────────────────────────────────────── */
#workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}

#workspace.mode-split { flex-direction: column; }

@media (orientation: landscape) and (min-width: 720px) {
  #workspace.mode-split { flex-direction: row; }
}

#workspace.mode-write #preview-pane,
#workspace.mode-write #pane-divider { display: none; }
#workspace.mode-read  #editor-pane,
#workspace.mode-read  #pane-divider { display: none; }

.pane {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.pane-divider {
  background: var(--border);
  flex-shrink: 0;
  height: 1px;
  width: 100%;
}

@media (orientation: landscape) and (min-width: 720px) {
  #workspace.mode-split .pane-divider {
    width: 1px;
    height: auto;
  }
}

/* ── CodeMirror 6 host ───────────────────────────────────── */
#editor-host {
  height: 100%;
  width: 100%;
}

.cm-editor {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-editor);
  font-size: 15px;
  line-height: 1.75;
}

.cm-editor.cm-focused { outline: none; }

.cm-scroller {
  font-family: var(--font-editor) !important;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  -webkit-overflow-scrolling: touch;
}
.cm-scroller::-webkit-scrollbar { width: 6px; height: 6px; }
.cm-scroller::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.cm-gutters {
  background: var(--bg) !important;
  border-right: 1px solid var(--border) !important;
  color: var(--text-dim) !important;
}
.cm-lineNumbers .cm-gutterElement { padding: 0 10px 0 8px; color: var(--text-dim); }
.cm-activeLineGutter { background: transparent !important; color: var(--text-muted) !important; }
.cm-activeLine { background: rgba(255,255,255,0.015) !important; }

.cm-content {
  caret-color: var(--accent);
  padding: 16px 0;
}

.cm-cursor, .cm-dropCursor { border-left-color: var(--accent) !important; border-left-width: 2px !important; }

.cm-selectionBackground,
.cm-editor.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground {
  background: var(--accent-dim) !important;
}

.cm-line { padding-left: 14px !important; padding-right: 14px !important; }

/* ── Preview pane ────────────────────────────────────────── */
#preview-pane { background: var(--bg); overflow: hidden; }

#preview-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 24px 22px 48px;
  padding-left: max(22px, calc(22px + env(safe-area-inset-left)));
  padding-right: max(22px, calc(22px + env(safe-area-inset-right)));
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#preview-scroll::-webkit-scrollbar { width: 6px; }
#preview-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Prose (markdown preview) ────────────────────────────── */
.prose {
  font-family: var(--font-prose);
  font-size: 16px;
  line-height: 1.82;
  color: var(--text);
  max-width: 680px;
  margin: 0 auto;
  word-wrap: break-word;
}

.prose h1 { font-size: 1.72em; font-weight: 700; margin: 0 0 0.5em; color: var(--accent); line-height: 1.2; }
.prose h2 { font-size: 1.35em; font-weight: 700; margin: 1.6em 0 0.5em; line-height: 1.3; }
.prose h3 { font-size: 1.12em; font-weight: 700; margin: 1.3em 0 0.4em; line-height: 1.35; }
.prose h4, .prose h5, .prose h6 {
  font-size: 1em; font-weight: 700; margin: 1.1em 0 0.3em; color: var(--text-muted);
}

.prose p { margin: 0 0 1em; }
.prose strong { font-weight: 700; }
.prose em { font-style: italic; }
.prose del { text-decoration: line-through; color: var(--text-muted); }

.prose a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
.prose a:hover { color: var(--accent-hov); }

.prose code {
  font-family: var(--font-editor);
  font-size: 0.84em;
  background: var(--surface2);
  color: var(--accent);
  padding: 2px 5px;
  border-radius: 3px;
}

.prose pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 1.1em 0;
  font-size: 13px;
  line-height: 1.6;
}
.prose pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: inherit;
}

.prose blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.1em 0;
  padding: 0.1em 0 0.1em 16px;
  color: var(--text-muted);
  font-style: italic;
}

.prose ul, .prose ol { margin: 0.5em 0 1em 1.6em; }
.prose li { margin: 0.25em 0; }
.prose li::marker { color: var(--accent); }

.prose hr { border: none; border-top: 1px solid var(--border); margin: 2.2em 0; }

.prose img { max-width: 100%; border-radius: var(--radius); display: block; }

.prose table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.1em 0;
  font-size: 0.9em;
  font-family: var(--font-editor);
}
.prose th, .prose td {
  border: 1px solid var(--border);
  padding: 7px 12px;
  text-align: left;
}
.prose th { background: var(--surface); font-weight: 700; color: var(--text-muted); }
.prose tr:hover td { background: var(--surface); }

.prose input[type="checkbox"] { accent-color: var(--accent); margin-right: 6px; }

/* Mermaid rendered diagrams */
.prose .mermaid-diagram {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 1.1em 0;
  overflow-x: auto;
  text-align: center;
}
.prose .mermaid-diagram svg { max-width: 100%; height: auto; }
.prose .mermaid-error {
  background: rgba(232, 85, 32, 0.08);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 1.1em 0;
  color: var(--red);
  font-family: var(--font-editor);
  font-size: 12px;
}

/* ── Syntax highlighting (highlight.js tokens mapped to theme) ── */
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-name { color: var(--accent); }
.hljs-string, .hljs-attr { color: var(--green); }
.hljs-number, .hljs-literal { color: var(--purple); }
.hljs-comment, .hljs-quote { color: var(--text-muted); font-style: italic; }
.hljs-title, .hljs-section, .hljs-function { color: var(--blue); }
.hljs-variable, .hljs-template-variable { color: var(--text); }
.hljs-tag, .hljs-meta { color: var(--text-muted); }
.hljs-type, .hljs-params { color: var(--purple); }

/* ── CSV preview ─────────────────────────────────────────── */
.csv-table {
  border-collapse: collapse;
  font-family: var(--font-editor);
  font-size: 13px;
  color: var(--text);
  margin: 0 auto;
  white-space: nowrap;
}
.csv-table th, .csv-table td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
  vertical-align: top;
}
.csv-table tbody tr:nth-child(even) td { background: var(--surface); }
.csv-table tbody tr:hover td           { background: var(--surface2); }
.csv-th {
  position: sticky; top: 0;
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  z-index: 1;
  transition: color var(--ease), background var(--ease);
}
.csv-th:hover { color: var(--text); background: var(--surface2); }
.csv-th.sorted { color: var(--accent); }
.csv-sort-ind {
  display: inline-block;
  min-width: 0.9em;
  font-size: 0.75em;
  color: var(--accent);
  vertical-align: middle;
}

#preview-scroll:has(.csv-table) {
  overflow-x: auto;
  padding: 16px 16px 40px;
}

.empty-preview {
  color: var(--text-muted);
  text-align: center;
  margin-top: 2em;
  font-family: var(--font-editor);
  font-size: 13px;
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  position: absolute;
  inset: var(--header-h) 0 var(--status-h) 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 5;
  pointer-events: auto;
}
.empty-inner { text-align: center; padding: 0 24px; max-width: 420px; }
.empty-logo {
  font-family: var(--font-prose);
  font-size: 44px;
  letter-spacing: -0.02em;
  color: var(--accent);
  margin-bottom: 12px;
}
.empty-hint {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 22px;
}
.empty-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.empty-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-family: var(--font-editor);
  font-size: 12px;
  letter-spacing: 0.04em;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
}
.empty-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* ── Status bar ──────────────────────────────────────────── */
#statusbar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--status-h);
  padding: 0 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-family: var(--font-editor);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

@supports (padding: env(safe-area-inset-bottom)) {
  #statusbar {
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: calc(14px + env(safe-area-inset-left));
    padding-right: calc(14px + env(safe-area-inset-right));
    height: calc(var(--status-h) + env(safe-area-inset-bottom));
  }
}

.stat-mode {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
}
.stat-sep  { color: var(--text-dim); }
.stat-save {
  color: var(--text-dim);
  min-width: 40px;
  text-align: right;
  margin-left: auto;
}
.stat-save.saving { color: var(--accent); }
.stat-save.saved  { color: var(--green); }
.stat-save.error  { color: var(--red); }

#statusbar:has(.install-btn:not([hidden])) .stat-save { margin-left: 0; }

.install-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  padding: 3px 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  font-family: var(--font-editor);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
}
.install-btn:hover { background: var(--accent-dim); border-color: var(--accent); }

/* ── Drag-drop overlay ───────────────────────────────────── */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(17, 16, 16, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  pointer-events: none;
  border: 3px dashed var(--accent);
  border-radius: 4px;
  animation: drop-in 0.12s ease;
}
/* Ensure the HTML `hidden` attribute always beats display overrides above. */
[hidden] { display: none !important; }
@keyframes drop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.drop-message {
  color: var(--accent);
  font-family: var(--font-editor);
  font-size: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 700;
}

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: absolute;
  bottom: calc(var(--status-h) + 14px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-ui);
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  animation: toast-in 0.18s ease;
}
.toast.error { border-color: var(--red); color: var(--red); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Tablet / desktop adjustments ────────────────────────── */
@media (min-width: 600px) {
  .prose { font-size: 17px; }
}
@media (min-width: 900px) {
  .prose { font-size: 18px; }
}

/* ═══════════════════════════════════════════════════════════
   ── Settings / menu panel (top-right dropdown) ──────────────
   ═══════════════════════════════════════════════════════════ */
.menu-panel {
  position: absolute;
  top: calc(var(--header-h) + 6px);
  right: 8px;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.55);
  padding: 6px 0;
  z-index: 50;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  animation: menu-in 0.12s ease-out;
}
@supports (top: env(safe-area-inset-top)) {
  .menu-panel {
    top: calc(var(--header-h) + env(safe-area-inset-top) + 6px);
    right: max(8px, env(safe-area-inset-right));
  }
}
@keyframes menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.menu-section {
  padding: 6px 0;
}
.menu-heading {
  padding: 4px 14px 6px;
  color: var(--text-muted);
  font-family: var(--font-editor);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 14px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background var(--ease);
}
.menu-row:hover { background: var(--surface2); }
.menu-row > span { color: var(--text); }

.menu-toggle {
  appearance: none;
  -webkit-appearance: none;
  width: 32px;
  height: 18px;
  background: var(--surface3);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background var(--ease);
  flex-shrink: 0;
}
.menu-toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform var(--ease), background var(--ease);
}
.menu-toggle:checked { background: var(--accent-dim); }
.menu-toggle:checked::after {
  transform: translateX(14px);
  background: var(--accent);
}

.menu-seg {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px;
  gap: 1px;
}
.menu-seg button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-editor);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 3px;
  transition: color var(--ease), background var(--ease);
}
.menu-seg button:hover { color: var(--text); }
.menu-seg button.active {
  background: var(--accent);
  color: #111010;
}

.menu-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 8px 14px;
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}
.menu-item:hover { background: var(--surface2); color: var(--accent); }
.menu-item.danger { color: var(--red); }
.menu-item.danger:hover { background: rgba(232, 85, 32, 0.08); color: var(--red); }

.menu-about {
  padding: 6px 14px 4px;
  color: var(--text-dim);
  font-family: var(--font-editor);
  font-size: 10.5px;
  letter-spacing: 0.04em;
}

/* ═══════════════════════════════════════════════════════════
   ── Floating action buttons (FAB) — bottom-right thumb zone ──
   ═══════════════════════════════════════════════════════════ */
.fab {
  position: absolute;
  right: 18px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  transition: background var(--ease), border-color var(--ease), transform var(--ease);
}
.fab:hover  { background: var(--surface3); border-color: var(--accent); }
.fab:active { transform: scale(0.94); }

.fab-view   { bottom: calc(var(--status-h) + 18px + var(--kbd-h)); }
.fab-search { bottom: calc(var(--status-h) + 76px + var(--kbd-h)); }

@supports (bottom: env(safe-area-inset-bottom)) {
  .fab-view {
    bottom: calc(var(--status-h) + env(safe-area-inset-bottom) + 18px + var(--kbd-h));
    right: max(18px, env(safe-area-inset-right));
  }
  .fab-search {
    bottom: calc(var(--status-h) + env(safe-area-inset-bottom) + 76px + var(--kbd-h));
    right: max(18px, env(safe-area-inset-right));
  }
}

/* View FAB lives only on small screens — desktop uses the header view-toggle. */
@media (min-width: 720px) {
  .fab-view { display: none; }
}

/* ═══════════════════════════════════════════════════════════
   ── Side navigation panel ────────────────────────────────────
   ═══════════════════════════════════════════════════════════ */
:root {
  --side-panel-w: 176px;
  --side-pull-w:   28px;
}

.side-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 44;
  animation: fade-in 0.18s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.side-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--side-panel-w);
  display: flex;
  flex-direction: row;
  transform: translateX(calc(var(--side-panel-w) - var(--side-pull-w)));
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 45;
  will-change: transform;
}
.side-panel.open {
  transform: translateX(0);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.55);
}

/* Pull tab — the always-visible ear on the left edge */
.side-pull {
  flex-shrink: 0;
  width: var(--side-pull-w);
  align-self: center;
  height: 68px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 10px 0 0 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
  margin-top: auto;
  margin-bottom: auto;
  /* Prevent the panel's own transition from visually moving the tab */
  position: relative;
}
.side-pull:hover  { background: var(--surface3); color: var(--accent); border-color: var(--accent); }
.side-pull:active { background: var(--surface3); }
.side-panel.open .side-pull { border-color: var(--border); color: var(--text-muted); }

/* Inner panel body */
.side-panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

/* Vertical action buttons at top */
.side-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0 4px;
  gap: 2px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.side-act-sep {
  width: 24px;
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}
.side-icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}
.side-icon-btn:hover { background: var(--surface2); color: var(--text); }
.side-icon-btn:active { background: var(--surface3); }

/* Vertical tab list */
.side-tabbar {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 4px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--surface3) transparent;
}
.side-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 8px 0 6px;
  gap: 4px;
  min-height: 60px;
  transition: background var(--ease), border-color var(--ease);
  color: var(--text-muted);
}
.side-tab:hover { background: var(--surface2); color: var(--text); }
.side-tab.active {
  background: var(--accent-dim);
  border-color: rgba(232, 160, 32, 0.25);
  color: var(--accent);
}
.side-tab-name {
  writing-mode: vertical-rl;
  transform: rotate(180deg);  /* read bottom-to-top = natural right-edge orientation */
  font-size: 11px;
  font-family: var(--font-ui);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 110px;
  line-height: 1.3;
  flex: 1;
  text-align: center;
}
.side-tab-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.side-tab-close {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  color: var(--text-muted);
  transition: opacity var(--ease), background var(--ease);
  font-size: 10px;
  cursor: pointer;
  padding: 0;
}
.side-tab:hover .side-tab-close { opacity: 1; }
.side-tab-close:hover { background: var(--surface3); color: var(--text); }

.side-spacer { flex: 1; min-height: 8px; max-height: 24px; }

/* Bottom area: menu button */
.side-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── side-panel-mode: hide the top header + tabbar ─────────── */
#app.side-panel-mode #header  { display: none; }
#app.side-panel-mode #tabbar  { display: none; }
#app.side-panel-mode .empty-state { top: 0; }
#app.side-panel-mode .menu-panel  { top: 8px; }
@supports (top: env(safe-area-inset-top)) {
  #app.side-panel-mode .menu-panel { top: calc(env(safe-area-inset-top) + 8px); }
}
/* FABs shift up slightly to avoid statusbar overlap — already handled by --kbd-h */
/* In side-panel-mode on mobile, FABs move to left of panel when panel is open */
#app.side-panel-mode .fab-search,
#app.side-panel-mode .fab-view {
  right: calc(var(--side-pull-w) + 14px);
  transition: right 0.22s cubic-bezier(0.4, 0, 0.2, 1),
              background var(--ease), border-color var(--ease), transform var(--ease);
}
#app.side-panel-mode.panel-open .fab-search,
#app.side-panel-mode.panel-open .fab-view {
  right: calc(var(--side-panel-w) + 14px);
}

/* ═══════════════════════════════════════════════════════════
   ── Search / find-replace panel ──────────────────────────────
   ═══════════════════════════════════════════════════════════ */
.search-panel {
  position: absolute;
  top: 8px;
  right: 8px;
  width: min(360px, calc(100vw - 16px));
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  z-index: 55;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: search-in 0.1s ease-out;
}

@keyframes search-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.sp-row {
  display: flex;
  align-items: center;
  gap: 3px;
}

.sp-input {
  flex: 1;
  min-width: 0;
  height: 28px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-editor);
  outline: none;
  transition: border-color var(--ease);
}
.sp-input:focus { border-color: var(--accent); }
.sp-input::placeholder { color: var(--text-muted); }
/* Remove browser-native search clear button */
.sp-input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

.sp-count {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 0 2px;
  min-width: 28px;
  text-align: right;
}
.sp-count.no-match { color: var(--red); }

.sp-opt {
  height: 26px;
  min-width: 26px;
  padding: 0 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-editor);
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}
.sp-opt:hover { background: var(--surface3); color: var(--text); }
.sp-opt[aria-pressed="true"] {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.sp-nav {
  height: 26px;
  width: 26px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--ease), color var(--ease);
}
.sp-nav:hover { background: var(--surface3); color: var(--text); }

.sp-close-btn {
  height: 26px;
  width: 26px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 1px;
  transition: background var(--ease), color var(--ease);
}
.sp-close-btn:hover { background: var(--surface3); color: var(--text); }

.sp-action {
  height: 26px;
  padding: 0 10px;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  transition: background var(--ease), border-color var(--ease);
}
.sp-action:hover { background: var(--surface); border-color: var(--accent); color: var(--accent); }

/* ═══════════════════════════════════════════════════════════
   ── Markdown formatting toolbar ─────────────────────────────
   ═══════════════════════════════════════════════════════════ */
.md-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}
.md-toolbar-inner {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.md-toolbar-inner::-webkit-scrollbar { display: none; }

.fmt-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 28px;
  padding: 0 7px;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  font-family: var(--font-editor);
  font-size: 12px;
  font-weight: 600;
  transition: color var(--ease), background var(--ease);
  flex-shrink: 0;
}
.fmt-btn:hover  { color: var(--accent); background: var(--surface2); }
.fmt-btn:active { background: var(--surface3); }
.fmt-btn b, .fmt-btn i, .fmt-btn s, .fmt-btn code {
  font-family: inherit;
  font-size: inherit;
}
.fmt-btn code { color: inherit; background: none; padding: 0; font-size: 11px; }

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