/* ===================================================================
   Git-KM stylesheet — one file, no build step.
   Refined product UI: indigo brand, layered surfaces, compact density.
   Theming: light by default; dark via system preference OR an explicit
   [data-theme] override set by theme-init.js / the toggle.
   =================================================================== */

/* ---- Design tokens ---- */
:root {
  color-scheme: light;

  /* Neutrals — three layers so panels read as distinct from content */
  --bg: oklch(0.985 0.004 275); /* app background (behind everything) */
  --panel: oklch(0.972 0.006 275); /* sidebars, topbar, toolbars */
  --surface: oklch(1 0 0); /* content cards, reading column */
  --inset: oklch(0.955 0.006 275); /* code, wells, table headers */

  --border: oklch(0.905 0.008 275);
  --border-strong: oklch(0.84 0.01 275);

  --text: oklch(0.27 0.02 275);
  --text-muted: oklch(0.47 0.02 275);
  --text-faint: oklch(0.6 0.018 275);

  /* Brand — refined indigo/violet, not generic blue */
  --brand: oklch(0.53 0.19 274);
  --brand-hover: oklch(0.47 0.2 274);
  --brand-ink: oklch(0.4 0.17 274); /* brand text on light bg (contrast-safe) */
  --brand-soft: oklch(0.95 0.03 274); /* selected/active tint */
  --brand-ring: oklch(0.53 0.19 274 / 0.4);
  --on-brand: oklch(0.99 0 0);

  --danger: oklch(0.55 0.2 25);
  --danger-soft: oklch(0.96 0.03 25);
  --success: oklch(0.55 0.14 155);
  --success-soft: oklch(0.95 0.04 155);
  --warning: oklch(0.62 0.14 75);
  --warning-soft: oklch(0.95 0.05 80);
  --info: var(--brand);

  --shadow-sm: 0 1px 2px oklch(0.4 0.03 275 / 0.06);
  --shadow: 0 1px 2px oklch(0.4 0.03 275 / 0.05),
    0 6px 20px oklch(0.4 0.03 275 / 0.08);

  --radius-lg: 12px;
  --radius: 9px;
  --radius-sm: 6px;

  /* Compact scale */
  --sidebar-w: 274px;
  --toc-w: 216px;
  --topbar-h: 52px;
  --content-max: 44rem;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "IBM Plex Sans Thai",
    "Sarabun", "Noto Sans Thai", Tahoma, Roboto, Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", "JetBrains Mono", "Fira Code", Consolas,
    "Liberation Mono", Menlo, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1); /* ease-out-quart */
  --dur: 160ms;

  /* z-index scale */
  --z-sticky: 30;
  --z-drawer: 45;
  --z-topbar: 50;
  --z-dropdown: 60;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: oklch(0.17 0.014 275);
  --panel: oklch(0.155 0.014 275);
  --surface: oklch(0.205 0.016 275);
  --inset: oklch(0.235 0.018 275);
  --border: oklch(0.3 0.02 275);
  --border-strong: oklch(0.4 0.025 275);
  --text: oklch(0.93 0.012 275);
  --text-muted: oklch(0.72 0.02 275);
  --text-faint: oklch(0.6 0.02 275);
  --brand: oklch(0.72 0.15 278);
  --brand-hover: oklch(0.78 0.14 278);
  --brand-ink: oklch(0.8 0.13 278);
  --brand-soft: oklch(0.3 0.07 275);
  --brand-ring: oklch(0.72 0.15 278 / 0.5);
  --on-brand: oklch(0.15 0.02 275);
  --danger: oklch(0.7 0.16 25);
  --danger-soft: oklch(0.32 0.08 25);
  --success: oklch(0.72 0.15 155);
  --success-soft: oklch(0.3 0.07 155);
  --warning: oklch(0.78 0.13 80);
  --warning-soft: oklch(0.32 0.06 80);
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.4);
  --shadow: 0 1px 2px oklch(0 0 0 / 0.4), 0 8px 24px oklch(0 0 0 / 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: oklch(0.17 0.014 275);
    --panel: oklch(0.155 0.014 275);
    --surface: oklch(0.205 0.016 275);
    --inset: oklch(0.235 0.018 275);
    --border: oklch(0.3 0.02 275);
    --border-strong: oklch(0.4 0.025 275);
    --text: oklch(0.93 0.012 275);
    --text-muted: oklch(0.72 0.02 275);
    --text-faint: oklch(0.6 0.02 275);
    --brand: oklch(0.72 0.15 278);
    --brand-hover: oklch(0.78 0.14 278);
    --brand-ink: oklch(0.8 0.13 278);
    --brand-soft: oklch(0.3 0.07 275);
    --brand-ring: oklch(0.72 0.15 278 / 0.5);
    --on-brand: oklch(0.15 0.02 275);
    --danger: oklch(0.7 0.16 25);
    --danger-soft: oklch(0.32 0.08 25);
    --success: oklch(0.72 0.15 155);
    --success-soft: oklch(0.3 0.07 155);
    --warning: oklch(0.78 0.13 80);
    --warning-soft: oklch(0.32 0.06 80);
    --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.4);
    --shadow: 0 1px 2px oklch(0 0 0 / 0.4), 0 8px 24px oklch(0 0 0 / 0.5);
  }
}

