:root {
  color-scheme: light;
  --seafoam: #79dccb;
  --seafoam-deep: #3a9f91;
  --champagne: #d4b879;
  --ink: #1e2928;
  --muted: #7b8582;
  --muted-strong: #5d6865;
  --line: #e6e6df;
  --line-soft: #efefe9;
  --page: #f7f5ef;
  --surface: #fffefa;
  --surface-elevated: #fffdf8;
  --surface-soft: #f1f1e9;
  --sidebar: #f2f2eb;
  --user-bubble: #e7f6f2;
  --topbar-bg: rgba(247, 245, 239, .88);
  --shadow: 0 20px 60px rgba(44, 54, 51, .08);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 11px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --seafoam: #79dccb;
  --seafoam-deep: #9cebe0;
  --champagne: #d4b879;
  --ink: #edf1ed;
  --muted: #8e9b97;
  --muted-strong: #bbc5c1;
  --line: #303b39;
  --line-soft: #283230;
  --page: #171d1d;
  --surface: #1e2726;
  --surface-elevated: #222d2b;
  --surface-soft: #26312f;
  --sidebar: #1a2322;
  --user-bubble: #203a38;
  --topbar-bg: rgba(23, 29, 29, .88);
  --shadow: 0 20px 60px rgba(0, 0, 0, .2);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .3s ease, color .3s ease;
}

button, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid rgba(121, 220, 203, .62); outline-offset: 3px; }

.app-shell { display: flex; min-height: 100vh; overflow: hidden; }

.sidebar {
  width: 284px;
  flex: 0 0 284px;
  display: flex;
  flex-direction: column;
  padding: 24px 16px 18px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  transition: background .3s ease, border-color .3s ease;
  position: relative;
  z-index: 20;
}

.sidebar-top, .profile-row, .topbar, .topbar-left, .topbar-actions, .section-label, .composer-footer, .connection-mini, .mobile-brand { display: flex; align-items: center; }
.sidebar-top { justify-content: space-between; gap: 12px; margin: 0 8px 32px; }
.brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; color: var(--ink); }
.brand-mark, .mobile-brand-mark {
  display: grid;
  place-items: center;
  background: transparent;
  color: inherit;
  border-radius: 50%;
  overflow: hidden;
  filter: drop-shadow(0 4px 9px rgba(79, 198, 181, .2));
}
.brand-mark { width: 36px; height: 36px; padding: 0; }
.brand-copy { display: flex; flex-direction: column; gap: 2px; }
.brand-copy strong { font: 800 15px/1 Manrope, sans-serif; letter-spacing: .08em; }
.brand-copy small { color: var(--muted); font-size: 10px; letter-spacing: .01em; }

.icon-button { display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 1px solid transparent; border-radius: 12px; background: transparent; cursor: pointer; transition: background .2s ease, border-color .2s ease, transform .2s ease; }
.icon-button:hover { background: var(--surface-soft); border-color: var(--line); }
.icon-button:active { transform: scale(.96); }
.icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-close { display: none; color: var(--muted); }

.new-chat-button { display: flex; align-items: center; gap: 11px; width: 100%; padding: 13px 13px; border: 1px solid rgba(121, 220, 203, .55); border-radius: 13px; background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; box-shadow: 0 5px 16px rgba(50, 83, 77, .05); transition: border .2s ease, background .2s ease, transform .2s ease; }
.new-chat-button:hover { border-color: var(--seafoam); background: var(--surface-elevated); transform: translateY(-1px); }
.new-chat-button svg { width: 17px; height: 17px; fill: none; stroke: var(--seafoam-deep); stroke-width: 2; stroke-linecap: round; }
.new-chat-button kbd { margin-left: auto; padding: 2px 5px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); font-size: 10px; font-family: inherit; }

