/* src/client/styles.css */
:root {
  --bg: #f7f7f5;
  --panel: #fff;
  --surface-2: #f1f1ee;
  --surface-3: #e9e9e5;
  --text-1: #1a1a1e;
  --text-2: #5c5c66;
  --text-3: #9494a0;
  --border: #e4e4e0;
  --border-strong: #cfcfca;
  --accent: #5d58c6;
  --accent-soft: #eceafa;
  --accent-contrast: #fff;
  --danger: #c2402f;
  --danger-bg: #fbedea;
  --font-sans: ui-sans-serif, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --radius-sm: 7px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --ease: cubic-bezier(.25, .6, .3, 1);
  --buncss-light: initial;
  --buncss-dark: ;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --buncss-light: ;
    --buncss-dark: initial;
    --bg: #131316;
    --panel: #1a1a1f;
    --surface-2: #232329;
    --surface-3: #2c2c33;
    --text-1: #ececf1;
    --text-2: #a4a4b2;
    --text-3: #71717e;
    --border: #26262c;
    --border-strong: #3a3a42;
    --accent: #8b85e8;
    --accent-soft: #2a2843;
    --accent-contrast: #15151a;
    --danger: #e06c5b;
    --danger-bg: #3a201b;
  }
}

* {
  box-sizing: border-box;
}

html, body, #root {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

button:disabled {
  cursor: default;
}

input, textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.mono {
  font-family: var(--font-mono);
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

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

.loading-screen {
  display: flex;
  color: var(--text-3);
  justify-content: center;
  align-items:  center;
  height: 100%;
  font-size: 13px;
}

.sidebar {
  display: flex;
  border-right: 1px solid var(--border);
  background: var(--bg);
  flex-direction: column;
  flex: none;
  gap: 2px;
  width: 264px;
  padding: 14px 10px 10px;
}

.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items:  center;
  padding: 0 6px 10px;
}

.wordmark {
  display: flex;
  letter-spacing: -.01em;
  align-items:  center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}

.wordmark-glyph {
  background: var(--accent);
  color: var(--accent-contrast);
  display: inline-flex;
  border-radius: 7px;
  flex: none;
  justify-content: center;
  align-items:  center;
  width: 22px;
  height: 22px;
}

.icon-button {
  border-radius: var(--radius-sm);
  display: inline-flex;
  color: var(--text-2);
  transition: background .12s var(--ease), color .12s var(--ease);
  justify-content: center;
  align-items:  center;
  width: 28px;
  height: 28px;
}

.icon-button:hover {
  background: var(--surface-2);
  color: var(--text-1);
}

.icon-button.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

.sidebar-search {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  background: var(--panel);
  transition: border-color .12s var(--ease);
  align-items:  center;
  gap: 7px;
  margin: 0 0 8px;
  padding: 6px 9px;
}

.sidebar-search:focus-within {
  border-color: var(--border-strong);
}

.sidebar-search input {
  outline: none;
  color: var(--text-1);
  background: none;
  border: none;
  flex: 1;
  min-width: 0;
  font-size: 13px;
}

.sidebar-search input::placeholder {
  color: var(--text-3);
}

.kbd {
  font-family: var(--font-mono);
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 11px;
  line-height: 16px;
}

.chat-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 1px;
  margin: 0 -2px;
  padding: 0 2px;
}

.chat-group-label {
  color: var(--text-3);
  padding: 10px 8px 4px;
  font-size: 11px;
}

.chat-row {
  display: flex;
  border-radius: var(--radius-sm);
  transition: background .12s var(--ease);
  align-items:  center;
  gap: 4px;
}

.chat-row:hover, .chat-row.selected {
  background: var(--surface-2);
}

.chat-select {
  text-align: left;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  padding: 7px 6px 7px 10px;
  font-size: 13px;
}

.chat-row.selected .chat-select {
  color: var(--text-1);
}

.chat-row .row-actions {
  display: flex;
  opacity: 0;
  transition: opacity .12s var(--ease);
  gap: 0;
  padding-right: 4px;
}

.chat-row:hover .row-actions, .chat-row:focus-within .row-actions {
  opacity: 1;
}

.row-actions .icon-button {
  width: 24px;
  height: 24px;
}

.rename-form {
  display: flex;
  flex: 1;
  align-items:  center;
  gap: 4px;
  padding: 3px 4px 3px 6px;
}