/* ---- Base ---- */
* {
  box-sizing: border-box;
}
html {
  font-size: 15px;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 16px);
}
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a {
  color: var(--brand-ink);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
::selection {
  background: var(--brand-soft);
}
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
.icon {
  display: inline-flex;
  width: 1.1em;
  height: 1.1em;
  vertical-align: -0.15em;
  flex-shrink: 0;
}
.icon svg {
  width: 100%;
  height: 100%;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ---- Buttons & forms ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.42rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover {
  background: var(--inset);
  border-color: var(--text-faint);
  text-decoration: none;
}
.btn:active {
  transform: translateY(0.5px);
}
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background: var(--inset);
  color: var(--text);
}
.btn-danger {
  border-color: var(--border-strong);
  color: var(--danger);
  background: transparent;
}
.btn-danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}
.btn-sm {
  padding: 0.28rem 0.55rem;
  font-size: 0.82rem;
}
.linklike {
  border: none;
  background: none;
  color: var(--brand-ink);
  font: inherit;
  cursor: pointer;
  padding: 0;
}
input,
select,
textarea {
  font: inherit;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  width: 100%;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}
.field {
  margin-bottom: 0.95rem;
}
.field .hint {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  height: var(--topbar-h);
  background: color-mix(in oklch, var(--panel) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.topbar-middle {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand:hover {
  text-decoration: none;
}
.brand .icon {
  color: var(--brand);
  width: 1.25em;
  height: 1.25em;
}
.brand-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-logo-img {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  object-fit: contain;
  flex-shrink: 0;
}
.brand-logo-emoji {
  font-size: 1.2rem;
  line-height: 1;
  flex-shrink: 0;
}
.icon-btn,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover,
.theme-toggle:hover {
  background: var(--inset);
  color: var(--text);
}
.menu-btn {
  display: none;
}
.theme-icon-dark {
  display: none;
}
:root[data-theme="dark"] .theme-icon-light {
  display: none;
}
:root[data-theme="dark"] .theme-icon-dark {
  display: inline-flex;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-light {
    display: none;
  }
  :root:not([data-theme="light"]) .theme-icon-dark {
    display: inline-flex;
  }
}

/* App view: brand cell matches the sidebar column, above the sidebar */
body.shell-view .topbar-inner {
  padding: 0;
}
body.shell-view .topbar-left {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding-left: 1.1rem;
  border-right: 1px solid var(--border);
  align-self: stretch;
}
body.shell-view .topbar-middle {
  padding-left: 0.5rem;
}
body.shell-view .topbar-right {
  padding-right: 1rem;
}

/* ---- Account menu ---- */
.account {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}
.account-menu {
  position: relative;
}
.account-menu > summary {
  list-style: none;
}
.account-menu > summary::-webkit-details-marker {
  display: none;
}
.account-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  z-index: var(--z-dropdown);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.account-dropdown a,
.account-dropdown .linklike {
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  text-align: left;
}
.account-dropdown a:hover,
.account-dropdown .linklike:hover {
  background: var(--inset);
  text-decoration: none;
}
.account-email {
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.2rem;
}

/* ---- Search box ---- */
.searchbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: min(420px, 100%);
  padding: 0 0.7rem;
  background: var(--inset);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-faint);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.searchbox:focus-within {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.searchbox .icon {
  width: 1em;
  height: 1em;
}
.searchbox input {
  border: none;
  background: transparent;
  padding: 0.4rem 0;
  font-size: 0.88rem;
}
.searchbox input:focus {
  outline: none;
  box-shadow: none;
}

/* ---- App shell (viewer) ---- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  max-width: 1440px;
  margin: 0 auto;
}
.toc-col {
  min-width: 0;
}
.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 1rem 0.6rem 3rem 0.7rem;
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.sidebar-app-name {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 0 0 0.6rem 0.5rem;
}
.main {
  min-width: 0;
  padding: 1.75rem clamp(1rem, 4vw, 3rem) 4rem;
  background: var(--surface);
}
.main-inner {
  max-width: var(--content-max);
  margin: 0 auto;
}
.toc {
  position: sticky;
  top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 1.75rem 1.1rem;
  font-size: 0.82rem;
}

/* ---- Sidebar nav ---- */
.sidebar-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0.3rem 0.5rem;
  margin-bottom: 0.6rem;
  border-radius: var(--radius-sm);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sidebar-back:hover {
  background: var(--inset);
  color: var(--text);
  text-decoration: none;
}
.sidebar-back .icon {
  width: 0.9em;
  height: 0.9em;
}
.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-list .nav-list {
  margin-left: 0.5rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--border);
}
.nav-link,
.nav-folder-link,
.nav-folder-label {
  display: block;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.45;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-link:hover,
.nav-folder-link:hover {
  background: var(--inset);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active,
.nav-folder-link.active {
  position: relative;
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 600;
}
.nav-link.active::before {
  content: "";
  position: absolute;
  left: -0.7rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 1.05em;
  border-radius: 2px;
  background: var(--brand);
}
.nav-folder > summary {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  list-style: none;
  cursor: pointer;
}
.nav-folder > summary::-webkit-details-marker {
  display: none;
}
.nav-folder-summary .nav-chevron {
  color: var(--text-faint);
  transition: transform var(--dur) var(--ease);
  flex-shrink: 0;
  width: 0.9em;
  height: 0.9em;
}
.nav-folder[open] > summary .nav-chevron {
  transform: rotate(90deg);
}
.nav-folder-label {
  color: var(--text);
  font-weight: 600;
  flex: 1;
}
.nav-folder-link {
  flex: 1;
  font-weight: 600;
  color: var(--text);
}

/* ---- TOC ---- */
.toc-title {
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 0.55rem;
}
.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}
.toc li a {
  display: block;
  padding: 0.22rem 0 0.22rem 0.75rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--text-muted);
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.toc li a:hover {
  color: var(--text);
  text-decoration: none;
}
.toc li a.active {
  color: var(--brand-ink);
  border-left-color: var(--brand);
  font-weight: 600;
}
.toc-l3 a {
  padding-left: 1.5rem;
  font-size: 0.95em;
}

/* ---- Breadcrumb ---- */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.9rem;
}
.breadcrumb a {
  color: var(--text-muted);
}
.breadcrumb-sep {
  color: var(--text-faint);
}

/* ---- Markdown content ---- */
.doc-content {
  font-size: 1.02rem;
  line-height: 1.75;
  overflow-wrap: break-word;
}
.doc-content > *:first-child {
  margin-top: 0;
}
.doc-content h1,
.doc-content h2,
.doc-content h3,
.doc-content h4 {
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: -0.015em;
  scroll-margin-top: calc(var(--topbar-h) + 12px);
  text-wrap: balance;
}
.doc-content h1 {
  font-size: 1.9rem;
  margin: 0 0 1rem;
}
.doc-content h2 {
  font-size: 1.4rem;
  margin: 2.2rem 0 0.9rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
.doc-content h3 {
  font-size: 1.15rem;
  margin: 1.7rem 0 0.6rem;
}
.doc-content h4 {
  font-size: 1rem;
  margin: 1.3rem 0 0.5rem;
}
.doc-content p {
  text-wrap: pretty;
}
.doc-content p,
.doc-content ul,
.doc-content ol {
  margin: 0 0 1rem;
}
.doc-content ul,
.doc-content ol {
  padding-left: 1.5rem;
}
.doc-content li {
  margin: 0.3rem 0;
}
.doc-content li::marker {
  color: var(--text-faint);
}
.doc-content a {
  color: var(--brand-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in oklch, var(--brand) 40%, transparent);
}
.doc-content a:hover {
  text-decoration-color: var(--brand);
}
.doc-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.doc-content blockquote {
  margin: 0 0 1rem;
  padding: 0.1rem 1rem;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}
.doc-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}
.doc-content kbd {
  font-family: var(--mono);
  font-size: 0.82em;
  padding: 0.12em 0.45em;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--inset);
}
/* Inline code */
.doc-content :not(pre) > code {
  font-family: var(--mono);
  font-size: 0.85em;
  padding: 0.12em 0.4em;
  border-radius: 5px;
  background: var(--inset);
  border: 1px solid var(--border);
  color: var(--text);
}
/* Code blocks (Shiki dual-theme via CSS variables) */
.doc-content pre {
  margin: 0 0 1.1rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.55;
  position: relative;
}
.doc-content pre code {
  font-family: var(--mono);
  display: block;
}
.shiki,
.shiki span {
  color: var(--shiki-light);
}
.shiki {
  background: var(--shiki-light-bg) !important;
}
:root[data-theme="dark"] .shiki,
:root[data-theme="dark"] .shiki span {
  color: var(--shiki-dark);
}
:root[data-theme="dark"] .shiki {
  background: var(--shiki-dark-bg) !important;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .shiki,
  :root:not([data-theme="light"]) .shiki span {
    color: var(--shiki-dark);
  }
  :root:not([data-theme="light"]) .shiki {
    background: var(--shiki-dark-bg) !important;
  }
}
.copy-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  opacity: 0;
  transition: opacity var(--dur) var(--ease), color var(--dur) var(--ease);
  padding: 0.2rem 0.4rem;
  font-size: 0.72rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
}
.doc-content pre:hover .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
}
.copy-btn.copied {
  color: var(--success);
  border-color: var(--success);
}

