:root {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #14221d;
  background: #f6faf8;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --login-bg: #f6faf8;
  --login-surface: #ffffff;
  --login-text: #14221d;
  --login-muted: #66756f;
  --login-weak: #98a39f;
  --login-brand: #42a982;
  --login-brand-dark: #2f8f6d;
  --login-border: #dce6e2;
  --login-error: #d85b5b;
  --login-disabled: #e8f0ed;
  --login-radius-card: 22px;
  --login-radius-control: 15px;
  --login-shadow: 0 18px 54px rgba(35, 79, 63, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--login-bg);
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(66, 169, 130, 0.2);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
}

.phone-frame {
  position: relative;
  width: min(calc(100% - 48px), 430px);
  height: min(860px, calc(100vh - 48px));
  min-height: 640px;
  overflow: hidden;
  background: #f8fbfa;
  border: 1px solid rgba(117, 135, 128, 0.22);
  border-radius: 28px;
  box-shadow: 0 28px 80px rgba(15, 31, 26, 0.18);
}

.phone-frame.login-mode {
  width: 100%;
  max-width: none;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: var(--login-bg);
  box-shadow: none;
}

.booting {
  height: 100%;
  display: grid;
  place-items: center;
  color: #557066;
}

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(30px, env(safe-area-inset-top))
    22px
    max(24px, env(safe-area-inset-bottom));
  background: var(--login-bg);
}

.login-content {
  width: min(100%, 460px);
  min-height: calc(100vh - 54px);
  min-height: calc(100dvh - 54px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.login-brand-area {
  position: relative;
  overflow: hidden;
  padding: 28px 16px 26px;
}

.brand-heading {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--login-brand);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(47, 143, 109, 0.2);
}

.brand-heading h1 {
  margin: 0;
  color: var(--login-text);
  font-size: 29px;
  line-height: 1.25;
  font-weight: 750;
  letter-spacing: 0;
}

.login-brand-area > p {
  position: relative;
  z-index: 1;
  margin: 20px 0 0;
  color: var(--login-muted);
  font-size: 15px;
  line-height: 1.7;
}

.brand-watermark {
  position: absolute;
  top: -28px;
  right: -18px;
  color: var(--login-brand);
  opacity: 0.07;
  pointer-events: none;
}

.login-card {
  min-width: 0;
  display: grid;
  gap: 22px;
  padding: 26px 24px 24px;
  border: 1px solid rgba(220, 230, 226, 0.9);
  border-radius: var(--login-radius-card);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--login-shadow);
}

.form-field {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.form-field > label {
  color: var(--login-text);
  font-size: 16px;
  line-height: 1.4;
  font-weight: 650;
}

.input-shell {
  width: 100%;
  min-width: 0;
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 15px;
  border: 1px solid var(--login-border);
  border-radius: var(--login-radius-control);
  background: var(--login-surface);
  color: #a5b0ac;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.input-shell:focus-within {
  border-color: var(--login-brand);
  box-shadow: 0 0 0 3px rgba(66, 169, 130, 0.11);
  color: var(--login-brand-dark);
}

.input-shell.invalid {
  border-color: var(--login-error);
}

.input-shell input {
  min-width: 0;
  flex: 1;
  height: 52px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--login-text);
  font-size: 16px;
  letter-spacing: 0;
}

.input-shell input::placeholder {
  color: var(--login-weak);
}

.input-clear {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  margin-right: -12px;
  border: 0;
  background: transparent;
  color: var(--login-weak);
}

.code-input-shell {
  gap: 10px;
  padding-right: 7px;
}

.input-divider {
  width: 1px;
  height: 26px;
  background: var(--login-border);
}

.send-code-button {
  min-width: 108px;
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--login-brand-dark);
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
}

.send-code-button:disabled {
  cursor: not-allowed;
  color: var(--login-weak);
}

.security-hint {
  min-height: 22px;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--login-weak);
  font-size: 13px;
  line-height: 1.6;
}

.field-error {
  margin: -3px 0 0;
  color: var(--login-error);
  font-size: 13px;
  line-height: 1.5;
}

.agreement-row {
  min-width: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 1px;
  padding: 5px 4px;
  border-radius: 10px;
  color: var(--login-muted);
  font-size: 12px;
  line-height: 1.7;
  transition: background 0.18s ease, color 0.18s ease;
}

