/* ==========================================================================
   DYNAMICWORK MD STUDIO - UNIVERSAL DESKTOP & MOBILE STYLESHEET (v2.0)
   Theme: Dynamicwork Rebrand 2026 (#0E0E0E / #E3791D / #004A2A) + Paper Light Mode
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Brand Accents */
  --orange: #e3791d;
  --orange-hover: #f38b30;
  --orange-soft: rgba(227, 121, 29, 0.15);
  --green: #004a2a;
  --green-bright: #12b86d;
  --green-soft: rgba(18, 184, 109, 0.15);
  --cyan: #38bdf8;
  --gold: #fbbf24;
  --red: #ef4444;

  /* Dark Studio Theme (Default) */
  --bg-app: #0e0e0e;
  --bg-header: rgba(18, 18, 18, 0.96);
  --bg-panel: #151515;
  --bg-surface: #181818;
  --bg-elevated: #222222;
  --bg-code: #111318;
  --bg-quote: rgba(227, 121, 29, 0.07);
  --bg-hashtag: rgba(56, 189, 248, 0.13);

  --text-main: #f3f4f6;
  --text-heading: #ffd89b;
  --text-h1: #ffffff;
  --text-strong: #ffffff;
  --text-muted: #a3a3a3;
  --text-dim: #737373;
  --text-hashtag: #7dd3fc;
  --text-inline-code: #fbbf24;

  --border-line: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(227, 121, 29, 0.45);
  --table-head-bg: #22252b;
  --table-row-alt: rgba(255, 255, 255, 0.025);
  --shadow-surface: 0 18px 46px rgba(0, 0, 0, 0.5);

  /* Dynamic Typography Controls */
  --reader-font-size: 17px;
  --reader-max-width: 920px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

/* ==================== PAPER LIGHT MODE ==================== */
html[data-theme="light"] {
  color-scheme: light;
  --bg-app: #efede8;
  --bg-header: rgba(255, 255, 255, 0.97);
  --bg-panel: #f8f7f4;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-code: #f4f6f9;
  --bg-quote: #fff8f1;
  --bg-hashtag: rgba(2, 132, 199, 0.12);

  --text-main: #1f2937;
  --text-heading: #9a3412;
  --text-h1: #111827;
  --text-strong: #0f172a;
  --text-muted: #4b5563;
  --text-dim: #6b7280;
  --text-hashtag: #0369a1;
  --text-inline-code: #b45309;

  --border-line: rgba(15, 23, 42, 0.15);
  --border-strong: rgba(227, 121, 29, 0.6);
  --table-head-bg: #f1f5f9;
  --table-row-alt: #f8fafc;
  --shadow-surface: 0 10px 32px rgba(15, 23, 42, 0.08);
}

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

[hidden] {
  display: none !important;
}

button {
  appearance: none;
  -webkit-appearance: none;
}

