:root {
  --ink: #101a2b; --ink-soft: #18263d; --paper: #f5f2eb; --paper-deep: #ebe7dd;
  --surface: #fffdf8; --line: #d9d4c8; --text: #172033; --muted: #687183;
  --side-text: #f8f7f2; --side-muted: #9da8b8; --blue: #2b62f0; --blue-dark: #1946b8;
  --green: #33d195; --danger: #b42318; --sidebar-width: 288px; --content-width: 820px;
  --shadow: 0 18px 50px rgba(28, 36, 52, .12);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--paper); color: var(--text); font: 15px/1.6 "Avenir Next", Avenir, "Segoe UI", ui-sans-serif, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(43, 98, 240, .25); outline-offset: 2px; }

/* Sidebar */
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--sidebar-width); display: flex; flex-direction: column; gap: 16px; padding: 24px 18px 18px; overflow: hidden; color: var(--side-text); background: radial-gradient(circle at 18% 4%, rgba(49,102,233,.2), transparent 28%), linear-gradient(165deg, #122039 0%, #0d1728 50%, #0a1321 100%); border-right: 1px solid rgba(255,255,255,.07); transition: transform .25s cubic-bezier(.2,.8,.2,1); }
.sidebar::after { content: ""; position: absolute; inset: auto -60px -90px auto; width: 210px; height: 210px; border: 1px solid rgba(255,255,255,.06); border-radius: 50%; box-shadow: 0 0 0 34px rgba(255,255,255,.018), 0 0 0 68px rgba(255,255,255,.012); pointer-events: none; }
body.sidebar-hidden .sidebar { transform: translateX(-100%); }
body.sidebar-hidden .main { margin-left: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 8px; }
.brand { display: flex; align-items: center; gap: 11px; font-size: 18px; font-weight: 760; letter-spacing: .06em; }
.brand-mark { position: relative; display: block; width: 27px; height: 27px; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; height: 1px; background: rgba(255,255,255,.5); transform-origin: left; }
.brand-mark::before { width: 17px; left: 5px; top: 8px; transform: rotate(34deg); }
.brand-mark::after { width: 16px; left: 6px; top: 20px; transform: rotate(-36deg); }
.brand-mark i { position: absolute; z-index: 1; width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(51,209,149,.13); }
.brand-mark i:nth-child(1) { left: 1px; top: 2px; }
.brand-mark i:nth-child(2) { right: 1px; top: 11px; background: #6f96ff; }
.brand-mark i:nth-child(3) { left: 1px; bottom: 0; background: #f5f2eb; }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; transition: background .15s, color .15s, transform .15s; }
.icon-btn:hover { background: rgba(23,32,51,.07); color: var(--text); }
.side-close { color: var(--side-muted); }
.side-close:hover { color: #fff; background: rgba(255,255,255,.08); transform: translateX(-2px); }
.new-chat { position: relative; z-index: 1; width: 100%; display: flex; align-items: center; gap: 11px; padding: 12px 14px; border: 1px solid rgba(255,255,255,.14); border-radius: 10px; background: rgba(255,255,255,.07); color: #fff; font-size: 13.5px; font-weight: 650; cursor: pointer; transition: background .18s, border-color .18s, transform .18s; }
.new-chat svg { color: var(--green); }
.new-chat:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.22); transform: translateY(-1px); }
.chats { flex: 1; min-height: 0; overflow-y: auto; position: relative; z-index: 1; }
.label { margin: 13px 10px 8px; color: var(--side-muted); font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.chat-list { display: flex; flex-direction: column; gap: 3px; }
.chat-item { width: 100%; display: flex; align-items: center; gap: 8px; padding: 10px 11px; overflow: hidden; border: 1px solid transparent; border-radius: 8px; background: transparent; color: #cbd3df; font-size: 13px; text-align: left; cursor: pointer; transition: .15s ease; }
.chat-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item:hover { color: #fff; background: rgba(255,255,255,.055); }
.chat-item.active { color: #fff; background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.07); box-shadow: inset 3px 0 var(--green); }
.chat-item .del { opacity: 0; border: 0; background: transparent; color: var(--side-muted); cursor: pointer; padding: 2px; }
.chat-item:hover .del, .chat-item:focus-within .del { opacity: 1; }
.chat-item .del:hover { color: #fff; }
.side-foot { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 4px; padding-top: 13px; border-top: 1px solid rgba(255,255,255,.1); }
.side-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px; border: 0; border-radius: 8px; background: transparent; color: #d6dce5; font-size: 13px; cursor: pointer; }
.side-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.account { display: flex; align-items: center; gap: 10px; padding: 9px 10px 3px; }
.avatar { width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center; border-radius: 9px; background: var(--blue); color: #fff; font-size: 13px; font-weight: 750; box-shadow: 0 6px 18px rgba(43,98,240,.28); }
.account-info { min-width: 0; flex: 1; }
.account-name { overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; font-weight: 650; white-space: nowrap; }
.account-sub { color: var(--side-muted); font-size: 10.5px; }
.account-sub.on { color: #5ce0ad; }
.logout-btn { width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--side-muted); cursor: pointer; transition: color .16s ease, background .16s ease; }
.logout-btn:hover { background: rgba(255,255,255,.09); color: #fff; }
.logout-btn:focus-visible { outline: 2px solid #76a3ff; outline-offset: 2px; }
.logout-btn:disabled { cursor: wait; opacity: .45; }
.logout-btn[hidden] { display: none; }

/* Main workspace */
.main { height: 100vh; margin-left: var(--sidebar-width); display: flex; flex-direction: column; background: var(--paper); transition: margin .25s cubic-bezier(.2,.8,.2,1); }
.main::before { content: ""; position: fixed; inset: 0 0 0 var(--sidebar-width); pointer-events: none; opacity: .45; background-image: radial-gradient(rgba(16,26,43,.075) .6px, transparent .6px); background-size: 19px 19px; mask-image: linear-gradient(to bottom, #000, transparent 38%); }
body.sidebar-hidden .main::before { left: 0; }
.topbar { position: relative; z-index: 5; min-height: 74px; display: flex; align-items: center; gap: 13px; padding: 13px 24px; border-bottom: 1px solid rgba(180,175,163,.5); background: rgba(245,242,235,.92); }
.workspace-title { display: flex; flex-direction: column; line-height: 1.15; }
.workspace-title .eyebrow { color: var(--muted); font-size: 9.5px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.workspace-title strong { margin-top: 4px; font-size: 14px; font-weight: 700; }
.topbar .pdf-btn { margin-left: auto; }
.messages { position: relative; z-index: 1; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 22px; padding: 42px 30px 190px; scroll-behavior: smooth; }
.messages > * { width: 100%; max-width: var(--content-width); margin-inline: auto; }
.empty { margin: auto; padding: 28px 12px 70px; display: flex; flex-direction: column; align-items: flex-start; text-align: left; animation: rise .5s ease both; }
.empty-symbol { position: relative; width: 76px; height: 47px; margin-bottom: 26px; }
.empty-symbol::before, .empty-symbol::after { content: ""; position: absolute; height: 1px; background: #9ca8b8; transform-origin: left; }
.empty-symbol::before { width: 50px; left: 11px; top: 11px; transform: rotate(25deg); }
.empty-symbol::after { width: 45px; left: 14px; top: 39px; transform: rotate(-28deg); }
.empty-symbol i { position: absolute; z-index: 2; width: 13px; height: 13px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 6px rgba(43,98,240,.1); }
.empty-symbol i:nth-child(1) { left: 0; top: 3px; }
.empty-symbol i:nth-child(2) { right: 0; top: 22px; background: var(--green); box-shadow: 0 0 0 6px rgba(51,209,149,.12); }
.empty-symbol i:nth-child(3) { left: 2px; bottom: 0; background: var(--ink); box-shadow: 0 0 0 6px rgba(16,26,43,.08); }
.empty-symbol span { position: absolute; left: 27px; top: 17px; width: 8px; height: 8px; border-radius: 50%; background: #8a94a5; }
.empty-kicker { margin: 0 0 10px; color: var(--blue-dark); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.empty h1 { margin: 0; color: var(--ink); font: 500 clamp(36px, 4.4vw, 62px)/1.03 Georgia, "Times New Roman", serif; letter-spacing: -.045em; }
.empty h1 em { color: var(--blue); font-weight: 400; }
.empty-copy { max-width: 525px; margin: 20px 0 0; color: var(--muted); font-size: 15px; }
.suggestions { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 30px; }
.suggestions button { display: inline-flex; align-items: center; gap: 8px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,253,248,.7); color: #485267; font-size: 12.5px; cursor: pointer; transition: .16s ease; }
.suggestions button span { color: var(--blue); }
.suggestions button:hover { transform: translateY(-2px); border-color: #aeb9d0; background: var(--surface); box-shadow: 0 8px 18px rgba(30,44,68,.08); }
.msg { display: flex; flex-direction: column; gap: 6px; animation: rise .25s ease both; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { max-width: 78%; padding: 11px 16px; border-radius: 16px 16px 4px 16px; background: var(--ink); color: #fff; box-shadow: 0 6px 18px rgba(16,26,43,.13); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant { padding-left: 19px; border-left: 2px solid rgba(43,98,240,.35); }
.msg.assistant .bubble { padding: 2px 12px 2px 0; color: #202a3c; line-height: 1.78; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .bubble strong { color: var(--ink); }
.msg.assistant .bubble code { padding: 2px 6px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper-deep); font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.msg.error .bubble { padding: 11px 14px; border: 1px solid #efb6b1; border-radius: 8px; background: #fff1ef; color: var(--danger); }
.tool { position: relative; padding: 10px 13px 10px 34px; border: 1px solid #d7dce5; border-radius: 8px; background: rgba(255,255,255,.48); color: #687386; font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-all; }
.tool::before { content: ""; position: absolute; left: 13px; top: 15px; width: 7px; height: 7px; border: 2px solid var(--green); border-radius: 50%; box-shadow: 0 0 0 3px rgba(51,209,149,.12); }
.tool b { color: var(--blue-dark); font-weight: 750; }
.typing { display: inline-flex; gap: 5px; padding: 7px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--blue); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .14s; }
.typing i:nth-child(3) { animation-delay: .28s; }
@keyframes blink { 0%,80%,100% { opacity:.2; transform: translateY(0); } 40% { opacity:1; transform: translateY(-3px); } }
@keyframes rise { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

/* Composer */
.composer { position: fixed; z-index: 10; left: var(--sidebar-width); right: 0; bottom: 0; padding: 48px 28px 15px; background: linear-gradient(to bottom, transparent, var(--paper) 36%); transition: left .25s cubic-bezier(.2,.8,.2,1); }
body.sidebar-hidden .composer { left: 0; }
.composer-inner { max-width: var(--content-width); margin: 0 auto; display: flex; align-items: flex-end; gap: 10px; padding: 9px 9px 9px 18px; border: 1px solid #c8c4ba; border-radius: 13px; background: var(--surface); box-shadow: 0 14px 34px rgba(30,38,54,.1), 0 1px 0 #fff inset; transition: border-color .16s, box-shadow .16s; }
.composer-inner:focus-within { border-color: #8099d3; box-shadow: 0 16px 38px rgba(30,38,54,.12), 0 0 0 3px rgba(43,98,240,.08); }
.composer textarea { flex: 1; min-width: 0; max-height: 180px; padding: 9px 0 7px; resize: none; overflow-y: hidden; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.5; }
.composer textarea::placeholder { color: #89909d; }
.send-btn { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; border: 0; border-radius: 9px; background: var(--blue); color: #fff; cursor: pointer; box-shadow: 0 7px 16px rgba(43,98,240,.28); transition: .15s ease; }
.send-btn:hover { background: var(--blue-dark); transform: translateY(-1px); }
.send-btn:disabled { background: #d5d3cd; color: #8d929a; box-shadow: none; cursor: not-allowed; transform: none; }
.disclaimer { max-width: var(--content-width); margin: 8px auto 0; text-align: center; color: #7d8390; font-size: 10.5px; }

/* Reports */
.pdf-btn { height: 38px; display: inline-flex; align-items: center; gap: 7px; padding: 0 13px; border: 1px solid #cfcac0; border-radius: 9px; background: rgba(255,253,248,.8); color: #3d485a; font-size: 12px; font-weight: 700; cursor: pointer; transition: .15s ease; }
.pdf-btn:hover { border-color: #aeb6c6; background: #fff; transform: translateY(-1px); }
.report-card { display: flex; align-items: center; gap: 13px; padding: 13px; border: 1px solid var(--line); border-left: 3px solid var(--blue); border-radius: 9px; background: var(--surface); box-shadow: 0 8px 24px rgba(30,38,54,.07); animation: rise .25s ease both; }
.report-ico { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; border-radius: 7px; background: #edf2ff; color: var(--blue-dark); font-size: 9px; font-weight: 850; letter-spacing: .06em; }
.report-info { flex: 1; min-width: 0; }
.report-title { color: var(--ink); font-size: 13.5px; font-weight: 750; }
.report-sub { overflow: hidden; color: var(--muted); font-size: 11.5px; text-overflow: ellipsis; white-space: nowrap; }
.report-dl { flex: 0 0 auto; padding: 8px 12px; border: 0; border-radius: 7px; background: var(--ink); color: #fff; font-size: 11.5px; font-weight: 700; cursor: pointer; }
.report-dl:hover { background: var(--blue-dark); }
.report-dl:disabled { opacity:.55; cursor:progress; }

/* Dialogs */
.scrim { position: fixed; inset: 0; z-index: 25; display: none; background: rgba(5,12,23,.55); opacity: 0; pointer-events: none; }
body.sidebar-open-mobile .scrim { display:block; opacity:1; pointer-events:auto; }
.settings { width: min(440px, calc(100vw - 28px)); max-height: 88vh; padding: 26px 28px 30px; overflow-y: auto; border: 1px solid #d6d0c5; border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.settings::backdrop { background: rgba(5,12,23,.62); backdrop-filter: blur(3px); }
.settings-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.settings-head h2 { margin: 4px 0 0; color: var(--ink); font: 500 30px/1.1 Georgia, "Times New Roman", serif; letter-spacing: -.025em; }
.dialog-kicker { color: var(--blue-dark); font-size: 9.5px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.settings-block { padding-top: 18px; border-top: 1px solid var(--line); }
.settings-intro { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.settings-intro strong { color: var(--ink); font-weight: 750; }
.grid { display: grid; gap: 13px; }
label { display: grid; gap: 6px; color: #4f596a; font-size: 11.5px; font-weight: 650; }
input, select { width: 100%; padding: 11px 12px; border: 1px solid #cec9bf; border-radius: 8px; outline: 0; background: #fbfaf6; color: var(--text); }
input:focus, select:focus { border-color: #748dc9; background: #fff; }
.settings button[type="submit"] { display: flex; align-items: center; justify-content: space-between; margin-top: 3px; padding: 12px 14px; border: 0; border-radius: 8px; background: var(--ink); color: #fff; font-weight: 700; cursor: pointer; transition: .15s ease; }
.settings button[type="submit"]:hover { background: var(--blue-dark); }
.settings button:disabled { opacity:.5; cursor:not-allowed; }
.status { min-height: 18px; margin: 0; color: var(--muted); font-size: 11.5px; }
.status.ok { color: #087c55; }
.status.err { color: var(--danger); }
.hint { margin: 0 0 13px; color: var(--muted); font-size: 12px; }
.export-dialog { width: min(450px, calc(100vw - 28px)); }

/* Authentication confirmation */
.toast { position: fixed; z-index: 100; top: 22px; right: 22px; width: min(360px, calc(100vw - 28px)); display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid #b9dfcf; border-radius: 12px; background: #f7fffb; color: var(--ink); box-shadow: 0 18px 45px rgba(12,35,27,.18); opacity: 0; transform: translateY(-10px); transition: opacity .2s ease, transform .2s ease; }
.toast.visible { opacity: 1; transform: none; }
.toast-icon { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; border-radius: 50%; background: #0d9b69; color: #fff; font-weight: 800; }
.toast div { display: grid; gap: 2px; }
.toast strong { font-size: 13px; }
.toast span:not(.toast-icon) { color: var(--muted); font-size: 11.5px; }

@media (max-width: 860px) {
  .sidebar { width: 280px; transform: translateX(-100%); }
  body.sidebar-open-mobile .sidebar { transform: none; box-shadow: 24px 0 60px rgba(3,10,22,.28); }
  .main { margin-left: 0; }
  .main::before { left: 0; }
  .composer { left: 0; padding-inline: 14px; }
  .messages { padding: 32px 18px 180px; }
  .topbar { min-height: 64px; padding: 10px 13px; }
  .empty { padding-bottom: 45px; }
}
@media (max-width: 560px) {
  .workspace-title .eyebrow { display: none; }
  .workspace-title strong { margin: 0; font-size: 13px; }
  .topbar .pdf-btn span { display: none; }
  .topbar .pdf-btn { width: 38px; padding: 0; justify-content: center; }
  .empty { align-items: flex-start; padding-inline: 2px; }
  .empty h1 { font-size: 38px; }
  .empty-copy { font-size: 13.5px; }
  .suggestions { flex-direction: column; align-items: stretch; }
  .suggestions button { justify-content: flex-start; }
  .msg.user .bubble { max-width: 90%; }
  .report-card { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; }
  .report-ico { grid-column: 1; grid-row: 1; }
  .report-info { grid-column: 2; grid-row: 1; width: 100%; }
  .report-title { white-space: normal; }
  .report-sub { white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.4; }
  .report-dl { grid-column: 2; grid-row: 2; justify-self: start; margin: 2px 0 0; }
  .settings { padding: 22px 20px 25px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; } }