.agreement-row.attention {
  background: rgba(216, 91, 91, 0.08);
  color: var(--login-error);
}

.agreement-toggle {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.agreement-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--login-brand-dark);
  cursor: pointer;
}

.policy-link {
  min-height: 34px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--login-brand-dark);
  font-weight: 600;
}

.login-submit {
  width: 100%;
  height: 54px;
  border: 0;
  border-radius: 15px;
  background: var(--login-brand-dark);
  color: #ffffff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0;
  box-shadow: 0 11px 24px rgba(47, 143, 109, 0.2);
  transition: transform 0.15s ease, background 0.15s ease;
}

.login-submit:not(:disabled):active {
  transform: translateY(1px);
  background: #287d60;
}

.login-submit:disabled,
.dialog-confirm:disabled {
  cursor: not-allowed;
  background: var(--login-disabled);
  color: var(--login-weak);
  box-shadow: none;
}

.login-help-links {
  min-height: 44px;
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  align-items: center;
  gap: 12px;
}

.login-help-links span {
  width: 1px;
  height: 18px;
  background: var(--login-border);
}

.login-help-links button {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--login-muted);
  font-size: 14px;
}

.login-security-footer {
  margin-top: auto;
  padding: 34px 10px 6px;
  color: #a3afaa;
  text-align: center;
}

.login-security-footer > span {
  display: inline-block;
  width: calc(50% - 28px);
  height: 1px;
  margin: 0 8px 5px;
  background: var(--login-border);
}

.login-security-footer p {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.6;
}

.login-toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px));
  max-width: calc(100vw - 40px);
  padding: 11px 16px;
  border-radius: 10px;
  background: rgba(20, 34, 29, 0.92);
  color: #ffffff;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 10px 30px rgba(20, 34, 29, 0.18);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(20, 34, 29, 0.38);
}

.app-dialog {
  width: min(100%, 390px);
  max-height: min(78vh, 650px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(220, 230, 226, 0.95);
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(20, 34, 29, 0.2);
}

.dialog-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px 22px;
  border-bottom: 1px solid #edf2f0;
}

.dialog-header h2 {
  margin: 0;
  color: var(--login-text);
  font-size: 19px;
  line-height: 1.4;
}

.dialog-close {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--login-muted);
}

.dialog-content {
  overflow-y: auto;
  padding: 20px 22px;
  overscroll-behavior: contain;
}

.dialog-footer {
  padding: 12px 22px max(18px, env(safe-area-inset-bottom));
  border-top: 1px solid #edf2f0;
}

.dialog-confirm {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 13px;
  background: var(--login-brand-dark);
  color: #ffffff;
  font-size: 16px;
  font-weight: 650;
}

.policy-copy p {
  margin: 0 0 16px;
  color: var(--login-muted);
  font-size: 14px;
  line-height: 1.8;
}

.policy-copy h3 {
  margin: 20px 0 8px;
  color: var(--login-text);
  font-size: 15px;
}

.help-list {
  display: grid;
  gap: 15px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.help-list li {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 9px;
  color: var(--login-muted);
  font-size: 14px;
  line-height: 1.7;
}

.help-list svg {
  margin-top: 3px;
  color: var(--login-brand-dark);
}

.support-contact {
  margin: 20px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: #f3f8f6;
  color: #50645c;
  font-size: 13px;
  line-height: 1.7;
}

.captcha-dialog-copy > p:first-child {
  margin: 0 0 15px;
  color: var(--login-muted);
  font-size: 14px;
  line-height: 1.7;
}

.captcha-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 10px;
}

.captcha-entry input {
  min-width: 0;
  height: 50px;
  padding: 0 13px;
  border: 1px solid var(--login-border);
  border-radius: 13px;
  outline: 0;
  color: var(--login-text);
  font-size: 16px;
}

.captcha-entry input:focus {
  border-color: var(--login-brand);
  box-shadow: 0 0 0 3px rgba(66, 169, 130, 0.11);
}

.captcha-entry button {
  height: 50px;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--login-border);
  border-radius: 13px;
  background: #f8fbfa;
  color: var(--login-brand-dark);
}

.captcha-entry img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.captcha-refresh-tip {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 9px 0 0;
  color: var(--login-weak);
  font-size: 12px;
}

