:root {
  --bg: #0f0f10;
  --bg-elevated: #161618;
  --panel: #1c1c1f;
  --ink: #f4f1ea;
  --muted: #a39e95;
  --subtle: #6f6a63;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --accent: #ff7f36;
  --accent-strong: #ff9a5c;
  --accent-soft: rgba(255, 127, 54, 0.14);
  --ok: #3dcf7a;
  --mid: #e0b43a;
  --bad: #f07178;
  --warn-bg: rgba(224, 180, 58, 0.1);
  --info-bg: rgba(255, 127, 54, 0.08);
  --font-sans: "Instrument Sans", system-ui, sans-serif;
  --font-heading: "Space Grotesk", "Instrument Sans", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --max: 1180px;
  --toc-w: 240px;
  --radius: 12px;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code, .mono { font-family: var(--font-mono); font-size: 0.88em; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  background: rgba(15, 15, 16, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: inherit;
  text-decoration: none;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand .mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #ff4d00);
  box-shadow: 0 0 0 1px rgba(255,127,54,.35), 0 6px 18px rgba(255,127,54,.25);
}
.brand strong { display: block; font-size: 0.92rem; letter-spacing: -0.02em; }
.brand em {
  display: block;
  font-style: normal;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.top-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-left: 0.5rem;
  font-size: 0.82rem;
}
.top-nav a { color: var(--muted); }
.top-nav a:hover { color: var(--ink); text-decoration: none; }
.badge {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid rgba(255,127,54,.35);
  background: var(--accent-soft);
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
}

.hero {
  max-width: var(--max);
  margin: 0 auto;
  padding: 3rem 1.25rem 1.5rem;
}
.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 0.75rem;
}
.hero h1 {
  font-family: var(--font-heading);
  font-size: clamp(2.1rem, 5vw, 3.2rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
  margin: 0 0 1rem;
  font-weight: 700;
}
.hero h1 span { color: var(--accent); }
.lede {
  max-width: 48rem;
  color: var(--muted);
  font-size: 1.08rem;
  margin: 0 0 1.25rem;
}
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  font-size: 0.85rem;
  color: var(--subtle);
}
.meta-row code { color: var(--ink); }
.meta-row b { color: var(--mid); font-weight: 600; }

.layout {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
  display: grid;
  grid-template-columns: var(--toc-w) minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
}

.toc {
  position: sticky;
  top: 64px;
  max-height: calc(100vh - 80px);
  overflow: auto;
  padding: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.8rem;
}
.toc-title {
  margin: 0 0 0.6rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtle);
  font-weight: 600;
}
.toc ol {
  margin: 0;
  padding: 0 0 0 1.1rem;
  color: var(--muted);
}
.toc li { margin: 0.35rem 0; }
.toc a { color: var(--muted); }
.toc a:hover, .toc a.is-active { color: var(--accent-strong); text-decoration: none; }

