:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-input: #0d1117;
  --bg-active: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #c9d1d9;
  --accent: #238636;
  --accent-bg: #1f6feb33;
  --shadow: rgba(0, 0, 0, 0.4);
}
:root[data-theme='light'] {
  --bg: #ffffff;
  --bg-elev: #f6f8fa;
  --bg-input: #ffffff;
  --bg-active: #eaeef2;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #424a53;
  --accent: #1a7f37;
  --accent-bg: #ddf4ff;
  --shadow: rgba(0, 0, 0, 0.08);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #ffffff;
    --bg-elev: #f6f8fa;
    --bg-input: #ffffff;
    --bg-active: #eaeef2;
    --border: #d0d7de;
    --text: #1f2328;
    --text-muted: #424a53;
    --accent: #1a7f37;
    --accent-bg: #ddf4ff;
    --shadow: rgba(0, 0, 0, 0.08);
  }
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.4rem;
}
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 1rem;
}
.topbar h1 {
  font-size: 1rem;
  margin: 0;
  letter-spacing: 0.02em;
}
.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.topbar nav button {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
}
.topbar nav button.active,
.topbar nav button:hover,
.topbar nav button:focus-visible {
  background: var(--bg-active);
  border-color: var(--border);
  outline: none;
}
main {
  padding: 1rem;
  max-width: 1100px;
  margin: 0 auto;
}
h2,
h3 {
  margin: 0.6rem 0 0.4rem;
}
.chat {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1rem;
  height: calc(100vh - 130px);
}
.chat aside {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-y: auto;
}
.chat aside .aside-h {
  padding: 0.4rem;
  opacity: 0.7;
}
.chat aside button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: inherit;
  border: 0;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
}
.chat aside button.active {
  background: var(--bg-active);
}
.chat .stream {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  overflow-y: auto;
  flex: 1 1 auto;
}
.composer {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.4rem;
}
.composer .completions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.composer .completions button {
  background: var(--bg-active);
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.2rem 0.7rem;
  cursor: pointer;
}
.msg {
  padding: 0.4rem 0.6rem;
  margin: 0.2rem 0;
  border-radius: 6px;
  background: var(--bg-elev);
}
.msg.me {
  background: var(--accent-bg);
  margin-left: 2rem;
}
.msg .meta {
  font-size: 0.75rem;
  opacity: 0.6;
}
.meta {
  font-size: 0.75rem;
  opacity: 0.7;
}
input,
textarea,
select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  width: 100%;
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button.primary {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
}
button {
  background: var(--bg-active);
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
}
.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.col {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
table {
  width: 100%;
  border-collapse: collapse;
}
td,
th {
  border-bottom: 1px solid var(--border);
  padding: 0.4rem;
  text-align: left;
}
.graph {
  border: 1px dashed var(--border);
  border-radius: 8px;
  min-height: 320px;
  padding: 0.5rem;
  position: relative;
}
.node {
  display: inline-block;
  background: var(--bg-active);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  margin: 0.2rem;
}
.operator .card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  background: var(--bg-elev);
}
.operator .big {
  font-size: 1.4rem;
  margin: 0.7rem 0 1rem;
}
.card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem;
  margin: 0.4rem 0;
  background: var(--bg-elev);
}
pre {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  overflow-x: auto;
}

.mode-badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  margin-left: auto;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.mode-badge.online {
  background: #033a16;
  color: #6dd58c;
  border-color: #1a532e;
}
.mode-badge.offline {
  background: #3a1a03;
  color: #f0a36c;
  border-color: #5a2c10;
}
:root[data-theme='light'] .mode-badge.online {
  background: #dafbe1;
  color: #1a7f37;
  border-color: #aceebb;
}
:root[data-theme='light'] .mode-badge.offline {
  background: #fff8c5;
  color: #9a6700;
  border-color: #ffd33d;
}
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: white;
  padding: 0.5rem 1rem;
  z-index: 1000;
}
.skip-link:focus {
  left: 0;
}

/* Connection guides (issue #10, R-M1..R-M8). */
.connection-guide {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
}
.connection-guide > h2 {
  margin: 0;
}
.local-server-help {
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  color: var(--text);
}
.local-server-help-opt pre {
  margin: 0.25rem 0;
  padding: 0.5rem;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.85rem;
}

/* Tutorial overlay (issue #10, R-M9..R-M12). */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
}
.tutorial-overlay .tutorial-step {
  max-width: 32rem;
  width: 100%;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.tutorial-overlay .tutorial-step h2 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}
.tutorial-overlay .tutorial-step .meta {
  font-size: 0.8rem;
  opacity: 0.75;
  margin: 0.5rem 0 0.75rem;
}
.tutorial-overlay .tutorial-step .row {
  flex-wrap: wrap;
  gap: 0.5rem;
}
.tutorial-toggle {
  margin-left: 0.5rem;
}

/* Tutorial spotlight (issue #25 R-N9, R-N10). When a step has a
   `tutorialId` the overlay drops the centred backdrop and instead lays
   four dimming panes around a transparent frame so the highlighted
   control reads as "the only lit thing on screen". The frame is
   absolutely positioned by JS using the target's bounding rect.
   Implementation note: we use `box-shadow` with a giant spread to dim
   everything *outside* the frame in a single element — that avoids
   coordinating four sibling rectangles whose sizes depend on the
   target rect. */