html, body {
  height: 100%;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: "Prompt", "Sarabun", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.mobile-only-ctrl,
.mobile-drawer-header,
.mobile-bottom-bar {
  display: none;
}

/* ==========================================================================
   1. TOP HEADER
   ========================================================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-line);
  flex-shrink: 0;
  flex-wrap: wrap;
}

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

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.brand-titles {
  min-width: 0;
}

.brand-titles h1 {
  font-family: "Sora", "Prompt", sans-serif;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.brand-full-sub {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.badge-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--orange-soft);
  color: var(--orange);
  border: 1px solid var(--border-strong);
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.brand-sub code {
  color: var(--text-inline-code);
  font-family: Consolas, monospace;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.file-title-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  padding: 3px 10px 3px 6px;
}

.star-doc-btn {
  background: transparent;
  border: none;
  font-size: 17px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
  transition: transform 0.15s ease, color 0.15s ease;
}

.star-doc-btn:hover {
  transform: scale(1.15);
  color: var(--gold);
}

.star-doc-btn.is-starred {
  color: var(--gold);
  text-shadow: 0 0 10px rgba(251, 191, 36, 0.45);
}

.doc-name-input {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  width: 185px;
  outline: none;
}

.doc-name-input:focus {
  color: var(--orange);
}

.font-control-group {
  display: inline-flex;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.font-scale-label {
  font-size: 12px;
  font-weight: 600;
  padding: 0 7px;
  color: var(--text-muted);
  min-width: 44px;
  text-align: center;
}

/* ==========================================================================
   2. BUTTONS & ACTION TOOLBAR
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  background: var(--bg-elevated);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--border-strong);
}

.btn-icon {
  padding: 4px 8px;
  border: none;
  background: transparent;
  font-weight: 700;
}

.btn-icon:hover {
  background: var(--orange-soft);
  color: var(--orange);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-primary {
  background: linear-gradient(135deg, #e3791d, #d06008);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(227, 121, 29, 0.32);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #f38b30, #e3791d);
  border-color: #ffd89b;
}

.btn-green,
.btn-install {
  background: linear-gradient(135deg, #076c40, #004a2a);
  color: #ffffff;
  border-color: rgba(18, 184, 109, 0.45);
  font-weight: 600;
}

.btn-green:hover,
.btn-install:hover {
  background: linear-gradient(135deg, #0b8751, #065c36);
}

.btn.is-active {
  background: var(--orange-soft);
  color: var(--orange);
  border-color: var(--border-strong);
}

html[data-theme="light"] .btn:not(.btn-primary):not(.btn-green):not(.btn-install):not(.is-active) {
  background-color: #ffffff;
  color: #1f2937;
  border-color: rgba(15, 23, 42, 0.18);
}

html[data-theme="light"] .btn-icon {
  background-color: transparent !important;
  color: #1f2937 !important;
  border: none !important;
}

.action-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-line);
  flex-shrink: 0;
  overflow-x: auto;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 7px;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border-line);
  flex-shrink: 0;
}

/* ==========================================================================
   3. WORKSPACE 3-COLUMN LAYOUT & SIDEBAR LIBRARY
   ========================================================================== */
.workspace-layout {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.left-sidebar {
  width: 310px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border-line);
  flex-shrink: 0;
}

.sidebar-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 4px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.sidebar-tab.is-active {
  color: var(--orange);
  border-bottom-color: var(--orange);
  background: var(--orange-soft);
}

.tab-count {
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-main);
}

.sidebar-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-search-wrap {
  padding: 10px;
  border-bottom: 1px solid var(--border-line);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.sidebar-search-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-line);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
}

.sidebar-search-input:focus {
  border-color: var(--orange);
}

.library-quick-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.library-pin-btn {
  flex: 1;
}

.toc-list,
.folder-file-list,
.library-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* TOC Items */
.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  padding: 6px 10px;
  border-radius: 0 6px 6px 0;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  transition: all 0.14s ease;
}

.toc-item:hover {
  background: var(--bg-elevated);
  color: var(--text-main);
}

.toc-item.is-active {
  border-left-color: var(--orange);
  background: var(--orange-soft);
  color: var(--text-strong);
  font-weight: 600;
}

.toc-level-1 { font-weight: 700; color: var(--text-main); }
.toc-level-2 { padding-left: 14px; }
.toc-level-3 { padding-left: 26px; font-size: 12px; }
.toc-level-4, .toc-level-5, .toc-level-6 { padding-left: 36px; font-size: 11.5px; }

html[data-theme="light"] .toc-item { color: #374151; }
html[data-theme="light"] .toc-level-1 { color: #111827; }
html[data-theme="light"] .toc-item.is-active { color: #9a3412; background-color: rgba(227, 121, 29, 0.16); }

/* Bookmarks & Recent Library Cards */
.lib-section {
  margin-bottom: 14px;
}

.lib-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 4px 6px 6px;
}

.lib-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lib-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 9px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease;
}

.lib-card:hover {
  border-color: var(--border-strong);
}

.lib-card.is-current {
  background: var(--orange-soft);
  border-color: var(--border-strong);
}

.lib-card-main {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  text-align: left;
  color: var(--text-main);
  font-family: inherit;
  cursor: pointer;
}

.lib-card-title {
  font-size: 12.5px;
  font-weight: 600;
  word-break: break-word;
  line-height: 1.35;
}

.lib-card-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.lib-progress-pill {
  font-size: 10px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--green-soft);
  color: var(--green-bright);
  font-weight: 600;
}

html[data-theme="light"] .lib-progress-pill {
  color: #047857;
}

.lib-card-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.lib-icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  padding: 3px 5px;
  border-radius: 5px;
  cursor: pointer;
}

