/* =============== CSS Variables =============== */
:root {
  --brand: #1b3a5c;
  --brand-light: #2a5a8c;
  --brand-lighter: #e8f0f8;
  --accent: #d4a029;
  --bg: #f5f2ed;
  --bg-editor: #ffffff;
  --bg-toolbar: #ffffff;
  --bg-sidebar: #fafaf7;
  --text: #2c2c2c;
  --text-muted: #7a7a7a;
  --text-toolbar: #444;
  --border: #e0ddd6;
  --border-light: #ece9e3;
  --hover: #f0ede7;
  --active-btn: #dce8f5;
  --shadow: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --radius: 0px;
  --sidebar-w: 320px;
  --header-h: 52px;
  --font-ui: 'Bricolage Grotesque', sans-serif;
  --font-editor: 'Source Serif 4', Georgia, serif;
  --note-active: #e8f0f8;
  --note-hover: #f0ede7;
  --scrollbar-thumb: #c5c0b8;
  --scrollbar-track: transparent;
  --placeholder: #b0a99e;
  --danger: #c0392b;
  --danger-hover: #e74c3c;
  --success: #27ae60;
  --editor-max-w: 816px;
  --line-opacity: 0.13;
  --page-h: 1056px;
}

html.dark {
  --brand: #5b9bd5;
  --brand-light: #7ab5e8;
  --brand-lighter: #1e2d3d;
  --accent: #e8b84d;
  --bg: #1a1a1f;
  --bg-editor: #22222a;
  --bg-toolbar: #2a2a32;
  --bg-sidebar: #1e1e25;
  --text: #e0ddd6;
  --text-muted: #8a8a8a;
  --text-toolbar: #c0bdb6;
  --border: #3a3a42;
  --border-light: #33333b;
  --hover: #33333b;
  --active-btn: #2a3a4d;
  --shadow: 0 1px 4px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
  --note-active: #2a3a4d;
  --note-hover: #33333b;
  --scrollbar-thumb: #4a4a52;
  --placeholder: #5a5a62;
  --danger: #e74c3c;
  --danger-hover: #ff6b6b;
  --line-opacity: 0.18;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* =============== Layout =============== */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* =============== Sidebar (Notes) =============== */
.sidebar {
  width: var(--sidebar-w);
  max-width: 85vw;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-md);
}
.sidebar.left { left: 0; }
.sidebar.open { transform: translateX(0); }

.panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.28s ease;
}
.panel-overlay.visible { display: block; opacity: 1; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--brand);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  border-radius: 0;
  transition: all 0.15s;
}
.panel-close:hover { color: var(--text); background: var(--hover); }

.sidebar-body { flex: 1; overflow-y: auto; padding: 16px; }

.btn-new-note {
  width: 100%;
  padding: 12px 16px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s;
}
.btn-new-note:hover { background: var(--brand-light); }

.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Stats */
.stats-section { margin-top: 20px; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; text-align: center; }
.stat-card { background: var(--hover); border-radius: var(--radius); padding: 10px 6px; }
.stat-card .stat-value { font-size: 20px; font-weight: 700; color: var(--brand); }
.stat-card .stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Notes section */
.notes-section { margin-top: 20px; }
.notes-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.notes-count {
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 0;
}

.search-box { position: relative; margin-bottom: 12px; }
.search-box input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.search-box input:focus { border-color: var(--brand); }
.search-box i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 13px;
}

.notes-list { display: flex; flex-direction: column; gap: 4px; }

.note-item {
  padding: 10px 12px;
  padding-left: 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
  border: 1px solid transparent;
  border-left: 4px solid var(--border-light);
}
.note-item:hover { background: var(--note-hover); }
.note-item.active { background: var(--note-active); border-color: var(--brand); border-left-color: var(--brand); }