.spinning {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 380px) {
  .login-page {
    padding-right: 18px;
    padding-left: 18px;
  }

  .login-brand-area {
    padding-right: 8px;
    padding-left: 8px;
  }

  .brand-heading h1 {
    font-size: 26px;
  }

  .login-card {
    padding-right: 18px;
    padding-left: 18px;
  }

  .send-code-button {
    min-width: 96px;
    font-size: 14px;
  }
}

@media (max-height: 700px) {
  .login-page {
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .login-brand-area {
    padding-top: 12px;
    padding-bottom: 18px;
  }

  .login-card {
    gap: 17px;
  }

  .login-security-footer {
    padding-top: 22px;
  }
}

@media (min-width: 700px) {
  .login-page {
    padding-top: 58px;
    padding-bottom: 40px;
  }
}

.topbar {
  height: 72px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 54px;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid #e0ebe7;
  background: rgba(255, 255, 255, 0.94);
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.topbar p {
  margin: 4px 0 0;
  color: #6a7d75;
  font-size: 12px;
}

.icon-btn,
.plain-btn {
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: #edf5f2;
  color: #285247;
}

.icon-btn {
  width: 38px;
  font-size: 20px;
}

.plain-btn {
  font-size: 13px;
}

.quota-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 12px 16px 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: #eaf5f1;
  color: #315d52;
  font-size: 13px;
}

.quota-strip strong {
  color: #0f735d;
}

.chat-area {
  height: calc(100% - 72px - 54px - 82px);
  overflow-y: auto;
  padding: 16px;
}

.empty-state {
  margin: 72px auto 0;
  max-width: 280px;
  text-align: center;
  color: #60756d;
}

.empty-state strong {
  display: block;
  margin-bottom: 8px;
  color: #20332c;
  font-size: 18px;
}

.empty-state p {
  margin: 0;
  font-size: 14px;
  line-height: 1.7;
}

.message {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 32px;
}

.message.user .avatar {
  grid-column: 2;
  background: #163d34;
}

.message.user .bubble {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  background: #0f8b6f;
  color: #ffffff;
  border-color: #0f8b6f;
}

.avatar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #dcebe6;
  color: #285247;
  font-size: 12px;
  font-weight: 800;
}

.bubble {
  max-width: 100%;
  width: fit-content;
  padding: 12px 13px;
  border: 1px solid #dbe7e3;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(31, 57, 49, 0.06);
}

.content {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
  font-size: 15px;
}

.markdown-content {
  white-space: normal;
}

.reasoning-panel {
  margin-bottom: 10px;
  border: 1px solid #dbe7e3;
  border-radius: 12px;
  background: #f2f7f5;
  color: #496259;
}

.reasoning-panel summary {
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: #315d52;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.reasoning-content {
  max-height: 220px;
  overflow-y: auto;
  padding: 0 10px 10px;
  color: #5d7169;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

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

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

.markdown-content p {
  margin: 0 0 10px;
}

.markdown-content ul,
.markdown-content ol {
  margin: 8px 0 10px;
  padding-left: 20px;
}

.markdown-content li + li {
  margin-top: 6px;
}

.markdown-content code {
  padding: 2px 5px;
  border-radius: 6px;
  background: #edf5f2;
  color: #0f735d;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.markdown-content pre {
  max-width: 100%;
  overflow-x: auto;
  margin: 10px 0;
  padding: 10px;
  border-radius: 10px;
  background: #13231e;
  color: #f4fffb;
}

.markdown-content pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.markdown-content table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}

.markdown-content th,
.markdown-content td {
  padding: 7px 9px;
  border: 1px solid #dbe7e3;
  white-space: nowrap;
}

.markdown-content a {
  color: #0f735d;
  font-weight: 700;
}

.typing {
  display: inline-block;
  margin-top: 8px;
  color: #0f8b6f;
  font-size: 12px;
}

.thinking-indicator {
  margin-bottom: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #f2f7f5;
  color: #5d7169;
  font-size: 13px;
}

.thinking-dots::after {
  content: "";
  display: inline-block;
  width: 3px;
  height: 3px;
  margin-left: 4px;
  border-radius: 50%;
  background: #0f8b6f;
  animation: thinking-dot 1.2s infinite;
}

@keyframes thinking-dot {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 1; }
}

