:root {
    --primary: #2563eb;
    --heading: #2563eb;
    --text: #1f2937;
    --line: #e5e7eb;
    --muted: #6b7280;
    --bg: #ffffff;
    --layout: 1440px;
    --side: 300px;
    --top: 64px;
    --read: 768px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.6 "Leelawadee UI", "Segoe UI", Tahoma, sans-serif;
    max-width: 100%;
}

body.is-admin { --top: 118px; }

a { color: inherit; }

button, input, select {
    font: inherit;
    color: inherit;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.nav-toggle {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.app {
    display: grid;
    grid-template-columns: var(--side) minmax(0, 1fr) 260px;
    grid-template-rows: auto 1fr;
    width: 100%;
    max-width: var(--layout);
    margin: 0 auto;
    min-height: 100vh;
}

.app.no-toc,
.app.bare { grid-template-columns: var(--side) minmax(0, 1fr); }

.app.bare { grid-template-columns: 1fr; }

.topbar {
    grid-column: 1 / -1;
    position: sticky;
    top: 0;
    z-index: 10;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.topbar-row {
    height: var(--top);
    display: grid;
    grid-template-columns: var(--side) minmax(0, 1fr);
    align-items: center;
    padding: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    width: auto;
    padding-left: 0;
    text-decoration: none;
    font-weight: 650;
    min-width: 0;
}

.badge,
.brand-logo {
    width: 28px;
    height: 28px;
    max-width: 28px;
    max-height: 28px;
    border-radius: 8px;
    flex: 0 0 28px;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}

.brand-logo {
    display: block;
    object-fit: contain;
    background: #fff;
}

.brand-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search {
    position: relative;
    grid-column: 2;
    width: min(640px, calc(100% - 56px));
    margin-left: 28px;
}

.search input {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    padding: 8px 92px 8px 16px;
    background: #fff;
}

.search input:focus {
    outline: 2px solid var(--primary);
    border-color: transparent;
}

.hint-keys {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 4px;
    pointer-events: none;
}

kbd {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0 6px;
    font-size: 12px;
    color: var(--muted);
    background: #f9fafb;
}

.nav-btn { display: none; }

.adminbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    align-items: center;
    padding: 8px 16px;
    background: #f8fafc;
    border-top: 1px solid var(--line);
}

.adminbar a,
.inline-form button,
.row-actions button,
.delete-form button,
#save-page,
.auth-card button,
.settings-form button,
.toolbar button {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 6px 10px;
    text-decoration: none;
    cursor: pointer;
}

#save-page,
.auth-card button,
.settings-form button {
    background: var(--primary);
    color: #fff;
    border-color: transparent;
}

.logout-btn {
    border: 1px solid #dc2626;
    border-radius: 8px;
    background: #dc2626;
    color: #fff;
    padding: 6px 12px;
    cursor: pointer;
}

.logout-btn:hover { background: #b91c1c; }

.inline-form,
.row-actions,
.adminbar form {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 0;
}

.adminbar .logout-form { margin-left: 0; }

.inline-form input,
.inline-form select,
.meta input,
.meta select,
.settings-form input,
.auth-card input {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 7px 10px;
    background: #fff;
}

.sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid transparent;
    padding: 12px 10px 12px 0;
    position: sticky;
    top: var(--top);
    height: calc(100vh - var(--top));
    overflow: hidden;
    transition: border-color .15s ease;
}

body.is-scrolling .sidebar {
    border-right-color: #eceef2;
}

.nav-tree {
    flex: 1;
    min-height: 0;
    overflow: auto;
    scrollbar-width: none;
}

.nav-tree::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.nav-tree,
.nav-tree ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-tree li { margin: 1px 0; }

.nav-row {
    display: flex;
    align-items: center;
}

.nav-row .nav-link { flex: 1; min-width: 0; }

.nav-link {
    display: grid;
    grid-template-columns: 1.35em minmax(0, 1fr);
    column-gap: 10px;
    align-items: center;
    min-height: 32px;
    padding: 4px 8px;
    border-radius: 6px;
    text-decoration: none;
    color: #66686d;
    font-family: "Segoe UI", "Noto Sans Thai", Tahoma, sans-serif;
    font-size: 15px;
    line-height: 1.2;
    font-weight: 400;
}

.nav-link .label {
    min-width: 0;
    overflow-wrap: break-word;
}

.nav-link:hover { background: #f3f4f6; }

.nav-link.active {
    color: var(--primary);
    background: transparent;
    font-weight: 600;
}

.depth-1 > .nav-row > .nav-link { font-weight: 650; }

.nav-children { display: none; }

.has-children.is-open > .nav-children { display: block; }

.nav-fold {
    width: 28px;
    height: 28px;
    border: 0;
    background: transparent;
    padding: 0;
    cursor: pointer;
    flex: 0 0 auto;
}

.nav-fold::before {
    content: "";
    display: block;
    width: 7px;
    height: 7px;
    margin: 0 auto;
    border-right: 1.5px solid #9ca3af;
    border-bottom: 1.5px solid #9ca3af;
    transform: rotate(-45deg);
}

.has-children.is-open > .nav-row > .nav-fold::before {
    transform: rotate(45deg);
}

.nav-ico,
.nav-link .nav-star,
.nav-link .nav-sword,
.nav-link .nav-gem {
    width: 1.35em;
    height: 1.35em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1em;
    line-height: 1;
}

.nav-link .nav-star {
    font-size: 0.78em;
    filter: saturate(.55) brightness(1.1);
}

.nav-link .nav-sword { font-size: 0.95em; }

.nav-link .nav-gem { font-size: 1.35em; }

.summary {
    color: #a1a1aa;
    font-size: 13px;
    line-height: 1.3;
    margin: 0 8px 6px 34px;
    overflow-wrap: anywhere;
}

.sidebar-brand-card {
    display: flex;
    flex: none;
    align-items: center;
    gap: 12px;
    min-height: 54px;
    margin: 12px 8px 0 0;
    padding: 12px 14px;
    border: 1px solid #e2e5ea;
    border-radius: 11px;
    background: #fff;
    color: #65686f;
    text-decoration: none;
    font-size: 14px;
    line-height: 1.35;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}

.sidebar-brand-card svg {
    flex: none;
    color: #73777f;
}

.sidebar-brand-card strong { font-weight: 650; }

.sidebar-brand-card:hover {
    border-color: #cfd4dc;
    background: #fafafa;
}

.content {
    padding: 28px 56px 32px 56px;
    min-width: 0;
}

.page {
    width: 100%;
    max-width: var(--read);
    margin: 0;
}

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.ask-page {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    margin-top: 4px;
    padding: 0 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    color: #3f3f46;
    font: inherit;
    font-size: 14px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
    cursor: pointer;
}

.ask-page:hover { background: #fafafa; }

.edit-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding-bottom: 18px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.edit-head h1 {
    margin: 0;
    font-size: 30px;
    line-height: 1.25;
}

.admin-end {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.edit-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

#public-link {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 7px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: #374151;
    font-weight: 600;
    text-decoration: none;
}

#public-link:hover { background: #f8fafc; }

.edit-actions #save-page {
    min-height: 38px;
    padding: 7px 16px;
    font-weight: 650;
}

.edit-actions #save-page.is-saved {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}

#save-status {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    z-index: 40;
    padding: 8px 14px;
    border-radius: 8px;
    background: #111827;
    color: #fff;
    font-size: 14px;
}

#save-status[hidden] { display: none; }

.crumb {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 10px;
    color: #2563eb;
    font-family: "Segoe UI", "Noto Sans Thai", Tahoma, sans-serif;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: 0;
}

.page-title {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    font-size: 32px;
    line-height: 40px;
    margin: 0;
    min-width: 0;
}

.page-title.has-icon {
    grid-template-columns: 36px minmax(0, 1fr);
}

.page-title-icon {
    width: 36px;
    height: 40px;
    display: grid;
    place-items: center;
    line-height: 0;
}

.page-title-icon > .nav-ico {
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 34px;
    line-height: 1;
    object-fit: contain;
    transform: translateY(-2px);
}

.updated {
    margin: 8px 0 0;
    color: #71717a;
    font-size: 16px;
    line-height: 1.5;
}

.muted, .hint { color: var(--muted); }

.prose h2,
.prose h3 {
    position: relative;
    color: var(--heading);
    scroll-margin-top: 88px;
}

.prose h2 { font-size: 24px; margin: 28px 0 12px; font-weight: 700; }

.prose h3 { font-size: 22px; }

.prose h2 ~ h2,
.prose h2 ~ h3,
.prose h3 ~ h2,
.prose h3 ~ h3 {
    margin-top: 36px;
    padding-top: 24px;
    border-top: 1px solid #e5e7eb;
}

.heading-text {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.heading-anchor {
    position: absolute;
    top: 0.08em;
    right: 100%;
    margin-right: 0.35em;
    color: #9ca3af;
    font-weight: 500;
    text-decoration: none;
    opacity: 0;
}

.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.heading-anchor:focus {
    opacity: 1;
}

.rich > .line {
    display: block;
}

.prose .align-left { text-align: left; }

.prose .align-center { text-align: center; }

.prose .align-right { text-align: right; }

.prose p.size-sm,
.prose h2.size-sm { font-size: 15px; line-height: 1.9; }

.prose h3.size-sm { font-size: 18px; line-height: 1.6; }

.prose p.size-lg { font-size: 20px; line-height: 1.7; }

.prose h2.size-lg { font-size: 32px; }

.prose h3.size-lg { font-size: 26px; }

.prose span.size-sm,
.rich .size-sm { font-size: 13px; }

.prose span.size-lg,
.rich .size-lg { font-size: 28px; line-height: 1.45; }

.prose .font-italic,
.rich .font-italic { font-style: italic; }

.prose .weight-light,
.rich .weight-light { font-weight: 300; }

.prose .font-leelawadee,
.rich .font-leelawadee { font-family: "Leelawadee UI", Tahoma, sans-serif; }

.prose .font-segoe,
.rich .font-segoe { font-family: "Segoe UI", Tahoma, sans-serif; }

.prose .font-tahoma,
.rich .font-tahoma { font-family: Tahoma, "Leelawadee UI", sans-serif; }

.prose .font-angsana,
.rich .font-angsana { font-family: "Angsana New", "Leelawadee UI", serif; }

.font-pick {
    height: 32px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: #fff;
    color: #1f2937;
    padding: 0 8px;
    font: inherit;
    font-size: 13px;
}

.font-pick:hover { border-color: #bfdbfe; background: #eff6ff; }

.size-pick { position: relative; width: 58px; }

.size-value {
    position: relative;
    width: 100%;
    height: 32px;
    border: 1px solid #c5d0e0;
    border-radius: 6px;
    background: #fff;
    color: #1f2937;
    padding: 0 16px 0 6px;
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.size-value::after {
    content: "";
    position: absolute;
    right: 6px;
    top: 50%;
    width: 0;
    height: 0;
    margin-top: -2px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #2563eb;
}

.size-pick.is-open .size-value::after {
    margin-top: -4px;
    border-top: 0;
    border-bottom: 6px solid #2563eb;
}

.size-mark {
    font-family: Georgia, "Times New Roman", serif;
    font-style: italic;
    font-weight: 700;
    font-size: 16px;
    line-height: 1;
    color: #2563eb;
}

.size-label { min-width: 1.1em; }

.size-value:hover,
.size-pick.is-open .size-value {
    border-color: #93c5fd;
    background: #f8fbff;
}

.size-menu {
    position: absolute;
    z-index: 30;
    top: calc(100% + 4px);
    left: 0;
    width: 58px;
    padding: 4px 0;
    border: 1px solid #c5d0e0;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

.size-option {
    display: block;
    width: 100%;
    height: 28px;
    line-height: 28px;
    border: 0;
    background: #fff;
    color: #1f2937;
    padding: 0 8px;
    font: inherit;
    font-size: 14px;
    text-align: center;
    cursor: pointer;
    white-space: nowrap;
}

.size-option:hover,
.size-option.is-on { background: #e8eef8; }

.prose hr.rule,
.rich hr.rule,
.block[data-type="divider"] hr.rule {
    border: 0;
    border-top: 1px solid #e5e7eb;
    margin: 28px 0;
}

.rich hr.rule { margin: 14px 0; }

.block[data-type="divider"] {
    padding-top: 0;
    padding-bottom: 0;
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}

.prose .text-mark,
.rich .text-mark {
    padding: 0.05em 0.2em;
    border-radius: 3px;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
}

.fmt-bar .mark-opacity {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 32px;
}

.fmt-bar .mark-opacity input[type="range"] {
    width: 58px;
    height: 16px;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    accent-color: #22c55e;
}

.fmt-bar .mark-opacity-num {
    width: 2.4em;
    font-size: 12px;
    color: #64748b;
}

.prose a.text-link,
.rich a.text-link {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.prose img.remote-image,
.rich img.remote {
    display: block;
    width: auto;
    height: auto;
    min-width: 0;
    max-width: min(100%, 375px);
    margin-left: auto;
    margin-right: auto;
}

.prose .align-left > img.remote-image,
.rich .remote-card[data-align="left"] img.remote {
    margin-left: 0;
    margin-right: auto;
}

.prose .align-right > img.remote-image,
.rich .remote-card[data-align="right"] img.remote {
    margin-left: auto;
    margin-right: 0;
}

.rich img.remote {
    margin-top: 8px;
    margin-bottom: 8px;
}

.rich .remote-card {
    display: block;
    width: 100%;
    margin: 0 0 16px;
    cursor: default;
    user-select: none;
}

.rich .remote-card.is-picked img.remote {
    outline: 2px solid #2563eb;
    outline-offset: 3px;
}

.rich .remote-card img.remote {
    margin-top: 0;
    margin-bottom: 0;
}

.prose p.remote-image-block {
    margin: 0;
    padding-top: 32px;
}

.prose p.remote-image-block > img.remote-image {
    margin: 0 auto;
}

.prose p.remote-image-block + h2,
.prose p.remote-image-block + h3 {
    margin-top: 0;
    padding-top: 32px;
}

.prose img.zoomable { cursor: zoom-in; }

.tabs {
    border: 1px solid #e6e8ec;
    border-radius: 10px;
    margin: 16px 0 20px;
    overflow: hidden;
    background: #fff;
}

.tabs .tab-bar {
    display: flex;
    flex-wrap: wrap;
    background: #f4f5f7;
    border-bottom: 1px solid #e6e8ec;
}

.tabs .tab {
    border: 0;
    border-right: 1px solid #e6e8ec;
    background: transparent;
    color: #4b5563;
    padding: 10px 16px;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}

.tabs .tab.is-on {
    background: #fff;
    color: #111827;
    font-weight: 650;
    margin-bottom: -1px;
    border-bottom: 1px solid #fff;
}

.tabs .tab-panel {
    padding: 14px 18px 16px;
}

.tabs .tab-panel p { margin: 8px 0; }

.tabs .tab-panel p:first-child { margin-top: 0; }

.prose ul { margin: 8px 0 16px; padding-left: 1.3rem; }

.prose li { margin: 6px 0; }

.prose p.note,
.prose blockquote.note,
.rich blockquote.line-note {
    margin: 8px 0 16px;
    padding: 2px 0 2px 14px;
    border-left: 2px solid #d0d5dd;
    color: inherit;
}

.prose p.note { font-style: italic; margin-top: 4px; }

.rich blockquote.line-note { margin: 8px 0; }

.data-table,
.edit-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 8px 0 20px;
}

.data-table th,
.edit-table th,
.data-table td,
.edit-table td {
    border-left: 1px solid #e6e8ee;
    padding: 12px 8px;
}

.prose .data-table img.remote-image,
.edit-table .table-rich img.remote {
    max-width: 75px;
    max-height: 100px;
    margin: 0 auto;
}

.data-table th,
.edit-table th {
    background: #f3f4f6;
    font-weight: 650;
}

.data-table th:first-child,
.edit-table th:first-child,
.data-table td:first-child,
.edit-table td:first-child { border-left: 0; }

.data-table th:first-child,
.edit-table th:first-child { border-radius: 12px 0 0 12px; }

.data-table th:last-child,
.edit-table th:last-child { border-radius: 0 12px 12px 0; }

.data-table td,
.edit-table td {
    border-bottom: 1px solid #e5e7eb;
}

.prose .data-table {
    table-layout: fixed;
    width: 100%;
    border: 1px solid #e6e8ee;
    border-radius: 12px;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
}

.prose .data-table th,
.prose .data-table td {
    border: 0;
    border-right: 1px solid #e6e8ee;
    border-bottom: 1px solid #e6e8ee;
    border-radius: 0;
    padding: 12px 16px;
    vertical-align: middle;
    background: #fff;
    overflow-wrap: break-word;
}

.prose .data-table th:last-child,
.prose .data-table td:last-child {
    border-right: 0;
}

.prose .data-table tr:last-child td {
    border-bottom: 0;
}

.prose .data-table th {
    background: #f4f5f7;
    font-weight: 650;
    color: #3f3f46;
}

.prose .data-table th:first-child:nth-last-child(3),
.prose .data-table td:first-child:nth-last-child(3) {
    width: 20%;
}

.prose .data-table th:nth-child(2):nth-last-child(2),
.prose .data-table td:nth-child(2):nth-last-child(2),
.prose .data-table th:nth-child(3):nth-last-child(1),
.prose .data-table td:nth-child(3):nth-last-child(1) {
    width: 40%;
}

.prose .data-table tbody tr:hover td {
    background: #f7f8fa;
}

.edit-table .rich {
    min-height: 36px;
    padding: 6px 8px;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.block[data-type="note"] .rich {
    border-left: 3px solid #d0d5dd;
    padding-left: 14px;
}

.banner,
.preview-figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: fit-content;
    max-width: min(100%, 768px);
}

.banner {
    margin: 24px auto;
}

.preview-figure {
    margin: 20px auto 0;
}

.banner.align-left,
.preview-figure.align-left {
    margin-left: 0;
    margin-right: auto;
}

.banner.align-center,
.preview-figure.align-center {
    margin-left: auto;
    margin-right: auto;
}

.banner.align-right,
.preview-figure.align-right {
    margin-left: auto;
    margin-right: 0;
}

.banner img,
.block img.preview {
    width: auto;
    height: auto;
    min-width: 0;
    max-width: min(100%, 768px);
    border-radius: 12px;
    display: block;
    margin: 0;
}

.banner figcaption,
.preview-figure .preview-caption {
    display: block;
    margin: 8px 0 0;
    text-align: center;
    color: #71717a;
    font-size: 14px;
    line-height: 1.5;
}

.page-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 48px 0 12px;
}

.page-nav-card {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 72px;
    padding: 12px 40px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    color: inherit;
    text-decoration: none;
}

.page-nav-card:hover {
    border-color: #a9c6ff;
}

.page-nav-card:hover .page-nav-title {
    color: #5876a9;
}

.page-nav-kicker {
    color: #71717a;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.35;
}

.page-nav-title {
    display: block;
    color: #27272a;
    font-size: 16px;
    font-weight: 400;
    line-height: 1.4;
}

.page-nav-title span:last-child,
.is-next .page-nav-title span:first-child {
    overflow-wrap: anywhere;
}

.page-nav-arrow {
    position: absolute;
    top: 50%;
    left: 16px;
    display: inline-flex;
    color: #71717a;
    transform: translateY(-50%);
}

.page-nav-card.is-next {
    align-items: flex-end;
    text-align: right;
}

.page-nav-card.is-next .page-nav-arrow {
    right: 16px;
    left: auto;
}

.page-last-updated {
    margin: 22px 0 0;
    color: #71717a;
    font-size: 14px;
    line-height: 1.5;
}

.figure-row {
    display: grid;
    gap: 22px 28px;
    margin: 8px 0 24px;
    align-items: start;
    justify-items: center;
}

.figure-row.cols-1 { grid-template-columns: minmax(0, 1fr); }
.figure-row.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.figure-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.figure-row.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.figure-row.align-left { justify-items: start; }
.figure-row.align-right { justify-items: end; }

.figure-row figure {
    display: block;
    width: fit-content;
    max-width: 100%;
    margin: 0;
}

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

.figure-row figcaption {
    display: block;
    margin: 8px 0 0;
    text-align: center;
    color: inherit;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.45;
}

.lightbox,
.lightbox[open] {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: none;
    outline: none;
    box-shadow: none;
    background: #fff;
    color-scheme: light;
}

.lightbox[open] {
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox::backdrop {
    background: #fff;
}

.lightbox img {
    display: block;
    width: auto;
    height: auto;
    max-width: 94vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}

img.emoji {
    height: 1.2em;
    width: auto;
    vertical-align: -0.2em;
}

.toc {
    min-width: 0;
    padding: 42px 16px 24px 12px;
    position: sticky;
    top: var(--top);
    height: calc(100vh - var(--top));
    overflow: auto;
}

.toc-card {
    min-width: 0;
    padding: 0 0 14px;
    border-bottom: 1px solid #e5e7eb;
}

.toc-title {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
    color: #6b7280;
    margin-bottom: 8px;
    text-align: left;
    cursor: pointer;
}

.toc-title:hover { color: #374151; }

.toc ul { list-style: none; margin: 0; padding: 0; }

.toc a {
    display: block;
    max-width: 100%;
    text-decoration: none;
    color: #6b7280;
    padding: 6px 8px;
    border-radius: 8px;
    line-height: 1.55;
    white-space: normal;
    overflow-wrap: break-word;
}

.toc a.active {
    color: var(--primary);
    background: #f3f4f6;
    font-weight: 600;
}

.toc a:hover:not(.active) { color: #374151; }

.toc-l3 a { padding-left: 16px; }

.flash {
    border-radius: 8px;
    padding: 10px 12px;
}

.flash.ok { background: #ecfdf5; color: #166534; }

.flash.err { background: #fef2f2; color: #b91c1c; }

.results { list-style: none; padding: 0; }

.results li { margin: 12px 0; }

.results a { color: var(--primary); font-weight: 650; text-decoration: none; }

.results span,
.results a { display: block; }

.auth-card {
    max-width: 420px;
    margin: 48px auto;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 24px;
}

.auth-card label,
.meta label,
.color-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 12px 0;
}

.settings-form {
    max-width: 680px;
    margin-top: 18px;
    padding: 8px 22px 22px;
    border: 1px solid #e6eef8;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.settings-block {
    padding: 16px 0;
    border-top: 1px solid #eef2f7;
}

.settings-block h2 {
    margin: 0 0 12px;
    color: #111827;
    font-size: 16px;
}

.settings-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 0 12px;
    color: #374151;
    font-size: 14px;
    font-weight: 650;
}

.settings-form input[type="text"],
.settings-form input[name="site_name"],
.settings-form input[name="site_short"] {
    min-height: 40px;
    border: 1px solid #dbe3ee;
    border-radius: 10px;
    padding: 8px 12px;
    background: #fff;
    font-weight: 400;
}

.settings-logo-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.settings-logo-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    min-width: 0;
}

.settings-logo {
    width: 64px;
    height: 64px;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    background: #f8fafc;
    object-fit: contain;
}

.settings-logo-fallback {
    display: grid;
    place-items: center;
    color: var(--primary);
    font-size: 22px;
    font-weight: 700;
}

.settings-form .file-pick {
    display: inline-flex;
    flex-direction: row;
    width: auto;
    margin: 0;
    color: #fff;
    font-weight: 650;
    position: relative;
}

.settings-file-name {
    margin: 8px 0 0;
    color: #6b7280;
    font-size: 13px;
    font-weight: 400;
}

.settings-form label.settings-check {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    width: auto;
    min-height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: #4b5563;
    font-size: 13px;
    font-weight: 500;
}

.settings-form label.settings-check input {
    width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    flex: none;
}

.settings-colors {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.settings-form label.settings-color {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    width: auto;
    margin: 0;
    padding: 8px 12px;
    border: 1px solid #e6eef8;
    border-radius: 10px;
    background: #fff;
}

.settings-form .settings-color input[type="color"] {
    width: 36px;
    height: 28px;
    padding: 2px;
    border: 1px solid #dbe3ee;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    flex: none;
}

.settings-form .settings-save {
    min-height: 40px;
    margin-top: 8px;
    padding: 0 18px;
    border-radius: 10px;
    font-weight: 650;
}

.meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 16px;
    margin: 16px 0;
}

.icon-field { grid-column: 1 / -1; }

.icon-choices,
.icon-upload-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.icon-choices { margin-top: 6px; }

.icon-upload-row { margin-top: 14px; }

.icon-choice,
#pick-icon {
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
}

.icon-choice.is-on {
    border-color: var(--primary);
    background: #eff6ff;
}

#pick-icon {
    width: auto;
    height: 36px;
    padding: 0 12px;
    font-size: 14px;
}

.meta .check-line {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin: 0;
    width: auto;
}

.row-actions,
.delete-form {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.delete-form input[type="checkbox"] { width: 16px; height: 16px; margin: 0; }

.toolbar .color-label {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin: 0;
    height: 34px;
    padding: 0 8px 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.toolbar .color-label input[type="color"],
.style-row input[type="color"] {
    width: 28px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fff;
}

.toolbar {
    position: sticky;
    top: var(--top);
    z-index: 9;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 12px 0 0;
    padding: 8px 0 10px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}

.block {
    position: relative;
    border: 1px solid #e6eef8;
    border-radius: 16px;
    padding: 14px;
    margin: 12px 0 28px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
    scroll-margin: 140px 0 32px;
}

.block.is-new {
    border-color: #60a5fa;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .18);
}

#blocks > .block + .block::before {
    content: "";
    position: absolute;
    top: -15px;
    left: 3%;
    right: 3%;
    height: 1px;
    background: #e5eaf1;
}

.block-kind {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 700;
}

.block[data-type="image"] .block-kind,
.block[data-type="imagerow"] .block-kind { background: #ecfdf5; color: #0f766e; }
.block[data-type="list"] .block-kind { background: #f5f3ff; color: #6d28d9; }
.block[data-type="note"] .block-kind { background: #fffbeb; color: #b45309; }
.block[data-type="richtext"] .block-kind { background: #f3f4f6; color: #374151; }
.block[data-type="tabs"] .block-kind { background: #eef2ff; color: #4338ca; }

.tab-edit {
    border: 1px solid #e6e8ec;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.tab-edit .tab-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    background: #f4f5f7;
    border-bottom: 1px solid #e6e8ec;
}

.tab-edit .tab {
    display: flex;
    align-items: center;
    border-right: 1px solid #e6e8ec;
}

.tab-edit .tab.is-on { background: #fff; }

.tab-edit .tab .tab-name {
    width: 7.5em;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 8px 4px 8px 12px;
    font: inherit;
    font-size: 14px;
}

.tab-edit .tab-x {
    border: 0;
    background: transparent;
    color: #9ca3af;
    padding: 0 8px 0 2px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.tab-edit .tab-add {
    border: 0;
    background: transparent;
    color: #2563eb;
    padding: 8px 14px;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}

.tab-edit .tab-pane .rich {
    border: 0;
    border-radius: 0;
    min-height: 140px;
}

.block[data-type="heading"] .heading-rich {
    font-size: 22px;
    font-weight: 700;
    color: var(--heading);
    line-height: 1.45;
    min-height: 52px;
}

.heading-rich:empty::before {
    content: attr(data-placeholder);
    color: #9ca3af;
    font-weight: 500;
}

.toolbar .tool-ico {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.toolbar .tool-ico svg { display: block; }

.block-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: -14px -14px 12px;
    padding: 10px 12px;
    border-bottom: 1px solid #dbe5f0;
    border-radius: 15px 15px 0 0;
    background: #f3f5f8;
}

.block[data-type="heading"] > .block-tools { background: #eaf3ff; }
.block[data-type="image"] > .block-tools,
.block[data-type="imagerow"] > .block-tools { background: #e8f8f4; }
.block[data-type="list"] > .block-tools { background: #f1ebff; }
.block[data-type="note"] > .block-tools { background: #fff3d9; }

.block-tools .fmt-btn {
    width: auto;
    height: 32px;
    padding: 0 10px;
    gap: 6px;
    font-size: 13px;
}

.block-tools .fmt-btn[data-del]:hover {
    color: #b91c1c;
    background: #fef2f2;
    border-color: #fecaca;
}

.fmt-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    margin: 8px 0;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    width: fit-content;
    max-width: 100%;
}

.fmt-btn {
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: #fff;
    color: #1f2937;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.fmt-btn:hover,
.fmt-btn.is-on {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: var(--primary);
}

.fmt-btn svg { display: block; }

.fmt-b { font-weight: 700; font-size: 15px; }

.fmt-i { font-style: italic; font-family: Georgia, serif; font-size: 15px; }

.fmt-l { font-weight: 300; font-size: 15px; }

.fmt-sm { font-size: 12px; font-weight: 650; }

.fmt-lg { font-size: 18px; font-weight: 650; }

.fmt-gap {
    width: 1px;
    height: 20px;
    background: #e5e7eb;
    margin: 0 4px;
}

.swatch {
    position: relative;
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    cursor: pointer;
}

.swatch:hover { border-color: #bfdbfe; background: #eff6ff; }

.swatch-face {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    border: 1px solid rgba(15, 23, 42, .18);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
}

.swatch input[type="color"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    border: 0;
    padding: 0;
}

.field-label {
    font-size: 13px;
    font-weight: 650;
    color: #374151;
    margin: 4px 0;
}

.block input,
.block select,
.rich { width: 100%; }

.block input[type="text"],
.block input:not([type="file"]):not([type="hidden"]):not([type="color"]) {
    border: 1px solid #d7e3f4;
    border-radius: 12px;
    background: #f8fbff;
    padding: 10px 12px;
}

.block input:focus {
    outline: 2px solid #bfdbfe;
    border-color: #93c5fd;
}

.prose { font-size: 16px; }

.rich {
    min-height: 140px;
    font-size: 16px;
    border: 1px dashed #93c5fd;
    border-radius: 8px;
    padding: 10px 12px;
    background: #f8fbff;
    display: block;
}

.rich[data-empty="1"]:not(.has-content):not(:focus):before {
    content: "พิมพ์ข้อความที่นี่";
    color: #94a3b8;
}

.rich:focus { outline: 2px solid var(--primary); }

.rich-scroll,
.block[data-type="list"] > .list-items {
    max-height: min(70vh, calc(100vh - var(--top) - 240px));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-padding-bottom: 48px;
    padding-bottom: 28px;
    cursor: default;
}

.rich-scroll > .rich {
    max-height: none;
    overflow: visible;
    cursor: text;
}

.list-items { display: flex; flex-direction: column; gap: 8px; }

.list-item { display: flex; gap: 8px; align-items: center; margin: 0; }

.list-item .rich {
    flex: 1;
    width: auto;
    min-width: 0;
    min-height: 42px;
    padding: 8px 12px;
}

.list-item .fmt-btn { flex: none; }

.list-add {
    margin-top: 8px;
    height: 34px;
    padding: 0 14px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    color: #374151;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.list-add:hover {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: var(--primary);
}

.drop {
    border: 1px dashed #93c5fd;
    border-radius: 12px;
    padding: 28px 18px;
    color: #64748b;
    text-align: center;
    background: #f8fbff;
}

.drop.is-over {
    border-color: var(--primary);
    background: #eff6ff;
}

.level-picks {
    display: inline-flex;
    gap: 0;
    margin: 4px 0 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.level-picks button {
    border: 0;
    border-right: 1px solid var(--line);
    background: #fff;
    color: #4b5563;
    border-radius: 0;
    padding: 4px 10px;
    font-size: 13px;
    line-height: 1.3;
    cursor: pointer;
}

.level-picks button:last-child { border-right: 0; }

.level-picks button.is-on {
    border-color: var(--primary);
    background: #eff6ff;
    color: var(--primary);
    font-weight: 650;
}

.file-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 14px 0;
}

.file-pick {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 16px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 650;
    cursor: pointer;
}

.file-pick input,
.block .file-pick input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.file-name {
    color: #64748b;
    font-size: 14px;
    line-height: 38px;
}

.row-cells {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.row-cell {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    padding: 12px;
    border: 1px dashed #93c5fd;
    border-radius: 12px;
    background: #f8fbff;
}

.row-cell.is-over { background: #eff6ff; }

.row-cell img.preview {
    max-width: 100%;
    max-height: 96px;
    margin: 0 auto;
}

.row-cell .caption-rich {
    min-height: 44px;
    font-size: 14px;
    padding: 8px 10px;
}

.row-cell .caption-rich[data-empty="1"]:not(.has-content):not(:focus):before {
    content: "ข้อความใต้รูป";
}

.row-cell .file-pick { width: 100%; }

.row-cell input { width: 100%; }

.row-cell [data-remove-cell] {
    appearance: none;
    margin-top: 2px;
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid #fecaca;
    border-radius: 8px;
    background: #fff;
    color: #dc2626;
    font-weight: 600;
    cursor: pointer;
}

.row-cell [data-remove-cell]:hover { background: #fef2f2; }

.block > [data-add-cell] {
    appearance: none;
    display: inline-flex;
    align-items: center;
    margin-top: 16px;
    min-height: 38px;
    padding: 0 16px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: #fff;
    color: #1d4ed8;
    font-weight: 650;
    cursor: pointer;
}

.block > [data-add-cell]:hover { background: #eff6ff; }

.image-back {
    margin-left: auto;
    border: 1px solid var(--line);
    background: #fff;
    color: #374151;
    border-radius: 8px;
    min-height: 38px;
    padding: 0 14px;
    cursor: pointer;
}

.image-back:hover { background: #f8fafc; }

.image-back[hidden] { display: none; }

.edit-image {
    border: 1px solid var(--line);
    background: #fff;
    color: #374151;
    border-radius: 8px;
    padding: 6px 12px;
    margin-bottom: 10px;
    cursor: pointer;
}

.edit-image:hover { background: #f8fafc; }

.image-source[hidden],
.edit-image[hidden] { display: none; }

.image-source [data-url] { margin-top: 8px; margin-bottom: 14px; }


#icon-preview { width: 28px; height: 28px; object-fit: contain; }

#search-pop {
    position: fixed;
    top: 72px;
    left: 50%;
    transform: translateX(-50%);
    width: min(560px, calc(100vw - 32px));
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, .12);
    z-index: 40;
    max-height: 50vh;
    overflow: auto;
    padding: 8px;
}

#search-pop[hidden] { display: none; }

#search-pop ul { list-style: none; margin: 0; padding: 0; }

#search-pop a,
#search-pop span { display: block; text-decoration: none; }

#search-pop a { padding: 8px; border-radius: 8px; font-weight: 650; }

#search-pop a:hover { background: #f3f4f6; }

#search-pop span { color: var(--muted); font-size: 13px; padding: 0 8px 8px; }

.emoji-dialog {
    border: 0;
    border-radius: 16px;
    padding: 0 0 8px;
    width: min(440px, calc(100vw - 32px));
    box-shadow: 0 24px 60px rgba(15, 23, 42, .22);
}

.emoji-dialog::backdrop { background: rgba(15, 23, 42, .4); }

.picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px 12px;
}

.picker-head strong { font-size: 16px; }

.picker-x {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: #f3f4f6;
    color: #374151;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.picker-x:hover { background: #e5e7eb; }

.picker-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 16px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-weight: 650;
    cursor: pointer;
}

.picker-upload input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.picker-status {
    margin: 10px 16px 0;
    color: var(--muted);
    font-size: 13px;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 10px;
    margin: 12px 0 0;
    padding: 0 16px 12px;
}

.emoji-grid button {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 6px;
    cursor: pointer;
}

.emoji-grid img { width: 32px; height: 32px; object-fit: contain; }

@media (max-width: 1180px) {
    .app { grid-template-columns: var(--side) minmax(0, 1fr); }
    .toc { display: none; }
}

@media (max-width: 860px) {
    .app,
    .app.no-toc { grid-template-columns: 1fr; }
    .topbar-row {
        height: auto;
        display: grid;
        grid-template-columns: 1fr auto;
        padding: 10px 12px;
        row-gap: 8px;
    }
    .brand { width: auto; padding-left: 0; }
    .search {
        position: static;
        transform: none;
        grid-column: 1 / -1;
        width: 100%;
        margin-left: 0;
    }
    .nav-btn {
        display: inline-flex;
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 6px 10px;
    }
    .sidebar { display: none; }
    .nav-toggle:checked ~ .app .sidebar {
        display: flex;
        position: fixed;
        z-index: 20;
        top: var(--top);
        left: 0;
        bottom: 0;
        width: min(320px, 88vw);
        height: calc(100vh - var(--top));
        background: #fff;
        box-shadow: 8px 0 24px rgba(15, 23, 42, .12);
    }
    .content { padding: 20px 16px 32px; }
    .figure-row.cols-3,
    .figure-row.cols-4,
    .row-cells { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .page-nav { grid-template-columns: 1fr; }
    .edit-head { align-items: flex-start; }
    .page-title { font-size: 26px; line-height: 40px; }
    .page-title-icon { height: 40px; }
    .meta { grid-template-columns: 1fr; }
    .hint-keys { display: none; }
}