.doc section {
  padding: 1.75rem 0 0.5rem;
  border-top: 1px solid var(--line);
  scroll-margin-top: 72px;
}
.doc section:first-of-type { border-top: 0; padding-top: 0.25rem; }
.doc h2 {
  font-family: var(--font-heading);
  font-size: 1.45rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.85rem;
}
.doc h3 {
  font-size: 1.05rem;
  margin: 1.35rem 0 0.55rem;
  color: var(--ink);
}
.doc p, .doc li { color: #d8d3cb; }
.doc ul, .doc ol { padding-left: 1.25rem; }
.doc li { margin: 0.3rem 0; }
.doc strong { color: var(--ink); }

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 1rem 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.tbl th, .tbl td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.tbl th {
  background: var(--panel);
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.tbl tr:last-child td { border-bottom: 0; }
.tbl td { color: #d8d3cb; }

.tree {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  color: #cfc8bc;
  font-size: 0.82rem;
  line-height: 1.55;
  margin: 1rem 0;
}

.callout {
  background: var(--info-bg);
  border: 1px solid rgba(255,127,54,.28);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin: 1rem 0;
  color: #e8e2d8;
}
.callout.warn {
  background: var(--warn-bg);
  border-color: rgba(224,180,58,.3);
  border-left-color: var(--mid);
}
.callout strong { display: block; margin-bottom: 0.35rem; }
.callout ul { margin: 0.35rem 0 0; }

.note {
  font-size: 0.9rem;
  color: var(--subtle);
  border-left: 2px solid var(--line-strong);
  padding-left: 0.85rem;
}

.pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  margin-right: 0.25rem;
}
.pill.ok { background: rgba(61,207,122,.15); color: var(--ok); }
.pill.mid { background: rgba(224,180,58,.15); color: var(--mid); }
.pill.bad { background: rgba(240,113,120,.15); color: var(--bad); }

.check {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}
.check li {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0.4rem 0;
  background: var(--bg-elevated);
}
.check input {
  margin-top: 0.25rem;
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.check label { cursor: pointer; color: #d8d3cb; }

.doc-foot {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}
.doc-foot .subtle { color: var(--subtle); font-size: 0.8rem; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .toc { position: relative; top: 0; max-height: none; }
  .top-nav { display: none; }
}

@media print {
  .topbar, .toc { display: none; }
  .layout { grid-template-columns: 1fr; }
  body { background: #fff; color: #111; }
  .doc p, .doc li, .tbl td { color: #222; }
}

/* ——— Floating HA assistant ——— */
.ha-assist { position: relative; z-index: 100; }
.ha-fab {
  position: fixed;
  right: 1.15rem;
  bottom: 1.15rem;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  border: 1px solid rgba(255, 127, 54, 0.45);
  background: linear-gradient(145deg, #ff8a45, #e85a10);
  color: #111;
  box-shadow: 0 10px 30px rgba(255, 127, 54, 0.35), 0 0 0 1px rgba(0,0,0,.3);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  z-index: 110;
  transition: transform .15s ease, box-shadow .15s ease;
}
.ha-fab:hover { transform: translateY(-2px) scale(1.03); }
.ha-fab.is-open { background: #1c1c1f; color: var(--accent); border-color: var(--line-strong); box-shadow: 0 8px 20px rgba(0,0,0,.4); }
.ha-fab-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #3dcf7a;
  box-shadow: 0 0 8px #3dcf7a;
}
.ha-fab.is-open .ha-fab-dot { background: var(--accent); box-shadow: none; }
.ha-fab-label { font-family: var(--font-heading); font-weight: 700; font-size: 0.85rem; letter-spacing: 0.04em; }

.ha-panel {
  position: fixed;
  right: 1.15rem;
  bottom: 5.2rem;
  width: min(400px, calc(100vw - 1.5rem));
  height: min(560px, calc(100vh - 7rem));
  background: #141416;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 105;
}
.ha-panel[hidden] { display: none !important; }

.ha-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 0.95rem;
  border-bottom: 1px solid var(--line);
  background: #1a1a1d;
}
.ha-head strong {
  display: block;
  font-family: var(--font-heading);
  font-size: 0.95rem;
}
.ha-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}
.ha-head-actions { display: flex; gap: 0.25rem; }
.ha-icon-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.95rem;
}
.ha-icon-btn:hover { color: var(--ink); border-color: var(--accent); }

.ha-status {
  font-size: 0.72rem;
  padding: 0.35rem 0.95rem;
  color: var(--subtle);
  border-bottom: 1px solid var(--line);
  background: #121214;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ha-status[data-kind="ok"] { color: var(--ok); }
.ha-status[data-kind="warn"] { color: var(--mid); }
.ha-status[data-kind="busy"] { color: var(--accent); }

.ha-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.ha-msg {
  max-width: 92%;
  padding: 0.55rem 0.7rem;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.45;
  border: 1px solid var(--line);
}
.ha-msg.is-user {
  align-self: flex-end;
  background: rgba(255, 127, 54, 0.12);
  border-color: rgba(255, 127, 54, 0.28);
}
.ha-msg.is-bot {
  align-self: flex-start;
  background: #1c1c20;
}
.ha-msg-meta {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--subtle);
  margin-bottom: 0.25rem;
  font-weight: 600;
}
.ha-msg-body { color: #e4dfd6; word-break: break-word; }
.ha-msg-body code {
  background: rgba(255,255,255,.06);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  font-size: 0.82em;
}
.ha-typing {
  align-self: flex-start;
  font-size: 0.8rem;
  color: var(--accent);
  padding: 0.25rem 0.5rem;
  animation: ha-pulse 1.2s ease-in-out infinite;
}
@keyframes ha-pulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}

.ha-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border-top: 1px solid var(--line);
  background: #121214;
}
.ha-chips button {
  font-size: 0.72rem;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #1a1a1d;
  color: var(--muted);
  cursor: pointer;
}
.ha-chips button:hover {
  color: var(--ink);
  border-color: rgba(255,127,54,.4);
}

.ha-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  padding: 0.65rem 0.75rem 0.8rem;
  border-top: 1px solid var(--line);
  background: #1a1a1d;
}
.ha-form textarea {
  resize: none;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f0f10;
  color: var(--ink);
  padding: 0.55rem 0.65rem;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  outline: none;
}
.ha-form textarea:focus { border-color: rgba(255,127,54,.5); }
.ha-send {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #111;
  font-weight: 700;
  padding: 0 0.9rem;
  cursor: pointer;
  font-family: var(--font-heading);
}
.ha-send:disabled { opacity: .5; cursor: wait; }
.ha-send:hover:not(:disabled) { background: var(--accent-strong); }

@media (max-width: 520px) {
  .ha-panel {
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
    bottom: 4.8rem;
    height: min(70vh, 520px);
  }
  .ha-fab { right: 0.85rem; bottom: 0.85rem; }
}