.note-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  cursor: pointer;
}
.note-item-title:hover { text-decoration: underline; text-decoration-style: dotted; }
.note-item-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.note-item-actions {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.note-item:hover .note-item-actions { opacity: 1; }

.note-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 5px;
  border-radius: 0;
  transition: all 0.12s;
}
.note-action-btn:hover { color: var(--brand); background: var(--hover); }
.note-action-btn.danger:hover { color: var(--danger); }

.pinned-icon { color: var(--accent); font-size: 10px; margin-left: 4px; }

/* =============== Appearance Panel (right side) =============== */
.appear-panel {
  width: 340px;
  max-width: 90vw;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-md);
}
.appear-panel.open { transform: translateX(0); }

.appear-body { flex: 1; overflow-y: auto; padding: 16px; }

.appear-section { margin-bottom: 22px; }
.appear-section:last-child { margin-bottom: 0; }

/* Paper Presets Grid */
.paper-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.paper-preset {
  background: none;
  border: 2px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  transition: all 0.15s;
  text-align: center;
}
.paper-preset:hover { border-color: var(--brand-light); }
.paper-preset.active { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(27,58,92,0.2); }
html.dark .paper-preset.active { box-shadow: 0 0 0 2px rgba(91,155,213,0.3); }

.preset-preview {
  width: 100%;
  height: 56px;
  position: relative;
}

.preset-label {
  padding: 5px 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  font-family: var(--font-ui);
  background: var(--bg);
}

