:root {
  color-scheme: dark;
  --page: #111214;
  --panel: #191a1d;
  --panel-raised: #202125;
  --panel-hover: #292a2f;
  --border: rgba(255,255,255,.09);
  --text: #f4f3ef;
  --muted: #9c9da3;
  --subtle: #85868c;
  --sidebar: #151619;
  --input: #121315;
  --button-bg: #f4f4f4;
  --button-text: #141414;
  --button-hover: #dddddf;
  --selected-bg: #f4f4f4;
  --selected-text: #141414;
  --focus: rgba(255,255,255,.22);
  --border-strong: rgba(255,255,255,.16);
  --shadow: 0 24px 80px rgba(0,0,0,.32);
  --toast: #28292e;
  --danger: #ff7777;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

[data-theme="light"] {
  color-scheme: light;
  --page: #f4f5f7;
  --panel: #ffffff;
  --panel-raised: #f0f1f3;
  --panel-hover: #e7e8eb;
  --border: rgba(22,23,26,.1);
  --text: #17181a;
  --muted: #67696f;
  --subtle: #777980;
  --sidebar: #eceef1;
  --input: #f6f7f8;
  --button-bg: #17181a;
  --button-text: #ffffff;
  --button-hover: #303135;
  --selected-bg: #17181a;
  --selected-text: #ffffff;
  --focus: rgba(22,23,26,.2);
  --border-strong: rgba(22,23,26,.16);
  --shadow: 0 24px 80px rgba(24,27,32,.12);
  --toast: #ffffff;
  --danger: #b4232d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
}

button, input, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.auth-view {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(460px, .85fr);
  grid-template-rows: minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 600px;
  overflow: hidden;
  background: var(--page);
}

.auth-hero {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(38px, 6vw, 100px);
  border-right: 1px solid var(--border);
  background:
    radial-gradient(ellipse at 20% 45%, var(--panel-raised), transparent 55%),
    var(--page);
}

.auth-hero-brand { align-self: flex-start; font-size: 19px; }
.auth-hero-brand .brand-logo { width: 42px; height: 42px; border-radius: 11px; }
.auth-hero-content { width: min(100%, 680px); margin: auto 0; padding: 64px 0; }
.auth-hero-content .eyebrow { margin-bottom: 20px; }
.auth-hero-content h2 { margin: 0; font-size: clamp(42px, 5.2vw, 76px); line-height: 1.02; letter-spacing: -.065em; }
.auth-hero-copy { max-width: 490px; margin: 23px 0 0; color: var(--muted); font-size: clamp(14px, 1.3vw, 17px); line-height: 1.7; }
.auth-hero-note { display: flex; width: fit-content; align-items: center; gap: 12px; margin-top: 40px; padding: 12px 16px 12px 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); }
.auth-hero-note img { width: 42px; height: 42px; border: 1px solid var(--border); border-radius: 10px; object-fit: cover; }
.auth-hero-note b, .auth-hero-note small { display: block; }
.auth-hero-note b { margin-bottom: 4px; font-size: 12px; }
.auth-hero-note small { color: var(--muted); font-size: 10px; }
.auth-hero-footer { margin: 0; color: var(--subtle); font-size: 9px; font-weight: 800; letter-spacing: .16em; }
.auth-hero-footer span { margin: 0 5px; }

.auth-card {
  display: flex;
  width: 100%;
  min-width: 0;
  height: 100%;
  flex-direction: column;
  justify-content: center;
  padding: clamp(40px, 7vw, 104px);
  background: var(--panel);
}

.auth-card > * { width: min(100%, 440px); margin-right: auto; margin-left: auto; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 850;
  text-decoration: none;
}

.brand-logo { display: block; width: 30px; height: 30px; flex: 0 0 auto; border: 1px solid var(--border); border-radius: 8px; object-fit: cover; }
.brand-wordmark { font-weight: 800; letter-spacing: .015em; }
.brand-separator { padding: 0 3px; color: var(--muted); font-weight: 500; }
.eyebrow { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .17em; }

.theme-toggle {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: background .16s ease, transform .16s ease;
}

.theme-toggle:hover { transform: translateY(-1px); background: var(--panel-hover); }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.auth-view > .theme-toggle { position: absolute; z-index: 2; top: 24px; right: 24px; }

.auth-card h1 {
  margin: 8px 0 10px;
  font-size: clamp(30px, 3vw, 40px);
  letter-spacing: -.04em;
}

.auth-subtitle, .privacy-note { color: var(--muted); line-height: 1.55; }
.auth-subtitle { margin: 0 0 25px; font-size: 14px; }
.privacy-note { margin: 20px 0 0; font-size: 11px; }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 22px;
  padding: 4px;
  border-radius: 11px;
  background: var(--input);
}