.sidebar-section { margin-top: 34px; }
.section-label { justify-content: space-between; padding: 0 9px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.history-count { display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 99px; background: var(--surface-soft); color: var(--muted-strong); font-size: 10px; }
.history-empty { display: flex; align-items: flex-start; gap: 10px; margin: 18px 8px 0; padding: 13px 10px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); }
.history-empty p { margin: 0; font-size: 12px; line-height: 1.45; }
.empty-dot { width: 7px; height: 7px; flex: 0 0 auto; margin-top: 5px; border: 1px solid var(--champagne); border-radius: 50%; }
.history-empty[hidden] { display: none; }
.history-list { display: grid; gap: 5px; margin: 18px 0 0; }
.history-item { display: flex; align-items: center; gap: 4px; min-width: 0; margin: 0 2px; padding: 2px; border: 1px solid transparent; border-radius: 11px; transition: background .2s ease, border-color .2s ease; }
.history-item:hover { border-color: var(--line); background: var(--surface-soft); }
.history-open { min-width: 0; flex: 1; overflow: hidden; padding: 8px; border: 0; background: transparent; color: var(--muted-strong); cursor: pointer; font-size: 11px; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.history-open:hover { color: var(--ink); }
.history-delete { width: 28px; height: 28px; flex: 0 0 auto; color: var(--muted); opacity: 0; }
.history-item:hover .history-delete, .history-delete:focus-visible { opacity: 1; }
.history-delete svg { width: 15px; height: 15px; }

.sidebar-bottom { margin-top: auto; }
.connection-mini { gap: 10px; margin: 0 8px 18px; padding: 11px 10px; border-top: 1px solid var(--line); color: var(--muted); }
.connection-mini strong, .connection-mini span { display: block; }
.connection-mini strong { color: var(--muted-strong); font-size: 11px; font-weight: 700; }
.connection-mini div span { margin-top: 3px; font-size: 10px; }
.status-dot, .preview-dot { display: inline-block; width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--champagne); box-shadow: 0 0 0 4px rgba(212, 184, 121, .14); }
.profile-row { gap: 10px; padding: 10px 8px 0; border-top: 1px solid var(--line); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 auto; border-radius: 50%; overflow: hidden; }
.avatar-user { background: rgba(212, 184, 121, .16); box-shadow: 0 4px 14px rgba(212, 184, 121, .2); }
.profile-copy { min-width: 0; flex: 1; }
.profile-copy strong, .profile-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-copy strong { font-size: 12px; }
.profile-copy span { margin-top: 2px; color: var(--muted); font-size: 10px; }
.profile-row > .icon-button { color: var(--muted); }

.main-panel { display: flex; flex: 1; min-width: 0; min-height: 100vh; flex-direction: column; padding-top: 78px; background: var(--page); }
.topbar { position: fixed; top: 0; right: 0; left: 284px; z-index: 100; justify-content: space-between; height: 78px; padding: 0 38px; border-bottom: 1px solid var(--line-soft); background: var(--topbar-bg); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.topbar-left, .topbar-actions { gap: 10px; }
.mobile-menu-button, .mobile-brand { display: none; }
.preview-pill { display: inline-flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted-strong); font-size: 11px; font-weight: 600; }
.export-actions { display: inline-flex; align-items: center; gap: 4px; }
.export-button { display: inline-flex; align-items: center; gap: 5px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted-strong); cursor: pointer; font: 700 10px Manrope, sans-serif; transition: border-color .2s ease, color .2s ease, background .2s ease; }
.export-button:hover:not(:disabled) { border-color: rgba(121, 220, 203, .75); background: var(--surface-soft); color: var(--seafoam-deep); }
.export-button:disabled { cursor: not-allowed; opacity: .38; }
.export-button > span:first-child { color: var(--champagne); font-size: 11px; }
.theme-toggle { color: var(--muted-strong); }
.moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