.rename-form input {
  border: 1px solid var(--border-strong);
  background: var(--panel);
  outline: none;
  border-radius: 5px;
  flex: 1;
  min-width: 0;
  padding: 3px 6px;
  font-size: 13px;
}

.empty-sidebar {
  color: var(--text-3);
  padding: 14px 10px;
  font-size: 12.5px;
}

.account-row {
  display: flex;
  border-radius: var(--radius-sm);
  transition: background .12s var(--ease);
  align-items:  center;
  gap: 9px;
  margin-top: 6px;
  padding: 7px 8px;
}

.account-row:hover {
  background: var(--surface-2);
}

.avatar {
  background: var(--surface-3);
  color: var(--text-2);
  display: inline-flex;
  border-radius: 50%;
  flex: none;
  justify-content: center;
  align-items:  center;
  width: 26px;
  height: 26px;
  font-size: 11px;
  font-weight: 600;
}

.account-name {
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
}

.account-row .row-actions {
  display: flex;
  opacity: 0;
  transition: opacity .12s var(--ease);
}

.sign-in-button {
  color: var(--accent);
  border: 1px solid var(--border-strong);
  transition: background .12s var(--ease);
  border-radius: 99px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 600;
}

.sign-in-button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.usage-meter {
  margin-top: 8px;
  padding: 0 8px;
}

.usage-bar {
  background: var(--surface-3);
  overflow: hidden;
  border-radius: 99px;
  height: 3px;
}

.usage-fill {
  display: block;
  background: var(--accent);
  transition: width .3s var(--ease);
  border-radius: 99px;
  height: 100%;
}

.usage-fill.warn {
  background: #c98a1b;
}

.usage-fill.full {
  background: var(--danger);
}

.usage-text {
  color: var(--text-3);
  margin-top: 5px;
}

.usage-scope {
  color: var(--text-3);
}

.account-row:hover .row-actions, .account-row:focus-within .row-actions {
  opacity: 1;
}

.workspace {
  display: flex;
  background: var(--panel);
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items:  center;
  gap: 10px;
  padding: 12px 22px 10px;
}

.topbar .menu-button {
  display: none;
}

.chat-heading {
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
}

.cost-root {
  position: relative;
  display: flex;
  margin-left: auto;
}

.cost-chip {
  color: var(--text-3);
  border: 1px solid var(--border);
  transition: color .12s var(--ease), border-color .12s var(--ease);
  border-radius: 99px;
  padding: 3px 9px;
}

.cost-chip:hover {
  color: var(--text-1);
  border-color: var(--border-strong);
}

.cost-popover {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  z-index: 30;
  animation: rise-in .14s var(--ease);
  width: 330px;
  max-width: calc(100vw - 40px);
  padding: 8px;
  top: calc(100% + 8px);
  right: 0;
}

.cost-row {
  display: flex;
  border-radius: var(--radius-sm);
  align-items: baseline;
  gap: 10px;
  padding: 5px 8px;
}

.cost-row.total {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 8px;
}

.cost-model {
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
}

.cost-row.total .cost-model {
  font-weight: 600;
}

.cost-tokens {
  color: var(--text-3);
  white-space: nowrap;
}

.cost-amount {
  color: var(--text-2);
  text-align: right;
  white-space: nowrap;
  min-width: 56px;
}

.stream-pill {
  display: inline-flex;
  color: var(--text-3);
  border: 1px solid var(--border);
  animation: fade-in .2s var(--ease);
  white-space: nowrap;
  border-radius: 99px;
  align-items:  center;
  gap: 6px;
  margin-left: auto;
  padding: 3px 9px;
  font-size: 12px;
}

.cost-root ~ .stream-pill {
  margin-left: 8px;
}

.stream-pill.error {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #0000;
}

.transcript {
  overflow-y: auto;
  flex: 1;
  padding: 10px 22px 8px;
}

.transcript-inner {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
}

.msg {
  animation: rise-in .18s var(--ease);
  margin-bottom: 22px;
}

.msg.user {
  display: flex;
  justify-content: flex-end;
}

.msg.user .msg-col {
  max-width: 76%;
}

.bubble {
  background: var(--surface-2);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  border-radius: 14px 14px 5px;
  padding: 9px 13px;
  font-size: 14px;
  line-height: 1.55;
}

.msg.assistant {
  display: flex;
  gap: 13px;
}

.msg-dot {
  background: var(--accent);
  border-radius: 50%;
  flex: none;
  width: 7px;
  height: 7px;
  margin-top: 9px;
}

