:root {
  color-scheme: light;
  --accent: #5e5ce6;
  --text: #171717;
  --muted: #767676;
  --faint: #a3a3a3;
  --line: #e7e7e7;
  --surface: #ffffff;
  --surface-muted: #f6f6f7;
  --field: #eeeeef;
  --incoming: #ffffff;
  --outgoing: #dcffd3;
  --danger: #c2410c;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app,
.main-view,
.pane,
.chat-view {
  min-height: 100dvh;
}

.setup-view {
  display: grid;
  min-height: 100dvh;
  padding: 28px 22px;
  place-items: center;
  background: var(--surface-muted);
}

.setup-panel {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 22px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.08);
}

.setup-panel h1,
.topbar h1,
.chat-topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.setup-panel p,
.topbar p,
.chat-topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
  background: var(--surface);
  color: var(--text);
}

input:focus,
textarea:focus {
  border-color: rgba(94, 92, 230, 0.7);
  box-shadow: 0 0 0 3px rgba(94, 92, 230, 0.12);
}

input {
  min-height: 46px;
  padding: 0 12px;
}

.primary,
.secondary,
.danger {
  min-height: 44px;
  border: 1px solid transparent;
  padding: 0 16px;
  border-radius: 12px;
  font-weight: 800;
}

.primary {
  border-color: rgba(94, 92, 230, 0.38);
  background: transparent;
  color: var(--accent);
}

.secondary {
  border-color: var(--line);
  background: transparent;
  color: var(--text);
}

.danger {
  border-color: rgba(194, 65, 12, 0.24);
  background: transparent;
  color: var(--danger);
}

.error {
  min-height: 18px;
  color: var(--danger) !important;
}

.main-view {
  padding-bottom: calc(62px + env(safe-area-inset-bottom));
  background: var(--surface);
}

.pane {
  padding-bottom: 8px;
}

.topbar,
.chat-topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  align-items: center;
  min-height: calc(66px + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.topbar {
  grid-template-columns: minmax(0, 1fr) auto;
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.icon-button:active {
  background: var(--field);
}

.list {
  display: grid;
  gap: 0;
}

.conversation-row,
.fellow-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.conversation-row:active,
.fellow-row:active {
  background: var(--surface-muted);
}

.avatar {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  background-color: var(--accent);
  background-repeat: no-repeat;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.row-main,
.row-title {
  min-width: 0;
}

.row-title {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
}

.row-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}

.row-title time {
  color: var(--faint);
  font-size: 12px;
}

.row-main p {
  margin: 4px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  padding: 36px 20px;
  color: var(--muted);
  text-align: center;
}

.settings-list {
  display: grid;
  gap: 14px;
  padding: 18px 14px;
}

.chat-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding-bottom: env(safe-area-inset-bottom);
  background: linear-gradient(150deg, #dbeec6 0%, #b6daa7 52%, #99c6aa 100%);
}

.chat-view::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0.12;
  background-image:
    radial-gradient(circle at 20px 20px, #3f7f5d 1px, transparent 1.5px),
    radial-gradient(circle at 52px 48px, #3f7f5d 1.2px, transparent 1.8px);
  background-size: 76px 76px;
  content: "";
}

.chat-topbar {
  grid-template-columns: auto 40px minmax(0, 1fr) auto;
  gap: 10px;
}

.chat-topbar .avatar {
  width: 40px;
  height: 40px;
}

.chat-topbar h1,
.chat-topbar p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding: 14px 10px 18px;
}

.message {
  display: grid;
  max-width: min(82%, 520px);
  gap: 4px;
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.bubble {
  padding: 9px 12px;
  border-radius: 17px;
  background: var(--incoming);
  color: var(--text);
  font-size: 16px;
  line-height: 1.42;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

.message.user .bubble {
  border-bottom-right-radius: 5px;
  background: var(--outgoing);
}

.message.assistant .bubble {
  border-bottom-left-radius: 5px;
}

.message time {
  padding: 0 4px;
  color: rgba(0, 0, 0, 0.42);
  font-size: 11px;
}

.message.user time {
  text-align: right;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: end;
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.composer textarea {
  max-height: 128px;
  min-height: 40px;
  resize: none;
  padding: 10px 12px;
}

.send-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  color: rgba(0, 0, 0, 0.32);
  font-size: 22px;
}

.send-button:not(:disabled) {
  color: rgba(0, 0, 0, 0.82);
}

.send-button:not(:disabled):active {
  background: var(--field);
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  min-height: calc(58px + env(safe-area-inset-bottom));
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
}

.nav-button {
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.nav-button.active {
  background: var(--field);
  color: var(--accent);
}
