:root {
  --bg: #f2f4f7; --card: #ffffff; --text: #1b2430; --muted: #5d6b7c; --line: #dde3ea;
  --brand: #164e84; --brand-text: #ffffff; --brand-soft: #e6eef7;
  --ok: #1d6b3a; --ok-bg: #e5f4ea; --info: #164e84; --info-bg: #e6eef7;
  --warn: #7a5200; --warn-bg: #fdf3dc; --err: #a1261f; --err-bg: #fbe7e5;
  --radius: 8px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --card: #19212b; --text: #e5eaf0; --muted: #9aa7b6; --line: #2b3643;
    --brand: #8fb8e8; --brand-text: #0d1824; --brand-soft: #1d2b3b;
    --ok: #7fd49c; --ok-bg: #16301f; --info: #8fb8e8; --info-bg: #1a2a3c;
    --warn: #f0c46a; --warn-bg: #352a12; --err: #f29b93; --err-bg: #3a1c1a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--brand); }
code, .mono { font-family: var(--mono); font-size: .92em; }
h1 { font-size: 1.45rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
img { max-width: 100%; }
[hidden] { display: none !important; }

.top { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem; padding: .6rem 1rem;
  background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; color: var(--text); text-decoration: none; }
.brand-mark { height: 28px; width: auto; }
.brand-tag { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; background: var(--brand);
  color: var(--brand-text); padding: .05rem .4rem; border-radius: 4px; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .9rem; }
.nav a { text-decoration: none; color: var(--muted); padding: .2rem 0; }
.nav a[aria-current="page"] { color: var(--text); font-weight: 600; border-bottom: 2px solid var(--brand); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }
.foot a { color: inherit; }
.banner { padding: .6rem 1rem; font-weight: 600; text-align: center; }
.banner.err { background: var(--err); color: #fff; }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid var(--line); }

.auth-wrap { max-width: 440px; margin: 0 auto; padding: 2rem 1rem 3rem; }
.lockup { text-align: center; margin-bottom: 1.25rem; }
.lockup-mark { height: 64px; width: auto; display: block; margin: 0 auto .5rem; }
.lockup-name { text-transform: uppercase; font-size: 24px; font-weight: 800; letter-spacing: .04em; }
.lockup-sub { text-transform: uppercase; font-size: .72rem; letter-spacing: .12em; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); margin-bottom: 1rem; min-width: 0; }
.card.narrow { max-width: 520px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 1rem; }
.grid2 > .card { margin: 0; }
.grid2 > .wide { grid-column: 1 / -1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }

.stack { display: flex; flex-direction: column; gap: .75rem; margin: 0 0 1rem; }
.stack label, label.stack { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 0 0 .75rem; }
.inline { display: inline; margin: 0; }
.stack > .btn, .stack > button, .stack label .badge, label.stack .badge { align-self: flex-start; }
.auth-wrap .stack > .btn.primary { align-self: stretch; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 6px; padding: .5rem .6rem; min-width: 0; max-width: 100%; }
textarea { min-height: 5rem; font-family: var(--mono); font-size: .9em; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.btn { display: inline-block; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 6px; padding: .5rem .9rem; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--brand); padding: 0; font: inherit; cursor: pointer; text-decoration: underline; }
.or { display: flex; align-items: center; gap: .75rem; color: var(--muted); margin: .25rem 0 1rem; font-size: .85rem; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.flash { border-radius: 6px; padding: .6rem .8rem; margin: 0 0 1rem; border: 1px solid transparent; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.info { background: var(--info-bg); color: var(--info); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.err { background: var(--err-bg); color: var(--err); }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .05rem .45rem; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.card .table { display: block; overflow-x: auto; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0 0 1rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; overflow-wrap: anywhere; }

.tiles { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.tile { display: flex; flex-direction: column; gap: .3rem; height: 100%; padding: 1rem; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); }
.tile:hover { border-color: var(--brand); }
.tile-icon { width: 40px; height: 40px; border-radius: 8px; object-fit: contain; }
.tile-icon.letter { display: grid; place-items: center; background: var(--brand); color: var(--brand-text); font-weight: 800; }
.tile-name { font-weight: 700; }
.tile-desc { color: var(--muted); font-size: .88rem; }
.tile .badge { align-self: flex-start; }

.qr { display: flex; justify-content: center; margin: .5rem 0; }
.qr svg { width: 200px; height: 200px; background: #fff; border-radius: 6px; }
.secret { word-break: break-all; }
.recovery-key { display: inline-block; font-size: 1.05rem; letter-spacing: .03em; padding: .6rem .8rem; background: var(--bg); border: 1px dashed var(--line); border-radius: 6px; line-height: 1.7; }
.codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: .3rem 1rem; }
.choice-list { display: grid; gap: .75rem; margin: 0 0 1rem; }
.choice { display: flex; flex-direction: column; gap: .4rem; padding: .9rem 1rem; border: 1px solid var(--line); border-radius: 10px;
  text-decoration: none; color: var(--text); background: var(--card); }
a.choice:hover { border-color: var(--brand); background: var(--brand-soft); }
.choice strong { color: var(--brand); }
.choice span { color: var(--muted); font-size: .9rem; }
.choice .btn { align-self: flex-start; }
.steps { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); font-weight: 700; margin: 0 0 .5rem; }
pre.code { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .75rem; overflow-x: auto; font-size: .85rem; }

/* ---------------------------------------------------------------------------
   Knowledge base (Admin → Help). Numbered how-to lists use .howto (never .steps,
   which is the setup progress header).
   --------------------------------------------------------------------------- */
.kb-wrap { max-width: 1280px; }
.kb-icon { width: 1.4rem; height: 1.4rem; flex: none; }
.kb-icon-sm { width: 1rem; height: 1rem; vertical-align: -.15em; }

.kb-hero { text-align: center; padding: 2.5rem 1rem 2rem; margin: -1.25rem -1rem 1.5rem;
  background: linear-gradient(180deg, var(--brand-soft), transparent); border-bottom: 1px solid var(--line); }
.kb-hero h1 { font-size: 2rem; margin-bottom: .4rem; letter-spacing: -.01em; }
.kb-hero p { color: var(--muted); margin: 0 auto 1.25rem; max-width: 640px; }
.kb-search { display: flex; align-items: center; gap: .6rem; max-width: 620px; margin: 0 auto; padding: 0 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); color: var(--muted); }
.kb-search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.kb-search input { border: 0; background: transparent; padding: .8rem 0; width: 100%; font-size: 1rem; outline: none; }
.kb-search-small { border-radius: 8px; padding: 0 .6rem; margin: 0 0 1rem; max-width: none; }
.kb-search-small input { padding: .5rem 0; font-size: .9rem; }

.kb-sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 1rem; }
.kb-extras { margin-top: 1.5rem; }
.kb-section-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1.25rem; box-shadow: var(--shadow); min-width: 0; }
.kb-section-card header { display: flex; gap: .85rem; align-items: flex-start; margin-bottom: .75rem; }
.kb-section-card h2 { margin: 0 0 .15rem; font-size: 1.1rem; }
.kb-section-card p { margin: 0; }
.kb-section-icon { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand); flex: none; }
.kb-guide-list { list-style: none; margin: 0; padding: 0; }
.kb-guide-list a { display: block; padding: .6rem .7rem; margin: 0 -.7rem; border-radius: 8px; text-decoration: none; color: var(--text); }
.kb-guide-list a:hover, .kb-guide-list a:focus-visible { background: var(--bg); }
.kb-guide-list a span:last-child { display: block; color: var(--muted); font-size: .88rem; margin-top: .1rem; }
.kb-guide-list a strong { color: var(--brand); }
.kb-section-card pre.code { margin: 0; }
.kb-empty { text-align: center; padding: 2rem 0; }