/* Preset preview backgrounds */
.prev-blank { background: #fff; }
.prev-cream { background: #faf5e8; }
.prev-lined {
  background: #fff;
  background-image: repeating-linear-gradient(to bottom, transparent 0px, transparent 10px, rgba(100,130,180,0.22) 10px, rgba(100,130,180,0.22) 11px);
}
.prev-dot {
  background: #fff;
  background-image: radial-gradient(circle, rgba(100,130,180,0.3) 1px, transparent 1px);
  background-size: 10px 10px;
}
.prev-graph {
  background: #fff;
  background-image:
    linear-gradient(rgba(100,130,180,0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100,130,180,0.18) 1px, transparent 1px);
  background-size: 10px 10px;
}
.prev-parchment {
  background: #f0e6d0;
  background-image:
    radial-gradient(ellipse at 30% 40%, rgba(160,120,60,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 70%, rgba(140,100,50,0.1) 0%, transparent 50%);
}
.prev-dark-journal { background: #2a2a32; }
.prev-rose {
  background: #fef0f0;
  background-image: repeating-linear-gradient(to bottom, transparent 0px, transparent 13px, rgba(200,120,120,0.18) 13px, rgba(200,120,120,0.18) 14px);
}
.prev-sky {
  background: #f0f4fe;
  background-image: radial-gradient(circle, rgba(100,130,200,0.2) 1px, transparent 1px);
  background-size: 10px 10px;
}

html.dark .prev-blank { background: #22222a; }
html.dark .prev-cream { background: #2a2720; }
html.dark .prev-lined { background: #22222a; background-image: repeating-linear-gradient(to bottom, transparent 0px, transparent 10px, rgba(140,170,220,0.15) 10px, rgba(140,170,220,0.15) 11px); }
html.dark .prev-dot { background: #22222a; background-image: radial-gradient(circle, rgba(140,170,220,0.22) 1px, transparent 1px); background-size: 10px 10px; }
html.dark .prev-graph { background: #22222a; background-image: linear-gradient(rgba(140,170,220,0.12) 1px, transparent 1px), linear-gradient(90deg, rgba(140,170,220,0.12) 1px, transparent 1px); background-size: 10px 10px; }
html.dark .prev-parchment { background: #2a2518; background-image: radial-gradient(ellipse at 30% 40%, rgba(200,160,80,0.08) 0%, transparent 60%), radial-gradient(ellipse at 70% 70%, rgba(180,140,70,0.06) 0%, transparent 50%); }
html.dark .prev-dark-journal { background: #18181e; }
html.dark .prev-rose { background: #2a2225; background-image: repeating-linear-gradient(to bottom, transparent 0px, transparent 13px, rgba(220,150,150,0.12) 13px, rgba(220,150,150,0.12) 14px); }
html.dark .prev-sky { background: #22252a; background-image: radial-gradient(circle, rgba(140,170,220,0.15) 1px, transparent 1px); background-size: 10px 10px; }

/* Paper Color Swatches */
.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 0;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(27,58,92,0.25);
}
html.dark .swatch.active { box-shadow: 0 0 0 2px rgba(91,155,213,0.35); }
.swatch.active::after {
  content: '\f00c';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 11px;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
}
.swatch.swatch-dark.active::after { color: #ccc; }

/* Line Style Selector */
.line-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.line-opt {
  background: none;
  border: 2px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  transition: all 0.15s;
  text-align: center;
}
.line-opt:hover { border-color: var(--brand-light); }
.line-opt.active { border-color: var(--brand); }

.line-prev {
  width: 100%;
  height: 36px;
  background: var(--bg);
}
.line-prev-none { /* blank */ }
.line-prev-college {
  background-image: repeating-linear-gradient(to bottom, transparent 0px, transparent 8px, rgba(100,130,180,0.25) 8px, rgba(100,130,180,0.25) 9px);
}
.line-prev-wide {
  background-image: repeating-linear-gradient(to bottom, transparent 0px, transparent 11px, rgba(100,130,180,0.25) 11px, rgba(100,130,180,0.25) 12px);
}
.line-prev-dot {
  background-image: radial-gradient(circle, rgba(100,130,180,0.35) 1px, transparent 1px);
  background-size: 8px 8px;
}
.line-prev-graph {
  background-image:
    linear-gradient(rgba(100,130,180,0.2) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100,130,180,0.2) 1px, transparent 1px);
  background-size: 8px 8px;
}

.line-opt-label {
  padding: 3px 2px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  font-family: var(--font-ui);
}

/* Font Selector */
.font-options { display: flex; flex-direction: column; gap: 6px; }

.font-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.12s;
  font-size: 15px;
  color: var(--text);
}
.font-opt:hover { border-color: var(--brand-light); background: var(--hover); }
.font-opt.active { border-color: var(--brand); background: var(--active-btn); }
.font-opt i { color: var(--text-muted); width: 16px; text-align: center; font-size: 12px; }

/* Width Toggle */
.width-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.width-btn {
  flex: 1;
  padding: 9px 8px;
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
  border-right: 1px solid var(--border);
}
.width-btn:last-child { border-right: none; }
.width-btn:hover { background: var(--hover); color: var(--text); }
.width-btn.active { background: var(--brand); color: #fff; }

/* Per-note indicator in sidebar */
.note-paper-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 0;
  margin-right: 4px;
  vertical-align: middle;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}

/* =============== Main Area =============== */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
}

/* Header */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.brand {
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.3px;
  white-space: nowrap;
}
.brand span { color: var(--accent); }

.header-right { display: flex; align-items: center; gap: 4px; }

.header-btn {
  background: none;
  border: none;
  color: var(--text-toolbar);
  cursor: pointer;
  font-size: 16px;
  padding: 8px;
  border-radius: var(--radius);
  transition: all 0.12s;
}
.header-btn:hover { background: var(--hover); color: var(--text); }

.brand-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 auto;
}
.header-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 5px 10px;
  border-radius: 0;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.header-nav a:hover {
  color: var(--brand);
  background: var(--hover);
}
.header-nav-sep {
  color: var(--border);
  font-size: 12px;
  user-select: none;
}

/* =============== Toolbar =============== */
.toolbar-wrap {
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.toolbar-rows {
  overflow: hidden;
  transition: max-height 0.25s ease;
  max-height: 200px;
}
.toolbar-rows.collapsed { max-height: 0; }
.toolbar-row {
  display: flex;
  align-items: center;
  padding: 4px 10px;
  gap: 2px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.toolbar-row::-webkit-scrollbar { display: none; }
.toolbar-row + .toolbar-row { border-top: 1px solid var(--border-light); }

.toolbar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0;
  height: 18px;
  border: none;
  background: var(--bg-toolbar);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  transition: background 0.12s, color 0.12s;
  border-top: 1px solid var(--border-light);
}
.toolbar-toggle:hover { background: var(--hover); color: var(--text); }
.toolbar-toggle i { transition: transform 0.25s ease; }
.toolbar-rows.collapsed + .toolbar-toggle i { transform: rotate(180deg); }

.tb {
  background: none;
  border: none;
  color: var(--text-toolbar);
  cursor: pointer;
  font-size: 14px;
  padding: 7px 8px;
  border-radius: 0;
  transition: all 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.tb:hover { background: var(--hover); color: var(--text); }
.tb.active { background: var(--active-btn); color: var(--brand); }

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

.tb-select, .color-pick-wrap, .dropdown-wrap { flex-shrink: 0; }

.tb-select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  height: 32px;
  min-width: 80px;
  transition: border-color 0.15s;
}
.tb-select:focus { border-color: var(--brand); }
.tb-select option { background: var(--bg); color: var(--text); }
.tb-select-sm { min-width: 56px; }

.color-pick-wrap { position: relative; display: flex; align-items: center; }
.color-pick-wrap input[type="color"] {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 5px;
  border: none;
  padding: 0;
  cursor: pointer;
  opacity: 0.8;
  background: transparent;
}
.color-pick-wrap input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-pick-wrap input[type="color"]::-webkit-color-swatch { border: none; border-radius: 0; }

.dropdown-wrap { position: relative; }
.dropdown-menu {
  display: none;
  position: fixed;
  background: var(--bg-toolbar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 1000;
  min-width: 160px;
  padding: 4px 0;
  animation: dropIn 0.15s ease;
}
.dropdown-menu.show { display: block; }

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

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-ui);
  transition: background 0.1s;
}
.dropdown-item:hover { background: var(--hover); }
.dropdown-item i { width: 16px; text-align: center; color: var(--text-muted); }

/* Caret button for split dropdown */
.tb-caret {
  padding: 0 4px;
  min-width: 18px;
  margin-left: -2px;
  font-size: 10px;
}

/* =============== Editor =============== */
.editor-container {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
  display: flex;
  justify-content: center;
  position: relative;
}

#editor {
  width: 100%;
  max-width: var(--editor-max-w);
  min-height: 1056px;
  border: 1px solid var(--border-light);
  border-radius: 0;
  padding: 72px 96px;
  font-family: var(--font-editor);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  outline: none;
  box-shadow: var(--shadow), 0 0 0 1px rgba(0,0,0,0.02);
  word-wrap: break-word;
  overflow-wrap: break-word;
  transition: background-color 0.35s ease, max-width 0.3s ease, box-shadow 0.3s ease;
  background-color: var(--bg-editor);
  background-image: none;
  background-position: 0 72px;
  background-attachment: local;
}

#editor:empty::before {
  content: attr(data-placeholder);
  color: var(--placeholder);
  pointer-events: none;
  font-style: italic;
}

#editor blockquote {
  border-left: 3px solid var(--brand);
  padding-left: 16px;
  margin: 12px 0;
  color: var(--text-muted);
  font-style: italic;
}
#editor pre, #editor code {
  background: rgba(128,128,128,0.1);
  border-radius: 0;
  padding: 2px 6px;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 14px;
}
#editor pre { padding: 12px 16px; margin: 12px 0; overflow-x: auto; }

#editor img {
  max-width: 100%;
  height: auto;
  border-radius: 0;
  margin: 8px 0;
  display: block;
}

/* =============== Editor Tables =============== */
#editor table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: inherit;
}
#editor td, #editor th {
  border: 1px solid var(--border);
  padding: 8px 12px;
  min-width: 40px;
  vertical-align: top;
}
#editor th {
  background: var(--hover);
  font-weight: 600;
}

/* =============== Status Bar =============== */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: var(--bg-toolbar);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
  gap: 8px;
}
.status-left { display: flex; align-items: center; gap: 16px; flex-shrink: 1; min-width: 0; overflow: hidden; }
.status-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.status-item { display: flex; align-items: center; gap: 4px; white-space: nowrap; }