.tutorial-overlay-spotlight {
  background: transparent;
  align-items: flex-end;
  padding: 1rem;
  /* Let pointer events fall through the overlay to the spotlighted
     control. The dialog card and the spotlight frame restore their own
     pointer behaviour below. Without this, the fixed-position overlay
     would swallow taps on the very nav button the spotlight is asking
     the user to tap. */
  pointer-events: none;
}
/* Place the dialog card opposite the spotlighted control so the card
   never overlaps its own anchor. `data-spotlight-side` is set by JS
   from the target's bounding rect (R-N9, R-N10). */
.tutorial-overlay-spotlight[data-spotlight-side='top'] {
  align-items: flex-start;
}
.tutorial-overlay-spotlight[data-spotlight-side='top'] .tutorial-step {
  margin-top: 0;
  margin-bottom: auto;
}
.tutorial-overlay-spotlight .tutorial-spotlight-frame {
  border-radius: 12px;
  box-shadow:
    0 0 0 9999px rgba(0, 0, 0, 0.55),
    0 0 0 3px rgba(102, 178, 255, 0.85);
}
.tutorial-overlay-spotlight .tutorial-step {
  position: relative;
  z-index: 1;
  margin-top: auto;
  pointer-events: auto;
}
@media (prefers-reduced-transparency: reduce) {
  .tutorial-overlay-spotlight .tutorial-spotlight-frame {
    box-shadow:
      0 0 0 9999px rgba(0, 0, 0, 0.85),
      0 0 0 3px rgba(102, 178, 255, 1);
  }
}

/* ----- Issue #25 — mobile-first AppShell + glass tokens ------------- */

/* Glass surface token (R-N11). The `prefers-reduced-transparency`
   media query ships a solid fallback so users who opt out of
   translucency still get a fully opaque chrome. */
:root {
  --surface-glass-bg: rgba(22, 27, 34, 0.62);
  --surface-glass-border: rgba(240, 246, 252, 0.08);
  --surface-glass-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
:root[data-theme='light'] {
  --surface-glass-bg: rgba(255, 255, 255, 0.72);
  --surface-glass-border: rgba(15, 23, 42, 0.08);
  --surface-glass-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}
.glass {
  background: var(--surface-glass-bg);
  border: 1px solid var(--surface-glass-border);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
}
@media (prefers-reduced-transparency: reduce) {
  .glass {
    background: var(--bg-elev);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

/* AppShell layout — flex container that swaps the primary-nav surface
   based on viewport classification (compact/medium/expanded). */
.app-shell {
  display: flex;
  width: 100%;
  min-height: calc(100vh - 56px);
}
.app-shell-body {
  flex: 1 1 auto;
  min-width: 0;
}
.app-shell-compact {
  flex-direction: column;
  /* Reserve space for the bottom-nav (R-N1) including safe-area inset. */
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
}
.app-shell-medium {
  flex-direction: row;
}
.app-shell-expanded {
  flex-direction: row;
}

/* Bottom navigation (compact ≤ 640 px). 56 × 56 px tap targets per
   Material 3 + WCAG 2.2 AAA touch guidance (R-N2). */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  overflow-x: auto;
  padding: 0.25rem;
  padding-bottom: calc(0.25rem + env(safe-area-inset-bottom, 0px));
  gap: 0.25rem;
  z-index: 50;
  box-shadow: var(--surface-glass-shadow);
}
.bottom-nav .nav-item {
  flex: 0 0 auto;
  min-width: 64px;
  min-height: 56px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  font-size: 0.78rem;
  cursor: pointer;
}
.bottom-nav .nav-item.active {
  background: var(--accent-bg);
  color: var(--text);
}

/* Navigation rail (medium 641-1023 px). 80 px wide, full-height. */
.side-rail {
  position: sticky;
  top: 0;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  width: 80px;
  height: 100vh;
  padding: 0.5rem;
  gap: 0.25rem;
  overflow-y: auto;
  box-shadow: var(--surface-glass-shadow);
}
.side-rail .nav-item {
  min-height: 56px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 12px;
  padding: 0.5rem 0.25rem;
  font-size: 0.7rem;
  cursor: pointer;
  text-align: center;
  word-break: keep-all;
}
.side-rail .nav-item.active {
  background: var(--accent-bg);
  color: var(--text);
}

/* Permanent drawer (expanded ≥ 1024 px). 256 px wide. */
.permanent-drawer {
  position: sticky;
  top: 0;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  width: 256px;
  height: 100vh;
  padding: 1rem 0.5rem;
  gap: 0.25rem;
  overflow-y: auto;
  box-shadow: var(--surface-glass-shadow);
}
.permanent-drawer .nav-item {
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  text-align: left;
  cursor: pointer;
  font-size: 0.95rem;
}
.permanent-drawer .nav-item.active {
  background: var(--accent-bg);
  color: var(--text);
}

/* Hide the legacy header nav block (now provided by AppShell). The
   topbar still hosts the brand, mode badge, tutorial / language /
   theme controls. */
.topbar > nav[aria-label='Primary'] {
  display: none;
}

/* Topbar gets the glass token so it visually matches the new nav. */
.topbar.glass {
  position: sticky;
  top: 0;
  z-index: 40;
}