/* Tables — horizontal rules + tinted header, no vertical grid */
.doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1.1rem;
  font-size: 0.92rem;
  display: block;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.doc-content th,
.doc-content td {
  padding: 0.5rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.doc-content thead th {
  background: var(--inset);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.doc-content tbody tr:last-child td {
  border-bottom: none;
}
.doc-content tbody tr {
  transition: background var(--dur) var(--ease);
}
.doc-content tbody tr:hover {
  background: color-mix(in oklch, var(--brand-soft) 45%, transparent);
}

/* Task lists */
.doc-content .task-list-item {
  list-style: none;
  margin-left: -1.5rem;
}
.doc-content .task-checkbox {
  width: auto;
  margin: 0 0.5rem 0 0;
  vertical-align: middle;
  accent-color: var(--brand);
}

/* GitHub alerts — full border + tint + colored title (no side stripe) */
.markdown-alert {
  margin: 0 0 1.1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--inset);
  color: var(--text);
}
.markdown-alert > *:last-child {
  margin-bottom: 0;
}
.markdown-alert-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin: 0 0 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.markdown-alert-title::before {
  content: "";
  width: 0.7em;
  height: 0.7em;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.markdown-alert-note {
  background: var(--brand-soft);
  border-color: color-mix(in oklch, var(--brand) 30%, var(--border));
}
.markdown-alert-note .markdown-alert-title {
  color: var(--brand-ink);
}
.markdown-alert-tip {
  background: var(--success-soft);
  border-color: color-mix(in oklch, var(--success) 30%, var(--border));
}
.markdown-alert-tip .markdown-alert-title {
  color: var(--success);
}
.markdown-alert-important {
  background: var(--brand-soft);
  border-color: color-mix(in oklch, var(--brand) 30%, var(--border));
}
.markdown-alert-important .markdown-alert-title {
  color: var(--brand-ink);
}
.markdown-alert-warning {
  background: var(--warning-soft);
  border-color: color-mix(in oklch, var(--warning) 30%, var(--border));
}
.markdown-alert-warning .markdown-alert-title {
  color: var(--warning);
}
.markdown-alert-caution {
  background: var(--danger-soft);
  border-color: color-mix(in oklch, var(--danger) 30%, var(--border));
}
.markdown-alert-caution .markdown-alert-title {
  color: var(--danger);
}

/* ---- Doc footer & prev/next ---- */
.doc-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}
.prevnext {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-top: 1.75rem;
}
.prevnext-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.prevnext-link:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
  text-decoration: none;
}
.prevnext-link.next {
  justify-content: flex-end;
  text-align: right;
}
.prevnext-link .icon {
  color: var(--text-faint);
}
.prevnext-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-faint);
}
.prevnext-title {
  display: block;
  font-weight: 600;
  color: var(--brand-ink);
  font-size: 0.9rem;
}