.filename-input {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  outline: none;
  width: 200px;
  max-width: 250px;
  transition: border-color 0.15s;
}
.filename-input:focus { border-color: var(--brand); }

.save-as-btn {
  padding: 5px 14px;
  border: none;
  border-radius: 0;
  background: var(--brand);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
}
.save-as-btn:hover { background: var(--brand-light); }

/* =============== Drag-Drop Overlay =============== */
.drag-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(27, 58, 92, 0.12);
  border: 3px dashed var(--brand);
  border-radius: 0;
  z-index: 20;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drag-overlay.visible {
  display: flex;
}
.drag-overlay-text {
  background: var(--bg-toolbar);
  color: var(--brand);
  padding: 16px 28px;
  border-radius: 0;
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
}
.drag-overlay-text i { font-size: 22px; }

/* =============== Fullscreen =============== */
.app-layout.fullscreen-mode .app-header,
.app-layout.fullscreen-mode .toolbar-wrap,
.app-layout.fullscreen-mode .status-bar { display: none; }
.app-layout.fullscreen-mode .editor-container { padding: 0; }
.app-layout.fullscreen-mode #editor {
  max-width: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
  min-height: 100vh;
}
.fullscreen-exit-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 50;
  background: var(--bg-toolbar);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: none;
  align-items: center;
  gap: 6px;
  font-family: var(--font-ui);
  font-weight: 600;
  transition: background 0.12s;
}
.fullscreen-exit-btn:hover { background: var(--hover); }
.app-layout.fullscreen-mode ~ .fullscreen-exit-btn { display: flex; }