.lib-icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.lib-icon-btn.is-starred {
  color: var(--gold);
}

/* Folder Pin Banner */
.folder-pin-banner {
  padding: 9px 10px;
  background: var(--orange-soft);
  border-bottom: 1px solid var(--border-strong);
}

.folder-pin-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.folder-pin-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-strong);
  word-break: break-all;
}

.folder-pin-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.file-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  margin-bottom: 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  cursor: pointer;
}

.file-item:hover {
  background: var(--bg-elevated);
  border-color: var(--border-line);
}

.file-item.is-active {
  background: var(--orange-soft);
  border-color: var(--border-strong);
}

.file-item-name {
  font-size: 13px;
  font-weight: 600;
  word-break: break-all;
}

.file-item-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-empty {
  padding: 14px 10px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}

/* ---- CENTER READER COLUMN ---- */
.reader-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.reader-subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 18px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-line);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.subbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.doc-stats {
  font-size: 12px;
  color: var(--text-muted);
}

.subbar-search {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  min-width: 250px;
}

.subbar-search:focus-within {
  border-color: var(--orange);
}

.doc-search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
  min-width: 130px;
}

.search-counter {
  font-size: 11.5px;
  color: var(--orange);
  font-weight: 600;
}

.search-nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 11px;
}

.search-nav-btn:hover {
  background: var(--orange-soft);
  color: var(--orange);
}

.usage-tip-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 18px;
  background: var(--orange-soft);
  border-bottom: 1px solid var(--border-strong);
  font-size: 12px;
  color: var(--text-main);
  flex-shrink: 0;
}

.usage-tip-text code {
  background: rgba(0, 0, 0, 0.25);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-inline-code);
}

html[data-theme="light"] .usage-tip-text code {
  background: rgba(255, 255, 255, 0.85);
}

.tip-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
}

.reader-scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 28px 24px 56px;
  scroll-behavior: smooth;
}

/* ==========================================================================
   4. RENDERED MARKDOWN SURFACE TYPOGRAPHY
   ========================================================================== */
.md-reader-surface {
  max-width: var(--reader-max-width);
  margin: 0 auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-lg);
  padding: 42px 50px;
  box-shadow: var(--shadow-surface);
  font-family: "Sarabun", "Prompt", sans-serif;
  font-size: var(--reader-font-size);
  line-height: 1.75;
  color: var(--text-main);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

body.wide-surface {
  --reader-max-width: 100%;
}

.md-heading {
  font-family: "Prompt", "Sarabun", sans-serif;
  color: var(--text-heading);
  line-height: 1.38;
  margin-top: 1.65em;
  margin-bottom: 0.6em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  scroll-margin-top: 20px;
}

.md-reader-surface > .md-heading:first-child {
  margin-top: 0;
}

.md-h1 {
  font-size: 1.8em;
  font-weight: 700;
  color: var(--text-h1);
  padding-bottom: 0.35em;
  border-bottom: 2px solid var(--border-strong);
}

.md-h2 {
  font-size: 1.4em;
  font-weight: 700;
  padding-bottom: 0.25em;
  border-bottom: 1px solid var(--border-line);
}

.md-h3 {
  font-size: 1.18em;
  font-weight: 600;
}

.md-h4, .md-h5, .md-h6 {
  font-size: 1.05em;
  font-weight: 600;
}

.md-p {
  margin-bottom: 0.92em;
}

.md-reader-surface strong {
  color: var(--text-strong);
  font-weight: 700;
}

.md-inline-code {
  font-family: Consolas, "JetBrains Mono", "Courier New", monospace;
  font-size: 0.88em;
  color: var(--text-inline-code);
  background: var(--bg-elevated);
  border: 1px solid var(--border-line);
  padding: 1px 6px;
  border-radius: 5px;
}

.md-link {
  color: var(--cyan);
  text-decoration: underline;
  text-underline-offset: 3px;
}

html[data-theme="light"] .md-link {
  color: #0284c7;
}

.md-hashtag {
  display: inline-block;
  color: var(--text-hashtag);
  background: var(--bg-hashtag);
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.94em;
}

.md-list {
  margin: 0.3em 0 1em 1.5em;
}

.md-list li {
  margin-bottom: 0.35em;
}