.composer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 10px;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid #e0ebe7;
  background: #ffffff;
}

.composer textarea {
  min-height: 48px;
  max-height: 96px;
  resize: none;
  padding: 13px 14px;
  line-height: 1.45;
}

.send-btn,
.stop-btn {
  min-height: 48px;
}

.send-btn {
  background: #0f8b6f;
  color: #ffffff;
}

.stop-btn {
  background: #ffe9e5;
  color: #bb3b2f;
}

.drawer-mask {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background: rgba(15, 33, 29, 0);
  transition: background 0.2s ease;
}

.drawer-mask.show {
  pointer-events: auto;
  background: rgba(15, 33, 29, 0.28);
}

.session-drawer {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 82%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  padding: 18px;
  background: #ffffff;
  transform: translateX(-102%);
  transition: transform 0.22s ease;
  box-shadow: 18px 0 50px rgba(20, 37, 32, 0.16);
}

.session-drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.new-session-btn {
  height: 44px;
  margin-bottom: 14px;
  background: #0f8b6f;
  color: #ffffff;
}

.session-list {
  overflow-y: auto;
  display: grid;
  gap: 8px;
}

.session-item {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 12px;
  border: 1px solid #e0ebe7;
  border-radius: 14px;
  background: #f8fbfa;
  color: #253b34;
  text-align: left;
}

.session-item.active {
  border-color: #0f8b6f;
  background: #eaf5f1;
}

.session-main {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.session-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.session-main small {
  color: #6f817a;
}

.session-actions {
  display: flex;
  gap: 8px;
}

.session-actions button,
.session-edit button {
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: #edf5f2;
  color: #285247;
  font-size: 12px;
  font-weight: 700;
}

.session-edit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  gap: 8px;
}

.session-edit input {
  min-width: 0;
  height: 32px;
  padding: 0 9px;
  border: 1px solid #cad8d2;
  border-radius: 9px;
  background: #ffffff;
  color: #17211d;
  outline: none;
}

@media (max-width: 520px) {
  .app-shell {
    display: block;
    min-height: 100vh;
    padding: 0;
  }

  .phone-frame {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
}

/* 登录后的手机端问答界面 */
:root {
  --chat-bg: #f6faf8;
  --chat-surface: #ffffff;
  --chat-text: #17231f;
  --chat-muted: #6f7f79;
  --chat-weak: #98a49f;
  --chat-brand: #149477;
  --chat-brand-dark: #0f705d;
  --chat-brand-soft: #eff7f4;
  --chat-border: #dfe9e5;
  --chat-control-border: #d9e6e1;
  --chat-danger: #c65353;
  --chat-radius-control: 13px;
  --chat-radius-card: 15px;
  --chat-shadow: 0 8px 24px rgba(28, 60, 50, 0.055);
}

.phone-frame.chat-mode {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: var(--chat-bg);
}

.chat-header {
  position: relative;
  z-index: 5;
  min-height: 82px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--chat-border);
  background: rgba(255, 255, 255, 0.98);
}

.header-menu-button,
.header-profile-button,
.history-header button {
  min-width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: var(--chat-brand-soft);
  color: var(--chat-brand-dark);
}

.assistant-summary {
  min-width: 0;
}

