:root {
  color-scheme: light;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #2d2d2d;
  background: #f7f7f8;
}

* { box-sizing: border-box; }
html, body { width: 100%; max-width: 100%; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; overflow: hidden; overflow-x: hidden; overscroll-behavior: none; background: #f7f7f8; }
button, input, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: wait; opacity: .55; }

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  height: var(--app-height, 100dvh);
}

.sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: calc(14px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  background: #f0f0f0;
  border-right: 1px solid #e3e3e3;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 3px 5px 14px; font-size: 15px; }
.brand-icon, .empty-logo {
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #202123;
  color: #fff;
  font-family: Georgia, "Songti SC", serif;
}
.brand-icon { width: 30px; height: 30px; font-size: 13px; }

.new-chat {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid #d7d7d7;
  border-radius: 9px;
  background: #fff;
  color: #2d2d2d;
  font-weight: 600;
}
.new-chat:hover { background: #fafafa; }
.new-chat span { font-size: 19px; font-weight: 350; }

.search-box { display: block; margin: 9px 0 6px; }
.search-box input {
  width: 100%;
  height: 38px;
  padding: 0 11px 0 34px;
  border: 1px solid transparent;
  border-radius: 9px;
  outline: none;
  background: #e7e7e7 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' fill='none' stroke='%23747474' stroke-width='1.6'%3E%3Ccircle cx='6.5' cy='6.5' r='4.3'/%3E%3Cpath d='m9.7 9.7 3.8 3.8'/%3E%3C/svg%3E") no-repeat 11px center;
  color: #2d2d2d;
  font-size: 16px;
}
.search-box input:focus { border-color: #c9c9c9; background-color: #fff; }

.topic-list { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 3px; overflow-y: auto; padding: 2px 0 8px; }
.topic-item {
  position: relative;
  display: flex;
  width: 100%;
  flex-direction: column;
  gap: 0;
  padding: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
}
.topic-item:hover { background: #e5e5e5; }
.topic-item.active { background: #dedede; }
.topic-select {
  display: flex;
  width: 100%;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
  padding: 10px 48px 10px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #363636;
  text-align: left;
}
.topic-select:hover { background: transparent; }
.topic-top { display: flex; min-width: 0; align-items: baseline; justify-content: space-between; gap: 8px; }
.topic-top strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.topic-top time { flex: none; color: #999; font-size: 8px; }
.topic-preview { overflow: hidden; color: #777; font-size: 10px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.topic-delete {
  position: absolute;
  top: 50%;
  right: 8px;
  min-width: 34px;
  min-height: 28px;
  padding: 0 5px;
  transform: translateY(-50%);
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #888;
  font-size: 10px;
  opacity: 0;
}
.topic-delete:hover, .topic-delete:focus-visible { background: #f8dddd; color: #a44949; opacity: 1; }
.topic-item:hover .topic-delete, .topic-item.active .topic-delete { opacity: 1; }
.topic-empty { display: grid; place-items: center; gap: 5px; padding: 44px 8px; color: #8c8c8c; text-align: center; }
.topic-empty strong { font-size: 12px; }
.topic-empty span { font-size: 10px; }

.daily-link {
  display: grid;
  width: 100%;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 10px 8px;
  border: 0;
  border-top: 1px solid #dedede;
  background: transparent;
  color: #3b3b3b;
  text-align: left;
}
.daily-link:hover { background: #e5e5e5; border-radius: 9px; }
.daily-link > span:nth-child(2) { display: flex; flex-direction: column; gap: 2px; }
.daily-link strong { font-size: 11px; }
.daily-link small { color: #858585; font-size: 9px; }
.daily-icon { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 8px; background: #d7d7d7; font-family: Georgia, serif; font-size: 11px; }

.chat-panel { display: grid; width: 100%; max-width: 100%; min-width: 0; min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto auto; background: #fff; }
.chat-header {
  display: flex;
  min-height: 58px;
  align-items: center;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 20px 8px;
  border-bottom: 1px solid #ededed;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(10px);
}
.chat-header h1 { min-width: 0; flex: 1; overflow: hidden; margin: 0; font-size: 15px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.rename-button, .icon-button { border: 0; border-radius: 8px; background: transparent; color: #707070; }
.rename-button { min-height: 34px; padding: 0 9px; font-size: 10px; }
.rename-button:hover, .icon-button:hover { background: #f0f0f0; color: #202020; }
.icon-button { display: grid; width: 36px; height: 36px; place-items: center; font-size: 22px; }
.mobile-only { display: none; }

.messages { width: 100%; min-width: 0; min-height: 0; overflow-x: hidden; overflow-y: auto; padding: 28px max(22px, calc((100% - 760px) / 2)) 20px; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }
.empty-state { display: flex; height: 100%; min-height: 300px; align-items: center; justify-content: center; flex-direction: column; color: #686868; text-align: center; }
.empty-state.compact { min-height: 220px; }
.empty-logo { width: 46px; height: 46px; font-size: 18px; box-shadow: 0 8px 22px rgba(0, 0, 0, .12); }
.empty-state h2 { margin: 18px 0 8px; color: #292929; font-size: 24px; font-weight: 650; }
.empty-state p { max-width: 390px; margin: 0; font-size: 12px; line-height: 1.65; }

.message-row { display: grid; width: 100%; min-width: 0; max-width: 760px; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; margin: 0 auto 28px; }
.avatar { display: grid; width: 28px; height: 28px; place-items: center; border: 1px solid #dadada; border-radius: 7px; background: #fff; color: #4d4d4d; font-size: 10px; font-weight: 650; }
.message-row.assistant .avatar { border-color: #202123; background: #202123; color: #fff; font-family: Georgia, serif; }
.message-body { min-width: 0; max-width: 100%; padding-top: 3px; }
.message-author { display: block; margin-bottom: 7px; font-size: 11px; }
.message-content { max-width: 100%; color: #343434; font-size: 13px; line-height: 1.75; overflow-wrap: anywhere; word-break: break-word; white-space: pre-wrap; }
.message-time { display: block; margin-top: 8px; color: #aaa; font-size: 8px; }
.thinking { display: flex; gap: 4px; padding: 7px 0; }
.thinking i { width: 5px; height: 5px; border-radius: 50%; background: #8a8a8a; animation: pulse 1.1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .13s; }
.thinking i:nth-child(3) { animation-delay: .26s; }
@keyframes pulse { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.failed-message { padding: 11px 12px; border: 1px solid #ead9c3; border-radius: 9px; background: #fff8ed; color: #765a3a; font-size: 11px; }
.failed-message p { margin: 0; }
.retry-button { margin-top: 8px; padding: 0; border: 0; background: transparent; color: #765a3a; font-size: 10px; text-decoration: underline; }

.status-message { min-height: 18px; margin: 0; padding: 0 max(22px, calc((100% - 760px) / 2)) 3px; color: #858585; font-size: 9px; }
.composer-wrap { width: auto; max-width: 100%; min-width: 0; margin: 0 max(18px, calc((100% - 760px) / 2)) calc(11px + env(safe-area-inset-bottom)); }
.composer {
  display: flex;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  position: relative;
  z-index: 2;
  align-items: flex-end;
  gap: 8px;
  overflow: hidden;
  padding: 10px 10px 10px 14px;
  border: 1px solid #d7d7d7;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .08);
}
.composer textarea { flex: 1 1 auto; width: auto; max-width: 100%; min-width: 0; min-height: 25px; max-height: 180px; overflow-y: hidden; padding: 2px 0; resize: none; border: 0; outline: none; background: transparent; color: #2d2d2d; font-size: 16px !important; line-height: 1.45; -webkit-appearance: none; }
.send-button { display: grid; flex: 0 0 38px; width: 38px; height: 38px; min-width: 38px; min-height: 38px; place-items: center; padding: 0; border: 0; border-radius: 50%; background: #202123; color: #fff; font-size: 18px; }
.composer-wrap > small { display: block; margin-top: 6px; color: #aaa; font-size: 8px; text-align: center; }

.digest-dialog { width: min(720px, calc(100% - 28px)); max-height: min(820px, calc(100dvh - 28px)); padding: 22px; border: 0; border-radius: 16px; background: #fff; color: #2d2d2d; box-shadow: 0 24px 90px rgba(0, 0, 0, .24); }
.digest-dialog::backdrop { background: rgba(0, 0, 0, .38); }
.digest-header { display: flex; align-items: center; justify-content: space-between; }
.digest-header small { color: #888; font-size: 9px; text-transform: uppercase; }
.digest-header h2 { margin: 3px 0 0; font-size: 22px; }
.digest-intro { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-top: 16px; padding: 13px 14px; border-radius: 11px; background: #f4f4f4; }
.digest-intro p { margin: 0; color: #676767; font-size: 10px; line-height: 1.5; }
.primary-button { flex: none; min-height: 35px; padding: 0 13px; border: 0; border-radius: 8px; background: #202123; color: #fff; font-size: 11px; }
.digest-dialog .status-message { padding: 8px 2px 2px; }
.digest-list { display: flex; max-height: calc(100dvh - 220px); min-height: 140px; flex-direction: column; gap: 10px; overflow-y: auto; }
.digest-card { padding: 15px; border: 1px solid #e5e5e5; border-radius: 11px; }
.digest-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 11px; }
.digest-card-header h3 { margin: 0; font-size: 15px; }
.digest-card-header span { color: #999; font-size: 9px; }
.digest-content { color: #3c3c3c; font-size: 11px; line-height: 1.75; white-space: pre-wrap; }
.digest-error { margin: 0; padding: 10px; border-radius: 8px; background: #fff5e8; color: #765a3a; font-size: 10px; }
.digest-empty { display: grid; place-items: center; gap: 5px; padding: 45px 10px; color: #858585; text-align: center; }
.digest-empty p { margin: 0; font-size: 10px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.login-page { display: grid; min-height: var(--app-height, 100dvh); place-items: center; padding: 24px; background: #f7f7f8; }
.login-card { width: min(390px, 100%); padding: 28px; border: 1px solid #e2e2e2; border-radius: 18px; background: #fff; box-shadow: 0 18px 60px rgba(0, 0, 0, .08); }
.login-brand { padding: 0 0 18px; font-size: 18px; }
.login-intro { margin: 0 0 24px; color: #777; font-size: 14px; line-height: 1.6; }
.login-form { display: grid; gap: 8px; }
.login-form label { margin-top: 7px; color: #555; font-size: 14px; }
.login-form input { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid #d7d7d7; border-radius: 9px; outline: none; background: #fff; color: #222; font-size: 16px; }
.login-form input:focus { border-color: #888; box-shadow: 0 0 0 3px rgba(32, 33, 35, .08); }
.login-form .primary-button { width: 100%; min-height: 44px; margin-top: 12px; font-size: 15px; }
.login-error { min-height: 20px; margin: 5px 0 0; color: #a24e3f; font-size: 13px; }

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { width: 100%; height: var(--app-height, 100dvh); border-right: 0; }
  .chat-panel { position: fixed; z-index: 5; top: var(--viewport-offset-top, 0px); right: auto; bottom: auto; left: 0; display: none; width: 100vw; max-width: 100vw; height: var(--app-height, 100dvh); max-height: var(--app-height, 100dvh); overflow: hidden; }
  body.chat-open .chat-panel { display: grid; }
  .mobile-only { display: grid; }
  .chat-header { min-height: 56px; padding-right: 10px; padding-left: 7px; }
  .messages { padding: 22px 14px 28px; touch-action: pan-y pinch-zoom; }
  .topic-delete { opacity: .78; }
  .message-row { width: 100%; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; margin-bottom: 24px; }
  .composer-wrap { width: calc(100vw - 18px); max-width: calc(100vw - 18px); margin: 0 9px calc(8px + env(safe-area-inset-bottom)); }
  .composer { padding-right: 54px; }
  .composer textarea { width: 100%; flex: 1 1 100%; max-height: 120px; padding-right: 0; }
  .send-button { position: absolute; right: 8px; bottom: 8px; }
  .composer-wrap > small { display: none; }
  .status-message { padding-right: 11px; padding-left: 11px; }
  .empty-state h2 { font-size: 21px; }
  .digest-dialog { width: 100%; max-width: none; max-height: 92dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .digest-intro { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; }
}
