:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: rgba(255, 255, 255, .86);
  --surface-solid: #ffffff;
  --text: #111111;
  --muted: #7a7a7a;
  --soft-text: #4b4b4b;
  --line: rgba(0, 0, 0, .08);
  --line-strong: rgba(0, 0, 0, .13);
  --user-bg: #eadcfb;
  --user-text: #37274b;
  --accent: #111111;
  --danger: #c2413a;
  --shadow: 0 14px 42px rgba(0, 0, 0, .12);
  --safe-area-top: env(safe-area-inset-top);
  --safe-area-bottom: env(safe-area-inset-bottom);
  --app-height: 100dvh;
  --keyboard-inset: 0px;
  --keyboard-translate: 0px;
  --viewport-top: 0px;
  --topbar-offset: 0px;
  --composer-height: 76px;
  --topbar-height: calc(84px + var(--safe-area-top));
  --message-font-size: 15px;
  --user-font-size: 15px;
  --composer-font-size: 15px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}
body {
  margin: 0;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}
button, textarea, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  height: max(100svh, var(--app-height));
  min-height: max(100svh, var(--app-height));
  display: grid;
  grid-template-rows: 1fr auto;
  padding-top: var(--topbar-height);
  position: fixed;
  inset: var(--viewport-top) 0 auto 0;
  width: 100%;
  z-index: 2;
  background: var(--bg);
}
.keyboard-open .app-shell {
  height: max(100svh, var(--app-height));
  min-height: max(100svh, var(--app-height));
  bottom: auto;
}

.keyboard-open .messages { padding-bottom: calc(var(--keyboard-inset) + var(--composer-height) + 16px); }
.keyboard-open .composer { --composer-pad-bottom: 0px; }
.keyboard-open .composer {
  transition: none;
}

.topbar {
  height: var(--topbar-height);
  padding: calc(var(--safe-area-top) + 10px) 32px 10px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 12px;
  pointer-events: none;
  position: fixed;
  inset: 0 0 auto;
  transform: translateY(var(--topbar-offset));
  will-change: transform;
  z-index: 10;
}
.brand {
  justify-self: center;
  min-width: 0;
  max-width: 100%;
  height: 52px;
  padding: 0 20px;
  border-radius: 999px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  color: var(--muted);
  background: rgba(255, 255, 255, .74);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  backdrop-filter: blur(24px) saturate(1.6);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .08), inset 0 0 0 1px rgba(255, 255, 255, .64);
  pointer-events: auto;
}
.brand strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #1683ff;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0;
}
.brand small {
  max-width: 100%;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #9a9a9a;
  font-size: 10px;
}

.icon-button, .text-button, .ghost-button, .send-button, .stop-button {
  border: 0;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}
.icon-button, .text-button {
  min-width: 44px;
  height: 44px;
  border-radius: 999px;
  display: inline-grid;
  place-content: center;
  border: 0;
  background: rgba(255, 255, 255, .76);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  backdrop-filter: blur(24px) saturate(1.5);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .08), inset 0 0 0 1px rgba(255, 255, 255, .66);
  pointer-events: auto;
}
.icon-button {
  gap: 5px;
  justify-self: start;
}
.icon-button span {
  display: block;
  width: 19px;
  height: 2.4px;
  border-radius: 2px;
  background: #111111;
}
.text-button {
  justify-self: end;
  width: 44px;
  padding: 0;
  font-size: 0;
  position: relative;
}
.settings-toggle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  border: 2.2px solid #111111;
  border-radius: 999px;
  transform: translate(-50%, -50%);
}
.settings-toggle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #111111;
  transform: translate(-50%, -50%);
}
.ghost-button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--soft-text);
  background: #f4f4f4;
}

