:root {
  --bg: #faf7f8; --card: #ffffff; --ink: #2a1a28; --muted: #6f5f6c; --line: #e6dde2;
  --plum: #5b2a55; --on-plum: #ffffff; --gold: #b8923a; --blush: #f6e9ee; --code: #f3eef1;
  --ok: #1f7a4d; --ok-bg: #e5f3ec; --bad: #b3261e; --bad-bg: #fbe9e7; --warn: #8a5a00; --warn-bg: #fdf1d6;
  --info: #1d5a8a; --info-bg: #e6f0f8;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171117; --card: #221a22; --ink: #f1e8ee; --muted: #a8979f; --line: #3a2d39;
    --plum: #c58bbd; --on-plum: #1b0f1a; --gold: #d8b560; --blush: #2e2130; --code: #2b212b;
    --ok: #5fd196; --ok-bg: #16301f; --bad: #ff8a80; --bad-bg: #3a1c1a; --warn: #f0c36a; --warn-bg: #3a2f14;
    --info: #7fb8e8; --info-bg: #14283a;
  }
}
* { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  scroll-padding-bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
}
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-wrap: break-word;
}
img, video { max-inline-size: 100%; block-size: auto; }
:where(a, code) { overflow-wrap: anywhere; }
h1, h2, h3 { text-wrap: balance; }
p, li { text-wrap: pretty; }
:root { --target-size: 24px; }
@media (pointer: coarse) {
  :root { --target-size: 44px; }
}
:where(button, select, textarea, input:not([type="checkbox"], [type="radio"]), [role="button"], .nav a, label:has(input[type="checkbox"], input[type="radio"])) {
  min-block-size: var(--target-size);
}
h1 { margin: 0 0 4px; font-size: clamp(20px, 4.5vw, 24px); color: var(--plum); letter-spacing: -.01em; }
h2 { margin: 0 0 6px; font-size: 17px; }
h3 { margin: 18px 0 6px; font-size: 15px; }
p { margin: 0 0 10px; }
a { color: var(--plum); }
code { background: var(--code); padding: 1px 5px; border-radius: 4px; font-size: .92em; word-break: break-word; }
.muted { color: var(--muted); }
.sub { color: var(--muted); margin: 0 0 20px; }
.small { font-size: 13px; }
.right { margin-left: auto; }
[hidden] { display: none !important; }

/* shell */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 20px 14px; background: var(--card); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 14px; }
.brand img { width: 40px; height: 40px; }
.brand b { display: block; color: var(--plum); line-height: 1.2; }
.brand span { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.nav a:hover { background: var(--blush); }
.nav a.active { background: var(--plum); color: var(--on-plum); }
.nav a.hl:not(.active) { border: 1px solid var(--gold); }
.side .foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 14px; }
.mode { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); width: fit-content; }
.mode.dry { color: var(--warn); background: var(--warn-bg); border-color: var(--warn); }
.mode.live { color: var(--ok); background: var(--ok-bg); border-color: var(--ok); }
.mode.paused { color: var(--bad); background: var(--bad-bg); border-color: var(--bad); }
main.page { padding: 28px clamp(14px, 4vw, 40px) 96px; max-width: 1120px; width: 100%; }

/* Mobile top bar, bottom quick-nav, and native scroll-snap Drawer */
.mobile-topbar, .mobile-tabbar { display: none; }