.kb-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr) 200px; gap: 2rem; align-items: start; }
.kb-side, .kb-toc-col { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 1rem); max-height: calc(100vh - 2rem); overflow-y: auto; }
.kb-nav-section { margin-bottom: 1.1rem; }
.kb-nav-title { display: flex; align-items: center; gap: .4rem; font-size: .74rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); margin-bottom: .3rem; }
.kb-side ul { list-style: none; margin: 0; padding: 0; }
.kb-side li a { display: block; padding: .32rem .6rem; border-radius: 6px; text-decoration: none; color: var(--text); font-size: .92rem; border-left: 2px solid transparent; }
.kb-side li a:hover { background: var(--card); }
.kb-side li a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; border-left-color: var(--brand); border-radius: 0 6px 6px 0; }

.kb-article { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 2rem 2.25rem; box-shadow: var(--shadow); min-width: 0; }
.kb-crumbs { display: flex; gap: .45rem; font-size: .85rem; color: var(--muted); margin-bottom: .75rem; }
.kb-crumbs a { color: var(--muted); }
.kb-article h1 { font-size: 1.9rem; letter-spacing: -.01em; margin-bottom: .35rem; }
.kb-lead { font-size: 1.1rem; color: var(--muted); margin: 0 0 .5rem; }
.kb-meta { display: flex; align-items: center; gap: .35rem; font-size: .85rem; color: var(--muted); margin: 0 0 1.5rem;
  padding-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.kb-body { font-size: 1rem; line-height: 1.7; }
.kb-body h2 { font-size: 1.3rem; margin: 2.25rem 0 .75rem; padding-top: .25rem; scroll-margin-top: 1rem; }
.kb-body h2:first-child { margin-top: 0; }
.kb-body p, .kb-body ul { margin: 0 0 1rem; }
.kb-body code { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: .05rem .3rem; }
.kb-body pre.code code, .kb-body pre code { background: none; border: 0; padding: 0; }
.kb-body pre.code { line-height: 1.5; margin: 0 0 1.25rem; }

.toc { font-size: .88rem; }
.toc-title { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .5rem; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.toc li a { display: block; padding: .3rem 0 .3rem .8rem; margin-left: -2px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; }
.toc li a:hover { color: var(--brand); border-left-color: var(--brand); }

.howto { counter-reset: howto; list-style: none; padding: 0; margin: 0 0 1.5rem; }
.howto > li { counter-increment: howto; position: relative; padding: .15rem 0 .9rem 2.6rem; min-height: 2rem; }
.howto > li::before { content: counter(howto); position: absolute; left: 0; top: 0; width: 1.8rem; height: 1.8rem;
  border-radius: 50%; background: var(--brand); color: var(--brand-text); font-weight: 700; font-size: .85rem;
  display: grid; place-items: center; }
.howto > li:not(:last-child)::after { content: ""; position: absolute; left: .87rem; top: 2rem; bottom: .1rem; width: 2px; background: var(--line); }

.tip, .note, .warning { position: relative; border: 1px solid; border-radius: 10px; padding: .8rem 1rem .8rem 1rem; margin: 0 0 1.25rem; }
.tip::before, .note::before, .warning::before { display: block; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; margin-bottom: .2rem; }
.tip { border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: var(--ok-bg); }
.tip::before { content: "Tip"; color: var(--ok); }
.note { border-color: color-mix(in srgb, var(--info) 35%, transparent); background: var(--info-bg); }
.note::before { content: "Note"; color: var(--info); }
.warning { border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: var(--warn-bg); }
.warning::before { content: "Important"; color: var(--warn); }

figure.shot { margin: 0 0 1.75rem; }
.shot-frame { display: block; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card);
  box-shadow: 0 6px 24px rgba(16, 24, 40, .10); transition: transform .15s ease, box-shadow .15s ease; }
.shot-frame:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(16, 24, 40, .16); }
.shot-bar { display: flex; gap: .35rem; padding: .5rem .7rem; background: var(--bg); border-bottom: 1px solid var(--line); }
.shot-bar i { width: .6rem; height: .6rem; border-radius: 50%; background: var(--line); }
figure.shot img { display: block; width: 100%; height: auto; }
figure.shot figcaption { color: var(--muted); font-size: .85rem; margin-top: .5rem; text-align: center; }

