* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: 'Noto Sans Thai', 'Sarabun', 'Leelawadee UI', Tahoma,
    -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f1f3f6;
  color: #1a1a1a;
  -webkit-font-smoothing: antialiased;
}

button,
textarea {
  font-family: inherit;
}

/* ---------- Layout: editor + preview (no top header — maximize usable space) ---------- */

.main-content {
  height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr;
  min-height: 0;
}

@media (min-width: 769px) {
  .main-content {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
  }
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #ffffff;
  overflow: hidden;
}

.editor-pane {
  border-bottom: 1px solid #e2e4e9;
}

@media (min-width: 769px) {
  .editor-pane {
    border-bottom: none;
    border-right: 1px solid #e2e4e9;
  }
}

/* Fixed height so the editor and preview header bars always match. Content
   overflows horizontally (never wraps) so it can never grow this taller. */
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  height: 46px;
  padding: 0 0.75rem;
  background: #fafbfc;
  border-bottom: 1px solid #e2e4e9;
  overflow-x: auto;
  overflow-y: hidden;
}

.pane-header-left,
.pane-header-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.pane-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7280;
  white-space: nowrap;
  flex-shrink: 0;
}

.toolbar-toggle .chevron {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 16px;
  margin-left: 0.1rem;
  font-size: 0.7rem;
  text-align: center;
  transition: transform 0.2s ease;
}

.toolbar-toggle[aria-expanded='true'] .chevron {
  transform: rotate(180deg);
}

/* Collapsible second row holding the syntax-insert toolbar. Animates
   open/closed via max-height; the border/background live on the inner
   .toolbar-scroll (not here) so nothing renders as a sliver while closed. */
.toolbar-row {
  max-height: 0;
  overflow: hidden;
  flex-shrink: 0;
  transition: max-height 0.25s ease;
}

.toolbar-row.open {
  max-height: 46px;
}

.toolbar-row .toolbar-scroll {
  height: 46px;
  padding: 0 0.75rem;
  background: #fafbfc;
  border-bottom: 1px solid #e2e4e9;
}

.toolbar-scroll {
  display: flex;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.toolbar-scroll::-webkit-scrollbar {
  height: 4px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.toolbar-divider {
  width: 1px;
  height: 22px;
  background: #d8dce2;
  flex-shrink: 0;
  margin: 0 0.15rem;
}

/* ---------- Buttons ---------- */

.btn {
  border: 1px solid #d0d7de;
  background: #ffffff;
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: #1f2328;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: #f3f4f6;
  border-color: #b8c0cc;
}

.btn-success {
  background: #f0fdf4;
  border-color: #15803d;
}

.icon {
  width: 16px;
  height: 16px;
  display: block;
  pointer-events: none;
}

.toolbar-toggle .icon {
  margin-right: 0.1rem;
}

.toolbar-btn {
  border: 1px solid #d0d7de;
  background: #ffffff;
  border-radius: 5px;
  min-width: 2rem;
  padding: 0.3rem 0.5rem;
  font-size: 0.78rem;
  line-height: 1;
  cursor: pointer;
  color: #1f2328;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toolbar-btn:hover {
  background: #eef2ff;
  border-color: #93a4f4;
}

.toolbar-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.toolbar-btn:disabled:hover {
  background: #ffffff;
  border-color: #d0d7de;
}


/* ---------- Editor textarea ---------- */

.editor-textarea {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 1rem;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #1f2328;
  background: #ffffff;
}

/* ---------- Preview pane ---------- */

.preview-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
}

/* ---------- Markdown typography ----------
   NOTE: this block is duplicated as EXPORT_CSS in app.js, because the
   "Export HTML" feature embeds it directly into a standalone downloaded
   file (no build step exists here to share one source between the two). */

.markdown-body {
  font-family: 'Noto Sans Thai', 'Sarabun', 'Leelawadee UI', Tahoma,
    -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  color: #1f2328;
  word-wrap: break-word;
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  font-weight: 600;
  line-height: 1.3;
  margin: 1.4em 0 0.6em;
}

.markdown-body h1 {
  font-size: 2em;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 0.3em;
}

.markdown-body h2 {
  font-size: 1.5em;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 0.3em;
}

.markdown-body h3 {
  font-size: 1.25em;
}

.markdown-body h4 {
  font-size: 1.1em;
}

.markdown-body p {
  margin: 0 0 1em;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0 0 1em;
  padding-left: 1.6em;
}

.markdown-body li {
  margin: 0.25em 0;
}

.markdown-body blockquote {
  margin: 0 0 1em;
  padding: 0.2em 1em;
  color: #57606a;
  border-left: 4px solid #d0d7de;
}

.markdown-body blockquote > *:last-child {
  margin-bottom: 0;
}

.markdown-body code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  background: rgba(175, 184, 193, 0.2);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

.markdown-body pre {
  background: #f6f8fa;
  padding: 1em;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0 0 1em;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
  line-height: 1.5;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1em;
  overflow-x: auto;
  display: block;
}

.markdown-body table th,
.markdown-body table td {
  border: 1px solid #d0d7de;
  padding: 0.5em 0.9em;
  text-align: left;
}

.markdown-body table th {
  background: #f6f8fa;
  font-weight: 600;
}

.markdown-body img {
  max-width: 100%;
  border-radius: 4px;
}

.markdown-body a {
  color: #2563eb;
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 1.6em 0;
}

.markdown-body input[type='checkbox'] {
  margin-right: 0.4em;
}

/* ---------- Print: show only the preview content ---------- */

@media print {
  html,
  body,
  .main-content {
    height: auto !important;
    overflow: visible !important;
  }

  .editor-pane,
  .preview-pane .pane-header {
    display: none !important;
  }

  .main-content {
    display: block !important;
  }

  .preview-pane {
    display: block !important;
    overflow: visible !important;
  }

  .preview-scroll {
    overflow: visible !important;
    height: auto !important;
    padding: 0 !important;
  }

  .markdown-body {
    font-size: 12pt;
    color: #000;
  }

  .markdown-body pre,
  .markdown-body code {
    background: #f6f8fa !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .markdown-body a {
    color: #000;
    text-decoration: underline;
  }

  .markdown-body h1,
  .markdown-body h2,
  .markdown-body h3 {
    page-break-after: avoid;
  }

  .markdown-body pre,
  .markdown-body table,
  .markdown-body blockquote,
  .markdown-body img {
    page-break-inside: avoid;
  }
}