.sessions-panel {
  position: fixed;
  inset: calc(84px + var(--safe-area-top)) auto 0 0;
  width: min(86vw, 360px);
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, .96);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  backdrop-filter: blur(24px) saturate(1.3);
  transform: translateX(-104%);
  transition: transform .2s ease;
  z-index: 8;
}
.standalone-mode .sessions-panel {
  bottom: 0;
  padding-bottom: 0;
}
.sessions-panel.open { transform: translateX(0); }
.panel-head {
  min-height: 56px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
  border-bottom: 1px solid var(--line);
}
.sessions-list { overflow: auto; padding: 8px; }
.session-item {
  width: 100%;
  margin-bottom: 4px;
  padding: 11px 10px;
  display: block;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  text-align: left;
}
.session-item.active {
  background: #f2f2f2;
}
.session-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.session-meta {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.messages {
  overflow: auto;
  padding: 14px 32px calc(var(--composer-height) + 24px);
  scroll-behavior: smooth;
  background: var(--bg);
}
.empty-state {
  min-height: 65%;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.empty-state h1 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 34px;
  letter-spacing: 0;
}
.empty-state p { margin: 0; line-height: 1.5; }

.message {
  max-width: 100%;
  margin: 0 0 22px;
  padding: 0;
  border-radius: 0;
  line-height: 1.65;
  white-space: normal;
  overflow-wrap: anywhere;
  font-size: var(--message-font-size);
  color: var(--text);
  box-shadow: none;
}
.message > :first-child { margin-top: 0; }
.message > :last-child { margin-bottom: 0; }
.message p { margin: 0 0 14px; }
.message h1, .message h2, .message h3, .message h4, .message h5, .message h6 {
  margin: 18px 0 10px;
  line-height: 1.25;
  letter-spacing: 0;
}
.message h1 { font-size: 24px; }
.message h2 { font-size: 22px; }
.message h3 { font-size: 20px; }
.message h4, .message h5, .message h6 { font-size: 18px; }
.message ul, .message ol {
  margin: 0 0 14px;
  padding-left: 24px;
}
.message li { margin: 5px 0; }
.message hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}
.message a {
  color: #0b57d0;
  text-decoration: none;
  border-bottom: 1px solid rgba(11, 87, 208, .28);
}
.message code {
  padding: 2px 5px;
  border-radius: 6px;
  background: #f2f2f2;
  color: #242424;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: .9em;
}
.message pre {
  margin: 0 0 14px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f7f7;
  font-size: 14px;
}
.message pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  white-space: pre;
}
.table-scroll {
  width: 100%;
  margin: 6px 0 16px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.message table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.45;
}
.message th, .message td {
  padding: 9px 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
.message th {
  position: sticky;
  top: 0;
  background: #f8f8f8;
  color: var(--text);
  font-weight: 700;
}
.message tr:last-child td { border-bottom: 0; }
.message th:last-child, .message td:last-child { border-right: 0; }
.message.user {
  width: fit-content;
  max-width: min(78%, 680px);
  margin-left: auto;
  padding: 13px 16px;
  border-radius: 24px;
  background: var(--user-bg);
  color: var(--user-text);
  font-size: var(--user-font-size);
}
.message.user code {
  background: rgba(255, 255, 255, .52);
  color: var(--user-text);
}
.message.user a {
  color: var(--user-text);
  border-bottom-color: rgba(55, 39, 75, .35);
}
.message.assistant {
  margin-right: auto;
}
.message.system {
  width: fit-content;
  max-width: 86%;
  margin-inline: auto;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  background: #f5f5f5;
  text-align: center;
  font-size: 13px;
}
.message.system.tool-log-message {
  width: min(86%, 680px);
  padding: 0;
  border-radius: 26px;
  background: transparent;
  text-align: left;
}
.tool-log {
  overflow: hidden;
  border-radius: 26px;
  background: #f5f5f5;
  color: var(--muted);
}
.tool-log-summary {
  min-height: 42px;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  list-style: none;
  cursor: pointer;
  text-align: center;
  user-select: none;
}
.tool-log-summary::-webkit-details-marker { display: none; }
.tool-log-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-style: italic;
  line-height: 1.35;
}
.tool-log-meta {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .05);
  color: #8a8a8a;
  font-size: 12px;
  line-height: 1.4;
}
.tool-log-body {
  padding: 0 12px 12px;
}
.tool-log:not([open]) .tool-log-body {
  display: none;
}
.tool-log-body pre {
  max-height: min(58vh, 520px);
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  border: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, .5);
  color: #777777;
  font-size: 12px;
  line-height: 1.55;
  -webkit-overflow-scrolling: touch;
}
.tool-log-body code {
  padding: 0;
  background: transparent;
  color: inherit;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.composer {
  --composer-pad-x: 32px;
  --composer-pad-top: 10px;
  --composer-pad-bottom: 10px;
  --composer-control: 40px;
  --composer-pill: 52px;
  --composer-left-slot: 52px;
  --composer-stop-width: 84px;
  --composer-button-inset: 12px;
  --composer-control-offset: 6px;
  min-height: var(--composer-height);
  padding: var(--composer-pad-top) var(--composer-pad-x) var(--composer-pad-bottom);
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, .9) 20%, rgba(255, 255, 255, .98));
  transform: translateY(var(--keyboard-translate));
  transition: transform .16s ease;
}
.composer::before {
  content: "+";
  width: var(--composer-left-slot);
  height: var(--composer-pill);
  border-radius: 26px 0 0 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #111111;
  font-size: 30px;
  line-height: 1;
  font-weight: 400;
  text-align: center;
  background: transparent;
  position: absolute;
  left: var(--composer-pad-x);
  bottom: var(--composer-pad-bottom);
  pointer-events: none;
  z-index: 3;
}
.composer::after {
  content: "";
  position: absolute;
  left: var(--composer-pad-x);
  right: var(--composer-pad-x);
  bottom: var(--composer-pad-bottom);
  height: var(--composer-pill);
  border-radius: 26px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 10px 34px rgba(0, 0, 0, .12), inset 0 0 0 1px rgba(0, 0, 0, .04);
  pointer-events: none;
  z-index: 1;
}
.composer > * {
  position: relative;
  z-index: 2;
}
.composer textarea {
  width: 100%;
  height: var(--composer-control);
  min-height: var(--composer-control);
  max-height: 150px;
  resize: none;
  border: 0;
  border-radius: 0;
  padding: 0 4px;
  color: var(--text);
  background: transparent;
  outline: none;
  font-size: var(--composer-font-size);
  line-height: var(--composer-control);
  position: absolute;
  left: calc(var(--composer-pad-x) + var(--composer-left-slot) + 8px);
  right: calc(var(--composer-pad-x) + var(--composer-button-inset) + var(--composer-control) + 12px);
  bottom: calc(var(--composer-pad-bottom) + var(--composer-control-offset));
  width: auto;
}
.composer textarea::placeholder { color: #8d8d8d; }
.send-button, .stop-button, .login-card button {
  min-height: 40px;
  border-radius: 999px;
  padding: 0 14px;
  color: #ffffff;
  font-weight: 700;
  background: #111111;
}
.send-button {
  width: var(--composer-control);
  height: var(--composer-control);
  padding: 0;
  font-size: 0;
  display: grid;
  place-content: center;
  position: absolute;
  right: calc(var(--composer-pad-x) + var(--composer-button-inset));
  bottom: calc(var(--composer-pad-bottom) + var(--composer-control-offset));
}
.send-button::before {
  content: "";
  width: 3px;
  height: 17px;
  border-radius: 999px;
  background: #ffffff;
  transform: translateY(2px);
}
.send-button::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 10px;
  width: 12px;
  height: 12px;
  border-left: 3px solid #ffffff;
  border-top: 3px solid #ffffff;
  border-radius: 2px 0 0 0;
  transform: translateX(-50%) rotate(45deg);
}
.stop-button {
  width: var(--composer-stop-width);
  height: var(--composer-control);
  min-height: var(--composer-control);
  padding: 0;
  color: #ffffff;
  background: #d33f3b;
  font-size: 17px;
  position: absolute;
  left: calc(var(--composer-pad-x) + var(--composer-button-inset));
  bottom: calc(var(--composer-pad-bottom) + var(--composer-control-offset));
  z-index: 3;
}
.composer:has(.stop-button:not([hidden]))::before {
  content: none;
}
.composer:has(.stop-button:not([hidden])) textarea {
  left: calc(var(--composer-pad-x) + var(--composer-button-inset) + var(--composer-stop-width) + 12px);
}
.send-button:disabled { opacity: .45; }

