/* =========================================================================
   FOLIO — Markdown to PDF Publishing Studio
   Design system: Platinum Cool Slate (light) / Obsidian Cool Zinc (dark)
   Brand accent: Violet → Blue gradient (publishing mark)
   ========================================================================= */
:root {
  /* Light Theme: Platinum Cool Slate */
  --bg-app: #f0f2f5;
  --bg-panel: #ffffff;
  --bg-subtle: #f8fafc;
  --border-color: #e2e8f0;
  --border-focus: #0f172a;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent: #0f172a;
  --accent-hover: #1e293b;
  --accent-subtle: #f1f5f9;
  --code-bg: #f1f5f9;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-doc: 0 10px 30px -4px rgba(15, 23, 42, 0.08), 0 4px 12px -2px rgba(15, 23, 42, 0.04);

  /* Brand accent (publishing mark) */
  --brand-1: #7c3aed;
  --brand-2: #2563eb;
  --brand-grad: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  --brand-ring: rgba(124, 58, 237, 0.35);

  /* Document Engine Variables */
  --doc-font-family: 'Sora', -apple-system, BlinkMacSystemFont, sans-serif;
  --doc-font-size: 11pt;
  --doc-line-height: 1.65;
  --doc-text-align: justify;
  --doc-heading-color: #020617;
  --doc-text-color: #0f172a;
  --doc-bg-color: #ffffff;
  --doc-accent-color: #0f172a;
  --doc-padding-x: 20mm;
  --doc-padding-y: 18mm;
  --doc-page-width: 210mm;
  --doc-page-min-height: 297mm;
  --doc-paragraph-spacing: 0.9em;
}

[data-theme="dark"] {
  /* Dark Theme: Obsidian Cool Zinc */
  --bg-app: #090b10;
  --bg-panel: #11141d;
  --bg-subtle: #171b26;
  --border-color: #232838;
  --border-focus: #f8fafc;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #f8fafc;
  --accent-hover: #e2e8f0;
  --accent-subtle: #1e2433;
  --code-bg: #191e2b;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-doc: 0 14px 40px -4px rgba(0, 0, 0, 0.5), 0 4px 12px -2px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: 'Plus Jakarta Sans', 'Sora', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--brand-1);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  background: var(--accent);
  color: var(--bg-panel);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  z-index: 999;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 8px; }

/* App Shell */
.app-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

/* Header Navigation */
.header-bar {
  height: 52px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  flex-shrink: 0;
  z-index: 30;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  gap: 8px;
}

.header-group {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

/* Brand lockup */
.app-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 16px;
  font-family: 'Bricolage Grotesque', 'Sora', -apple-system, sans-serif;
  letter-spacing: -0.4px;
  color: var(--text-main);
  padding-right: 12px;
  border-right: 1px solid var(--border-color);
  margin-right: 4px;
  user-select: none;
  text-decoration: none;
  flex-shrink: 0;
}

.app-logo img {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: block;
}

.app-logo .brand-tagline {
  display: none;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.2px;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

.doc-title-field {
  border: none;
  background: transparent;
  color: var(--text-main);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px;
  font-weight: 600;
  min-width: 60px;
  max-width: 220px;
  padding: 6px 8px;
  border-radius: 6px;
  outline: none;
}
.doc-title-field:hover { background: var(--accent-subtle); }
.doc-title-field:focus { background: var(--accent-subtle); box-shadow: 0 0 0 2px var(--brand-ring); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-main);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--accent-subtle);
  border-color: #cbd5e1;
}

[data-theme="dark"] .btn:hover {
  border-color: #334155;
}

.btn:active {
  transform: scale(0.97);
}

.btn-icon-only {
  width: 32px;
  height: 32px;
  padding: 0;
  position: relative;
}

.btn-icon-only.active {
  background: var(--accent-subtle);
  border-color: var(--border-focus);
  color: var(--text-main);
}

.btn-primary {
  background: var(--brand-grad);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  filter: brightness(1.08);
  color: #ffffff;
  border-color: transparent;
}

.btn svg {
  width: 15px;
  height: 15px;
  stroke-width: 2;
  stroke: currentColor;
  fill: none;
}