.assistant-summary h1 {
  overflow: hidden;
  margin: 0;
  color: var(--chat-text);
  font-size: 17px;
  line-height: 1.35;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.assistant-summary p {
  overflow: hidden;
  margin: 3px 0 0;
  color: var(--chat-muted);
  font-size: 11px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-profile-button {
  max-width: 120px;
  grid-template-columns: 18px minmax(0, auto);
  gap: 6px;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 650;
}

.header-profile-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-quota {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 16px 0;
  padding: 8px 14px;
  border: 1px solid rgba(217, 230, 225, 0.75);
  border-radius: 13px;
  background: var(--chat-brand-soft);
  color: #365c51;
  font-size: 13px;
}

.session-quota-guidance {
  flex-basis: 100%;
  margin: -2px 0 0 26px;
  color: #6c8078;
  font-size: 12px;
  line-height: 1.55;
}

.session-quota > div {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.session-quota small {
  overflow: hidden;
  max-width: 150px;
  color: #6c8078;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-quota-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 0 0 auto;
}

.quota-link {
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid rgba(31, 107, 82, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: #2f6d59;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.quota-link:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.session-quota svg,
.session-quota strong {
  color: var(--chat-brand-dark);
}

.session-quota strong {
  font-size: 14px;
  font-weight: 700;
}

.session-quota.exhausted {
  border-color: rgba(198, 83, 83, 0.25);
  background: #fff5f4;
}

.session-quota.exhausted strong {
  color: var(--chat-danger);
}

.session-quota.exhausted .session-quota-guidance {
  color: var(--chat-danger);
}

.message-list {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 18px 16px 28px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #cfddd8 transparent;
}

.chat-empty-state,
.chat-loading-state {
  min-height: 48%;
  display: grid;
  place-content: center;
  text-align: center;
}

.chat-empty-state strong {
  color: var(--chat-text);
  font-size: 18px;
  font-weight: 680;
}

.chat-empty-state p,
.chat-loading-state {
  margin: 8px 0 0;
  color: var(--chat-muted);
  font-size: 14px;
  line-height: 1.65;
}

.chat-message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  margin-bottom: 18px;
  scroll-margin-top: 12px;
}

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

.assistant-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: #e4f1ed;
  color: var(--chat-brand-dark);
}

.message-bubble {
  min-width: 0;
  width: fit-content;
  max-width: 100%;
  padding: 13px 15px 10px;
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-card);
  background: var(--chat-surface);
  box-shadow: var(--chat-shadow);
}

.chat-message.user .message-bubble {
  max-width: 82%;
  border-color: var(--chat-brand);
  border-bottom-right-radius: 5px;
  background: var(--chat-brand);
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(20, 148, 119, 0.15);
}

.message-content {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  color: inherit;
  font-size: 15px;
  line-height: 1.7;
  letter-spacing: 0;
}

.chat-message time {
  display: block;
  margin-top: 6px;
  color: var(--chat-weak);
  font-size: 11px;
  line-height: 1.3;
}

.chat-message.user time {
  color: rgba(255, 255, 255, 0.72);
  text-align: right;
}

.generation-state {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  color: var(--chat-muted);
  font-size: 13px;
}

.generation-state span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--chat-brand);
  animation: generation-pulse 1.2s ease-in-out infinite;
}

.generation-state span:nth-child(2) { animation-delay: 0.14s; }
.generation-state span:nth-child(3) { animation-delay: 0.28s; margin-right: 4px; }

.message-error-state {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px 12px;
  margin-top: 10px;
  padding: 10px 11px;
  border: 1px solid #ead5cf;
  border-radius: 11px;
  background: #fff8f5;
  color: #8a5043;
  font-size: 13px;
  line-height: 1.5;
}

.message-error-state span {
  flex: 1 1 190px;
}

.message-error-state button {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 11px;
  border: 1px solid #bf7765;
  border-radius: 9px;
  background: #ffffff;
  color: #8a4434;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.message-error-state button:hover {
  background: #fff0eb;
}

.message-error-state button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

@keyframes generation-pulse {
  0%, 70%, 100% { opacity: 0.25; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-2px); }
}

.markdown-content {
  white-space: normal;
}

.markdown-content > :first-child { margin-top: 0; }
.markdown-content > :last-child { margin-bottom: 0; }
.markdown-content p { margin: 0 0 8px; }

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
  margin: 15px 0 6px;
  color: var(--chat-text);
  line-height: 1.42;
  font-weight: 700;
}

.markdown-content h1 { font-size: 20px; }
.markdown-content h2 { font-size: 18px; }
.markdown-content h3 { font-size: 17px; }
.markdown-content h4 { font-size: 16px; }
.markdown-content h5,
.markdown-content h6 { font-size: 15px; }

.markdown-content ul,
.markdown-content ol {
  margin: 6px 0 9px;
  padding-left: 21px;
}

.markdown-content li + li { margin-top: 3px; }
.markdown-content strong { color: var(--chat-text); font-weight: 700; }

.markdown-content blockquote {
  margin: 9px 0;
  padding: 7px 11px;
  border-left: 3px solid #8cc7b6;
  background: var(--chat-brand-soft);
  color: #526b63;
}

.markdown-content blockquote p { margin: 0; }

.markdown-content hr {
  margin: 14px 0;
  border: 0;
  border-top: 1px solid var(--chat-border);
}

