:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #f7f7f5;
  color: #1f2320;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f7f7f5;
}
.gate-panel { width: min(100%, 380px); text-align: center; }
.brand-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  background: #1f2320;
  color: white;
  border-radius: 8px;
  font-size: 24px;
  font-weight: 700;
}
.gate-panel h1 { margin: 0 0 10px; font-size: 24px; }
.gate-panel p { margin: 0 0 22px; color: #626861; line-height: 1.65; }
.access-form { display: grid; grid-template-columns: 1fr auto; gap: 9px 10px; text-align: left; }
.access-form > label:not(.show-password) {
  grid-column: 1 / -1;
  margin-bottom: -3px;
  color: #343a35;
  font-size: 12px;
  font-weight: 600;
}
.access-form > input {
  grid-column: 1 / -1;
  width: 100%;
  height: 42px;
  border: 1px solid #cfd2cc;
  border-radius: 6px;
  padding: 0 11px;
  outline: none;
}
.access-form #device-code { font-size: 18px; font-weight: 650; text-align: center; }
.access-form > input:focus { border-color: #1f5f48; box-shadow: 0 0 0 2px rgba(31,95,72,.14); }
.login-options { display: flex; align-items: center; gap: 14px; color: #626861; font-size: 12px; }
.login-options label { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.login-options input { width: 16px; height: 16px; margin: 0; accent-color: #1f5f48; }
.access-form .button { min-width: 112px; }

.app { height: 100%; display: grid; grid-template-columns: 300px minmax(0, 1fr); }
.sidebar { min-width: 0; border-right: 1px solid #dedfdb; background: #f2f3f0; overflow: hidden; display: flex; flex-direction: column; }
.sidebar-header, .conversation-header { min-height: 58px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #dedfdb; }
.sidebar-header { padding: 9px 12px 9px 16px; justify-content: space-between; }
.sidebar-header strong { display: block; font-size: 15px; }
.connection-label { display: block; margin-top: 2px; color: #70766f; font-size: 11px; }
.connection-label.online { color: #178348; }
.connection-label.offline { color: #b43b31; }
.account-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 6px; padding: 8px 10px 0; }
.account-bar > button:first-child { min-width: 0; height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 7px; border: 0; border-radius: 6px; background: #e4e9e5; padding: 0 9px; color: #3d4640; }
.account-bar > button:first-child:hover { background: #dce3de; }
.account-bar span { font-size: 11px; }
.account-bar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #176f43; font-size: 12px; font-variant-numeric: tabular-nums; }
.sidebar-tools { display: flex; gap: 6px; padding: 10px 10px 8px; }
.sidebar-tools input {
  min-width: 0;
  flex: 1;
  height: 36px;
  border: 1px solid #d4d6d1;
  border-radius: 6px;
  background: white;
  padding: 0 10px;
  outline: none;
}
.sidebar-tools input:focus, .composer textarea:focus { border-color: #3b7760; box-shadow: 0 0 0 2px rgba(59,119,96,.14); }
.icon-button {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #353a36;
  font-size: 23px;
  line-height: 1;
}
.icon-button:hover { background: #e3e5e0; }
.thread-list { flex: 1; overflow: auto; padding: 2px 7px 12px; }
.thread-item {
  width: 100%;
  min-height: 58px;
  display: block;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 9px 10px;
  color: inherit;
  text-align: left;
}
.thread-item:hover { background: #e6e8e3; }
.thread-item.active { background: #dce5df; }
.thread-item strong, .thread-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-item strong { font-size: 13px; font-weight: 600; }
.thread-item span { margin-top: 5px; color: #747a73; font-size: 11px; }

.conversation { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: #fff; }
.conversation-header { padding: 8px 14px; }
.conversation-heading { min-width: 0; flex: 1; }
.conversation-heading strong, .conversation-heading span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-heading strong { font-size: 14px; }
.conversation-heading span { margin-top: 3px; color: #747a73; font-size: 11px; }
.model-select, .effort-select {
  height: 32px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 0 5px;
  color: #353a36;
  font-size: 12px;
  outline: none;
  text-overflow: ellipsis;
}
.model-select { width: min(160px, 38vw); }
.effort-select { width: 82px; }
.model-select:focus, .effort-select:focus { border-color: #3b7760; box-shadow: 0 0 0 2px rgba(59,119,96,.14); }
.messages { min-height: 0; overflow: auto; padding: 24px max(18px, calc((100% - 820px) / 2)); scroll-behavior: smooth; }
.empty-state { padding-top: 18vh; color: #8a8f89; text-align: center; }
.message { margin: 0 0 22px; }
.message-meta { margin-bottom: 6px; color: #7b817a; font-size: 11px; }
.message-body { line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user { margin-left: auto; max-width: 82%; }
.message.user .message-meta { text-align: right; }
.message.user .message-body { padding: 10px 12px; border-radius: 8px 2px 8px 8px; background: #e8f1ec; }
.message.assistant { max-width: 100%; }
.message.assistant .message-body { color: #222824; }
.message.system .message-body { padding-left: 10px; border-left: 2px solid #d3d6d1; color: #6f756f; font-size: 13px; }
.typing::after { content: ""; display: inline-block; width: 6px; height: 14px; margin-left: 3px; background: #4f6659; vertical-align: -2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer { padding: 12px max(14px, calc((100% - 820px) / 2)) max(12px, env(safe-area-inset-bottom)); border-top: 1px solid #e0e1dd; background: rgba(255,255,255,.97); }
.composer-surface { width: 100%; border: 1px solid #d4d6d1; border-radius: 8px; background: white; box-shadow: 0 2px 9px rgba(31,35,32,.06); }
.composer:focus-within .composer-surface { border-color: #3b7760; box-shadow: 0 0 0 2px rgba(59,119,96,.14); }
.composer textarea { width: 100%; min-height: 54px; max-height: 170px; display: block; resize: none; border: 0; border-radius: 8px 8px 0 0; padding: 12px 13px 5px; outline: none; line-height: 1.45; }
.composer textarea:focus { border-color: transparent; box-shadow: none; }
.composer-toolbar { min-height: 42px; display: flex; align-items: center; gap: 7px; padding: 4px 7px 7px 10px; }
.composer-spacer { min-width: 0; flex: 1; }
.send-button { width: 34px; height: 34px; flex: 0 0 auto; border: 0; border-radius: 50%; background: #1f5f48; color: white; font-size: 20px; line-height: 1; }
.send-button.stopping { background: #252a26; font-size: 12px; }
.send-button:not(:disabled):hover { background: #174d3a; }
.send-button.stopping:not(:disabled):hover { background: #111411; }
.button { min-height: 34px; border: 1px solid #cfd2cc; border-radius: 6px; background: white; padding: 6px 12px; color: #252a26; }
.button:hover { background: #f0f2ee; }
.button.primary { border-color: #1f5f48; background: #1f5f48; color: white; }
.button.danger { border-color: #d9b4af; color: #a32f27; }

.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(20,24,21,.58); }
.account-dialog { width: min(100%, 560px); max-height: calc(100vh - 40px); overflow: auto; border-radius: 8px; background: white; box-shadow: 0 18px 60px rgba(0,0,0,.24); }
.account-dialog > header { min-height: 54px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #dedfdb; padding: 8px 14px 8px 18px; }
.account-dialog h2 { margin: 0; font-size: 16px; }
.account-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid #dedfdb; }
.account-tabs button { min-height: 42px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: #747a73; }
.account-tabs button.active { border-bottom-color: #1f5f48; color: #1f5f48; font-weight: 650; }
.account-panel { padding: 20px; }
.usage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid #e0e1dd; margin-bottom: 18px; }
.usage-grid > div { min-width: 0; min-height: 70px; border-bottom: 1px solid #e0e1dd; padding: 12px 8px; }
.usage-grid > div:nth-child(odd) { border-right: 1px solid #e0e1dd; }
.usage-grid span, .usage-grid strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage-grid span { color: #747a73; font-size: 11px; }
.usage-grid strong { margin-top: 7px; font-size: 16px; font-variant-numeric: tabular-nums; }
.inline-error { margin-bottom: 12px; color: #a32f27; font-size: 12px; }
#recharge-panel label { display: block; margin-bottom: 8px; font-size: 12px; font-weight: 650; }
#recharge-panel input { width: 100%; height: 42px; border: 1px solid #d4d6d1; border-radius: 6px; padding: 0 11px; outline: none; }
#recharge-panel input:focus { border-color: #3b7760; box-shadow: 0 0 0 2px rgba(59,119,96,.14); }
.recharge-result { margin: 12px 0; border-left: 3px solid #1f5f48; background: #edf4ef; padding: 10px 12px; color: #315745; font-size: 12px; line-height: 1.7; }
#recharge-submit-button { margin-top: 14px; }

.toast { position: fixed; left: 50%; bottom: 78px; z-index: 10; max-width: calc(100vw - 32px); transform: translateX(-50%); border-radius: 6px; background: #222824; padding: 9px 13px; color: white; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.mobile-only { display: none; }

@media (max-width: 720px) {
  .app { display: block; position: relative; overflow: hidden; }
  .sidebar, .conversation { position: absolute; inset: 0; transition: transform .18s ease; }
  .sidebar { border-right: 0; transform: translateX(0); }
  .conversation { transform: translateX(100%); }
  .app.thread-open .sidebar { transform: translateX(-28%); }
  .app.thread-open .conversation { transform: translateX(0); }
  .mobile-only { display: inline-grid; place-items: center; }
  .conversation-header { gap: 7px; padding-inline: 8px; }
  .conversation-heading span { display: none; }
  .model-select { width: min(150px, 38vw); }
  .effort-select { width: 76px; }
  .messages { padding: 18px 14px; }
  .message.user { max-width: 90%; }
  .overlay { padding: 10px; }
  .account-dialog { max-height: calc(100vh - 20px); }
  .account-panel { padding: 16px 14px; }
  .usage-grid strong { font-size: 14px; }
}

@media (max-width: 390px) {
  .login-options { align-items: flex-start; flex-direction: column; gap: 8px; }
  .access-form .button { align-self: end; }
}