.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 30;
}
.settings-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(0, 0, 0, .22);
}
.settings-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 18px calc(18px + var(--safe-area-bottom));
  border-radius: 22px 22px 0 0;
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 -16px 44px rgba(0, 0, 0, .16);
  -webkit-backdrop-filter: blur(28px) saturate(1.4);
  backdrop-filter: blur(28px) saturate(1.4);
}
.settings-head {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.settings-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}
.close-button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: #f0f0f0;
  position: relative;
}
.close-button::before,
.close-button::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 18px;
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: #111111;
}
.close-button::before { transform: rotate(45deg); }
.close-button::after { transform: rotate(-45deg); }
.setting-row {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: var(--soft-text);
  font-size: 13px;
}
.setting-row span {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.setting-row output {
  color: var(--muted);
}
.setting-row input[type="range"] {
  width: 100%;
  accent-color: #111111;
}
.setting-row select,
.setting-row input[type="text"] {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 0 12px;
  color: var(--text);
  background: #ffffff;
  outline: none;
  font-size: 15px;
}
.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}
.primary-button,
.secondary-button {
  height: 42px;
  border: 0;
  border-radius: 999px;
  font-weight: 700;
}
.primary-button {
  color: #ffffff;
  background: #111111;
}
.secondary-button {
  color: var(--text);
  background: #f1f1f1;
}
.settings-status {
  display: block;
  min-height: 18px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #ffffff;
}
.login-card {
  width: min(100%, 380px);
  padding: 24px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.login-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: #111111;
  font-weight: 800;
}
.login-card h1 {
  margin: 18px 0 6px;
  color: var(--text);
  font-size: 24px;
  letter-spacing: 0;
}
.login-card p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
}
.login-card input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: var(--text);
  background: #ffffff;
  outline: none;
}
.login-card button {
  width: 100%;
  border: 0;
  margin-top: 12px;
}
.login-card small {
  display: block;
  min-height: 20px;
  margin-top: 10px;
  color: var(--danger);
}

@media (max-width: 430px) {
  .topbar {
    padding-left: 32px;
    padding-right: 32px;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }
  .messages {
    padding-left: 32px;
    padding-right: 32px;
  }
  .composer {
    --composer-pad-x: 28px;
  }
}

@media (min-width: 760px) {
  .app-shell {
    grid-template-columns: 320px 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .topbar { grid-column: 1 / -1; }
  .sessions-panel {
    position: static;
    grid-row: 2 / 4;
    width: auto;
    transform: none;
    box-shadow: none;
  }
  .messages {
    grid-column: 2;
    padding-left: min(8vw, 88px);
    padding-right: min(8vw, 88px);
  }
  .composer {
    grid-column: 2;
    left: 320px;
  }
  #sessionsToggle { visibility: hidden; }
}