.chat-composer {
  position: relative;
  z-index: 6;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 10px;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--chat-border);
  background: rgba(255, 255, 255, 0.98);
}

.chat-composer textarea {
  width: 100%;
  min-height: 50px;
  max-height: 108px;
  resize: none;
  overflow-y: hidden;
  padding: 13px 15px;
  border: 1px solid var(--chat-control-border);
  border-radius: var(--chat-radius-control);
  outline: 0;
  background: #ffffff;
  color: var(--chat-text);
  font-size: 16px;
  line-height: 1.45;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.chat-composer textarea:focus {
  border-color: var(--chat-brand);
  box-shadow: 0 0 0 3px rgba(20, 148, 119, 0.1);
}

.chat-composer textarea::placeholder { color: var(--chat-weak); }

.composer-send,
.composer-stop,
.composer-voice {
  min-width: 78px;
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--chat-radius-control);
  color: #ffffff;
  font-size: 15px;
  font-weight: 650;
}

.composer-voice {
  min-width: 50px;
  padding: 0 13px;
  border: 1px solid var(--chat-control-border);
  background: #ffffff;
  color: var(--chat-brand-deep);
}

.composer-voice:disabled { cursor: not-allowed; opacity: 0.55; }
.composer-voice.cancel { color: var(--chat-danger); }
.composer-voice.finish { border-color: var(--chat-brand); background: var(--chat-brand); color: #ffffff; }

.voice-recording-panel {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 15px;
  border: 1px solid rgba(20, 148, 119, 0.34);
  border-radius: var(--chat-radius-control);
  background: rgba(20, 148, 119, 0.07);
  color: var(--chat-brand-deep);
}

.voice-recording-panel span:last-child { color: var(--chat-weak); font-size: 12px; }
.voice-pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--chat-danger); animation: voice-pulse 1.1s ease-in-out infinite; }
.voice-input-error { grid-column: 1 / -1; margin: -2px 3px 0; color: var(--chat-danger); font-size: 12px; }

@keyframes voice-pulse { 50% { opacity: 0.35; transform: scale(0.78); } }

.composer-send { background: var(--chat-brand); }
.composer-stop { background: var(--chat-danger); }

.composer-send:disabled {
  cursor: not-allowed;
  background: #dbe8e3;
  color: #93a39d;
}

.message-feedback-button { margin-top: 8px; display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border: 0; border-radius: 7px; background: transparent; color: var(--chat-weak); font-size: 12px; }
.message-feedback-button:hover { background: rgba(20, 148, 119, 0.08); color: var(--chat-brand-deep); }
.feedback-dialog p { margin: 0 0 12px; color: var(--chat-muted); line-height: 1.65; }
.feedback-dialog textarea { width: 100%; resize: vertical; padding: 12px; border: 1px solid var(--chat-control-border); border-radius: 10px; font: inherit; }
.feedback-dialog-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; color: var(--chat-weak); font-size: 12px; }
.feedback-dialog-footer button { min-height: 38px; padding: 0 18px; border: 0; border-radius: 9px; background: var(--chat-brand); color: white; font-weight: 650; }
.feedback-dialog-footer button:disabled { opacity: 0.5; }

.history-mask {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  background: rgba(20, 36, 31, 0);
  transition: background 0.22s ease;
}

.history-mask.visible {
  pointer-events: auto;
  background: rgba(20, 36, 31, 0.32);
}

.history-drawer {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 45;
  width: 84%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 15px max(16px, env(safe-area-inset-bottom));
  background: #fbfdfc;
  transform: translateX(-102%);
  transition: transform 0.22s ease;
  box-shadow: 18px 0 50px rgba(20, 36, 31, 0.15);
}

.history-drawer.open { transform: translateX(0); }

.history-header {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.history-header h2 {
  margin: 0;
  color: var(--chat-text);
  font-size: 19px;
}

.new-chat-button {
  width: 100%;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
  border: 0;
  border-radius: 13px;
  background: var(--chat-brand);
  color: #ffffff;
  font-size: 15px;
  font-weight: 680;
}

.history-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  padding: 1px 2px 8px;
  overscroll-behavior: contain;
}

.history-state {
  padding: 48px 10px;
  color: var(--chat-muted);
  font-size: 14px;
  text-align: center;
}

.history-item {
  padding: 13px 14px 10px;
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  background: #ffffff;
}