.conversation { flex: 1; overflow: auto; }
.conversation-inner { width: min(860px, calc(100% - 72px)); min-height: 100%; margin: 0 auto; padding: 76px 0 30px; }
.welcome-block { display: flex; flex-direction: column; align-items: center; text-align: center; }
.welcome-orb { position: relative; display: grid; place-items: center; width: 84px; height: 84px; margin-bottom: 28px; border: 1px solid rgba(121, 220, 203, .5); border-radius: 30px; background: linear-gradient(145deg, rgba(121, 220, 203, .22), rgba(212, 184, 121, .19)); transform: rotate(-6deg); box-shadow: 0 16px 35px rgba(74, 134, 124, .1); }
.orb-core { width: 28px; height: 28px; border: 5px solid var(--seafoam); border-right-color: var(--champagne); border-radius: 50%; transform: rotate(21deg); }
.orb-line { position: absolute; width: 47px; height: 14px; border: 1px solid var(--champagne); border-left: 0; border-right: 0; border-radius: 50%; transform: rotate(31deg); opacity: .8; }
.orb-line-two { width: 18px; border-color: var(--seafoam); transform: rotate(-58deg); }
.eyebrow { margin: 0 0 13px; color: var(--seafoam-deep); font-size: 11px; font-weight: 800; letter-spacing: .17em; text-transform: uppercase; }
h1 { max-width: 600px; margin: 0; font: 800 clamp(32px, 4.1vw, 58px)/1.05 Manrope, sans-serif; letter-spacing: -.055em; }
h1 em { color: var(--seafoam-deep); font-style: normal; }
.welcome-copy { max-width: 470px; margin: 20px 0 0; color: var(--muted-strong); font-size: 15px; line-height: 1.65; }
.welcome-note { display: inline-flex; align-items: center; gap: 9px; max-width: 470px; margin-top: 28px; padding: 10px 14px; border: 1px solid rgba(212, 184, 121, .45); border-radius: 10px; background: rgba(212, 184, 121, .1); color: var(--muted-strong); font-size: 11px; line-height: 1.4; text-align: left; }
.welcome-note strong { color: var(--ink); }
.note-icon, .banner-icon { display: grid; place-items: center; flex: 0 0 auto; }
.note-icon svg, .banner-icon svg { width: 16px; height: 16px; fill: none; stroke: var(--champagne); stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.messages { display: flex; flex-direction: column; gap: 18px; margin-top: 38px; }
.message { display: flex; min-width: 0; gap: 12px; max-width: 78%; animation: rise .25s ease both; }
.message-user { align-self: flex-end; flex-direction: row-reverse; }
.message-avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 auto; border-radius: 50%; overflow: hidden; }
.message-assistant .message-avatar { background: rgba(121, 220, 203, .13); box-shadow: 0 4px 14px rgba(79, 198, 181, .2); }
.message-user .message-avatar { background: rgba(212, 184, 121, .16); box-shadow: 0 4px 14px rgba(212, 184, 121, .2); }
.avatar-icon { display: block; width: 100%; height: 100%; }
.avatar-icon-ai { object-fit: cover; object-position: center; }
.avatar-icon-user { object-fit: cover; object-position: center; }
.brand-mark .avatar-icon { width: 34px; height: 34px; }
.mobile-brand-mark .avatar-icon { width: 26px; height: 26px; }
.message-avatar .avatar-icon { width: 32px; height: 32px; }
.message-bubble { min-width: 0; max-width: 100%; overflow: hidden; overflow-wrap: anywhere; padding: 12px 15px; border-radius: 16px; color: var(--ink); font-size: 14px; line-height: 1.55; -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
.message-assistant .message-bubble { border: 1px solid var(--line); background: var(--surface); border-top-left-radius: 4px; }
.message-user .message-bubble { background: var(--user-bubble); border-top-right-radius: 4px; }
.thinking-duration { display: inline-flex; align-items: center; gap: 6px; margin: 0 0 9px; color: var(--muted); font-size: 10px; line-height: 1.2; letter-spacing: .01em; opacity: .82; }
.thinking-duration svg { width: 13px; height: 13px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.5; }
.message-text { white-space: pre-wrap; }

.composer-area { padding: 14px 38px 22px; }
.composer-wrap { width: min(860px, 100%); margin: 0 auto; }
.connection-banner { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 11px; color: var(--muted-strong); font-size: 11px; }
.connection-banner .banner-icon svg { width: 15px; height: 15px; stroke: var(--champagne); }
.banner-separator { width: 3px; height: 3px; border-radius: 50%; background: var(--line); }
.banner-muted { color: var(--muted); }
.composer { position: relative; padding: 14px 14px 10px 18px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface-elevated); box-shadow: var(--shadow); transition: border .2s ease, box-shadow .2s ease, background .3s ease; }
.composer:focus-within { border-color: rgba(121, 220, 203, .72); box-shadow: 0 16px 45px rgba(53, 116, 107, .12); }
textarea { display: block; width: 100%; min-height: 28px; max-height: 142px; padding: 0; border: 0; outline: 0; resize: none; overflow-y: auto; background: transparent; color: var(--ink); font-size: 14px; line-height: 1.55; }
textarea::placeholder { color: var(--muted); }
.composer-footer { justify-content: space-between; min-height: 38px; margin-top: 7px; }
.composer-hint { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10px; }
.hint-key { padding: 3px 5px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted-strong); }
.send-button { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 11px; background: var(--seafoam); color: #1e4d47; cursor: pointer; transition: transform .2s ease, filter .2s ease, opacity .2s ease; }
.send-button:hover:not(:disabled) { filter: saturate(1.1) brightness(1.03); transform: translateY(-1px); }
.send-button:disabled { cursor: not-allowed; opacity: .4; }
.send-button svg { width: 18px; height: 18px; fill: currentColor; stroke: none; }
.disclaimer { margin: 10px 0 0; color: var(--muted); font-size: 10px; text-align: center; }
.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; }
.sidebar-scrim { display: none; }