.md-task-list {
  list-style: none;
  margin-left: 0.3em;
}

.md-task-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--green-bright);
  vertical-align: middle;
  margin-right: 6px;
}

.md-task-item.is-checked {
  color: var(--text-muted);
}

.md-hr {
  border: none;
  border-top: 1px solid var(--border-line);
  margin: 1.8em 0;
}

.md-blockquote,
.md-alert {
  margin: 1em 0;
  padding: 12px 18px;
  border-left: 4px solid var(--orange);
  background: var(--bg-quote);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.md-alert-title {
  font-family: "Prompt", sans-serif;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.alert-note { border-left-color: #38bdf8; background: rgba(56, 189, 248, 0.08); }
.alert-tip { border-left-color: #12b86d; background: rgba(18, 184, 109, 0.08); }
.alert-important { border-left-color: #a855f7; background: rgba(168, 85, 247, 0.08); }
.alert-warning { border-left-color: #f59e0b; background: rgba(245, 158, 11, 0.09); }
.alert-caution { border-left-color: #ef4444; background: rgba(239, 68, 68, 0.09); }

.md-table-wrap {
  margin: 1.2em 0;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-panel);
}

.md-table-toolbar,
.md-code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-line);
  font-family: "Prompt", sans-serif;
  font-size: 12px;
}

.md-table-badge,
.md-code-lang {
  font-weight: 600;
  color: var(--text-muted);
}

.md-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
}

.md-table th,
.md-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-line);
  border-right: 1px solid var(--border-line);
  text-align: left;
}

.md-table th:last-child,
.md-table td:last-child { border-right: none; }
.md-table tr:last-child td { border-bottom: none; }

.md-table th {
  background: var(--table-head-bg);
  color: var(--text-strong);
  font-family: "Prompt", sans-serif;
  font-weight: 600;
}

.md-table tbody tr:nth-child(even) {
  background: var(--table-row-alt);
}

.md-code-wrap,
.md-mermaid-wrap {
  margin: 1.15em 0;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-code);
}

.md-pre {
  padding: 14px 16px;
  overflow-x: auto;
  font-family: Consolas, "JetBrains Mono", "Courier New", monospace;
  font-size: 0.88em;
  line-height: 1.6;
  color: var(--text-main);
}

.md-mermaid-stage {
  padding: 18px;
  overflow-x: auto;
  display: flex;
  justify-content: center;
}

.md-image {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}

.md-frontmatter {
  margin-bottom: 1.2em;
  padding: 8px 12px;
  border: 1px dashed var(--border-line);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-muted);
}

.md-frontmatter summary { cursor: pointer; font-weight: 600; }
.md-frontmatter pre { margin-top: 8px; font-family: Consolas, monospace; white-space: pre-wrap; }

/* ==========================================================================
   5. QUICK-COPY & SECTION BOOKMARK PILLS
   ========================================================================== */
.md-quick-bar {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  opacity: 0.78;
  transition: opacity 0.15s ease;
  flex-wrap: wrap;
}

.md-heading:hover .md-quick-bar {
  opacity: 1;
}

@media (hover: none) {
  .md-quick-bar {
    opacity: 1;
  }
}

.quick-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  font-family: "Prompt", sans-serif;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-main);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.14s ease;
  vertical-align: middle;
}

.quick-copy-btn:hover {
  background: var(--orange);
  color: #ffffff;
  border-color: var(--orange);
}

.quick-copy-btn.quick-copy-subtle {
  border-color: var(--border-line);
  color: var(--text-muted);
}

.quick-copy-btn.quick-copy-subtle:hover {
  background: var(--green-bright);
  color: #062819;
  border-color: var(--green-bright);
}

.quick-bookmark-btn.is-pinned {
  background: var(--orange-soft);
  border-color: var(--orange);
  color: var(--orange);
}

html[data-theme="light"] .quick-copy-btn {
  background-color: #ffffff;
  color: #1f2937;
}

html[data-theme="light"] .quick-copy-btn:hover {
  background-color: var(--orange);
  color: #ffffff;
}

.quick-copy-kv,
.quick-copy-sub {
  margin-left: 8px;
}

.md-subblock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 1.15em;
  margin-bottom: 0.45em;
  padding-top: 0.4em;
  border-top: 1px dashed var(--border-line);
  flex-wrap: wrap;
}

