/* Building Regulations AI (/regulations). Loaded after site.css, which holds the tokens,
   fonts and header; this file only lays out the tool. A working tool, not a page: the chat on
   the left and the code itself on the right (desktop); on a phone the code opens in a sheet
   over the chat. */

/* The tool is denser than the marketing page: a narrower gutter and 16 px body text. */
@media (min-width: 768px) { :root { --side: 28px; } }
html, body { height: 100%; }
html { scroll-behavior: auto; }
body { font-size: 16px; }
button { font: inherit; color: inherit; }
:focus-visible { outline-offset: 2px; }
.site-header .frame { max-width: none; }

/* ---------- App frame ---------- */
/* dvh keeps the composer above the phone's browser bar; % is the fallback for older browsers. */
.app { height: calc(100% - var(--head-h)); height: calc(100dvh - var(--head-h)); display: grid; grid-template-columns: 1fr; }
/* The code opens beside the chat only when someone asks for it (a quote, "Show the code"). */
@media (min-width: 960px) { .app.with-code { grid-template-columns: minmax(380px, 44fr) 56fr; } }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }
.chat-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px var(--side);
  border-bottom: var(--hair); min-height: 52px;
}
.chat-bar .bar-title { margin: 0 auto 0 0; font: 500 15px/1.2 var(--sans); letter-spacing: 0; }
.scope { color: var(--muted); font-weight: 400; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px;
  border: var(--hair); background: transparent; cursor: pointer; font-size: 14px; font-weight: 500;
  line-height: 1.2; white-space: nowrap; color: var(--ink); text-decoration: none;
}
.tool-btn:hover { border-color: var(--ink); }
@media (max-width: 640px) {
  .chat-bar { gap: 6px; }
  .chat-bar .bar-title { font-size: 14px; }
  .chat-bar .scope { display: none; }
  .tool-btn { padding: 0 9px; font-size: 13.5px; }
}
.tool-btn.code-btn { display: inline-flex; }
.tool-btn.code-btn[aria-expanded="true"] { border-color: var(--ink); }

.thread { position: relative; flex: 1; overflow-y: auto; padding: 28px var(--side) 24px; overscroll-behavior: contain; }
.thread-inner { max-width: 680px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }

/* Welcome */
.welcome h1 { font: 400 clamp(30px, 4vw, 40px)/1.08 var(--serif); letter-spacing: -.015em; margin: 0 0 14px; text-wrap: balance; max-width: 18ch; }
.welcome .lede { margin: 0 0 22px; font-size: 17px; max-width: 34em; }
.coverage { border-top: var(--hair); border-bottom: var(--hair); padding: 14px 0; margin: 0 0 26px; display: grid; gap: 4px; }
.coverage .label { font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--green); }
.coverage p { margin: 0; font-size: 15px; }
.coverage .doc { font-family: var(--serif); font-size: 18px; line-height: 1.3; }
.samples-label { font-size: 14px; font-weight: 500; color: var(--muted); margin: 0 0 10px; }
.samples { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sample {
  width: 100%; text-align: left; background: var(--panel); border: 1px solid transparent; cursor: pointer;
  padding: 12px 14px; font-size: 15px; line-height: 1.4; display: flex; justify-content: space-between; gap: 12px;
}
.sample:hover { border-color: var(--ink); }
.sample .arrow { color: var(--green); flex: none; }
.or-ask { margin: 14px 0 0; font-size: 14px; color: var(--muted); }
.practice { margin: 28px 0 0; padding-top: 14px; border-top: var(--hair); font-size: 14px; color: var(--muted); }

/* Messages */
.msg-q { align-self: flex-end; max-width: 88%; background: var(--panel); padding: 10px 14px; font-size: 16px; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg-a { display: grid; gap: 14px; min-width: 0; }
.a-label { display: flex; align-items: baseline; gap: 10px; font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.a-body p { margin: 0 0 10px; max-width: 62ch; }
.a-body p:last-child { margin-bottom: 0; }
.a-body strong { font-weight: 500; background: linear-gradient(transparent 62%, var(--mark) 62%); }

/* A quote card: the whole card is a pointer target, its "Show in the code" button is the
   keyboard and screen-reader control (a button can't hold a quote or a table). */
.quotes { display: grid; gap: 10px; min-width: 0; }
.quote { background: var(--paper); border: var(--hair); padding: 12px 14px; cursor: pointer; min-width: 0; }
.quote:hover { border-color: var(--green); }
.quote.active { border-color: var(--green); box-shadow: inset 3px 0 0 var(--green); }
.cite { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; font-size: 13px; color: var(--green); font-weight: 500; margin: 0 0 6px; font-variant-numeric: tabular-nums; }
.cite .page { color: var(--muted); font-weight: 400; }
.quote blockquote { margin: 0; font: 400 16.5px/1.5 var(--serif); }
.quote blockquote p { margin: 0 0 6px; }
.quote blockquote p:last-child { margin: 0; }
.quote .gap { color: var(--muted); }
.quote .open { display: block; margin-top: 8px; padding: 0; border: 0; background: none; font-size: 13px; color: var(--green); cursor: pointer; text-align: left; }
.quote table { border-collapse: collapse; font: 14px/1.35 var(--sans); width: 100%; font-variant-numeric: tabular-nums; }
.quote th, .quote td { border: var(--hair); padding: 6px 8px; text-align: left; vertical-align: top; }
.quote th { font-weight: 500; background: var(--panel); font-size: 12.5px; }
.tablewrap { overflow-x: auto; }

.notice { border: 1px solid var(--ink); padding: 12px 14px; display: grid; gap: 4px; }
.notice .label { font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.notice p { margin: 0; font-size: 15px; }
.notice.out { border-color: var(--line); background: var(--paper); }

.related { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 14px; }
.related .label { color: var(--muted); margin-right: 2px; }
.chip { border: var(--hair); background: transparent; padding: 4px 9px; cursor: pointer; font-size: 13.5px; }
.chip:hover { border-color: var(--green); color: var(--green); }

/* Progress while the answer is written and its quotes checked (no streaming: decision 0003). */
.progress { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14.5px; color: var(--muted); }
.progress li { display: flex; gap: 10px; align-items: center; }
.progress .dot { width: 9px; height: 9px; border: 1px solid var(--muted); flex: none; }
.progress .done { color: var(--ink); }
.progress .done .dot { background: var(--green); border-color: var(--green); }
.progress .now .dot { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { background: var(--line); } }
@media (prefers-reduced-motion: reduce) { .progress .now .dot { animation: none; background: var(--line); } }

.banner { border-top: var(--hair); border-bottom: var(--hair); padding: 12px 0; display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; font-size: 15px; }
.banner p { margin: 0; max-width: 46ch; }
.error { color: var(--error); }

/* Composer */
.composer { border-top: var(--hair); padding: 12px var(--side) calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--stone); }
.composer-inner { max-width: 680px; margin: 0 auto; }
.composer noscript .error { margin: 0 0 8px; font-size: 15px; }
.turnstile:not(:empty) { margin-bottom: 8px; }
.turnstile-hint { margin: 0 0 8px; font-size: 15px; font-weight: 500; color: var(--green); }
.ask { display: flex; gap: 8px; align-items: flex-end; }
.ask textarea {
  flex: 1; min-width: 0; resize: none; border: 1px solid var(--ink); border-radius: 0; background: #FFFFFF; color: var(--ink);
  padding: 12px 14px; font: 16px/1.4 var(--sans); max-height: 160px; min-height: 48px;
}
.ask textarea::placeholder { color: var(--muted); }
.send {
  flex: none; width: 48px; height: 48px; border: 0; background: var(--green); color: #FFFFFF; cursor: pointer;
  display: grid; place-items: center; font-size: 20px;
}
.send:hover { background: var(--green-dark); }
.send[disabled] { opacity: .45; cursor: default; }
.fineprint { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
/* The registered name, which Hong Kong law requires on the company's website (AGENTS.md). */
.fineprint .legal { white-space: nowrap; }
.limit { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.limit p { margin: 0; font-size: 15px; max-width: 40ch; }
.limit .button { min-height: 44px; padding: 0 18px; font-size: 15px; gap: 10px; }

/* ---------- The code (desktop pane, phone sheet) ---------- */
.source { display: none; min-height: 0; min-width: 0; border-left: var(--hair); background: var(--paper); flex-direction: column; }
@media (min-width: 960px) { .app.with-code .source { display: flex; } }
.source-head { padding: 12px var(--side); border-bottom: var(--hair); display: flex; gap: 12px; align-items: center; min-height: 52px; }
.source-title { margin-right: auto; min-width: 0; }
.source-title .name { font: 400 17px/1.2 var(--serif); }
.source-title .meta { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.reader { flex: 1; overflow-y: auto; padding: 22px var(--side) 40px; overscroll-behavior: contain; }
.reader-inner { max-width: 720px; margin: 0 auto; }
.reader-note { font-size: 15px; color: var(--muted); margin: 0; }

.crumbs { font-size: 13px; color: var(--muted); margin: 0 0 6px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.crumbs button { background: none; border: 0; padding: 0; color: var(--green); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }
.reader h2 { font: 400 26px/1.15 var(--serif); margin: 0 0 18px; text-wrap: balance; }
.unit { padding: 14px 0 18px; border-top: var(--hair); scroll-margin-top: 16px; }
.unit.target { background: #FFFFFF; box-shadow: 0 0 0 1px var(--green); padding-left: 14px; padding-right: 14px; margin: 0 -14px; }
.unit-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 8px; }
.unit-head .id { font-weight: 500; font-size: 15px; }
.unit-head .t { color: var(--muted); font-size: 14px; }
.unit-head .pg { margin-left: auto; font-size: 13px; font-variant-numeric: tabular-nums; }
.unit-body { font: 400 17px/1.55 var(--serif); overflow-wrap: break-word; }
.unit-body p { margin: 0 0 8px; }
.unit-body .i1 { padding-left: 1.6em; } .unit-body .i2 { padding-left: 3.2em; } .unit-body .i3 { padding-left: 4.8em; }
.unit-body .i4 { padding-left: 6.4em; } .unit-body .i5 { padding-left: 8em; }
.unit-body strong { font-weight: 400; font-style: italic; }
.unit-body mark { background: var(--mark); color: inherit; box-shadow: 0 2px 0 var(--green); padding: 0 1px; }
.unit-body .tablewrap { margin: 6px 0 12px; }
.unit-body table { border-collapse: collapse; font: 14px/1.4 var(--sans); min-width: 100%; font-variant-numeric: tabular-nums; }
.unit-body th, .unit-body td { border: var(--hair); padding: 7px 9px; text-align: left; vertical-align: top; }
.unit-body th { background: var(--panel); font-weight: 500; font-size: 13px; }
.unit-body tr.hit td { background: var(--mark); }
.diagram-note { font: 14px/1.45 var(--sans); color: var(--muted); }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; padding-top: 16px; border-top: var(--hair); }
.pager button { background: none; border: 0; padding: 0; color: var(--green); cursor: pointer; font-size: 14px; text-align: left; max-width: 48%; }
.pager .next { text-align: right; margin-left: auto; }

/* Contents */
.contents h2 { margin-bottom: 6px; }
.contents .intro { margin: 0 0 18px; font-size: 15px; color: var(--muted); max-width: 48ch; }
.contents details { border-top: var(--hair); }
.contents summary { cursor: pointer; padding: 12px 0; font-weight: 500; list-style: none; display: flex; gap: 10px; }
.contents summary::-webkit-details-marker { display: none; }
.contents summary .pl { color: var(--green); width: 3.2em; flex: none; }
.contents .sec { margin: 0 0 4px 3.2em; font-size: 13px; color: var(--muted); padding-top: 6px; }
.contents ul { list-style: none; margin: 0 0 12px 3.2em; padding: 0; }
.contents li button { background: none; border: 0; padding: 4px 0; cursor: pointer; text-align: left; font-size: 15px; display: flex; gap: 10px; width: 100%; }
.contents li button:hover { color: var(--green); }
.contents li .sid { width: 3.4em; flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.contents .legal { margin: 24px 0 0; padding-top: 14px; border-top: var(--hair); font-size: 13px; color: var(--muted); }

/* Phone sheet */
.sheet {
  position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-width: 100%; height: 78dvh; max-height: 100dvh;
  padding: 0; border: 0; border-top: var(--hair); background: var(--paper); color: var(--ink);
  display: flex; flex-direction: column; transform: translateY(0); transition: transform .22s ease, height .22s ease;
}
.sheet:not([open]) { display: none; }
.sheet.full { height: 100dvh; }
.sheet::backdrop { background: rgba(31, 29, 26, .38); }
@media (prefers-reduced-motion: reduce) { .sheet { transition: none; } }
.grab { padding: 8px 0 2px; display: grid; place-items: center; touch-action: none; cursor: grab; }
.grab span { width: 40px; height: 4px; background: var(--line); }
.sheet .source-head { padding-top: 6px; }
.sheet .reader { padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)); }

/* Narrow phones: the site header already names the page, so the bar keeps only its tools. */
@media (max-width: 400px) {
  .chat-bar .bar-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .chat-bar .tool-btn:first-of-type { margin-left: auto; }
}