@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 820px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(294px, 86vw); transform: translateX(-102%); box-shadow: 18px 0 50px rgba(15, 25, 23, .14); transition: transform .28s ease; }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-close, .mobile-menu-button, .mobile-brand { display: inline-grid; }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 10; background: rgba(18, 27, 25, .35); opacity: 0; pointer-events: none; transition: opacity .28s ease; }
  .sidebar-scrim.is-visible { display: block; opacity: 1; pointer-events: auto; }
  .main-panel { padding-top: 68px; }
  .topbar { right: 0; left: 0; height: 68px; padding: 0 18px; }
  .mobile-menu-button { color: var(--muted-strong); }
  .mobile-brand { display: flex; gap: 8px; font: 800 13px Manrope, sans-serif; letter-spacing: .09em; }
.mobile-brand-mark { width: 27px; height: 27px; padding: 0; }
  .conversation-inner { width: min(100% - 36px, 620px); padding-top: 54px; }
  .history-delete { opacity: 1; }
  .composer-area { padding: 12px 18px 17px; }
  .connection-banner { flex-wrap: wrap; text-align: center; }
}

@media (max-width: 520px) {
  .topbar-actions { gap: 4px; }
  .preview-pill { padding: 6px 8px; font-size: 10px; }
  .export-button { padding: 7px 6px; }
  .export-label { display: none; }
  .conversation-inner { width: calc(100% - 32px); padding-top: 42px; }
  .welcome-orb { width: 70px; height: 70px; margin-bottom: 23px; border-radius: 24px; }
  .orb-core { width: 24px; height: 24px; }
  .welcome-copy { margin-top: 16px; font-size: 14px; }
  .welcome-note { align-items: flex-start; margin-top: 22px; padding: 10px 11px; }
  .connection-banner { gap: 5px; font-size: 10px; }
  .banner-muted, .banner-separator { display: none; }
  .composer { padding: 13px 12px 9px 14px; border-radius: 19px; }
  .composer-hint { font-size: 9px; }
  .message { max-width: 92%; }
  .message-bubble { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

.composer.is-pending { opacity: .86; }
.composer.is-pending .send-button { cursor: wait; }
.inline-notice { width: fit-content; max-width: 100%; margin: 2px auto; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); text-align: left; }
.inline-notice.loading { border-color: rgba(121, 220, 203, .5); }
.inline-notice.error { display: inline-flex; align-items: center; gap: 10px; border-color: rgba(212, 184, 121, .62); background: color-mix(in srgb, var(--champagne) 10%, var(--surface)); color: var(--muted-strong); font-size: 11px; box-shadow: 0 8px 22px rgba(54, 66, 62, .06); }
.inline-notice.loading { display: inline-flex; align-items: center; gap: 9px; padding: 7px 2px; border: 0; background: transparent; color: var(--muted-strong); font-size: 11px; }
.loading-label { letter-spacing: .01em; }
.loading-dots { display: inline-flex; align-items: center; gap: 4px; height: 12px; }
.loading-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--seafoam-deep); animation: breathe 1.15s ease-in-out infinite; }
.loading-dots i:nth-child(2) { animation-delay: .16s; }
.loading-dots i:nth-child(3) { animation-delay: .32s; }
.retry-button { flex: 0 0 auto; padding: 4px 8px; border: 1px solid rgba(121, 220, 203, .65); border-radius: 7px; background: var(--surface); color: var(--seafoam-deep); font-size: 10px; font-weight: 700; cursor: pointer; transition: background .2s ease, border-color .2s ease, transform .2s ease; }
.retry-button:hover:not(:disabled) { border-color: var(--seafoam); background: var(--surface-soft); transform: translateY(-1px); }
.retry-button:disabled { cursor: wait; opacity: .55; }
.message-assistant .message-avatar { font-size: 8px; letter-spacing: -.04em; }
@media (max-width: 520px) { .inline-notice { max-width: calc(100vw - 32px); font-size: 10px; } .inline-notice.error { gap: 8px; padding: 7px 9px; } .retry-button { font-size: 9px; } }