body.hide-quick-copy .md-quick-bar,
body.hide-quick-copy .quick-copy-kv,
body.hide-quick-copy .quick-copy-sub {
  display: none !important;
}

.copy-target-preview {
  outline: 2px dashed var(--orange);
  outline-offset: 4px;
  background-color: var(--orange-soft) !important;
  border-radius: 6px;
}

mark.md-search-mark {
  background: rgba(250, 204, 21, 0.38);
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

mark.md-search-mark.is-current {
  background: #f97316;
  color: #ffffff;
  outline: 2px solid #fbbf24;
}

/* ==========================================================================
   6. OFFICIAL DYNAMICWORK BRAND CREDIT FOOTER
   ========================================================================== */
.app-footer {
  max-width: var(--reader-max-width);
  margin: 22px auto 12px;
}

.footer-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 14px 20px;
  background: var(--bg-panel);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-md);
  flex-wrap: wrap;
}

.footer-logo-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 6px;
  border-radius: 10px;
  background: #111111;
  border: 1px solid rgba(227, 121, 29, 0.35);
  flex-shrink: 0;
  transition: transform 0.16s ease, border-color 0.16s ease;
}

.footer-logo-link:hover {
  transform: translateY(-1px);
  border-color: var(--orange);
}

.footer-dw-logo {
  width: 100%;
  height: 100%;
  display: block;
}

.footer-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.footer-credit-line {
  font-size: 13px;
  color: var(--text-main);
}

.footer-credit-line strong {
  color: var(--orange);
  font-weight: 700;
}

.footer-th-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.footer-contact-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12.5px;
}

.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease;
}

.footer-link:hover {
  color: var(--orange);
  text-decoration: underline;
}

.footer-dot {
  color: var(--text-dim);
}

/* ==========================================================================
   7. RIGHT MARKDOWN EDITOR DRAWER
   ========================================================================== */
.editor-drawer {
  width: 44%;
  max-width: 640px;
  min-width: 340px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-line);
  flex-wrap: wrap;
}

.editor-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.markdown-textarea {
  flex: 1;
  width: 100%;
  padding: 16px 18px;
  background: var(--bg-code);
  color: var(--text-main);
  border: none;
  resize: none;
  outline: none;
  font-family: "Sarabun", Consolas, "Courier New", monospace;
  font-size: 15px;
  line-height: 1.68;
}

/* ==========================================================================
   8. OVERLAYS, MOBILE BACKDROP, ACTION SHEET & TOAST
   ========================================================================== */
.mobile-backdrop {
  position: fixed;
  inset: 0;
  z-index: 650;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(2px);
}

.mobile-action-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 800;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-strong);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.55);
  max-height: 82vh;
  overflow-y: auto;
}

.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-line);
  margin: 4px auto 10px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-line);
  margin-bottom: 12px;
  font-size: 14px;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.sheet-btn.is-primary {
  background: linear-gradient(135deg, #e3791d, #d06008);
  color: #ffffff;
  border-color: transparent;
}

.sheet-btn.is-green {
  background: linear-gradient(135deg, #076c40, #004a2a);
  color: #ffffff;
  border-color: transparent;
}

.sheet-row-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-md);
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(14, 14, 14, 0.86);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.drop-overlay-box {
  border: 2px dashed var(--orange);
  background: #181818;
  border-radius: 20px;
  padding: 44px 56px;
  text-align: center;
  color: #ffffff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
}

.drop-icon { font-size: 52px; margin-bottom: 12px; }

.toast-container {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 420px;
  pointer-events: none;
}

.toast-card {
  background: #171717;
  color: #f5f5f5;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--green-bright);
  border-radius: var(--radius-md);
  padding: 11px 15px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
  font-size: 13px;
  animation: toastSlideIn 0.2s ease-out;
}

.toast-title {
  font-weight: 700;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.toast-preview {
  font-size: 12px;
  color: #a3a3a3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   9. TABLET & MOBILE RESPONSIVE BREAKPOINTS
   ========================================================================== */
@media (max-width: 1024px) {
  .mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-line);
    font-size: 13px;
  }

  .left-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(340px, 88vw);
    z-index: 700;
    box-shadow: 16px 0 44px rgba(0, 0, 0, 0.55);
  }

  .editor-drawer {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    min-width: 0;
    z-index: 750;
  }

  .md-reader-surface {
    padding: 28px 24px;
  }
}

