.app-page { min-height: 100dvh; overflow: hidden; }
.app-header {
  width: min(1500px, calc(100vw - 40px));
  height: 64px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.app-header-actions { justify-self: end; display: flex; align-items: center; gap: 16px; }
.environment-label { color: var(--muted); font: 650 11px/1 var(--mono); letter-spacing: .09em; text-transform: uppercase; }
.account-menu { justify-self: end; display: flex; align-items: center; gap: 10px; color: var(--muted); font: 600 10px/1.2 var(--mono); }
.account-menu[hidden] { display: none; }
.account-menu .button { min-height: 32px; padding: 0 10px; }
.app-shell {
  width: min(1500px, calc(100vw - 40px));
  height: calc(100dvh - 64px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 0;
  overflow: hidden;
}
.setup-rail { padding: 26px 24px 50px 0; overflow-y: auto; border-right: 1px solid var(--line); }
.rail-heading { padding: 8px 4px 26px; }
.rail-heading .eyebrow, .chat-header .eyebrow { margin-bottom: 12px; }
.rail-heading h1 { font-size: 34px; letter-spacing: -.045em; }
.rail-heading > p:last-child { margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.activation-card { margin: 0 0 12px; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.activation-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.activation-top h2 { font-size: 15px; }
.activation-top strong { color: var(--muted); font: 700 10px/1 var(--mono); }
.activation-track { height: 3px; margin: 13px 0 15px; overflow: hidden; border-radius: 99px; background: var(--line); }
.activation-track span { display: block; width: 33.333%; height: 100%; background: var(--accent); transition: width 180ms ease; }
.activation-list { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: 11px; }
.activation-list li { display: flex; align-items: center; gap: 9px; }
.activation-list li > span { width: 20px; height: 20px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 50%; font: 700 9px/1 var(--mono); }
.activation-list li.is-complete { color: var(--ink); }
.activation-list li.is-complete > span { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.setup-card { width: 100% !important; margin: 0 0 12px !important; padding: 18px !important; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.card-title-row, .card-title-row > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-title-row h2 { font-size: 18px; letter-spacing: -.025em; }
.step-number { color: var(--accent); font: 700 10px/1 var(--mono); }
.status-chip { padding: 6px 8px; border-radius: 999px; background: var(--surface-strong); color: var(--muted); font: 700 9px/1 var(--mono); text-transform: uppercase; letter-spacing: .06em; }
.status-chip.is-ready { color: var(--ink); background: color-mix(in srgb, var(--accent) 24%, var(--surface-strong)); }
.setup-card label { display: block; margin: 16px 0 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.setup-card label span { font-weight: 500; }
.setup-card input, .setup-card select {
  width: 100%; min-width: 0; height: 42px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: 12px/1 var(--mono);
}
.inline-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.full-button { width: 100%; margin-top: 14px; }
.field-help, .form-message { margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.form-message:empty { display: none; }
.form-message.is-error { color: #c94b39; }
.account-control { margin-top: 18px; padding-top: 2px; border-top: 1px solid var(--line); }
.setup-card-copy { margin: 14px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.connection-detail { margin: 10px 0 0; color: var(--muted); font: 10px/1.45 var(--mono); }

.auth-dialog, .install-dialog { padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: 0 28px 90px rgba(0,0,0,.45); }
.auth-dialog { width: min(460px, calc(100vw - 32px)); }
.auth-dialog::backdrop, .install-dialog::backdrop { background: rgba(5, 7, 8, .84); backdrop-filter: blur(7px); }
.auth-shell { padding: 30px; }
.auth-shell h1 { margin-top: 12px; font-size: 39px; letter-spacing: -.05em; }
.auth-shell > p:not(.eyebrow, .auth-note) { margin: 12px 0 22px; color: var(--muted); line-height: 1.55; }
.auth-shell label { display: block; margin: 14px 0 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.auth-shell input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--ink); }
.auth-switch { width: 100%; margin: 14px 0 0; padding: 6px; border: 0; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.auth-note { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font: 9px/1.5 var(--mono); }

.install-dialog { width: min(900px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.install-shell { display: flex; min-height: 0; max-height: calc(100dvh - 34px); flex-direction: column; }
.install-content { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; min-height: 0; overflow-y: auto; background: var(--line); }
.install-option { min-width: 0; padding: 25px; background: var(--surface); }
.install-option.is-primary { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.install-option h3 { margin: 6px 0 10px; font-size: 23px; letter-spacing: -.035em; }
.install-option > p:not(.guide-kicker, .install-warning) { min-height: 66px; margin: 0 0 17px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.install-option .button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.install-option .inline-field input { min-width: 0; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: 10px/1 var(--mono); }
.install-warning { margin: 10px 0 0; color: var(--muted); font: 9px/1.5 var(--mono); }
.install-option ol { margin: 0; padding-left: 18px; color: var(--muted); font-size: 11px; line-height: 1.65; }
.install-option code { overflow-wrap: anywhere; }

.guide-dialog {
  width: min(720px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  max-height: min(860px, calc(100dvh - 32px));
  min-width: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.guide-dialog::backdrop { background: rgba(5, 7, 8, .82); }
.guide-shell { width: 100%; max-width: 100%; min-width: 0; max-height: min(860px, calc(100dvh - 32px)); display: flex; flex-direction: column; overflow: hidden; }
.guide-header { width: 100%; min-width: 0; flex: 0 0 auto; padding: 24px 26px 20px; display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; border-bottom: 1px solid var(--line); }
.guide-header > div { min-width: 0; }
.guide-header .eyebrow { margin-bottom: 9px; }
.guide-header h2 { font-size: 32px; letter-spacing: -.045em; }
.guide-header .dialog-close { position: static; flex: 0 0 auto; }
.guide-progress { width: 100%; min-width: 0; flex: 0 0 auto; padding: 13px 26px; background: var(--surface-strong); border-bottom: 1px solid var(--line); }
.guide-progress-copy { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font: 650 10px/1.2 var(--mono); }
.guide-progress-track { height: 3px; overflow: hidden; border-radius: 99px; background: var(--line); }
.guide-progress-track span { display: block; width: 20%; height: 100%; background: var(--accent); transition: width 180ms ease; }
#google-form, .account-step { width: 100%; max-width: 100%; min-width: 0; min-height: 0; flex: 1 1 auto; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
#google-form[hidden] { display: none; }
.guide-dialog .guide-step { width: 100% !important; max-width: 100%; min-width: 0; margin: 0 !important; padding: 28px 34px 32px !important; overflow-x: hidden; }
.guide-dialog .guide-step[hidden] { display: none !important; }
.guide-kicker { margin: 0 0 8px; color: var(--accent); font: 700 10px/1 var(--mono); letter-spacing: .09em; text-transform: uppercase; }
.guide-step h3 { font-size: 28px; letter-spacing: -.04em; }
.guide-step > p:not(.guide-kicker, .form-message, .permission-note) { margin: 12px 0 20px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.guide-step label { display: block; margin: 18px 0 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.guide-step label span { font-weight: 500; }
.guide-step input, .guide-step select { width: 100%; min-width: 0; height: 44px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: 12px/1 var(--mono); }
.guide-link-grid { width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.guide-link { width: 100%; min-width: 0; min-height: 76px; padding: 13px 14px; display: flex; justify-content: space-between; gap: 14px; align-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); overflow: hidden; }
.guide-link > span:first-child { min-width: 0; }
.guide-link:hover { border-color: var(--accent); }
.guide-link strong, .guide-link small { display: block; }
.guide-link strong { font-size: 13px; overflow-wrap: anywhere; }
.guide-link small { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.35; overflow-wrap: anywhere; }
.guide-link > span:last-child { color: var(--accent); font-size: 18px; }
.secondary-help { display: inline-block; margin-top: 12px; color: var(--muted); font-size: 11px; font-weight: 650; text-decoration: underline; text-underline-offset: 3px; }
.choice-note { margin-top: 20px; padding: 13px 14px; display: grid; gap: 4px; border-radius: 8px; background: var(--surface-strong); }
.choice-note strong { font-size: 12px; }
.choice-note span { color: var(--muted); font-size: 11px; line-height: 1.45; }
.review-list { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.review-list div { min-height: 44px; padding: 0 13px; display: flex; justify-content: space-between; gap: 20px; align-items: center; border-bottom: 1px solid var(--line); }
.review-list div:last-child { border-bottom: 0; }
.review-list span { color: var(--muted); font-size: 12px; }
.review-list strong { font: 650 11px/1.2 var(--mono); }
.permission-note { margin: 14px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.oauth-diagnostics { margin-top: 18px; padding: 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
.diagnostics-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.diagnostics-heading .guide-kicker { margin-bottom: 5px; }
.diagnostics-heading h4 { font-size: 16px; letter-spacing: -.02em; }
.diagnostics-status { padding: 5px 7px; border-radius: 99px; background: var(--surface-strong); color: var(--muted); font: 700 9px/1 var(--mono); text-transform: uppercase; }
.diagnostics-status.is-success { color: var(--ink); background: color-mix(in srgb, var(--accent) 24%, var(--surface-strong)); }
.diagnostics-status.is-error { color: #c94b39; background: color-mix(in srgb, #c94b39 12%, var(--surface-strong)); }
.diagnostics-summary { margin: 10px 0 12px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.diagnostics-events { max-height: 190px; margin: 0; padding: 0; overflow: auto; list-style: none; border-top: 1px solid var(--line); }
.diagnostics-event { padding: 9px 0; display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 8px; align-items: start; border-bottom: 1px solid var(--line); }
.diagnostics-event-dot { width: 7px; height: 7px; margin-top: 4px; border-radius: 50%; background: var(--muted); }
.diagnostics-event.is-success .diagnostics-event-dot { background: var(--accent); }
.diagnostics-event.is-error .diagnostics-event-dot { background: #c94b39; }
.diagnostics-event-copy { min-width: 0; }
.diagnostics-event-copy strong { display: block; font: 650 10px/1.35 var(--mono); overflow-wrap: anywhere; }
.diagnostics-event-copy span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; line-height: 1.4; overflow-wrap: anywhere; }
.diagnostics-event time { color: var(--muted); font: 9px/1.3 var(--mono); }
.diagnostics-actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 7px; }
.diagnostics-actions .button { min-height: 34px; padding: 0 10px; font-size: 10px; }
.diagnostics-note { margin: 10px 0 0; color: var(--muted); font: 9px/1.45 var(--mono); }
.account-step .account-control { margin-top: 0; padding-top: 0; border-top: 0; }
.connection-complete { margin-top: 18px; padding: 15px; display: flex; gap: 12px; border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line)); border-radius: 9px; background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.connection-complete > span { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.connection-complete strong { font-size: 13px; }
.connection-complete p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.guide-footer { width: 100%; min-width: 0; min-height: 0; margin: 0; flex: 0 0 auto; padding: 14px 26px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; border-top: 1px solid var(--line); background: var(--surface); }
.guide-footer-note { color: var(--muted); font: 9px/1.3 var(--mono); text-align: center; }
.guide-footer .button[hidden] { display: none; }

.app-shell > .chat-panel { width: auto; min-width: 0; min-height: 0; height: 100%; margin: 0; padding: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; overflow: hidden; background: var(--surface); }
.chat-header { padding: 28px 32px 24px; display: flex; justify-content: space-between; align-items: flex-end; gap: 30px; border-bottom: 1px solid var(--line); }
.chat-header h2 { font-size: clamp(30px, 3.2vw, 48px); }
.chat-actions { display: flex; align-items: center; gap: 14px; }
.connection-summary { max-width: 240px; color: var(--muted); font: 600 10px/1.4 var(--mono); text-align: right; }
.account-safety-banner { padding: 11px 32px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
.account-safety-banner[hidden] { display: none; }
.account-safety-copy { min-width: 0; display: flex; align-items: center; gap: 10px; }
.safety-indicator { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.account-safety-copy strong { display: block; font: 750 9px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.account-safety-copy p { margin: 3px 0 0; color: var(--muted); font: 10px/1.35 var(--mono); overflow-wrap: anywhere; }
.receipt-summary { display: flex; align-items: center; gap: 8px; }
.receipt-summary > span { color: var(--muted); font: 700 9px/1 var(--mono); text-transform: uppercase; }
#receipt-summary-items { display: flex; gap: 5px; }
.receipt-mini { padding: 5px 7px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font: 700 9px/1 var(--mono); }
.receipt-mini.is-pending { border-color: color-mix(in srgb, var(--accent) 70%, var(--line)); }
.receipt-mini.is-invalidated, .receipt-mini.is-failed { color: #c94b39; }
.messages { min-height: 0; padding: 28px max(28px, 8vw); overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; scroll-behavior: smooth; }
.empty-state { max-width: 700px; margin: clamp(40px, 10vh, 110px) auto 0; text-align: center; }
.empty-state > p { margin: 0 auto 26px; max-width: 560px; color: var(--muted); font-size: 17px; line-height: 1.55; }
.starter-prompts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.starter-prompts button { min-height: 94px; padding: 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--ink); text-align: left; font-size: 12px; line-height: 1.4; cursor: pointer; }
.starter-prompts button:hover { border-color: var(--accent); }
.message { max-width: 820px; margin: 0 auto 22px; }
.message-role { margin: 0 0 7px; color: var(--muted); font: 700 10px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.message-body { width: fit-content; max-width: 88%; margin: 0; padding: 13px 15px; border: 1px solid var(--line); border-radius: 4px 12px 12px 12px; background: var(--bg); white-space: pre-wrap; line-height: 1.55; }
.message-user .message-role { text-align: right; }
.message-user .message-body { margin-left: auto; border-radius: 12px 4px 12px 12px; background: var(--surface-strong); }
.message-error .message-body { border-color: #c94b39; }
.tool-events { max-width: 820px; margin: -10px auto 22px; }
.tool-event { margin: 7px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-strong); }
.tool-event summary { padding: 10px 12px; cursor: pointer; color: var(--muted); font: 650 11px/1.4 var(--mono); }
.tool-event pre { margin: 0; padding: 12px; border-top: 1px solid var(--line); overflow: auto; color: var(--ink); font: 11px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; }
.tool-event.is-error summary { color: #c94b39; }
.tool-event.is-recovered summary { color: #9a6500; }
.receipt-state { margin: 0; padding: 9px 12px; display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); color: var(--muted); font: 700 10px/1.3 var(--mono); }
.receipt-state strong { color: var(--ink); }
.receipt-state.is-expired strong, .receipt-state.is-invalidated strong, .receipt-state.is-failed strong { color: #c94b39; }
.typing { opacity: .65; }

.composer { padding: 18px 32px 20px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; border-top: 1px solid var(--line); background: var(--surface); }
.composer textarea { min-width: 0; max-height: 140px; resize: none; padding: 12px 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
.composer .button { align-self: stretch; min-width: 84px; }
.composer-note { grid-column: 1 / -1; margin: 0; color: var(--muted); font: 10px/1.3 var(--mono); }
.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; }

@media (max-width: 900px) {
  .app-page { overflow: auto; }
  .app-shell { width: min(100% - 28px, 760px); height: auto; grid-template-columns: 1fr; overflow: visible; }
  .app-header { width: min(100% - 28px, 760px); grid-template-columns: 1fr auto; }
  .environment-label { display: none; }
  .setup-rail { padding: 24px 0; overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
  .app-shell > .chat-panel { height: auto; min-height: 0; grid-template-rows: auto auto auto auto; overflow: visible; }
  .chat-header { padding: 25px 20px 20px; }
  .account-safety-banner { padding: 11px 20px; align-items: flex-start; flex-direction: column; }
  .messages { min-height: 420px; padding: 24px 20px 40px; overflow: visible; }
  .composer { padding: 15px 20px 18px; position: static; }
}

@media (max-width: 620px) {
  .app-header-actions .text-link { font-size: 0; }
  .app-header-actions .text-link span { font-size: 18px; }
  .chat-header { align-items: flex-start; flex-direction: column; }
  .chat-actions { width: 100%; justify-content: space-between; }
  .connection-summary { text-align: left; }
  .starter-prompts { grid-template-columns: 1fr; }
  .starter-prompts button { min-height: 60px; }
  .message-body { max-width: 96%; }
  .composer { grid-template-columns: 1fr; }
  .composer .button { min-height: 44px; }
  .composer-note { grid-column: 1; }
  .guide-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .guide-shell { max-height: calc(100dvh - 16px); }
  .guide-header { padding: 19px 18px 16px; }
  .guide-header h2 { font-size: 27px; }
  .guide-progress { padding: 12px 18px; }
  .guide-dialog .guide-step { padding: 24px 20px 28px !important; }
  .guide-step h3 { font-size: 25px; }
  .guide-link-grid { grid-template-columns: 1fr; }
  .guide-footer { padding: 12px 18px; grid-template-columns: 1fr; }
  .guide-footer-note { display: none; }
  .guide-footer .button { width: 100%; }
}

@media (max-width: 700px) {
  .account-menu > span { display: none; }
  .install-content { grid-template-columns: 1fr; }
  .install-option > p:not(.guide-kicker, .install-warning) { min-height: 0; }
}