.history-item.active {
  border-color: var(--chat-brand);
  background: #f3faf7;
}

.history-main {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.history-main strong {
  display: -webkit-box;
  overflow: hidden;
  color: var(--chat-text);
  font-size: 15px;
  line-height: 1.45;
  font-weight: 680;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.history-main time,
.history-main span {
  color: var(--chat-muted);
  font-size: 11px;
  line-height: 1.45;
}

.history-main time { white-space: nowrap; }
.history-main span { grid-column: 1 / -1; }

.history-actions {
  display: flex;
  gap: 18px;
  margin-top: 8px;
}

.history-actions button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--chat-brand-dark);
  font-size: 13px;
  font-weight: 620;
}

.history-actions button.danger { color: var(--chat-danger); }

.session-dialog-form {
  display: grid;
  gap: 9px;
}

.session-dialog-form label {
  color: var(--chat-text);
  font-size: 14px;
  font-weight: 650;
}

.session-dialog-form input {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid var(--chat-control-border);
  border-radius: 12px;
  outline: 0;
  color: var(--chat-text);
  font-size: 16px;
}

.session-dialog-form input:focus {
  border-color: var(--chat-brand);
  box-shadow: 0 0 0 3px rgba(20, 148, 119, 0.1);
}

.session-dialog-form p {
  margin: 0;
  color: var(--chat-weak);
  font-size: 12px;
  text-align: right;
}

.confirm-copy {
  margin: 0;
  color: var(--chat-muted);
  font-size: 15px;
  line-height: 1.75;
}

.help-card-dialog {
  display: grid;
  gap: 12px;
}

.help-card-dialog p {
  margin: 0;
  color: var(--chat-muted);
  font-size: 13px;
  line-height: 1.65;
}

.help-card-dialog textarea {
  width: 100%;
  min-height: min(48vh, 420px);
  resize: vertical;
  padding: 14px;
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  outline: 0;
  background: #ffffff;
  color: var(--chat-text);
  font: inherit;
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.help-card-dialog textarea:focus {
  border-color: var(--chat-brand);
  box-shadow: 0 0 0 3px rgba(20, 148, 119, 0.1);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.dialog-actions button {
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 650;
}

.dialog-secondary { background: #edf3f1; color: var(--chat-muted); }
.dialog-primary { background: var(--chat-brand); color: #ffffff; }
.dialog-danger { background: var(--chat-danger); color: #ffffff; }

.dialog-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.chat-toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px));
  max-width: calc(100vw - 40px);
  padding: 11px 16px;
  border-radius: 10px;
  background: rgba(23, 35, 31, 0.92);
  color: #ffffff;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 10px 30px rgba(20, 34, 29, 0.18);
}

body.drawer-open { overflow: hidden; }

@media (max-width: 390px) {
  .chat-header {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 7px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .assistant-summary h1 { font-size: 15px; }
  .assistant-summary p { font-size: 10px; }
  .header-profile-button { max-width: 94px; padding: 0 8px; }
  .session-quota { margin-right: 12px; margin-left: 12px; }
  .session-quota-actions { gap: 5px; }
  .quota-link { padding: 0 6px; font-size: 11px; }
  .message-list { padding-right: 12px; padding-left: 12px; }
  .chat-composer { padding-right: 10px; padding-left: 10px; }
  .composer-send,
  .composer-stop { min-width: 72px; padding: 0 11px; }
}

@media (max-width: 350px) {
  .header-profile-button { width: 44px; grid-template-columns: 1fr; padding: 0; }
  .header-profile-button span { display: none; }
  .chat-header { grid-template-columns: 44px minmax(0, 1fr) 44px; }
}

@media (max-height: 680px) {
  .chat-header { min-height: 70px; }
  .session-quota { min-height: 42px; margin-top: 8px; }
  .message-list { padding-top: 12px; padding-bottom: 16px; }
  .chat-composer { padding-top: 9px; }
}

@media (min-width: 521px) {
  .phone-frame.chat-mode {
    height: min(860px, calc(100dvh - 48px));
  }

  .modal-backdrop {
    position: absolute;
    border-radius: 28px;
  }
}

@media (max-width: 520px) {
  .phone-frame.chat-mode {
    height: 100dvh;
    min-height: 0;
  }
}
