:root {
  color-scheme: light;
  --paper: #efe7d6;
  --panel: #f7f1e4;
  --ink: #1c1712;
  --muted: #6d6256;
  --line: #ddcfb6;
  --seal: #9c3b2e;
  --seal-dark: #74281e;
  --ok: #2f6b45;
  --warn: #8a4b12;
  --shadow: 0 18px 50px rgba(60, 36, 18, 0.12);
  --sans: "PingFang HK", "Noto Sans CJK TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", "Segoe UI", sans-serif;
  --mono: "Sarasa Mono TC", "Noto Sans Mono CJK TC", ui-monospace, "Cascadia Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(156, 59, 46, 0.08), transparent 28rem),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

button, input, textarea { font: inherit; color: inherit; }

button, .file-button {
  background: var(--seal);
  color: #fffaf3;
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.1rem;
  cursor: pointer;
}

button:hover, .file-button:hover { background: var(--seal-dark); }

button.ghost, .file-button {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button:disabled { opacity: 0.55; cursor: wait; }

.hidden { display: none !important; }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.card {
  width: min(28rem, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1.4rem;
  box-shadow: var(--shadow);
  padding: 1.6rem;
}

.mark {
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  margin: 0;
  border-radius: 0.7rem;
  background: var(--seal);
  color: #fffaf3;
  font-weight: 700;
}

.mark.small { width: 2.2rem; height: 2.2rem; border-radius: 0.5rem; }

h1, h2, h3 { font-weight: 650; letter-spacing: -0.02em; margin: 0.4rem 0; }

.lede, .muted, .empty { color: var(--muted); }

form { display: grid; gap: 0.45rem; }

label { font-size: 0.92rem; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  border-radius: 0.8rem;
  padding: 0.75rem 0.85rem;
  font-size: 16px;
}

textarea { resize: vertical; min-height: 5.5rem; }

input:focus, textarea:focus, button:focus-visible {
  outline: 3px solid rgba(156, 59, 46, 0.35);
  outline-offset: 2px;
}

.banner {
  min-height: 1.2rem;
  margin: 0.2rem 0;
  color: var(--seal-dark);
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 18rem 1fr;
}

#sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1rem;
  border-right: 1px solid var(--line);
  background: rgba(247, 241, 228, 0.9);
}

.brand { display: flex; gap: 0.7rem; align-items: center; }
.brand span { display: block; color: var(--muted); font-size: 0.85rem; }

#thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
}

#thread-list button {
  width: 100%;
  text-align: left;
  border-radius: 0.8rem;
  background: transparent;
  color: var(--ink);
  border: 1px solid transparent;
}

#thread-list button.active {
  background: #fffdf8;
  border-color: var(--line);
}

#logout { margin-top: auto; }

#chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.chat-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
}

#nav-toggle { display: none; }

#messages {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.message {
  max-width: 46rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ink);
  border-radius: 0.9rem;
  padding: 0.8rem 0.95rem;
}

.message.user { border-left-color: var(--seal); margin-left: auto; }

.meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 0.35rem;
}

.status.sent { color: var(--ok); }
.status.failed { color: var(--seal); }
.status.pending { color: var(--warn); }

.message .body p { margin: 0.35rem 0; }
.message .body pre {
  overflow: auto;
  background: #efe4cf;
  border-radius: 0.6rem;
  padding: 0.7rem;
}
.message .body code { font-family: var(--mono); font-size: 0.92em; }
.message .body a { color: var(--seal-dark); }

.options, .files { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }

.options button, .files a, .files button {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
}

.preview {
  display: block;
  max-width: min(100%, 28rem);
  margin-top: 0.5rem;
  border-radius: 0.6rem;
  border: 1px solid var(--line);
}

iframe.preview { width: min(100%, 40rem); height: 24rem; background: white; }

.empty { padding: 0 1rem 1rem; }

#compose-form { padding: 0 1rem 1rem; }

.composer {
  display: grid;
  gap: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0.7rem;
}

.composer-actions { display: flex; justify-content: space-between; gap: 0.6rem; }

.file-button { display: inline-flex; align-items: center; }
.file-button input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#file-list { list-style: none; padding: 0; margin: 0; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(18rem, 86vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 2;
    box-shadow: var(--shadow);
  }
  .app.show-nav #sidebar { transform: none; }
  #nav-toggle { display: inline-flex; }
  .message { max-width: 100%; }
  iframe.preview { height: 18rem; }
}