/* ---- Home / app cards ---- */
.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2.5rem clamp(1rem, 4vw, 2rem) 4rem;
}
.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}
.page-lead {
  color: var(--text-muted);
  margin: 0 0 2rem;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.9rem;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}
a.card:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
  text-decoration: none;
}
.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.card-title .icon {
  color: var(--brand);
}
.card-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
}
.badge-public {
  color: var(--success);
  border-color: color-mix(in oklch, var(--success) 35%, var(--border));
  background: var(--success-soft);
}
.badge-restricted {
  color: var(--text-muted);
  background: var(--inset);
}
.badge-idle {
  color: var(--success);
  border-color: color-mix(in oklch, var(--success) 35%, var(--border));
  background: var(--success-soft);
}
.badge-syncing {
  color: var(--brand-ink);
  border-color: color-mix(in oklch, var(--brand) 35%, var(--border));
  background: var(--brand-soft);
}
.badge-error {
  color: var(--danger);
  border-color: color-mix(in oklch, var(--danger) 35%, var(--border));
  background: var(--danger-soft);
}

/* ---- Search results ---- */
.result {
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--border);
}
.result-title {
  font-size: 1.02rem;
  font-weight: 600;
}
.result-snippet {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}
.result-snippet mark {
  background: var(--brand-soft);
  color: var(--brand-ink);
  padding: 0 0.15em;
  border-radius: 3px;
}

