:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --panel: #ffffff;
  --ink: #1f2a2e;
  --muted: #637176;
  --line: #d9e0dc;
  --accent: #2f6f73;
  --accent-strong: #184c50;
  --danger: #a33b3b;
}

@font-face {
  font-family: "Sarabun";
  src: url("/static/fonts/Sarabun-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Sarabun";
  src: url("/static/fonts/Sarabun-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Sarabun";
  src: url("/static/fonts/Sarabun-Italic.ttf") format("truetype");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Sarabun", "Noto Sans Thai", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { font-weight: 700; font-size: 20px; }

.topbar nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar form { margin: 0; }

.page {
  width: min(1120px, calc(100vw - 32px));
  margin: 28px auto 56px;
}

.hero {
  padding: 24px 0 16px;
  border-bottom: 1px solid var(--line);
}

.hero h1 {
  margin: 0;
  font-size: 36px;
}

.hero p { color: var(--muted); margin: 8px 0 0; }

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.wiki-layout {
  display: grid;
  gap: 18px;
  margin-top: 20px;
}

.chapter, .auth-panel, .editor, .proposal, .doc-view {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.chapter h2 { margin: 0 0 12px; }
.section h3 { margin: 16px 0 8px; color: var(--accent-strong); }

.doc-list {
  list-style: none;
  padding: 0 0 0 22px;
  margin: 0;
  display: grid;
  gap: 8px;
}

.doc-list li {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.doc-list li > div {
  display: grid;
  gap: 2px;
}

.doc-list span, .muted { color: var(--muted); font-size: 13px; }

.doc-list .doc-abstract {
  color: var(--ink);
  font-size: 15px;
}

button, .button {
  appearance: none;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 9px 13px;
  font-weight: 650;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  line-height: 1.2;
}

button:hover, .button:hover { background: var(--accent-strong); text-decoration: none; }

button.secondary, .button.secondary {
  background: #536568;
}

button.secondary:hover, .button.secondary:hover {
  background: #37484b;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #762727;
}

button.subtle {
  padding: 6px 9px;
  font-size: 13px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
}

label { font-weight: 650; }

.form-help {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.form-help.warning {
  color: #8a5a00;
}

.auth-panel {
  max-width: 440px;
  margin: 80px auto;
}

.auth-panel form, .stack {
  display: grid;
  gap: 12px;
}

.error { color: var(--danger); }

.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}

.doc-actions form { margin: 0; }

.doc-path {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.65;
}

.row-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.row-heading h2, .row-heading h3 {
  margin-right: auto;
}

.row-heading form {
  margin: 0;
}

.title-edit {
  display: inline;
  color: var(--accent-strong);
  font: inherit;
  font-weight: inherit;
  line-height: inherit;
  text-decoration: none;
}

.title-edit:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.section-title {
  color: var(--accent-strong);
}

.edit-dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 22px 60px rgba(31, 42, 46, 0.28);
}

.edit-dialog::backdrop {
  background: rgba(31, 42, 46, 0.38);
}

.edit-dialog h2 {
  margin: 0 0 18px;
}

.dialog-body {
  padding: 24px;
}

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  background: #f7f8f5;
}

.dialog-footer form {
  margin: 0;
}

.dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  margin: 0;
}

.dialog-close button {
  width: 34px;
  height: 34px;
  justify-content: center;
  padding: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
}

.dialog-close button:hover {
  background: #edf3ef;
  color: var(--ink);
}

.create-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.create-grid label {
  display: grid;
  gap: 6px;
}

.create-grid .wide {
  grid-column: 1 / -1;
}

.create-grid button {
  justify-self: start;
}

.deleted-list {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
  display: grid;
  gap: 10px;
}

.deleted-list li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.deleted-list li > div {
  display: grid;
  gap: 4px;
}

.deleted-list span {
  color: var(--muted);
  font-size: 13px;
}

.user-list {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
  display: grid;
  gap: 12px;
}

.user-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(130px, 0.8fr) minmax(220px, 1.2fr) 160px auto;
  gap: 10px;
  align-items: center;
}

.user-row input[readonly] {
  background: #f2f4f0;
}

.bottom-link {
  display: grid;
  gap: 4px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.markdown-body {
  max-width: 780px;
  font-size: 15px;
  line-height: 1.65;
}

.markdown-body blockquote {
  margin: 16px 0 16px 24px;
  padding: 10px 14px;
  border-left: 4px solid var(--line);
  color: var(--ink);
  font-size: 15px;
}

.markdown-body pre {
  overflow: auto;
  margin: 16px 0 16px 24px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfa;
  font-size: 15px;
  line-height: 1.65;
}

.markdown-body code {
  font-size: 15px;
}

.markdown-body pre code {
  font: inherit;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
}

.markdown-body th, .markdown-body td {
  border: 1px solid var(--line);
  padding: 8px 10px;
}

.editor textarea {
  min-height: 62vh;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: 12px 0;
}

.wysiwyg-editor {
  margin: 12px 0;
}

.editor-actions {
  display: flex;
  gap: 10px;
}

.toastui-editor-defaultUI,
.toastui-editor-contents,
.toastui-editor-md-container {
  font-family: "Sarabun", "Noto Sans Thai", system-ui, sans-serif;
}

.toastui-editor-contents,
.toastui-editor-contents p,
.toastui-editor-contents li,
.toastui-editor-contents td,
.toastui-editor-contents th,
.toastui-editor-md-container,
.toastui-editor-md-container .toastui-editor,
.toastui-editor-md-container .toastui-editor-md-preview,
.toastui-editor-md-container .toastui-editor-md-preview p,
.toastui-editor-ww-container .ProseMirror {
  font-size: 15px;
  line-height: 1.65;
}

.proposal pre {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f2f4f0;
}

.ai-status {
  display: grid;
  grid-template-rows: repeat(5, minmax(20px, auto));
  gap: 4px;
  min-height: 124px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2f4f0;
  color: var(--muted);
}

.ai-status strong {
  color: var(--accent-strong);
}

.proposal-output {
  min-height: 38vh;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: 8px 0 14px;
}

.pdf-preview {
  display: grid;
  gap: 16px;
}

.pdf-preview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.pdf-preview-header h1 {
  margin: 0;
}

.send-pdf-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.send-pdf-form label {
  display: grid;
  gap: 6px;
}

.pdf-frame {
  width: 100%;
  height: min(78vh, 900px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.notice {
  margin: 0;
  color: var(--accent-strong);
  font-weight: 650;
}

@media (max-width: 680px) {
  .topbar {
    height: auto;
    padding: 12px 16px;
    align-items: flex-start;
    gap: 12px;
  }
  .topbar nav { flex-wrap: wrap; justify-content: flex-end; }
  .doc-list { padding-left: 14px; }
  .create-grid { grid-template-columns: 1fr; }
  .row-heading, .deleted-list li { align-items: flex-start; }
  .user-list li, .user-row { grid-template-columns: 1fr; }
  .pdf-preview-header, .send-pdf-form { grid-template-columns: 1fr; }
  .pdf-preview-header { display: grid; }
}