/* =============== Modal =============== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.show { display: flex; animation: fadeIn 0.15s ease; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--bg-toolbar);
  border-radius: 0;
  box-shadow: var(--shadow-md);
  max-width: 400px;
  width: 100%;
  padding: 24px;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 10px; color: var(--text); }
.modal-body { font-size: 14px; color: var(--text-muted); margin-bottom: 18px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.modal-btn {
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
}
.modal-btn-secondary { background: var(--hover); color: var(--text); }
.modal-btn-secondary:hover { background: var(--border); }
.modal-btn-primary { background: var(--brand); color: #fff; }
.modal-btn-primary:hover { opacity: 0.9; }
.modal-btn-danger { background: var(--danger); color: #fff; }
.modal-btn-danger:hover { background: var(--danger-hover); }

/* =============== Toast =============== */
.toast-container {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--brand);
  color: #fff;
  padding: 10px 20px;
  border-radius: 0;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2s forwards;
  pointer-events: auto;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-8px); } }

/* =============== Find Bar =============== */
.find-bar {
  display: none;
  flex-direction: column;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.find-bar.open { display: flex; animation: slideDown 0.15s ease; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.find-row {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  gap: 6px;
}
.find-row + .find-row { padding-top: 0; }

.find-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  outline: none;
}
.find-input:focus { border-color: var(--brand); }
.find-input::placeholder { color: var(--placeholder); }

.find-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 44px;
  text-align: center;
}

.find-btn {
  background: none;
  border: none;
  color: var(--text-toolbar);
  cursor: pointer;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 0;
  transition: all 0.1s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.find-btn:hover { background: var(--hover); color: var(--text); }
.find-btn.active { background: var(--active-btn); color: var(--brand); }

.replace-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.1s;
  flex-shrink: 0;
  white-space: nowrap;
}
.replace-btn:hover { border-color: var(--brand); background: var(--hover); }