/* ---- Auth / centered forms ---- */
.center-wrap {
  min-height: calc(100vh - var(--topbar-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  position: relative;
  isolation: isolate;
}
/* Subtle branded backdrop so the page isn't an empty void */
.center-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(
      60% 55% at 50% 0%,
      color-mix(in oklch, var(--brand) 12%, transparent),
      transparent 70%
    ),
    radial-gradient(
      40% 40% at 85% 90%,
      color-mix(in oklch, var(--brand) 8%, transparent),
      transparent 70%
    );
}
.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 1.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  justify-content: center;
  margin-bottom: 1.25rem;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  color: var(--text);
}
.auth-brand .icon {
  color: var(--brand);
  width: 1.4em;
  height: 1.4em;
}
.auth-card h1 {
  margin: 0 0 1.25rem;
  font-size: 1.2rem;
  text-align: center;
}

/* ---- Alerts / flash ---- */
.flash {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.1rem;
  font-size: 0.88rem;
  border: 1px solid transparent;
}
.flash-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in oklch, var(--danger) 30%, var(--border));
}
.flash-success {
  background: var(--success-soft);
  color: var(--success);
  border-color: color-mix(in oklch, var(--success) 30%, var(--border));
}
.flash-info {
  background: var(--brand-soft);
  border-color: color-mix(in oklch, var(--brand) 25%, var(--border));
  color: var(--brand-ink);
}
.secret-box {
  font-family: var(--mono);
  background: var(--inset);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  word-break: break-all;
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

/* ---- Admin ---- */
.admin-layout {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  max-width: 1160px;
  margin: 0 auto;
  gap: 1.75rem;
  padding: 1.75rem clamp(1rem, 3vw, 2rem);
}
.admin-nav {
  position: sticky;
  top: calc(var(--topbar-h) + 1rem);
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.4rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.admin-nav a {
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.admin-nav a:hover {
  background: var(--inset);
  color: var(--text);
  text-decoration: none;
}
.admin-nav a.active {
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 600;
}
.admin-main {
  min-width: 0;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.section-head h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.table th,
.table td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table thead th {
  background: var(--inset);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  font-weight: 600;
}
.table tbody tr:last-child td {
  border-bottom: none;
}
.table tbody tr {
  transition: background var(--dur) var(--ease);
}
.table tbody tr:hover {
  background: var(--panel);
}
.table .actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.muted {
  color: var(--text-muted);
}
.mono {
  font-family: var(--mono);
  font-size: 0.82em;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.row > * {
  flex: 1;
  min-width: 180px;
}
/* One-line form: fields + a submit button, all bottom-aligned on one baseline */
.form-inline {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-inline > .field {
  margin-bottom: 0;
  flex: 1;
  min-width: 160px;
}
.form-inline > .btn {
  flex: 0 0 auto;
}

/* Searchable combobox */
.combobox-control {
  position: relative;
}
.combobox-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: var(--z-dropdown);
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.combobox-list[hidden] {
  display: none;
}
.combobox-option {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.combobox-option[hidden] {
  display: none;
}
.combobox-option:hover,
.combobox-option.active {
  background: var(--inset);
}
.co-name {
  font-weight: 500;
}
.co-email {
  color: var(--text-muted);
  font-size: 0.85em;
}
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--surface);
  margin-bottom: 1.25rem;
}
.panel h2 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.inline-form {
  display: inline;
}

/* ---- App workspace (tabbed manage page, "1b") ---- */
.ws-header {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 1.1rem;
}
.ws-avatar {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  background: var(--brand);
  color: var(--on-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
  overflow: hidden;
}
.ws-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* When a logo is set, drop the brand fill so the logo/emoji sits on a neutral
   surface; the indigo fill is reserved for the initials fallback. */
.ws-avatar-plain {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.ws-headings {
  flex: 1;
  min-width: 0;
}
.ws-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.ws-title-row h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.ws-slug {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-muted);
  background: var(--inset);
  padding: 0.1rem 0.45rem;
  border-radius: 5px;
}
.ws-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.2rem;
}
.ws-header-actions {
  flex-shrink: 0;
}

/* Status bar */
.statusbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}
.statusbar-idle {
  background: var(--success-soft);
  border-color: color-mix(in oklch, var(--success) 30%, var(--border));
}
.statusbar-error {
  background: var(--danger-soft);
  border-color: color-mix(in oklch, var(--danger) 30%, var(--border));
}
.statusbar-syncing {
  background: var(--brand-soft);
  border-color: color-mix(in oklch, var(--brand) 30%, var(--border));
}
.statusbar .status-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 220px;
}
.status-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot-idle {
  background: var(--success);
}
.status-dot-error {
  background: var(--danger);
}
.status-dot-syncing {
  background: var(--brand);
  animation: pulse 1.4s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.statusbar .actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* CSS-only tabs (no JS needed) */
.tabs {
  position: relative;
}
.tab-radio {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.tabbar {
  display: flex;
  gap: 0.1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar {
  display: none;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.8rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tab:hover {
  color: var(--text);
}
.tabpanel {
  display: none;
}
#tab-general:checked ~ .tabbar .tab[for="tab-general"],
#tab-github:checked ~ .tabbar .tab[for="tab-github"],
#tab-webhook:checked ~ .tabbar .tab[for="tab-webhook"],
#tab-members:checked ~ .tabbar .tab[for="tab-members"] {
  color: var(--brand-ink);
  border-bottom-color: var(--brand);
  font-weight: 600;
}
#tab-danger:checked ~ .tabbar .tab[for="tab-danger"] {
  color: var(--danger);
  border-bottom-color: var(--danger);
  font-weight: 600;
}
.tab-danger {
  color: var(--danger);
}
#tab-general:checked ~ #panel-general,
#tab-github:checked ~ #panel-github,
#tab-webhook:checked ~ #panel-webhook,
#tab-members:checked ~ #panel-members,
#tab-danger:checked ~ #panel-danger {
  display: block;
}
.tab-radio:focus-visible ~ .tabbar .tab {
  outline: none;
}
.form-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.4rem;
}
.form-actions .spacer {
  flex: 1;
}
.logo-field {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.logo-preview {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: var(--inset);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  overflow: hidden;
}
.logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--text-muted);
}
.empty-state .empty-icon {
  width: 2.75rem;
  height: 2.75rem;
  color: var(--text-faint);
  margin-bottom: 0.75rem;
}
.empty-state h2 {
  margin: 0 0 0.4rem;
  color: var(--text);
  font-size: 1.15rem;
}

/* ---- Drawer backdrop (mobile) ---- */
.backdrop {
  display: none;
  position: fixed;
  inset: var(--topbar-h) 0 0;
  background: oklch(0.2 0.02 275 / 0.45);
  backdrop-filter: blur(2px);
  z-index: var(--z-drawer);
}
body.drawer-open .backdrop {
  display: block;
}

/* ---- Responsive ---- */
@media (max-width: 1150px) {
  .shell {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }
  .toc {
    display: none;
  }
}
@media (max-width: 860px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .menu-btn {
    display: inline-flex;
  }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(82vw, var(--sidebar-w));
    z-index: var(--z-drawer);
    transform: translateX(-100%);
    transition: transform 0.22s var(--ease);
  }
  body.drawer-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow);
  }
  .admin-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .admin-nav {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .topbar-middle {
    display: none;
  }
  body.shell-view .topbar-inner {
    padding: 0 1rem;
  }
  body.shell-view .topbar-left {
    width: auto;
    padding-left: 0;
    border-right: none;
  }
  body.shell-view .topbar-right {
    padding-right: 0;
  }
}