.msg-dot.streaming {
  animation: pulse 1.2s var(--ease) infinite;
}

.msg.assistant .msg-col {
  flex: 1;
  min-width: 0;
  max-width: 90%;
}

.msg-text {
  overflow-wrap: break-word;
  font-size: 14px;
  line-height: 1.65;
}

.md > :first-child {
  margin-top: 0;
}

.md > :last-child {
  margin-bottom: 0;
}

.md p, .md ul, .md ol, .md blockquote, .md pre, .md table {
  margin: 0 0 .75em;
}

.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  letter-spacing: -.01em;
  margin: 1.1em 0 .45em;
  font-weight: 600;
  line-height: 1.35;
}

.md h1 {
  font-size: 16px;
}

.md h2 {
  font-size: 15px;
}

.md h3, .md h4, .md h5, .md h6 {
  font-size: 14px;
}

.md ul, .md ol {
  display: flex;
  flex-direction: column;
  gap: .25em;
  padding-left: 1.4em;
}

.md li > p {
  margin: 0;
}

.md li > ul, .md li > ol {
  margin: .25em 0 0;
}

.md code {
  font-family: var(--font-mono);
  background: var(--surface-2);
  border-radius: 5px;
  padding: .1em .35em;
  font-size: 12.5px;
}

.md pre {
  background: var(--surface-2);
  border-radius: var(--radius-md);
  overflow-x: auto;
  padding: 11px 13px;
}

.md pre code {
  background: none;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.6;
}

.md blockquote {
  border-left: 3px solid var(--border-strong);
  color: var(--text-2);
  padding: 2px 0 2px 12px;
}

.md a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}

.md table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  max-width: 100%;
  font-size: 13px;
}

.md th, .md td {
  border: 1px solid var(--border);
  text-align: left;
  padding: 5px 10px;
}

.md th {
  background: var(--surface-2);
  font-weight: 600;
}

.md img {
  border-radius: var(--radius-sm);
  max-width: 100%;
}

.msg-text .caret {
  display: inline-block;
  background: var(--accent);
  vertical-align: -2px;
  animation: blink .9s steps(2) infinite;
  width: 7px;
  height: 15px;
  margin-left: 2px;
}

.msg-error {
  display: inline-flex;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: var(--radius-sm);
  align-items:  center;
  gap: 7px;
  margin-top: 6px;
  padding: 6px 10px;
  font-size: 12.5px;
}

.msg-meta {
  display: flex;
  color: var(--text-3);
  opacity: 0;
  transition: opacity .15s var(--ease);
  align-items:  center;
  gap: 10px;
  min-height: 18px;
  margin-top: 5px;
}

.msg:hover .msg-meta, .msg:focus-within .msg-meta {
  opacity: 1;
}

.msg.user .msg-meta {
  justify-content: flex-end;
}