@keyframes breathe { 0%, 60%, 100% { opacity: .35; transform: translateY(0) scale(.82); } 30% { opacity: 1; transform: translateY(-2px) scale(1); } }


.message-sources { margin-top: 15px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.sources-heading { margin: 0 0 8px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.source-list { display: grid; min-width: 0; gap: 7px; }
.source-card { display: flex; min-width: 0; max-width: 100%; align-items: center; gap: 9px; overflow: hidden; padding: 9px 10px; border: 1px solid color-mix(in srgb, var(--line) 75%, transparent); border-radius: 14px; background: color-mix(in srgb, var(--surface) 78%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); box-shadow: 0 5px 16px rgba(44, 54, 51, .035); color: var(--ink); text-decoration: none; transition: background .2s ease, border-color .2s ease, transform .2s ease, box-shadow .2s ease; }
.source-card:hover { border-color: rgba(121, 220, 203, .72); background: color-mix(in srgb, var(--surface-soft) 82%, transparent); box-shadow: 0 9px 22px rgba(44, 54, 51, .08); transform: translateY(-1px) scale(1.01); }
.source-number { display: grid; place-items: center; width: 22px; height: 22px; flex: 0 0 auto; border-radius: 7px; background: rgba(121, 220, 203, .16); color: var(--seafoam-deep); font: 700 9px Manrope, sans-serif; }
.source-favicon { width: 18px; height: 18px; flex: 0 0 auto; border-radius: 5px; object-fit: contain; background: var(--surface-soft); }
.source-copy { min-width: 0; display: flex; flex: 1 1 auto; flex-direction: column; gap: 3px; overflow: hidden; }
.source-copy strong, .source-meta, .source-detail { min-width: 0; max-width: 100%; overflow: hidden; overflow-wrap: anywhere; text-overflow: ellipsis; }
.source-copy strong { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; font-size: 11px; font-weight: 700; line-height: 1.3; }
.source-meta { white-space: nowrap; color: var(--muted); font-size: 10px; }
.source-detail { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; color: var(--muted); font-size: 9px; line-height: 1.35; opacity: .82; }
@media (max-width: 520px) {
  .message-sources { margin-top: 12px; padding-top: 10px; }
  .source-card { gap: 7px; padding: 8px; }
  .source-number { width: 20px; height: 20px; }
  .source-favicon { width: 16px; height: 16px; }
  .source-copy strong { font-size: 10px; }
  .source-meta { font-size: 9px; }
  .source-detail { font-size: 8px; }
}
