/* QuadrantLink Help demo. Layout: a one-screen help app. Desktop: guide pane on the left, chat on the right.
   Below 1024px the guide becomes a drawer and the chat takes the full screen. */
:root {
  --bg: #f4f7f6;
  --panel: #ffffff;
  --panel-2: #f9fbfa;
  --ink: #142320;
  --ink-2: #33433f;
  --muted: #5b6b66;
  --line: #dee6e3;
  --line-strong: #c8d3cf;
  --accent: #0a7462;
  --accent-hover: #075f50;
  --accent-ink: #ffffff;
  --accent-soft: #e2f2ed;
  --user: #133029;
  --user-ink: #f0f7f4;
  --warn: #8a5300;
  --warn-soft: #fcf2e1;
  --scrim: rgb(9 16 14 / 46%);
  --shadow-sm: 0 1px 2px rgb(20 35 32 / 6%);
  --shadow-md: 0 1px 2px rgb(20 35 32 / 5%), 0 6px 18px -8px rgb(20 35 32 / 16%);
  --shadow-lg: 0 24px 60px -20px rgb(20 35 32 / 35%);
  --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --col: 760px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1211; --panel: #131b19; --panel-2: #0f1615; --ink: #e5edea; --ink-2: #c4d0cc; --muted: #93a39d;
    --line: #233029; --line-strong: #31403c; --accent: #45c4a9; --accent-hover: #63d4bb; --accent-ink: #052019;
    --accent-soft: #14302a; --user: #2a4b44; --user-ink: #eef6f3; --warn: #e8a84e; --warn-soft: #2a2114;
    --scrim: rgb(0 0 0 / 60%);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 30%);
    --shadow-md: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 22px -10px rgb(0 0 0 / 60%);
    --shadow-lg: 0 24px 60px -20px rgb(0 0 0 / 70%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font: 15px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.col { width: 100%; max-width: var(--col); margin-inline: auto; }

/* App frame */
.app { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.topbar {
  display: flex; align-items: center; gap: 12px; min-height: 58px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px)) 10px max(18px, env(safe-area-inset-left, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 19px; height: 19px; stroke-width: 1.9; }
.brand-name { font-weight: 600; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { flex: none; font: 500 10.5px/1 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; padding: 5px 7px 4px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.byline { font-size: 13px; color: var(--muted); white-space: nowrap; }

.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; border: 0; background: none; color: var(--ink-2); cursor: pointer; flex: none; }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small svg { width: 16px; height: 16px; }
.quiet-btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink-2); font-size: 14px; font-weight: 500; cursor: pointer; }
.quiet-btn svg { width: 18px; height: 18px; }
.secondary-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 7px 14px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink); font-size: 14px; font-weight: 500; cursor: pointer; }
.primary-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 600; cursor: pointer; }
.link-btn { border: 0; background: none; padding: 6px 4px; color: var(--muted); font-size: 14px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
button:disabled { cursor: default; }

.body { display: grid; grid-template-columns: 320px minmax(0, 1fr); min-height: 0; }
.narrow-only { display: none; }

/* Guide pane */
.guide { display: flex; flex-direction: column; min-height: 0; background: var(--panel-2); border-right: 1px solid var(--line); }
.guide-head { padding: 16px 16px 12px; display: grid; gap: 12px; border-bottom: 1px solid var(--line); }
.guide-title-row { display: flex; align-items: center; justify-content: space-between; min-height: 24px; }
.guide h2 { margin: 0; font: 500 12px/1 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.search { display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; color: var(--muted); cursor: text; }
.search svg { width: 17px; height: 17px; }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; padding: 9px 0; font-size: 15px; color: var(--ink); }
.search input::placeholder { color: var(--muted); opacity: 1; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.guide-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 8px 20px; }
.group + .group { margin-top: 10px; }
.group h3 { margin: 10px 10px 4px; font: 500 11px/1.4 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.group ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-item { width: 100%; display: grid; gap: 1px; padding: 9px 10px; border: 0; border-radius: 10px; background: none; text-align: left; cursor: pointer; color: var(--ink); }
.nav-item .t { font-size: 14px; font-weight: 500; line-height: 1.35; }
.nav-item .m { font: 400 11.5px/1.4 var(--font-mono); color: var(--muted); }
.nav-item[aria-current="true"] { background: var(--accent-soft); }
.nav-item[aria-current="true"] .t { color: var(--accent); }
.empty { padding: 18px 10px; display: grid; gap: 12px; justify-items: start; color: var(--muted); font-size: 14px; }
.empty p { margin: 0; }
.article { padding: 4px 10px 8px; }
.back { display: inline-flex; align-items: center; gap: 4px; margin-left: -6px; padding: 6px; border: 0; border-radius: 8px; background: none; color: var(--accent); font-size: 14px; font-weight: 500; cursor: pointer; }
.back svg { width: 17px; height: 17px; }
.article .menu { margin: 12px 0 2px; font: 400 12px/1.4 var(--font-mono); color: var(--muted); }
.article h3 { margin: 0 0 14px; font-size: 19px; line-height: 1.3; text-wrap: balance; }
.article .steps { margin-bottom: 18px; }
.guide-foot { margin: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); font-size: 12px; line-height: 1.45; color: var(--muted); }

/* Chat */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { flex: none; padding: 16px max(24px, env(safe-area-inset-right, 0px)) 14px max(24px, env(safe-area-inset-left, 0px)); border-bottom: 1px solid var(--line); background: var(--bg); }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.head-text { min-width: 0; }
.chat-head h1 { margin: 0; font-size: 18px; line-height: 1.3; font-weight: 600; letter-spacing: -.005em; }
.chat-head p { margin: 2px 0 0; font-size: 13.5px; line-height: 1.45; color: var(--muted); }
.mode { flex: none; display: inline-flex; align-items: center; gap: 6px; font: 500 12px/1 var(--font-mono); padding: 7px 10px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap; background: var(--panel); }
.mode[data-mode="ai"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.notice-wrap { flex: none; padding: 12px max(24px, env(safe-area-inset-right, 0px)) 0 max(24px, env(safe-area-inset-left, 0px)); }
.notice { display: flex; align-items: flex-start; gap: 8px; padding: 9px 6px 9px 14px; border-radius: 12px; background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 28%, transparent); font-size: 13.5px; line-height: 1.5; }
.notice p { margin: 0; padding-top: 3px; flex: 1; min-width: 0; }
.notice b { color: var(--warn); font-weight: 600; }
.notice .icon-btn { color: var(--warn); margin-top: -2px; }

.log { position: relative; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.log:focus-visible { outline-offset: -3px; }
.log-inner { padding: 20px max(24px, env(safe-area-inset-right, 0px)) 28px max(24px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; gap: 12px; align-items: flex-start; }
.row.user { justify-content: flex-end; }
.avatar { flex: none; width: 32px; height: 32px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-top: 2px; }
.avatar svg { width: 18px; height: 18px; }
.bubble { max-width: min(82%, 540px); padding: 10px 15px; border-radius: 18px 18px 5px 18px; background: var(--user); color: var(--user-ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.card { flex: 0 1 auto; min-width: 0; max-width: 640px; padding: 14px 18px 14px; border-radius: 5px 16px 16px 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-sm); overflow-wrap: anywhere; }
.card p { margin: 0; white-space: pre-wrap; }
.card p + p, .card p + .steps, .card .steps + p { margin-top: 10px; }
.steps { list-style: none; counter-reset: step; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 10px; align-items: start; }
.steps li::before { content: counter(step); width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font: 600 12px/24px var(--font-mono); text-align: center; }
.card-foot { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; }
.source { display: inline-flex; align-items: center; gap: 7px; min-height: 32px; padding: 4px 8px 4px 0; border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 500; text-align: left; cursor: pointer; }
.source svg { width: 16px; height: 16px; }
span.source { cursor: default; color: var(--muted); }
.feedback { display: flex; align-items: center; gap: 2px; font-size: 13px; color: var(--muted); }
.feedback span { margin-right: 4px; }
.fb { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 9px; background: none; color: var(--muted); cursor: pointer; }
.fb svg { width: 17px; height: 17px; }
.fb[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.card .act { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.typing { display: inline-flex; gap: 5px; align-items: center; height: 24px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .4; }

/* Support hand-off inside an answer */
.handoff { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 12px; }
.handoff .lead { margin: 0; font-size: 14px; color: var(--ink-2); }
.field { display: grid; gap: 5px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field .opt { font-weight: 400; color: var(--muted); }
.field input, .field textarea { width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink); font-size: 15px; font-weight: 400; }
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.handoff .row-btns { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ticket { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); display: grid; gap: 4px; font-size: 14px; }
.ticket strong { color: var(--accent); }
.ticket p { margin: 0; color: var(--ink-2); white-space: normal; }

/* Dock */
.dock { flex: none; background: var(--bg); padding: 10px max(24px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(24px, env(safe-area-inset-left, 0px)); border-top: 1px solid var(--line); }
.dock-inner { display: grid; gap: 10px; }
.chips {
  display: flex; flex-wrap: nowrap; gap: 8px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; padding-block: 2px 4px;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 40px), transparent);
}
.chips::-webkit-scrollbar { display: none; }
.chips::after { content: ""; flex: 0 0 24px; }
.chip { scroll-snap-align: start; }
.chip { flex: none; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink-2); font-size: 13.5px; line-height: 1.3; white-space: nowrap; cursor: pointer; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 16px; border-radius: 16px; border: 1px solid var(--line-strong); background: var(--panel); box-shadow: var(--shadow-md); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-md); }
.composer textarea { flex: 1; min-width: 0; max-height: 140px; padding: 9px 0; border: 0; outline: none; resize: none; background: transparent; color: var(--ink); font-size: 16px; line-height: 1.45; }
.composer textarea::placeholder { color: var(--muted); opacity: 1; }
.send { flex: none; width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); cursor: pointer; transition: background-color .15s ease; }
.send svg { stroke-width: 2.2; }
.send:disabled { background: var(--line); color: var(--muted); }
.dock-note { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }

.scrim { position: fixed; inset: 0; z-index: 30; background: var(--scrim); }

/* About dialog */
.about { width: min(580px, calc(100vw - 32px)); max-height: min(86vh, 760px); padding: 0; border: 0; border-radius: 18px; background: var(--panel); color: var(--ink); box-shadow: var(--shadow-lg); }
.about::backdrop { background: var(--scrim); }
.about-inner { padding: 22px 24px 24px; display: grid; gap: 18px; }
.about-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -4px -8px -4px 0; }
.about h2 { margin: 0; font-size: 20px; line-height: 1.3; }
.about h3 { margin: 0 0 8px; font: 500 12px/1.4 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.about p { margin: 0; color: var(--ink-2); }
.about section { display: grid; }
.about-steps { margin: 0; padding: 0; list-style: none; counter-reset: a; display: grid; gap: 10px; }
.about-steps li { counter-increment: a; display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 10px; }
.about-steps li::before { content: counter(a); width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font: 600 12px/24px var(--font-mono); text-align: center; }
.about-list { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--ink-2); }
.about-note { padding: 12px 14px; border-radius: 12px; background: var(--warn-soft); }
.about-note h3 { color: var(--warn); }
.about-foot { font-size: 12.5px; color: var(--muted) !important; }

@media (hover: hover) {
  .icon-btn:hover, .back:hover, .fb:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
  .quiet-btn:hover, .secondary-btn:hover { border-color: var(--accent); color: var(--accent); }
  .primary-btn:hover, .send:not(:disabled):hover { background: var(--accent-hover); border-color: var(--accent-hover); }
  .chip:hover { border-color: var(--accent); color: var(--accent); }
  .nav-item:hover { background: var(--panel); }
  .nav-item[aria-current="true"]:hover { background: var(--accent-soft); }
  .source:hover { text-decoration: underline; text-underline-offset: 3px; }
  .link-btn:hover { color: var(--accent); }
}

/* Tablet and phone: the guide becomes a drawer */
@media (max-width: 1023px) {
  .body { grid-template-columns: minmax(0, 1fr); }
  .narrow-only { display: grid; }
  .topbar { padding-left: max(8px, env(safe-area-inset-left, 0px)); }
  .guide {
    position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(380px, 88vw);
    padding-top: env(safe-area-inset-top, 0px); padding-left: env(safe-area-inset-left, 0px);
    border-right: 1px solid var(--line); box-shadow: var(--shadow-lg);
    transform: translateX(-102%); visibility: hidden;
    transition: transform .24s ease, visibility 0s linear .24s;
  }
  .guide.open { transform: none; visibility: visible; transition: transform .24s ease, visibility 0s; }
  .guide-head { padding-top: 12px; }
}
@media (max-width: 760px) {
  .byline { display: none; }
  .about-label { display: none; }
  .quiet-btn { width: 40px; padding: 0; justify-content: center; border-color: transparent; background: none; }
  .quiet-btn svg { width: 20px; height: 20px; }
}
@media (max-width: 640px) {
  .topbar { min-height: 54px; gap: 6px; padding-right: max(8px, env(safe-area-inset-right, 0px)); }
  .brand { gap: 8px; }
  .brand-mark { width: 30px; height: 30px; }
  .brand-name { font-size: 15px; }
  .chat-head { padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); }
  .chat-head h1 { font-size: 15.5px; }
  .chat-head p { font-size: 12.5px; }
  .mode { padding: 6px 9px; font-size: 11.5px; }
  .notice-wrap { padding: 10px max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); }
  .notice { font-size: 13px; }
  .log-inner { padding: 16px max(16px, env(safe-area-inset-right, 0px)) 20px max(16px, env(safe-area-inset-left, 0px)); gap: 16px; }
  .row { gap: 8px; }
  .avatar { width: 28px; height: 28px; border-radius: 8px; }
  .avatar svg { width: 16px; height: 16px; }
  .card { padding: 12px 14px; }
  .bubble { max-width: 88%; }
  .dock { padding: 8px 0 calc(10px + env(safe-area-inset-bottom, 0px)); }
  .dock-inner { gap: 8px; }
  .chips {
    padding: 2px max(16px, env(safe-area-inset-left, 0px)) 4px; scroll-padding-inline: 16px;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  }
  .chips::after { flex-basis: 8px; }
  .chip { padding: 8px 13px; }
  .composer { margin-inline: max(12px, env(safe-area-inset-left, 0px)) max(12px, env(safe-area-inset-right, 0px)); }
  .dock-note { display: none; }
  .about { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 88vh; }
  .about-inner { padding: 18px 18px calc(22px + env(safe-area-inset-bottom, 0px)); }
}
@media (pointer: coarse) {
  .nav-item { padding-block: 11px; }
  .chip { min-height: 38px; }
  .field input, .field textarea, .search input { font-size: 16px; }
}
@media (prefers-reduced-motion: no-preference) {
  .log-inner.live .row { animation: rise .22s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
  .typing i { animation: pulse 1.1s ease-in-out infinite; }
  .typing i:nth-child(2) { animation-delay: .15s; }
  .typing i:nth-child(3) { animation-delay: .3s; }
  @keyframes pulse { 0%, 80%, 100% { opacity: .3; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }
  .about[open] { animation: pop .18s ease-out; }
  @keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) {
  .guide, .guide.open { transition: none; }
}