.btn-dropdown-wrap { position: relative; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 190px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: var(--shadow-doc);
  padding: 6px;
  z-index: 60;
  display: none;
  flex-direction: column;
  gap: 2px;
}
.dropdown-menu.open { display: flex; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  background: none;
  border: none;
  text-align: left;
  width: 100%;
  font-family: inherit;
}
.dropdown-item:hover { background: var(--accent-subtle); }
.dropdown-item svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; flex-shrink: 0; }
.dropdown-item .kbd { margin-left: auto; font-size: 10.5px; color: var(--text-muted); }

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

/* Notification badge for save status pulses */
.badge-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #10b981;
  display: inline-block;
}

/* =========================================================================
   TOOLBAR (formatting)
   ========================================================================= */
.format-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s ease, color 0.12s ease;
}
.tb-btn:hover { background: var(--accent-subtle); color: var(--text-main); }
.tb-btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; }
.tb-sep { width: 1px; height: 18px; background: var(--border-color); margin: 0 4px; flex-shrink: 0; }

/* Find & Replace bar */
.find-bar {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.find-bar.open { display: flex; }
.find-bar input {
  height: 28px;
  padding: 0 8px;
  font-size: 12.5px;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  background: var(--bg-panel);
  color: var(--text-main);
  font-family: inherit;
  width: 140px;
  outline: none;
}
.find-bar input:focus { border-color: var(--brand-1); }
.find-bar .find-count { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.find-bar .btn { height: 28px; padding: 0 8px; font-size: 11.5px; }

/* Main Split Workspace */
.workspace-area {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Left Editor Panel */
.editor-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  min-width: 0;
  transition: flex 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
  position: relative;
}

.editor-section.collapsed {
  flex: 0 0 0 !important;
  overflow: hidden;
  border-right: none;
  opacity: 0;
  pointer-events: none;
}

.editor-body {
  display: flex;
  flex: 1;
  position: relative;
  overflow: hidden;
}

.editor-gutter {
  width: 44px;
  padding: 14px 0;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  text-align: right;
  user-select: none;
  overflow: hidden;
  border-right: 1px solid var(--border-color);
  flex-shrink: 0;
  opacity: 0.7;
}

.editor-gutter div { padding-right: 10px; }
.editor-gutter div.active-line { color: var(--brand-1); opacity: 1; font-weight: 600; }

.editor-textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 14px 18px;
  font-family: 'JetBrains Mono', Consolas, Monaco, monospace;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-main);
  background: var(--bg-panel);
  tab-size: 2;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.editor-textarea.drag-over {
  background: var(--accent-subtle);
}

.drop-hint {
  position: absolute;
  inset: 8px;
  border: 2px dashed var(--brand-1);
  border-radius: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  background: rgba(124, 58, 237, 0.06);
  color: var(--brand-1);
  font-weight: 600;
  font-size: 13px;
  z-index: 20;
  pointer-events: none;
}
.drop-hint.show { display: flex; }
.drop-hint svg { width: 28px; height: 28px; stroke: currentColor; fill: none; stroke-width: 1.6; }

.editor-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 28px;
  padding: 0 14px;
  background: var(--bg-subtle);
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
  flex-shrink: 0;
  gap: 10px;
}
.editor-bottom-bar .stats-group { display: flex; gap: 12px; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Right Preview Panel */
.preview-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  overflow-y: auto;
  overflow-x: auto;
  padding: 32px 20px;
  align-items: center;
  min-width: 0;
  transition: flex 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.preview-section.collapsed {
  flex: 0 0 0 !important;
  overflow: hidden;
  opacity: 0;
  padding: 0;
  pointer-events: none;
}

.preview-toolbar {
  position: sticky;
  top: 0;
  align-self: stretch;
  display: flex;
  justify-content: center;
  margin: -32px -20px 16px -20px;
  padding: 8px 20px;
  background: linear-gradient(to bottom, var(--bg-app) 65%, transparent);
  z-index: 10;
  pointer-events: none;
}
.zoom-control {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 3px;
  box-shadow: var(--shadow-sm);
  pointer-events: auto;
}
.zoom-control button {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--text-main);
  border-radius: 5px; cursor: pointer;
}
.zoom-control button:hover { background: var(--accent-subtle); }
.zoom-control button svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2.2; }
.zoom-control .zoom-value { font-size: 11.5px; font-weight: 600; color: var(--text-muted); width: 42px; text-align: center; user-select: none; }

