/* เรียน SQL กับ Phai - the layout of Phai Studio's help (phai-studio/docs/help/help.css), in the
   colours and fonts of phai-sql's site (site/assets/site.css: its red, cool greys, the same font
   stacks; the owner, 2026-12-03), and after it what an SQL guide adds: SQL in colour, results,
   answers. No internet needed. */
:root {
  --bg: #ffffff;
  --text: #1f2937;
  --ink: #111827;
  --muted: #5b6472;
  --line: #e7e9ee;
  --panel: #f7f8fa;
  --accent: #e11d2e;
  --code-bg: #f3f4f6;
  --code-soft: #ffe8ea;     /* inline code, as on the site */
  --code-ink: #b3121f;
  --note: #ffe8ea;
  --warn: #fff6e0;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --sans: "IBM Plex Sans Thai", "Leelawadee UI", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --text: #e5e7eb;
    --ink: #f3f4f6;
    --muted: #9aa3b2;
    --line: #2c3442;
    --panel: #1a2130;
    --accent: #ff4d5c;
    --code-bg: #1e2635;
    --code-soft: #3a1d24;
    --code-ink: #ff9aa3;
    --note: #3a1d24;
    --warn: #3a3220;
  }
}
* { box-sizing: border-box; }
html { font-size: 14px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  line-height: 1.7;
}
.layout { display: flex; min-height: 100vh; }
/* The sidebar: folding groups with icons, a search box, put away with « and back with ☰ (help.js). */
nav {
  width: 288px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  font-size: 0.92rem;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
}
.nav-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 16px 12px 10px 16px;
  position: sticky; top: 0; z-index: 2; background: var(--panel); border-bottom: 1px solid transparent;
}
nav .brand { display: flex; align-items: center; gap: 10px; flex: 1; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
nav .brand img { border-radius: 7px; }
.nav-close, .nav-open {
  display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.nav-close:hover, .nav-open:hover { background: var(--line); color: var(--text); }
.nav-search {
  flex-basis: 100%; margin: 4px 0 0; padding: 7px 12px 7px 32px; border: 1px solid var(--line); border-radius: 9px; font: inherit; color: var(--text);
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a9099' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6'/%3E%3Cpath d='M20 20l-4.5-4.5'/%3E%3C/svg%3E") no-repeat 10px center / 15px;
}
.nav-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.nav-body { padding: 4px 10px 24px 12px; }
.nav-none { color: var(--muted); padding: 6px 10px; margin: 0; }
svg.ni { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
nav a {
  display: flex; align-items: center; gap: 10px; padding: 5px 10px; margin: 1px 0; border-radius: 8px;
  color: var(--text); text-decoration: none; line-height: 1.45;
}
nav a svg.ni { color: var(--muted); }
nav a[hidden], details.grp[hidden] { display: none; }
nav a:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
nav a.here { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
nav a.here svg.ni { color: var(--accent); }
nav img.ti { width: 18px; height: 18px; flex: none; opacity: .85; }
nav a.here img.ti { opacity: 1; }
nav .num {
  display: grid; place-items: center; width: 20px; height: 20px; flex: none; border-radius: 6px;
  background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--muted); font-size: .72rem; font-weight: 700;
}
nav a.here .num { background: var(--accent); color: #fff; }
details.grp { margin-top: 8px; }
details.grp > summary {
  display: flex; align-items: center; gap: 6px; padding: 6px 6px; border-radius: 8px; cursor: pointer; list-style: none; user-select: none;
  font-size: .76rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
}
details.grp > summary::-webkit-details-marker { display: none; }
details.grp > summary:focus { outline: none; }
details.grp > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
details.grp > summary:hover { color: var(--text); background: color-mix(in srgb, var(--text) 5%, transparent); }
details.grp > summary svg.ni { width: 14px; height: 14px; transition: transform .18s ease; }
details.grp[open] > summary svg.ni { transform: rotate(90deg); }
details.grp.sub { margin: 2px 0 2px 10px; }
details.grp.sub > summary { text-transform: none; letter-spacing: 0; font-size: .8rem; font-weight: 600; padding: 4px 6px; }
details.grp.sub > .grp-body { border-left: 1px solid var(--line); margin-left: 12px; padding-left: 6px; }
.nav-open { position: fixed; top: 12px; left: 12px; z-index: 20; background: var(--panel); border-color: var(--line); box-shadow: 0 2px 8px rgba(0,0,0,.08); display: none; }
html.nav-ready nav { transition: margin-left .22s ease, transform .22s ease; }
html.nav-hidden nav { margin-left: -289px; }
html.nav-hidden .nav-open { display: grid; }
.nav-shade { display: none; }
@media (prefers-color-scheme: dark) {
  nav img.ti { filter: invert(1) brightness(.9); }
}
@media (max-width: 860px) {
  nav { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.25); margin-left: 0 !important; }
  body.nav-drawn nav { transform: none; }
  body.nav-drawn .nav-shade { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.35); }
  .nav-open { display: grid; }
  main { padding: 64px 18px 60px !important; }
}
main { flex: 1; min-width: 0; padding: 32px 48px 80px; max-width: 920px; }
h1, h2, h3 { color: var(--ink); }
h1 { font-size: 1.75rem; line-height: 1.3; margin: 0 0 8px; }
h2 { font-size: 1.35rem; margin: 40px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
h3 { font-size: 1.1rem; margin: 28px 0 6px; }
.lead { color: var(--muted); font-size: 1.05rem; margin-top: 0; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.88em; background: var(--code-soft); color: var(--code-ink); padding: 1px 6px; border-radius: 6px; }
pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; overflow-x: auto; line-height: 1.5; }
pre code { background: none; color: inherit; padding: 0; font-size: 0.88rem; }
.note, .warn, .try { border-radius: 10px; padding: 10px 16px; margin: 16px 0; }
.note { background: var(--note); border-left: 4px solid var(--accent); }
.warn { background: var(--warn); border-left: 4px solid #d29922; }
.try { background: var(--panel); border: 1px dashed var(--line); }
.try::before { content: "ลองทำ"; display: block; font-weight: 700; margin-bottom: 4px; }
table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 0.94rem; }
th, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
th { background: var(--panel); }
kbd { font-family: "Segoe UI", sans-serif; font-size: 0.85em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 6px; background: var(--panel); white-space: nowrap; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin: 16px 0; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; text-decoration: none; color: var(--text); display: block; }
.card:hover { border-color: var(--accent); }
.card b { display: block; margin-bottom: 4px; }
.card span { color: var(--muted); font-size: 0.9rem; }
.pager { display: flex; justify-content: space-between; margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--line); }
.pager a { text-decoration: none; }
@media (max-width: 760px) {
  table { display: block; overflow-x: auto; }
}


/* ---- what the SQL guide adds ---------------------------------------------------------- */
:root {
  --sql-k: #0b63c4; --sql-f: #7a3e9d; --sql-s: #a3471c; --sql-n: #0f7f5f; --sql-c: #6a737d; --sql-t: #b0006e;
  --ok: #12855f; --err: #c62828; --null: #9aa0a6;
}
@media (prefers-color-scheme: dark) {
  :root { --sql-k: #6cb6ff; --sql-f: #d2a8ff; --sql-s: #f0a07a; --sql-n: #7ee2b8; --sql-c: #8b949e; --sql-t: #ff7ab2; --ok: #3fbf8f; --err: #ff7b72; --null: #7d8590; }
}
.example, .answer { margin: 14px 0 18px; }
.code { position: relative; }
.code pre { margin: 0; padding-right: 44px; }
.code .copy {
  position: absolute; top: 7px; right: 7px; display: grid; place-items: center; width: 28px; height: 28px; padding: 0;
  border: 1px solid transparent; border-radius: 6px; background: var(--code-bg); color: var(--muted); cursor: pointer; opacity: .55;
}
.code:hover .copy, .code .copy:focus-visible { opacity: 1; }
.code .copy:hover { background: var(--line); color: var(--text); }
.code .copy.done { color: var(--ok); opacity: 1; }
.code .copy svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.code .badge {
  position: absolute; top: -9px; left: 12px; padding: 0 8px; border-radius: 10px; font-size: .72rem; font-weight: 700; line-height: 18px;
  background: var(--accent); color: #fff;
}
code.sql .k { color: var(--sql-k); font-weight: 600; }
code.sql .f { color: var(--sql-f); }
code.sql .s { color: var(--sql-s); }
code.sql .n { color: var(--sql-n); }
code.sql .c { color: var(--sql-c); font-style: italic; }
code.sql .t { color: var(--sql-t); }

/* A result, as it came out of phai-sql: joined to the example above it. */
.code + .result, .result + .result { margin-top: -1px; }
.example .code pre, .answer .code pre { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.result {
  border: 1px solid var(--line); border-radius: 0 0 6px 6px; padding: 8px 12px 6px; background: var(--bg);
}
.result::before {
  content: "ผลลัพธ์"; display: block; font-size: .72rem; font-weight: 700; color: var(--muted); letter-spacing: .04em; margin-bottom: 4px;
}
html[lang="en"] .result::before { content: "RESULT"; }
.result .scroll { overflow-x: auto; }
.result table { width: auto; min-width: 40%; margin: 0; font-size: .9rem; }
.result th, .result td { padding: 3px 12px; white-space: nowrap; }
.result th { font-weight: 600; }
.result td.num { text-align: right; font-variant-numeric: tabular-nums; }
.result td.null { color: var(--null); font-style: italic; }
.result td.blob { font-family: var(--mono); font-size: .85em; }
.result .count { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.result.ok { color: var(--ok); font-weight: 600; font-size: .92rem; }
.result.err { color: var(--err); font-size: .92rem; }
.result.ok::before, .result.err::before { display: none; }
.scroll { overflow-x: auto; }
table.doc { margin: 12px 0; }

/* An exercise's answer: folded until asked for. */
details.answer { border: 1px solid var(--line); border-radius: 10px; padding: 0; }
details.answer > summary {
  cursor: pointer; padding: 7px 14px; font-weight: 600; color: var(--accent); list-style: none; user-select: none;
}
details.answer > summary::-webkit-details-marker { display: none; }
details.answer > summary::before { content: "▸ "; }
details.answer[open] > summary::before { content: "▾ "; }
details.answer[open] > summary { border-bottom: 1px solid var(--line); }
details.answer .code pre { border: 0; border-radius: 0; }
details.answer .result { border-width: 1px 0 0; border-radius: 0 0 6px 6px; }
html[lang="en"] .try::before { content: "Try it"; }
.try p:first-child, .note p:first-child, .warn p:first-child { margin-top: 0; }
.try p:last-child, .note p:last-child, .warn p:last-child { margin-bottom: 0; }
pre.plain { line-height: 1.5; }
.foot { color: var(--muted); font-size: .82rem; margin-top: 40px; padding-top: 14px; border-top: 1px solid var(--line); }
.try ol, .try ul, .note ol, .note ul, .warn ol, .warn ul { margin: 4px 0 0; padding-left: 22px; }
