:root {
  color-scheme: light;
  --ink: #272b2f;
  --muted: #777b7f;
  --line: rgba(38, 42, 46, .11);
  --paper: rgba(255, 255, 255, .82);
  --paper-solid: #fff;
  --accent: #db6547;
  --accent-deep: #bd4c32;
  --accent-pale: #fff0ea;
  --blue: #3c6f98;
  --green: #42816a;
  --red: #b84b46;
  --shadow: 0 24px 70px rgba(68, 57, 46, .12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-family: var(--font);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: #f4f1eb;
}
button, input, textarea { color: inherit; font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; text-decoration: none; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(219, 101, 71, .25);
  outline-offset: 2px;
}
.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; }
.background { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.background i { position: absolute; display: block; border-radius: 50%; filter: blur(2px); }
.background i:nth-child(1) { top: -230px; right: -120px; width: 620px; height: 620px; background: radial-gradient(circle, rgba(243, 181, 146, .45), transparent 66%); }
.background i:nth-child(2) { bottom: -260px; left: -180px; width: 620px; height: 620px; background: radial-gradient(circle, rgba(150, 188, 196, .28), transparent 68%); }
.background i:nth-child(3) { inset: 0; border-radius: 0; opacity: .18; background-image: linear-gradient(rgba(80, 70, 60, .08) 1px, transparent 1px), linear-gradient(90deg, rgba(80, 70, 60, .08) 1px, transparent 1px); background-size: 54px 54px; mask-image: linear-gradient(black, transparent 78%); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px max(24px, calc((100vw - 1240px) / 2));
  border-bottom: 1px solid rgba(255, 255, 255, .68);
  background: rgba(244, 241, 235, .72);
  backdrop-filter: blur(20px) saturate(140%);
}
.brand { display: inline-flex; align-items: center; gap: 11px; }
.brand-mark { display: grid; width: 43px; height: 43px; place-items: center; border-radius: 14px; color: #fff; background: linear-gradient(145deg, #e47b5e, #c34e34); box-shadow: 0 10px 26px rgba(193, 76, 48, .22); font-size: 13px; font-weight: 850; letter-spacing: -.04em; }
.brand > span:last-child { display: grid; gap: 1px; }
.brand b { font-size: 17px; }
.brand small { color: var(--muted); font-size: 9px; letter-spacing: .09em; text-transform: uppercase; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions > button, .quiet-button { min-height: 36px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.66); font-size: 11px; font-weight: 700; }
.connection-pill { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 999px; color: #7a675f; background: rgba(255,255,255,.58); font-size: 10px; font-weight: 750; }
.connection-pill i { width: 7px; height: 7px; border-radius: 50%; background: #c29247; }
.connection-pill.connected { color: var(--green); background: #e8f3ed; }
.connection-pill.connected i { background: var(--green); }

.shell { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; width: min(1240px, calc(100% - 36px)); margin: 24px auto 50px; align-items: start; }
.chat-card, .side-card { border: 1px solid rgba(58, 52, 47, .1); background: var(--paper); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.chat-card { display: grid; min-height: calc(100vh - 150px); grid-template-rows: auto minmax(360px, 1fr) auto auto; overflow: hidden; border-radius: var(--radius-xl); }
.chat-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 26px 28px 20px; border-bottom: 1px solid var(--line); }
.eyebrow { display: block; margin-bottom: 7px; color: var(--accent-deep); font-size: 9px; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
.chat-header h1 { margin-bottom: 7px; font-size: clamp(24px, 3vw, 36px); letter-spacing: -.035em; }
.chat-header p { max-width: 620px; margin-bottom: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.quiet-button { flex: 0 0 auto; background: #f6f3ef; }

.messages { min-height: 0; padding: 24px 28px; overflow-y: auto; overscroll-behavior: contain; }
.message { display: flex; max-width: 82%; align-items: flex-start; gap: 10px; margin-bottom: 18px; }
.message.user { margin-left: auto; flex-direction: row-reverse; }
.message .avatar { display: grid; width: 32px; min-width: 32px; height: 32px; place-items: center; border-radius: 11px; color: #fff; background: var(--accent); font-size: 9px; font-weight: 850; }
.message.user .avatar { color: #3f5364; background: #dce8ee; }
.message > div:last-child { min-width: 0; padding: 11px 13px; border: 1px solid var(--line); border-radius: 5px 16px 16px; background: #fff; box-shadow: 0 7px 24px rgba(67, 58, 50, .05); }
.message.user > div:last-child { border-radius: 16px 5px 16px 16px; background: #fff1eb; }
.message b { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; font-size: 10px; }
.message b span { padding: 2px 5px; border-radius: 999px; color: var(--blue); background: #eaf2f7; font-size: 7px; text-transform: uppercase; }
.message p { margin: 0; overflow-wrap: anywhere; font-size: 13px; line-height: 1.65; white-space: pre-wrap; }
.message small { display: block; margin-top: 7px; color: var(--muted); font-size: 8px; }
.message.intro { opacity: .9; }
.sync-note { padding: 8px 28px; border-top: 1px solid var(--line); color: var(--muted); background: rgba(249,247,244,.84); font-size: 9px; }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 13px 16px 16px; border-top: 1px solid rgba(255,255,255,.8); background: rgba(255,255,255,.68); }
.composer textarea { min-height: 48px; max-height: 180px; resize: none; padding: 13px 15px; border: 1px solid var(--line); border-radius: 15px; outline: none; background: #fff; font-size: 13px; line-height: 1.5; }
.composer button { display: flex; min-width: 88px; align-items: center; justify-content: center; gap: 8px; border-radius: 15px; color: #fff; background: var(--accent); font-size: 12px; font-weight: 800; }
.composer button:hover:not(:disabled), .primary:hover:not(:disabled) { background: var(--accent-deep); }
.composer button i { font-size: 16px; font-style: normal; }

.side-column { display: grid; gap: 14px; }
.side-card { padding: 22px; border-radius: var(--radius-lg); }
.side-card h2 { margin-bottom: 14px; font-size: 17px; letter-spacing: -.02em; }
.flow-card ol { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; counter-reset: flow; }
.flow-card li { position: relative; display: grid; gap: 3px; padding-left: 36px; counter-increment: flow; }
.flow-card li::before { position: absolute; top: 0; left: 0; display: grid; width: 25px; height: 25px; place-items: center; border-radius: 9px; color: var(--accent-deep); background: var(--accent-pale); content: counter(flow); font-size: 9px; font-weight: 850; }
.flow-card li b { font-size: 11px; }
.flow-card li span { color: var(--muted); font-size: 10px; line-height: 1.45; }
.install-card dl { display: grid; gap: 8px; margin: 0 0 14px; }
.install-card dl div { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 8px; align-items: baseline; }
.install-card dt { color: var(--muted); font-size: 9px; }
.install-card dd { min-width: 0; margin: 0; }
.install-card code { overflow-wrap: anywhere; color: #4a4e52; font-size: 9px; }
.install-card p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.55; }

.modal { width: min(500px, calc(100% - 24px)); max-height: calc(100vh - 32px); padding: 26px; overflow-y: auto; border: 1px solid rgba(255,255,255,.6); border-radius: 22px; background: #fff; box-shadow: 0 30px 100px rgba(34, 29, 25, .28); }
.modal::backdrop { background: rgba(40, 35, 31, .48); backdrop-filter: blur(7px); }
.settings-modal { width: min(620px, calc(100% - 24px)); }
.modal-close { position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border-radius: 50%; color: #6f7376; background: #f0efed; font-size: 19px; }
.modal h2 { margin-bottom: 7px; font-size: 22px; }
.modal-copy { margin-bottom: 18px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 12px; padding: 4px; border-radius: 12px; background: #f1efec; }
.tabs button { min-height: 36px; border-radius: 9px; background: transparent; font-size: 11px; font-weight: 750; }
.tabs button[aria-selected="true"] { background: #fff; box-shadow: 0 4px 14px rgba(50,45,40,.08); }
.form-stack { display: grid; gap: 11px; }
.form-stack label { display: grid; gap: 5px; color: #53585c; font-size: 9px; font-weight: 800; letter-spacing: .035em; text-transform: uppercase; }
.form-stack input, .form-stack textarea { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 10px; outline: none; background: #fbfbfa; font-size: 11px; font-weight: 450; letter-spacing: 0; text-transform: none; }
.form-stack textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; line-height: 1.5; }
.form-stack fieldset { display: grid; gap: 10px; margin: 0; padding: 13px; border: 1px solid var(--line); border-radius: 14px; }
.form-stack legend { padding: 0 6px; color: #474c50; font-size: 10px; font-weight: 850; }
.primary { min-height: 42px; border-radius: 11px; color: #fff; background: var(--accent); font-size: 11px; font-weight: 800; }
.form-error, .form-success { margin: 0; padding: 8px 10px; border-radius: 9px; font-size: 10px; line-height: 1.45; }
.form-error { color: var(--red); background: #fff0ef; }
.form-success { color: var(--green); background: #eaf5ef; }
.field-help { margin: -3px 0 0; color: var(--muted); font-size: 9px; }
.key-card { display: grid; gap: 9px; padding: 13px; border: 1px solid #efd2c8; border-radius: 14px; background: #fff7f3; }
.key-card > span { display: grid; gap: 2px; }
.key-card b { font-size: 11px; }
.key-card small { color: var(--muted); font-size: 9px; }
.key-card input { width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 9px; background: #fff; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 9px; }
.key-card > div { display: flex; gap: 7px; }
.key-card button, .danger-link { min-height: 32px; padding: 6px 10px; border-radius: 9px; background: #f0edea; font-size: 9px; font-weight: 750; }
.danger-link { margin-top: 14px; color: var(--red); background: #fff0ef; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 80; max-width: min(360px, calc(100% - 40px)); padding: 11px 14px; border-radius: 12px; color: #fff; background: #34383b; box-shadow: 0 15px 50px rgba(30,30,30,.2); font-size: 10px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chat-card { min-height: 72vh; }
}
@media (max-width: 620px) {
  .topbar { position: static; padding: 12px 14px; }
  .brand small, .connection-pill { display: none; }
  .shell { width: min(100% - 16px, 620px); margin-top: 8px; }
  .chat-card { border-radius: 20px; }
  .chat-header { padding: 20px 18px 16px; }
  .chat-header .quiet-button { display: none; }
  .messages { padding: 20px 16px; }
  .message { max-width: 96%; }
  .sync-note { padding-inline: 18px; }
  .composer { grid-template-columns: 1fr; }
  .composer button { min-height: 44px; }
  .side-column { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
