:root {
  color-scheme: light;
  --paper: #f5f2eb;
  --panel: rgba(255, 255, 255, 0.78);
  --ink: #1d2524;
  --muted: #67706d;
  --line: rgba(29, 37, 36, 0.13);
  --accent: #c7603d;
  --accent-deep: #a74729;
  --assistant: #ffffff;
  --user: #263c39;
  --shadow: 0 18px 54px rgba(48, 39, 31, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(199, 96, 61, 0.12), transparent 32rem),
    radial-gradient(circle at 86% 15%, rgba(39, 82, 76, 0.10), transparent 28rem),
    var(--paper);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

button, textarea, input { font: inherit; }
button { cursor: pointer; }

.shell {
  width: min(940px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 24px 20px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.17em;
}

h1 { margin: 0; font-family: Georgia, "Noto Serif SC", serif; font-size: clamp(26px, 4vw, 38px); }
.actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }

button {
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
  transition: transform .15s ease, background .15s ease, opacity .15s ease;
}

button:hover { transform: translateY(-1px); background: var(--accent-deep); }
button:disabled { cursor: wait; opacity: .58; transform: none; }
button.ghost { color: var(--ink); background: transparent; border: 1px solid var(--line); }
button.ghost:hover { background: rgba(255, 255, 255, .7); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status i { width: 8px; height: 8px; border-radius: 50%; background: #9a9d9c; }
.status.ready i { background: #2e9b68; box-shadow: 0 0 0 4px rgba(46, 155, 104, .12); }
.status.busy i { background: #d68b28; box-shadow: 0 0 0 4px rgba(214, 139, 40, .12); }
.status.error i { background: #cb3f3f; }
.mode-badge {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, .55);
  font-size: 11px;
  white-space: nowrap;
}
.mode-badge.full { color: #9f2f2f; border-color: rgba(159, 47, 47, .3); background: rgba(203, 63, 63, .08); }
.mode-badge.web { color: #276f50; border-color: rgba(39, 111, 80, .25); }

.messages {
  min-height: 300px;
  overflow-y: auto;
  padding: 18px 3px 28px;
  scrollbar-width: thin;
}

.message { display: flex; align-items: flex-start; gap: 12px; margin: 0 0 22px; }
.message.user { flex-direction: row-reverse; }
.avatar {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #fff;
  background: var(--accent);
  font: 700 17px Georgia, serif;
  box-shadow: 0 7px 16px rgba(167, 71, 41, .18);
}
.user .avatar { background: var(--user); box-shadow: none; font-family: inherit; font-size: 12px; }
.bubble {
  max-width: min(740px, calc(100% - 44px));
  padding: 14px 17px;
  border: 1px solid var(--line);
  border-radius: 6px 18px 18px 18px;
  background: var(--assistant);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.68;
}
.user .bubble {
  color: #fff;
  background: var(--user);
  border-color: transparent;
  border-radius: 18px 6px 18px 18px;
  box-shadow: none;
}
.bubble p { margin: 0 0 9px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble .muted, .muted { color: var(--muted); font-size: 13px; }
.user .muted { color: rgba(255, 255, 255, .65); }
.meta { display: block; margin-top: 8px; color: var(--muted); font-size: 11px; }

.composer-wrap { position: sticky; bottom: 0; padding-top: 3px; background: linear-gradient(transparent, var(--paper) 14%); }
.composer {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
textarea {
  width: 100%;
  min-height: 82px;
  max-height: 240px;
  resize: vertical;
  padding: 5px 7px 10px;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  line-height: 1.55;
}
.attachments { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 7px 10px; }
.attachment {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, .55);
  font-size: 12px;
}
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment button { padding: 0 3px; color: var(--muted); background: transparent; font-size: 15px; }
.attachment button:hover { color: #b63232; background: transparent; transform: none; }
.upload-status { min-height: 1.2em; margin: 0 7px 7px; color: var(--muted); font-size: 11px; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.composer-tools { display: flex; align-items: center; gap: 10px; }
.composer-tools .attach { padding: 7px 12px; color: var(--ink); background: transparent; border: 1px solid var(--line); font-size: 12px; }
.composer-tools .attach:hover { background: rgba(255, 255, 255, .7); }
#counter { padding-left: 7px; color: var(--muted); font-size: 11px; }
.privacy { margin: 9px 0 0; text-align: center; color: var(--muted); font-size: 11px; }

dialog {
  width: min(460px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 28px 90px rgba(29, 37, 36, .24);
}
dialog::backdrop { background: rgba(18, 25, 24, .48); backdrop-filter: blur(4px); }
dialog form { padding: 26px; }
dialog h2 { margin: 0 0 8px; font-family: Georgia, "Noto Serif SC", serif; }
dialog p { color: var(--muted); line-height: 1.55; }
dialog label { display: block; margin: 20px 0 7px; font-size: 13px; font-weight: 700; }
dialog input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; outline: 0; }
dialog input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(199, 96, 61, .12); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
.error { min-height: 1.4em; margin-bottom: 0; color: #b63232; font-size: 13px; }
.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; }

@media (max-width: 650px) {
  .shell { padding: 18px 14px 12px; }
  .topbar { align-items: flex-start; }
  .actions { gap: 6px; }
  .actions .ghost { padding: 8px 11px; font-size: 12px; }
  .status { width: 100%; justify-content: flex-end; order: 3; }
  .messages { padding-top: 8px; }
  .bubble { padding: 12px 14px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #171c1b;
    --panel: rgba(31, 38, 36, .84);
    --ink: #eef0ec;
    --muted: #9aa39f;
    --line: rgba(238, 240, 236, .12);
    --assistant: #222927;
    --user: #34534e;
    --shadow: 0 18px 54px rgba(0, 0, 0, .2);
  }
  dialog { background: #222927; }
}