.doc-page-scale-wrap {
  transform-origin: top center;
}

/* Printable Page Simulator */
.doc-page {
  width: var(--doc-page-width);
  min-height: var(--doc-page-min-height);
  padding: var(--doc-padding-y) var(--doc-padding-x);
  background: var(--doc-bg-color);
  box-shadow: var(--shadow-doc);
  border-radius: 3px;
  color: var(--doc-text-color);
  font-family: var(--doc-font-family);
  font-size: var(--doc-font-size);
  line-height: var(--doc-line-height);
  word-wrap: break-word;
  transition: width 0.15s ease, padding 0.15s ease, font-family 0.1s ease;
  position: relative;
}

/* Cover / title page */
.doc-cover-page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  min-height: calc(var(--doc-page-min-height) - (var(--doc-padding-y) * 2));
  padding-bottom: var(--doc-padding-y);
  page-break-after: always;
  break-after: page;
  border-bottom: 2px dashed var(--border-color);
  margin-bottom: 2.2em;
}
.doc-cover-eyebrow {
  font-size: 0.78em;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--doc-accent-color);
  margin-bottom: 1.4em;
  opacity: 0.75;
}
.doc-cover-title {
  font-size: 3em;
  font-weight: 700;
  line-height: 1.1;
  color: var(--doc-heading-color);
  letter-spacing: -1px;
  margin-bottom: 0.4em;
}
.doc-cover-subtitle {
  font-size: 1.25em;
  font-weight: 400;
  color: var(--text-muted);
  margin-bottom: 2.2em;
  max-width: 80%;
}
.doc-cover-meta {
  font-size: 0.85em;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  border-top: 1px solid var(--border-color);
  padding-top: 1em;
}
.doc-cover-meta strong { color: var(--doc-text-color); font-weight: 600; }

/* Table of Contents block */
.doc-toc {
  margin: 0 0 2.2em 0;
  padding: 1.2em 1.4em;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-subtle);
  page-break-inside: avoid;
  break-inside: avoid;
}
.doc-toc-title {
  font-size: 0.78em;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.8em;
}
.doc-toc ol { list-style: none; padding-left: 0; margin: 0; }
.doc-toc li { margin-bottom: 0.5em; font-size: 0.95em; }
.doc-toc a {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-decoration: none;
  color: var(--doc-text-color);
  border-bottom: 1px dotted var(--border-color);
  padding-bottom: 2px;
}
.doc-toc .toc-lvl-2 { padding-left: 1.2em; opacity: 0.9; }
.doc-toc .toc-lvl-3 { padding-left: 2.4em; opacity: 0.75; font-size: 0.9em; }

/* Rendered Markdown Elements */
.doc-rendered { width: 100%; }

.doc-rendered h1,
.doc-rendered h2,
.doc-rendered h3,
.doc-rendered h4,
.doc-rendered h5,
.doc-rendered h6 {
  color: var(--doc-heading-color);
  font-weight: 600;
  line-height: 1.25;
  margin-top: 1.35em;
  margin-bottom: 0.45em;
  page-break-after: avoid;
  break-after: avoid;
  scroll-margin-top: 40px;
}

