:root {
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #17211d;
  background: #e9efed;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.phone-frame {
  position: relative;
  width: min(100%, 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);
}

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

.login-panel {
  height: 100%;
  padding: 72px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #f3faf7 100%);
}

.brand-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: #0f8b6f;
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0;
}

.login-panel h1 {
  margin: 10px 0 0;
  font-size: 28px;
  line-height: 1.2;
}

.login-panel p {
  margin: 0 0 18px;
  color: #5f746c;
}

.login-panel label {
  display: grid;
  gap: 8px;
  color: #40524b;
  font-size: 14px;
}

.login-panel input,
.composer textarea {
  width: 100%;
  border: 1px solid #cad8d2;
  border-radius: 14px;
  background: #ffffff;
  color: #17211d;
  outline: none;
}

.login-panel input {
  height: 48px;
  padding: 0 14px;
}

.login-panel input:focus,
.composer textarea:focus {
  border-color: #0f8b6f;
  box-shadow: 0 0 0 3px rgba(15, 139, 111, 0.12);
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 10px;
}

.primary,
.secondary,
.send-btn,
.stop-btn,
.new-session-btn {
  border: 0;
  border-radius: 14px;
  font-weight: 700;
}

.primary {
  height: 50px;
  margin-top: 8px;
  background: #0f8b6f;
  color: #ffffff;
}

.secondary {
  background: #e5f3ef;
  color: #0f735d;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.form-tip {
  min-height: 20px;
  color: #657970;
  font-size: 13px;
}

.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;
}

.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;
}

.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;
  }
}