.msg-model {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.msg-meta .icon-button {
  color: var(--text-3);
  width: 22px;
  height: 22px;
}

.time-link {
  color: inherit;
  text-decoration: none;
}

.time-link:hover {
  color: var(--text-1);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg.flash .bubble, .msg.flash .msg-text {
  animation: permalink-flash 1.6s var(--ease);
  border-radius: var(--radius-sm);
}

.msg-meta .icon-button:hover {
  color: var(--text-1);
}

.empty-main {
  display: flex;
  color: var(--text-3);
  text-align: center;
  flex-direction: column;
  flex: 1;
  justify-content: center;
  align-items:  center;
  gap: 6px;
  padding: 24px;
}

.empty-main .wordmark-glyph {
  border-radius: 10px;
  width: 34px;
  height: 34px;
  margin-bottom: 8px;
}

.empty-main h2 {
  color: var(--text-1);
  letter-spacing: -.01em;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.empty-main p {
  max-width: 360px;
  margin: 0;
  font-size: 13px;
}

.composer-area {
  padding: 8px 22px 18px;
}

.send-error {
  display: flex;
  border-radius: var(--radius-md);
  background: var(--danger-bg);
  color: var(--danger);
  animation: rise-in .18s var(--ease);
  align-items:  center;
  gap: 9px;
  max-width: 720px;
  margin: 0 auto 10px;
  padding: 8px 12px;
  font-size: 12.5px;
}

.send-error span {
  flex: 1;
}

.send-error .sign-in-button {
  flex: none;
}

.composer {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  transition: border-color .15s var(--ease);
  max-width: 720px;
  margin: 0 auto;
  padding: 11px 12px 9px;
}

.composer:focus-within {
  border-color: var(--accent);
}

.composer textarea {
  display: block;
  outline: none;
  resize: none;
  background: none;
  border: none;
  width: 100%;
  max-height: 200px;
  padding: 1px 2px 10px;
  font-size: 14px;
  line-height: 1.5;
}

.composer textarea::placeholder {
  color: var(--text-3);
}

.composer-foot {
  display: flex;
  align-items:  center;
  gap: 8px;
}

.model-chip {
  display: inline-flex;
  font-family: var(--font-mono);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  transition: background .12s var(--ease);
  align-items:  center;
  gap: 5px;
  max-width: 60%;
  padding: 4px 9px;
  font-size: 11px;
}

.model-chip span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-chip:hover {
  background: var(--surface-2);
}

.send-button {
  background: var(--accent);
  color: var(--accent-contrast);
  display: inline-flex;
  transition: opacity .12s var(--ease), transform .12s var(--ease);
  border-radius: 10px;
  flex: none;
  justify-content: center;
  align-items:  center;
  width: 30px;
  height: 30px;
  margin-left: auto;
}

.send-button:hover {
  transform: translateY(-1px);
}

.send-button:disabled {
  opacity: .35;
  transform: none;
}

.model-popover {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  z-index: 30;
  animation: rise-in .14s var(--ease);
  width: 300px;
  max-width: calc(100vw - 60px);
  padding: 8px;
  bottom: calc(100% + 8px);
  left: 8px;
}

.model-popover .popover-search {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  align-items:  center;
  gap: 7px;
  margin-bottom: 6px;
  padding: 5px 8px;
}

.model-popover .popover-search input {
  outline: none;
  color: var(--text-1);
  background: none;
  border: none;
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
}

.model-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 300px;
}

.model-option {
  display: flex;
  text-align: left;
  border-radius: var(--radius-sm);
  transition: background .1s var(--ease);
  justify-content: space-between;
  align-items:  center;
  gap: 10px;
  padding: 6px 9px;
}

.model-option:hover {
  background: var(--surface-2);
}

.model-option .model-name {
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12.5px;
}

.model-option .model-id {
  font-family: var(--font-mono);
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11px;
}

.model-option .selected-check {
  color: var(--accent);
  flex: none;
}

.model-empty {
  color: var(--text-3);
  padding: 12px 10px;
  font-size: 12.5px;
}

.auth-screen {
  display: flex;
  justify-content: center;
  align-items:  center;
  height: 100%;
  padding: 24px;
}

.auth-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 340px;
  padding: 28px;
}

.auth-panel .wordmark-glyph {
  border-radius: 9px;
  width: 32px;
  height: 32px;
  margin-bottom: 10px;
}

.auth-panel h1 {
  letter-spacing: -.01em;
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.auth-panel > p {
  color: var(--text-2);
  margin: 0 0 12px;
  font-size: 13px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form label {
  display: flex;
  color: var(--text-2);
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
}

.auth-form input {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  outline: none;
  transition: border-color .12s var(--ease);
  padding: 8px 10px;
  font-size: 13.5px;
}

.auth-form input:focus {
  border-color: var(--accent);
}

.button.primary {
  display: inline-flex;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius-sm);
  transition: opacity .12s var(--ease);
  justify-content: center;
  align-items:  center;
  gap: 7px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-weight: 600;
}

.button.primary:hover {
  opacity: .92;
}

.text-button {
  color: var(--text-2);
  align-self:  flex-start;
  margin-top: 12px;
  font-size: 12.5px;
}

.text-button:hover {
  color: var(--text-1);
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes pulse {
  50% {
    opacity: .35;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

@keyframes permalink-flash {
  0%, 35% {
    background-color: var(--accent-soft);
  }

  100% {
    background-color: #0000;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *:before, *:after {
    animation: none !important;
    transition: none !important;
  }
}

.sidebar-backdrop {
  display: none;
}

@media (width <= 760px) {
  .sidebar {
    position: fixed;
    z-index: 40;
    transition: transform .2s var(--ease);
    inset: 0 auto 0 0;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    z-index: 35;
    background: #00000059;
    inset: 0;
  }

  .topbar .menu-button {
    display: inline-flex;
  }

  .transcript, .composer-area {
    padding-left: 14px;
    padding-right: 14px;
  }

  .msg.user .msg-col {
    max-width: 88%;
  }
}