.doc-rendered h1:first-child,
.doc-rendered h2:first-child { margin-top: 0; }
.doc-rendered h1 { font-size: 2.1em; border-bottom: 1px solid #e2e8f0; padding-bottom: 0.25em; }
.doc-rendered h2 { font-size: 1.45em; border-bottom: 1px solid #f1f5f9; padding-bottom: 0.2em; }
.doc-rendered h3 { font-size: 1.2em; }
.doc-rendered h4 { font-size: 1.05em; }
.doc-rendered h5 { font-size: 0.95em; }
.doc-rendered h6 { font-size: 0.85em; opacity: 0.8; }

.doc-rendered p {
  margin-top: 0;
  margin-bottom: var(--doc-paragraph-spacing);
  text-align: var(--doc-text-align);
  text-justify: inter-word;
}

.doc-rendered.dropcap > p:first-of-type::first-letter {
  float: left;
  font-size: 3.4em;
  line-height: 0.82;
  font-weight: 700;
  padding: 0.05em 0.08em 0 0;
  color: var(--doc-accent-color);
}

.doc-rendered ul,
.doc-rendered ol {
  margin-top: 0;
  margin-bottom: var(--doc-paragraph-spacing);
  padding-left: 1.6em;
}

.doc-rendered li { margin-bottom: 0.3em; }
.doc-rendered li > p { margin-bottom: 0.2em; }

.doc-rendered blockquote {
  margin: 1.1em 0;
  padding: 0.6em 1.1em;
  color: #334155;
  background: #f8fafc;
  border-left: 3.5px solid var(--doc-accent-color);
  border-radius: 0 4px 4px 0;
  page-break-inside: avoid;
  break-inside: avoid;
}
.doc-rendered blockquote p:last-child { margin-bottom: 0; }

.doc-rendered table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2em 0;
  font-size: 0.92em;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-rendered th,
.doc-rendered td {
  border: 1px solid #cbd5e1;
  padding: 8px 12px;
  text-align: left;
}

.doc-rendered th {
  background-color: #f1f5f9;
  font-weight: 600;
  color: var(--doc-heading-color);
}

.doc-rendered tr:nth-child(even) { background-color: #f8fafc; }

.doc-rendered code {
  font-family: 'JetBrains Mono', Consolas, Monaco, monospace;
  font-size: 0.88em;
  background: #f1f5f9;
  padding: 0.15em 0.4em;
  border-radius: 3px;
  color: #0f172a;
}

.doc-rendered pre {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 12px 16px;
  margin: 1.1em 0;
  overflow-x: auto;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-rendered pre code { background: transparent; padding: 0; border-radius: 0; font-size: 0.86em; line-height: 1.5; }

.doc-rendered hr { height: 1px; background-color: #e2e8f0; border: none; margin: 1.8em 0; }

.doc-rendered a { color: #2563eb; text-decoration: underline; text-underline-offset: 2.5px; }

.doc-rendered img { max-width: 100%; height: auto; border-radius: 4px; margin: 0.8em 0; page-break-inside: avoid; break-inside: avoid; }

/* Math Elements */
.math-block-wrapper { display: flex; justify-content: center; margin: 1.2em 0; page-break-inside: avoid; break-inside: avoid; overflow-x: auto; }
.katex-display { margin: 0 !important; text-align: center; }

/* Running footer (page number simulation for screen preview) */
.doc-footer-note {
  margin-top: 2.4em;
  padding-top: 0.8em;
  border-top: 1px solid var(--border-color);
  font-size: 0.72em;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* Slide-out Sidebar Drawer */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.sidebar-overlay.active { opacity: 1; pointer-events: auto; }

.settings-sidebar {
  position: fixed;
  top: 0;
  right: -360px;
  width: 340px;
  height: 100%;
  background: var(--bg-panel);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  z-index: 100;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border-color);
}
.settings-sidebar.open { transform: translateX(-360px); }

.sidebar-header {
  height: 52px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.sidebar-header h3 { font-size: 14px; font-weight: 600; color: var(--text-main); }

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.setting-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.setting-item { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.setting-item:last-child { margin-bottom: 0; }

.setting-label { font-size: 12.5px; font-weight: 500; color: var(--text-main); display: flex; justify-content: space-between; }

.setting-control {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  background: var(--bg-panel);
  color: var(--text-main);
  outline: none;
}

input.setting-control { appearance: auto; -webkit-appearance: auto; }

select.setting-control {
  background: var(--bg-panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat calc(100% - 10px) center;
  padding-right: 28px;
}

.setting-control:focus { border-color: var(--border-focus); }

.setting-row { display: flex; gap: 8px; }

.color-picker-input {
  width: 34px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-panel);
  cursor: pointer;
}

.setting-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0;
}
.setting-toggle-row .setting-label { margin: 0; }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border-color);
  border-radius: 999px;
  transition: 0.2s;
}
.switch-slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
  background: white; border-radius: 50%; transition: 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.switch input:checked + .switch-slider { background: var(--brand-grad); }
.switch input:checked + .switch-slider::before { transform: translateX(16px); }

.theme-preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.theme-preset-chip {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--bg-panel);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.theme-preset-chip:hover { border-color: var(--brand-1); }
.theme-preset-chip.active { border-color: var(--brand-1); box-shadow: 0 0 0 1px var(--brand-1); }
.theme-preset-chip .chip-title { font-size: 12px; font-weight: 600; color: var(--text-main); display: block; }
.theme-preset-chip .chip-sub { font-size: 10.5px; color: var(--text-muted); }

.sidebar-footer-links {
  padding: 14px 18px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.sidebar-footer-links a {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 0;
}
.sidebar-footer-links a:hover { color: var(--brand-1); }
.sidebar-footer-links svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }

/* Mobile Bottom Navigation Bar */
.mobile-tab-bar {
  display: none;
  height: 48px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  align-items: center;
  justify-content: space-around;
  flex-shrink: 0;
  z-index: 30;
}
.mobile-tab {
  flex: 1; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; font-weight: 500; color: var(--text-muted);
  background: none; border: none; cursor: pointer;
}
.mobile-tab.active { color: var(--brand-1); }
.mobile-tab svg { width: 18px; height: 18px; stroke-width: 2; stroke: currentColor; fill: none; }

.hidden-input { display: none; }

/* =========================================================================
   FOOTER CREDIT BAR (site-wide, "about the author")
   ========================================================================= */
.credit-bar {
  height: 34px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  flex-shrink: 0;
  z-index: 30;
  font-size: 11.5px;
  color: var(--text-muted);
  gap: 10px;
}
.credit-left {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
}
.credit-left .credit-name { font-weight: 600; color: var(--text-main); }
.credit-left .credit-dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.credit-tagline { display: none; }

.credit-socials {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.credit-socials a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease;
}
.credit-socials a:hover { color: #ffffff; background: var(--brand-grad); }
.credit-socials svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 1.9; }
.credit-socials .icon-fill svg { fill: currentColor; stroke: none; }
.credit-socials a:hover .icon-fill svg { fill: #ffffff; }

@media (min-width: 560px) {
  .credit-tagline { display: inline; }
}

/* Keyboard shortcuts modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-doc);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-color);
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-body { padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 10px; }
.kbd-row { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; }
.kbd-row .kbd-label { color: var(--text-main); }
.kbd-keys { display: flex; gap: 4px; }
.kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  background: var(--accent-subtle);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--text-main);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent);
  color: var(--bg-panel);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-doc);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2.2; }

/* Responsive Layout */
@media (max-width: 768px) {
  .header-bar { padding: 0 10px; }
  .btn-desktop-label { display: none; }
  .btn { padding: 0 8px; }
  .mobile-tab-bar { display: flex; }
  .app-logo .brand-tagline { display: none !important; }
  .doc-title-field { display: none; }
  .workspace-area { position: relative; }
  .editor-section, .preview-section { position: absolute; inset: 0; width: 100%; height: 100%; border: none; }
  .editor-section.mobile-hidden, .preview-section.mobile-hidden { display: none !important; }
  .preview-section { padding: 16px 10px; }
  .doc-page { width: 100% !important; min-height: auto; padding: 18px 16px !important; box-shadow: none; }
  .settings-sidebar { width: 85%; max-width: 320px; }
  .credit-tagline { display: none; }
  .credit-bar { padding: 0 10px; }
  .format-toolbar { padding: 5px 6px; }
}

@media (max-width: 420px) {
  .credit-left .credit-name { max-width: 90px; text-overflow: ellipsis; overflow: hidden; }
}

/* =========================================================================
   PRINT STYLESHEET (Clean Native PDF Generation)
   ========================================================================= */
@media print {
  html, body { height: auto !important; background: #ffffff !important; color: #000000 !important; overflow: visible !important; }

  .header-bar, .editor-section, .sidebar-overlay, .settings-sidebar, .mobile-tab-bar,
  .editor-gutter, .editor-bottom-bar, .format-toolbar, .find-bar, .preview-toolbar,
  .credit-bar, .modal-overlay, .toast {
    display: none !important;
  }

  .app-root, .workspace-area, .preview-section {
    display: block !important;
    height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #ffffff !important;
    overflow: visible !important;
  }

  .doc-page-scale-wrap { transform: none !important; }

  .doc-page {
    width: 100% !important;
    min-height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: #000000 !important;
  }

  h1, h2, h3, h4, h5, h6 { color: #000000 !important; page-break-after: avoid !important; break-after: avoid !important; }
  p, blockquote, table, pre, img, .math-block-wrapper { page-break-inside: avoid !important; break-inside: avoid !important; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}