.kb-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.kb-pager a { display: flex; flex-direction: column; gap: .2rem; padding: .9rem 1rem; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--brand); }
.kb-pager a:hover { border-color: var(--brand); background: var(--brand-soft); }
.kb-pager-next { text-align: right; grid-column: 2; }

@media (max-width: 1100px) {
  .kb-layout { grid-template-columns: 220px minmax(0, 1fr); }
  .kb-toc-col { display: none; }
}
@media (max-width: 760px) {
  .kb-layout { grid-template-columns: 1fr; gap: 1rem; }
  .kb-side { position: static; max-height: none; }
  .kb-side nav { display: none; }
  .kb-side:focus-within nav { display: block; }
  .kb-article { padding: 1.25rem; }
  .kb-hero h1 { font-size: 1.6rem; }
  .kb-pager { grid-template-columns: 1fr; }
  .kb-pager-next { grid-column: 1; }
}

.matrix th.rot { white-space: nowrap; }
.matrix td { white-space: nowrap; }
.sudo { background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: .5rem .8rem; margin-bottom: 1rem; }

/* ---------------------------------------------------------------------------
   Admin console: left sidebar navigation (collapses to a menu on phones).
   --------------------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
  background: var(--card); border-right: 1px solid var(--line); padding: 1rem .75rem calc(1rem + env(safe-area-inset-bottom, 0px)); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 .5rem .9rem; }
.side-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.side-nav { flex: 1; }
.side-group { padding: .35rem 0; }
.side-group + .side-group { border-top: 1px solid var(--line); margin-top: .35rem; padding-top: .7rem; }
.side-title { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 0 .65rem .3rem; }
.side-link { display: flex; align-items: center; gap: .65rem; width: 100%; padding: .45rem .65rem; border-radius: 8px; color: var(--text);
  text-decoration: none; font: inherit; font-size: .93rem; background: none; border: 0; cursor: pointer; text-align: left; }
.side-link:hover { background: var(--bg); }
.side-link[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.side-icon { width: 1.15rem; height: 1.15rem; flex: none; opacity: .85; }
.side-foot { border-top: 1px solid var(--line); padding-top: .75rem; margin-top: .75rem; }
.side-foot form { margin: 0; }
.side-user { display: flex; flex-direction: column; padding: 0 .65rem .5rem; font-size: .88rem; }
.side-user span { color: var(--muted); font-size: .78rem; text-transform: capitalize; }
.side-menu { display: none; }
.side-menu summary { list-style: none; cursor: pointer; display: flex; flex-direction: column; gap: 4px; padding: .55rem .45rem; border-radius: 8px; }
.side-menu summary::-webkit-details-marker { display: none; }
.side-menu summary span { display: block; width: 20px; height: 2px; background: var(--text); border-radius: 2px; }
.shell-main { min-width: 0; width: 100%; padding-top: 1.75rem; }
.admin-shell .foot { margin-left: 240px; }
.admin-shell .kb-layout { grid-template-columns: 220px minmax(0, 1fr) 190px; }
@media (max-width: 1350px) { .admin-shell .kb-layout { grid-template-columns: 210px minmax(0, 1fr); } .admin-shell .kb-toc-col { display: none; } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 10; height: auto; padding: .5rem .75rem; padding-top: calc(.5rem + env(safe-area-inset-top, 0px));
    border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .side-head { padding: 0; }
  .side-body { display: none; }
  .side-menu { display: block; position: static; }
  .side-menu-body { position: absolute; left: 0; right: 0; top: 100%; max-height: calc(100vh - 4rem); overflow-y: auto;
    background: var(--card); border-bottom: 1px solid var(--line); padding: .5rem .75rem 1rem; box-shadow: 0 8px 24px rgba(16, 24, 40, .12); }
  .admin-shell .foot { margin-left: 0; }
  .admin-shell .kb-layout { grid-template-columns: 1fr; }
}
