* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #0f1115;
  color: #e7e9ee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

.app {
  display: flex;
  height: 100%;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #161922;
  border-right: 1px solid #232733;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 12px 12px;
}

.sidebar-top {
  padding: 10px 6px;
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-item {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #c8ccd6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.conv-item:hover {
  background: #1f232e;
}

.conv-item.active {
  background: #2b3142;
  color: #fff;
}

.conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-del {
  border: none;
  background: transparent;
  color: #7d8290;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.conv-item:hover .conv-del {
  opacity: 1;
}

.conv-del:hover {
  background: #3a3f50;
  color: #ff6b6b;
}

.sidebar-bottom {
  border-top: 1px solid #232733;
  padding-top: 10px;
  margin-top: 6px;
}

.model-label {
  display: block;
  font-size: 12px;
  color: #8a8f9c;
  margin-bottom: 4px;
  padding: 0 4px;
}

.select {
  width: 100%;
  background: #1f232e;
  color: #e7e9ee;
  border: 1px solid #2c313e;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  outline: none;
}

/* ---------- 主区域 ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #232733;
}

.title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.icon-btn {
  border: 1px solid #2c313e;
  background: #1a1e28;
  color: #c8ccd6;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: none;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 0;
  scroll-behavior: smooth;
}

.msg {
  max-width: 760px;
  margin: 0 auto 10px;
  padding: 14px 18px;
}

.msg-role {
  font-size: 12px;
  color: #8a8f9c;
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.msg-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.role-user .msg-content {
  color: #d8dce6;
}

.msg.role-assistant .msg-content {
  color: #f3f5f8;
}

/* ---------- 思考过程 ---------- */
.reasoning {
  margin: 6px 0 12px;
  padding: 8px 12px;
  background: #161922;
  border: 1px solid #232733;
  border-radius: 8px;
  font-size: 13px;
}

.reasoning summary {
  cursor: pointer;
  font-style: italic;
  color: #6a7387;
  user-select: none;
  list-style: none;
}

.reasoning summary::-webkit-details-marker {
  display: none;
}

.reasoning summary::before {
  content: "💭 ";
}

.reasoning-body {
  margin-top: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  font-style: italic;
  color: #7a8398;
}

.reasoning-badge {
  display: inline-block;
  font-size: 12px;
  color: #6a7387;
  font-style: italic;
  padding: 2px 8px;
  background: #161922;
  border-radius: 6px;
}

.reasoning-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: #8a8f9c;
  cursor: pointer;
  padding: 0 4px;
}

.reasoning-toggle input {
  margin: 0;
  cursor: pointer;
}

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

.msg.role-assistant {
  display: flex;
  justify-content: flex-start;
}

.msg.role-user .bubble {
  background: #1f3a66;
  color: #e7e9ee;
  border-radius: 10px;
  padding: 11px 14px;
  max-width: 78%;
  display: inline-block;
  text-align: left;
}

.msg.role-assistant .bubble {
  background: #1a1e28;
  color: #f3f5f8;
  border: 1px solid #232733;
  border-radius: 10px;
  padding: 11px 14px;
  max-width: 88%;
  display: inline-block;
}

/* ---------- 编辑分支 ---------- */
.branch-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #8a8f9c;
  margin-bottom: 6px;
  padding: 3px 8px;
  background: #161922;
  border: 1px solid #232733;
  border-radius: 6px;
  width: fit-content;
}

.branch-btn {
  border: none;
  background: transparent;
  color: #c8ccd6;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
}

.branch-btn:hover:not(:disabled) {
  background: #2b3142;
  color: #fff;
}

.branch-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.branch-pos {
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.msg-content-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.msg-content-row .msg-content {
  flex: 1;
}

.msg-edit {
  border: none;
  background: transparent;
  color: #6a7387;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.msg.role-user:hover .msg-edit {
  opacity: 1;
}

.msg-edit:hover {
  color: #c8ccd6;
  background: rgba(255, 255, 255, 0.08);
}

.edit-input {
  width: 100%;
  resize: vertical;
  min-height: 60px;
  background: #0f1115;
  color: #e7e9ee;
  border: 1px solid #3a4258;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  margin: 4px 0 6px;
}

.edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.edit-actions .btn {
  font-size: 13px;
  padding: 6px 12px;
}

.msg-content .cursor {
  display: inline-block;
  width: 8px;
  height: 1em;
  background: #6aa1ff;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

.empty {
  text-align: center;
  color: #6a6f7d;
  padding: 40px 18px;
  font-size: 14px;
}

/* ---------- 输入区 ---------- */
.composer {
  border-top: 1px solid #232733;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.input {
  flex: 1;
  resize: none;
  max-height: 160px;
  background: #1a1e28;
  color: #e7e9ee;
  border: 1px solid #2c313e;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
}

.input:focus {
  border-color: #3a4258;
}

.btn {
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 500;
}

.btn-primary {
  background: #3a6ea5;
  color: #fff;
}

.btn-primary:hover {
  background: #4579bd;
}

.btn-primary:disabled {
  background: #2a3a55;
  cursor: not-allowed;
  opacity: 0.7;
}

.send-btn {
  white-space: nowrap;
}

/* ---------- 跳到最新 ---------- */
.jump-latest {
  position: absolute;
  right: 16px;
  bottom: 90px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid #2c313e;
  background: #1f232e;
  color: #c8ccd6;
  font-size: 16px;
  cursor: pointer;
  display: none;
  z-index: 30;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.jump-latest:hover {
  background: #2b3142;
  color: #fff;
}

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 50;
    box-shadow: 2px 0 18px rgba(0, 0, 0, 0.5);
  }

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

  .icon-btn {
    display: inline-block;
  }

  .composer {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .msg {
    padding: 12px 16px;
  }
}

/* ---------- 侧栏遮罩 ---------- */
.sidebar-overlay {
  display: none;
}

@media (max-width: 720px) {
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  .sidebar.open ~ .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }
}