@media (max-width: 768px) {
  .desktop-only-ctrl,
  .action-toolbar,
  .brand-sub,
  .brand-full-sub,
  .hide-sm {
    display: none !important;
  }

  .mobile-only-ctrl {
    display: inline-flex;
  }

  .app-header {
    padding: 8px 12px;
    gap: 8px;
    flex-wrap: nowrap;
  }

  .brand-logo {
    width: 34px;
    height: 34px;
  }

  .brand-titles h1 {
    font-size: 14.5px;
    gap: 5px;
    white-space: nowrap;
  }

  .header-controls {
    gap: 5px;
    flex-wrap: nowrap;
    min-width: 0;
  }

  .file-title-pill {
    padding: 2px 7px 2px 4px;
    max-width: 145px;
  }

  .doc-name-input {
    width: 100%;
    min-width: 0;
    font-size: 16px; /* Prevents iOS auto-zoom on focus */
    transform: scale(0.82);
    transform-origin: left center;
  }

  /* Mobile Search Subbar (Toggled via magnifying glass icon) */
  .reader-subbar {
    display: none;
    padding: 6px 12px;
  }

  body.mobile-search-open .reader-subbar {
    display: flex;
  }

  .subbar-search {
    width: 100%;
    min-width: 0;
  }

  .doc-search-input,
  .sidebar-search-input,
  .markdown-textarea {
    font-size: 16px; /* Prevents iOS Safari zoom */
  }

  .usage-tip-banner {
    padding: 6px 12px;
    font-size: 11.5px;
  }

  .reader-scroll-area {
    padding: 12px 10px calc(86px + env(safe-area-inset-bottom));
  }

  .md-reader-surface {
    padding: 20px 16px;
    border-radius: 14px;
  }

  .md-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .quick-copy-kv {
    display: inline-flex;
    margin-left: 4px;
    margin-top: 4px;
  }

  .footer-card {
    padding: 12px 14px;
    justify-content: flex-start;
  }

  .footer-th-sub {
    display: none;
  }

  /* Fixed Thumb-Friendly Mobile Bottom Bar */
  .mobile-bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 600;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: var(--bg-header);
    border-top: 1px solid var(--border-line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    backdrop-filter: blur(10px);
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 5px 2px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    cursor: pointer;
    border-radius: 10px;
  }

  .mobile-nav-item:active,
  .mobile-nav-item.is-active {
    color: var(--orange);
    background: var(--orange-soft);
  }

  .mobile-nav-item.m-nav-accent .m-nav-icon {
    background: linear-gradient(135deg, #e3791d, #d06008);
    color: #ffffff;
    width: 34px;
    height: 26px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    box-shadow: 0 3px 10px rgba(227, 121, 29, 0.35);
  }

  .m-nav-icon {
    font-size: 17px;
    line-height: 1.1;
  }

  .m-nav-label {
    font-size: 10.5px;
    font-weight: 600;
    white-space: nowrap;
  }

  .toast-container {
    left: 12px;
    right: 12px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    max-width: none;
  }
}

@media (max-width: 400px) {
  .hide-xs { display: none; }
  .file-title-pill { max-width: 118px; }
}

/* ==========================================================================
   10. CLEAN A4 PRINT PDF STYLESHEET
   ========================================================================== */
@media print {
  @page {
    size: A4;
    margin: 1.8cm;
  }

  html, body {
    height: auto !important;
    overflow: visible !important;
    background: #ffffff !important;
    color: #111827 !important;
  }

  .no-print,
  [data-ui-only],
  .quick-copy-btn,
  .md-quick-bar {
    display: none !important;
  }

  .workspace-layout,
  .reader-column,
  .reader-scroll-area {
    display: block !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .md-reader-surface {
    max-width: 100% !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #111827 !important;
    font-size: 11.5pt !important;
  }

  .md-heading,
  .md-h1,
  .md-reader-surface strong {
    color: #111827 !important;
  }

  .md-table th {
    background: #f1f5f9 !important;
    color: #111827 !important;
  }

  .md-table th,
  .md-table td {
    border: 1px solid #cbd5e1 !important;
  }
}