.auth-tab {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.auth-tab.is-active { background: var(--selected-bg); color: var(--selected-text); }
.field-label { display: block; margin: 15px 0 7px; color: var(--text); font-size: 12px; font-weight: 700; }

.auth-card input {
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: var(--input);
  color: var(--text);
}

.auth-card input:focus { border-color: var(--text); box-shadow: 0 0 0 3px var(--focus); }
.form-error { color: var(--danger); font-size: 12px; line-height: 1.45; }

.primary-button {
  border: 0;
  border-radius: 10px;
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  font-weight: 800;
}

.primary-button:hover { background: var(--button-hover); }
.primary-button:disabled { cursor: wait; opacity: .7; }
.auth-submit { width: 100%; min-height: 46px; margin-top: 20px; }

.app-view { display: flex; width: 100%; height: 100dvh; min-height: 500px; overflow: hidden; }
.sidebar { display: flex; width: 280px; flex: 0 0 280px; flex-direction: column; padding: 18px 12px 12px; border-right: 1px solid var(--border); background: var(--sidebar); }
.sidebar-top { display: grid; gap: 23px; padding: 3px 7px 21px; }
.new-chat-button { display: flex; width: 100%; min-height: 42px; align-items: center; gap: 10px; padding: 0 11px; border: 1px solid transparent; border-radius: 10px; background: var(--button-bg); color: var(--button-text); text-align: left; cursor: pointer; font-size: 12px; font-weight: 700; }
.new-chat-button:hover { background: var(--button-hover); }
.new-chat-button svg, .icon-button svg, .send-button svg, .suggestion-icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.new-chat-button svg { color: currentColor; }
.shortcut { margin-left: auto; color: var(--subtle); font-size: 10px; font-weight: 500; }
.history-heading { padding: 0 12px 9px; color: var(--subtle); font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.chat-list { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 3px; overflow: auto; }
.chat-item { display: flex; min-height: 39px; align-items: center; gap: 9px; padding: 0 11px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; text-align: left; }
.chat-item:hover { background: var(--panel-hover); color: var(--text); }
.chat-item.is-active { background: var(--selected-bg); color: var(--selected-text); }
.chat-item svg { width: 15px; height: 15px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.chat-item span { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-bottom { padding: 12px 5px 0; border-top: 1px solid var(--border); }
.account-row { display: flex; align-items: center; gap: 9px; min-height: 41px; }
.user-avatar { display: grid; width: 29px; height: 29px; flex: 0 0 auto; place-items: center; border: 1px solid var(--border-strong); border-radius: 50%; background: var(--panel-raised); color: var(--text); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.user-name { overflow: hidden; flex: 1; color: var(--text); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { display: grid; width: 36px; height: 36px; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-button:hover { background: var(--panel-hover); color: var(--text); }
.icon-button svg { width: 18px; height: 18px; }
.logout-button { width: 31px; height: 31px; }
.model-status { display: flex; align-items: center; gap: 7px; padding: 8px 8px 2px; color: var(--subtle); font-size: 10px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text); }

.conversation { display: flex; min-width: 0; flex: 1; flex-direction: column; background: var(--page); }
.topbar { display: flex; height: 58px; flex: 0 0 58px; align-items: center; gap: 12px; padding: 0 25px; border-bottom: 1px solid rgba(255,255,255,.035); }
.sidebar-toggle { display: none; }
.topbar-title { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 750; }
.model-pill { padding: 4px 8px; border: 1px solid var(--border); border-radius: 20px; background: var(--panel-raised); color: var(--muted); font-size: 10px; font-weight: 700; }
.theme-toggle#themeToggleApp { margin-left: auto; }
.topbar-link { margin-left: 0; color: var(--muted); font-size: 11px; text-decoration: none; }
.topbar-link:hover { color: var(--text); }
.conversation-scroll { display: flex; min-height: 0; flex: 1; flex-direction: column; overflow-y: auto; scroll-behavior: smooth; }
.welcome-view { width: min(100% - 40px, 700px); margin: auto; padding: 46px 0 34px; text-align: center; }
.welcome-mark { display: block; width: 58px; height: 58px; margin: 0 auto 22px; border: 1px solid var(--border); border-radius: 15px; object-fit: cover; }
.welcome-view .eyebrow { margin-bottom: 11px; }
.welcome-view h1 { margin: 0; font-size: clamp(30px, 5vw, 44px); letter-spacing: -.055em; }
.welcome-copy { max-width: 490px; margin: 13px auto 30px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.suggestions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: left; }
.suggestion { display: flex; min-height: 92px; align-items: flex-start; gap: 11px; padding: 14px 12px; border: 1px solid var(--border); border-radius: 13px; background: var(--panel); cursor: pointer; text-align: left; transition: background .16s ease, border-color .16s ease, transform .16s ease; }
.suggestion:hover { transform: translateY(-2px); border-color: var(--border-strong); background: var(--panel-raised); }
.suggestion-icon { display: grid; width: 29px; height: 29px; flex: 0 0 auto; place-items: center; border-radius: 9px; background: var(--panel-raised); color: var(--text); }
.suggestion-icon svg { width: 16px; height: 16px; }
.suggestion b, .suggestion small { display: block; }
.suggestion b { margin: 2px 0 5px; font-size: 11px; }
.suggestion small { color: var(--muted); font-size: 10px; line-height: 1.4; }
.message-list { width: min(100% - 40px, 760px); margin: 0 auto; padding: 32px 0 26px; }
.message-row { display: flex; gap: 12px; margin: 0 0 28px; }
.message-row.user { justify-content: flex-end; }
.message-avatar { display: grid; width: 29px; height: 29px; flex: 0 0 auto; place-items: center; border: 1px solid var(--border); border-radius: 50%; background: var(--panel-raised); color: var(--text); }
.message-avatar img { width: 16px; height: 16px; border-radius: 4px; object-fit: cover; }
.message-content { max-width: min(100%, 650px); padding-top: 5px; color: var(--text); font-size: 14px; line-height: 1.72; overflow-wrap: anywhere; white-space: pre-wrap; }
.message-row.user .message-content { max-width: min(84%, 580px); padding: 10px 14px; border: 1px solid var(--border); border-radius: 17px 17px 4px 17px; background: var(--panel-raised); color: var(--text); }
.message-row.assistant .message-content { flex: 1; }
.message-content.is-error { color: var(--danger); }
.message-content.is-streaming:after { display: inline-block; width: 5px; height: 15px; margin-left: 3px; background: var(--text); content: ""; vertical-align: -2px; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

.composer { width: min(100% - 40px, 760px); margin: 0 auto; padding: 0 0 18px; }
.composer-box { padding: 12px 12px 9px 16px; border: 1px solid var(--border-strong); border-radius: 17px; background: var(--panel); box-shadow: 0 9px 32px rgba(0,0,0,.12); transition: border-color .16s ease, box-shadow .16s ease; }
.composer-box:focus-within { border-color: var(--text); box-shadow: 0 0 0 3px var(--focus), 0 9px 32px rgba(0,0,0,.12); }
.composer textarea { display: block; width: 100%; max-height: 180px; min-height: 29px; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 14px; line-height: 1.55; }
.composer textarea::placeholder { color: var(--subtle); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.composer-hint { color: var(--subtle); font-size: 9px; }
.send-button { display: grid; width: 33px; height: 33px; flex: 0 0 auto; place-items: center; border: 0; border-radius: 10px; background: var(--button-bg); color: var(--button-text); cursor: pointer; }
.send-button:disabled { cursor: wait; opacity: .55; }
.send-button:hover:not(:disabled) { background: var(--button-hover); transform: translateY(-1px); }
.send-button svg { width: 17px; height: 17px; stroke-width: 2.2; }
.toast { position: fixed; right: 22px; bottom: 24px; z-index: 20; max-width: min(420px, calc(100vw - 32px)); padding: 12px 16px; border: 1px solid var(--border); border-radius: 11px; background: var(--toast); box-shadow: 0 14px 42px rgba(0,0,0,.2); color: var(--text); font-size: 12px; }
.sidebar-scrim { display: none; }

@media (max-width: 720px) {
  .auth-view { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: auto; min-height: 100vh; min-height: 100svh; overflow: visible; }
  .auth-hero { min-height: 34svh; padding: 28px 26px 22px; border-right: 0; border-bottom: 1px solid var(--border); }
  .auth-hero-brand { font-size: 16px; }
  .auth-hero-brand .brand-logo { width: 34px; height: 34px; }
  .auth-hero-content { padding: 26px 0 10px; }
  .auth-hero-content .eyebrow { margin-bottom: 10px; }
  .auth-hero-content h2 { font-size: clamp(30px, 8vw, 44px); }
  .auth-hero-copy { margin-top: 12px; font-size: 12px; }
  .auth-hero-note { margin-top: 18px; padding: 8px 12px 8px 8px; }
  .auth-hero-note img { width: 34px; height: 34px; }
  .auth-hero-footer { display: none; }
  .auth-card { height: auto; min-height: 66svh; padding: 40px 26px 48px; }
  .auth-view > .theme-toggle { top: 22px; right: 20px; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 12; width: min(300px, calc(100vw - 48px)); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 18px 0 50px rgba(0,0,0,.4); }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-scrim.is-open { position: fixed; inset: 0; z-index: 11; display: block; background: rgba(0,0,0,.55); }
  .sidebar-toggle { display: grid; }
  .topbar { height: 54px; flex-basis: 54px; padding: 0 12px; }
  .welcome-view { width: min(100% - 32px, 520px); padding-top: 35px; }
  .suggestions { grid-template-columns: 1fr; gap: 8px; }
  .suggestion { min-height: 66px; align-items: center; padding: 10px 12px; }
  .suggestion b { margin-top: 0; }
  .message-list, .composer { width: calc(100% - 28px); }
  .composer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .composer-hint { max-width: 245px; line-height: 1.35; }
}

@media (max-width: 430px) {
  .auth-hero { min-height: 32svh; padding: 22px 21px 18px; }
  .auth-card { min-height: 68svh; padding: 34px 22px 42px; }
  .welcome-copy { font-size: 13px; }
  .message-content { font-size: 13px; }
}