.Drawer {
  --drawer-width: min(20em, 82dvw, calc(100dvw - 24px));
  --drawer-backdrop: 0;
  inset: 0; width: auto; height: auto; max-width: none; max-height: none;
  margin: 0; padding: 0; background: transparent; border: 0; overflow: visible;
}
.Drawer::backdrop {
  background: #000;
  opacity: calc(var(--drawer-backdrop) * 0.52);
}
.Drawer-scroller {
  position: relative; display: grid;
  grid-template-columns: var(--drawer-width) 100%;
  overflow-x: scroll; overscroll-behavior: none; scrollbar-width: none;
  scroll-snap-type: x mandatory;
}
.Drawer-scroller::-webkit-scrollbar { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .Drawer-scroller { scroll-behavior: smooth; }
}
.Drawer-scroller::after {
  content: ''; scroll-snap-align: end; scroll-initial-target: nearest;
}
.Drawer-sheet {
  display: grid; grid-template-rows: auto 1fr;
  height: 100svh; background: var(--card); color: var(--ink);
  border-right: 1px solid var(--line); overflow-y: auto;
  scroll-snap-align: start; scrollbar-width: none;
}
@supports (animation-timeline: scroll()) {
  @property --drawer-backdrop {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
  }
  @keyframes fade-drawer-backdrop {
    0% { --drawer-backdrop: 1; }
    100% { --drawer-backdrop: 0; }
  }
  .Drawer {
    timeline-scope: --drawer-fade;
    animation: fade-drawer-backdrop linear both;
    animation-timeline: --drawer-fade;
  }
  .Drawer-scroller {
    scroll-timeline: --drawer-fade x;
  }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; min-height: auto; }
  .side { display: none; }
  main.page { padding: 14px 12px calc(76px + env(safe-area-inset-bottom, 0px)); }
  /* Prevent iOS Safari viewport zoom when tapping inputs */
  input, select, textarea { font-size: 16px; }
  dialog.dlg, dialog.dlg.wide { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0 0; border-radius: 16px 16px 0 0; padding: 16px; }
  .mobile-topbar {
    position: sticky; top: 0; z-index: 35;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    background: var(--card); border-bottom: 1px solid var(--line);
    padding: max(8px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px));
  }
  .mobile-brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .mobile-brand img { width: 28px; height: 28px; flex: none; }
  .mobile-brand b { color: var(--plum); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    display: flex; justify-content: space-around; align-items: stretch;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 4px max(8px, env(safe-area-inset-right, 0px)) max(6px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  }
  .mob-tab {
    flex: 1; border: 0; background: transparent; color: var(--muted); text-decoration: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    font: inherit; font-size: 11px; padding: 4px 2px; border-radius: 8px; cursor: pointer;
  }
  .mob-tab.active { color: var(--plum); font-weight: 700; background: var(--blush); }
  .mob-ico { font-size: 17px; line-height: 1.1; }
}

/* controls */
.btn { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--plum); background: var(--plum); color: var(--on-plum); cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.3; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--plum); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost.danger { background: transparent; color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); max-width: 100%; }
input[type=checkbox], input[type=radio] { padding: 0; width: 16px; height: 16px; accent-color: var(--plum); }
textarea { width: 100%; min-height: 90px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; }
.field > label, .field > .lbl { font-weight: 600; font-size: 13px; }
.field .hint { font-size: 12.5px; color: var(--muted); }
.field input, .field select { width: 100%; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }
.check input { margin-top: 3px; flex: none; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.gap-lg { gap: 16px; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.sp { height: 14px; }

/* cards & tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 14px; }
.card.warn { border-color: var(--gold); }
.card > h2 + p.muted { margin-top: -2px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 700; color: var(--plum); line-height: 1.1; }
.stat .l { font-size: 13px; color: var(--muted); }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--blush); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 6px 14px; font-size: 14px; }
.kv > :nth-child(odd) { color: var(--muted); }
.kv > * { min-width: 0; word-break: break-word; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.badge.bad { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
.badge.warn { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.badge.info { color: var(--info); background: var(--info-bg); border-color: transparent; }
.chip { display: inline-block; padding: 0 8px; margin: 0 4px 2px 0; border-radius: 6px; background: var(--blush); font-size: 12.5px; }

.banner { padding: 11px 14px; border-radius: var(--radius); margin: 0 0 14px; border: 1px solid var(--line); background: var(--card); }
.banner.ok { background: var(--ok-bg); border-color: var(--ok); }
.banner.bad { background: var(--bad-bg); border-color: var(--bad); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn); }
.banner.info { background: var(--info-bg); border-color: var(--info); }
.banner > :last-child { margin-bottom: 0; }

/* checklist */
.cl { list-style: none; padding: 0; margin: 0; }
.cl li { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; border-bottom: 1px solid var(--line); }
.cl li:last-child { border-bottom: 0; }
.cl .mark { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; border: 2px solid var(--line); color: var(--muted); }
.cl .done .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.cl .done .t { color: var(--muted); }
.cl .opt .mark { border-style: dashed; }
.cl .t { flex: 1; }
.cl .go { font-size: 13px; white-space: nowrap; }

/* code blocks */
.codeblock { position: relative; margin: 8px 0 12px; }
.codeblock pre { margin: 0; background: var(--code); border-radius: 8px; padding: 10px 70px 10px 12px; overflow: auto; font-size: 13px; white-space: pre-wrap; word-break: break-all; }
.codeblock .btn { position: absolute; top: 6px; right: 6px; }
pre.log { background: var(--code); border-radius: 8px; padding: 10px; margin: 8px 0 0; overflow: auto; max-height: 280px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); text-align: center; }
.login img { width: 84px; height: 84px; }
.login form { text-align: left; margin-top: 14px; }

/* dialog & toast */
dialog.dlg { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); padding: 20px; width: min(620px, 94vw); max-height: 90vh; overflow: auto; }
dialog.dlg::backdrop { background: rgba(20, 8, 20, .55); }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.form-err { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--bad-bg); color: var(--bad); font-size: 14px; white-space: pre-wrap; }
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--plum); color: var(--on-plum); box-shadow: 0 4px 16px rgba(0, 0, 0, .25); }
.toast.bad { background: var(--bad); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }

/* inbox */
.inbox { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 820px) { .inbox { grid-template-columns: 1fr; } }
.convs { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); max-height: 70vh; overflow-y: auto; }
.conv { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.conv:hover, .conv.active { background: var(--blush); }
.conv .who { font-weight: 600; }
.conv .last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.msgs { display: flex; flex-direction: column; gap: 8px; max-height: 52vh; overflow-y: auto; padding: 4px 2px 10px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 12px; background: var(--blush); white-space: pre-wrap; word-break: break-word; }
.bubble.out { align-self: flex-end; background: var(--plum); color: var(--on-plum); }
.bubble.echo { align-self: flex-end; background: var(--info-bg); color: var(--ink); }
.bubble .meta { display: block; font-size: 11px; opacity: .75; margin-top: 3px; }

/* guide */
.guide { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 960px) { .guide { grid-template-columns: 1fr; } }
.toc { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
@media (max-width: 960px) { .toc { position: static; flex-direction: row; flex-wrap: wrap; gap: 6px; } }
.toc button { font: inherit; text-align: left; background: none; border: 0; padding: 5px 8px; border-radius: 6px; cursor: pointer; color: var(--ink); }
.toc button:hover { background: var(--blush); }
@media (max-width: 960px) { .toc button { border: 1px solid var(--line); } }
.gsec { scroll-margin-top: 12px; margin: 0 0 28px; }
.gsec > h2 { font-size: 20px; color: var(--plum); border-bottom: 2px solid var(--gold); padding-bottom: 4px; margin-bottom: 12px; }
.steps { list-style: none; counter-reset: s; padding: 0; margin: 0 0 12px; }
.steps > li { counter-increment: s; position: relative; padding: 0 0 12px 38px; }
.steps > li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--plum); color: var(--on-plum); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.steps > li > :last-child { margin-bottom: 0; }
.flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; margin: 10px 0 14px; }
.flow .node { flex: 1 1 180px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.flow .node b { display: block; color: var(--plum); }
.flow .arrow { align-self: center; color: var(--gold); font-weight: 700; }
details.qa { border: 1px solid var(--line); border-radius: 8px; background: var(--card); margin: 0 0 8px; }
details.qa summary { cursor: pointer; padding: 9px 12px; font-weight: 600; }
details.qa > div { padding: 0 12px 10px; }