.find-icon {
  color: var(--text-muted);
  font-size: 13px;
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}

/* Find Highlights */
#editor mark.find-hl {
  background: rgba(255, 213, 0, 0.4);
  color: inherit;
  padding: 1px 0;
  border-radius: 0;
}
#editor mark.find-hl.find-current {
  background: rgba(255, 140, 0, 0.65);
  box-shadow: 0 0 0 2px rgba(255, 140, 0, 0.3);
}
html.dark #editor mark.find-hl {
  background: rgba(255, 213, 0, 0.25);
}
html.dark #editor mark.find-hl.find-current {
  background: rgba(255, 160, 0, 0.45);
  box-shadow: 0 0 0 2px rgba(255, 160, 0, 0.2);
}

/* Hyperlink modal extras */
.modal-field { margin-bottom: 12px; }
.modal-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.modal-field input, .modal-field select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  outline: none;
}
.modal-field input:focus, .modal-field select:focus { border-color: var(--brand); }

/* Two-column modal fields for table dialog */
.modal-field-row {
  display: flex;
  gap: 12px;
}
.modal-field-row .modal-field { flex: 1; }

/* Export modal format options */
.export-formats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.export-format-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
}
.export-format-btn:hover { border-color: var(--brand-light); background: var(--hover); }
.export-format-btn.active { border-color: var(--brand); background: var(--active-btn); }
.export-format-btn i { font-size: 16px; color: var(--text-muted); width: 20px; text-align: center; }
.export-format-btn.active i { color: var(--brand); }

/* =============== Responsive =============== */
@media (max-width: 640px) {
  .brand { font-size: 15px; }
  .header-nav a { font-size: 11px; padding: 4px 6px; }
  .header-nav-sep { font-size: 10px; }
  .brand-logo { width: 22px; height: 22px; }
  #editor { padding: 48px 32px; font-size: 16px; min-height: 700px; background-position: 0 48px; }
  .editor-container { padding: 12px; }
  .toolbar-row { padding: 3px 6px; gap: 1px; }
  .tb { padding: 6px 6px; min-width: 28px; height: 28px; font-size: 13px; }
  .tb-select { font-size: 12px; min-width: 65px; height: 28px; padding: 3px 6px; }
  .tb-select-sm { min-width: 46px; }
  .tb-sep { margin: 0 2px; height: 18px; }
  .paper-presets { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .line-options { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .filename-input { width: 130px; font-size: 12px; }
  .status-left .status-item:nth-child(n+3) { display: none; }
}

@media (max-width: 480px) {
  .header-nav { display: none; }
}

@media (max-width: 380px) {
  .tb-select { min-width: 55px; }
  .editor-container { padding: 8px; }
  #editor { padding: 36px 20px; min-height: 500px; background-position: 0 36px; }
  .filename-input { width: 100px; }
}

@media print {
  @page { size: letter; margin: 1in; }
  .toolbar-wrap, .app-header, .status-bar, .sidebar, .appear-panel, .fullscreen-exit-btn, .find-bar, .panel-overlay, .toast-container { display: none !important; }
  html, body { height: auto !important; overflow: visible !important; }
  .app-layout { display: block !important; height: auto !important; overflow: visible !important; }
  .main-area { display: block !important; height: auto !important; }
  .editor-container { overflow: visible !important; padding: 0 !important; height: auto !important; flex: none !important; }
  #editor {
    max-width: 100% !important;
    width: 100% !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    min-height: auto !important;
    background-image: none !important;
    background-color: transparent !important;
  }
  #editor p, #editor div, #editor h1, #editor h2, #editor h3, #editor h4, #editor h5, #editor h6 {
    page-break-inside: avoid;
  }
  #editor table { page-break-inside: auto; }
  #editor tr { page-break-inside: avoid; }
  #editor img { page-break-inside: avoid; max-width: 100% !important; }
}