:root {
  --bg: #f6f5f2; --panel: #ffffff; --side: #eeece6; --fg: #1d1c1a; --muted: #6d6a62;
  --line: #dcd8ce; --accent: #2f5d50; --accent-fg: #ffffff; --me: #e3ece8; --err: #a33a2a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161716; --panel: #1e201f; --side: #121312; --fg: #e8e6e1; --muted: #9a978f;
    --line: #2e312f; --accent: #7fb8a6; --accent-fg: #0f1a16; --me: #23302b; --err: #e58a7a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 8px 14px; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.link { border: 0; background: none; padding: 4px 6px; color: var(--muted); text-decoration: underline; }
button.icon { border: 0; background: none; font-size: 20px; padding: 4px 8px; }
button:disabled { opacity: .5; cursor: default; }
.wide { width: 100%; }
.muted { color: var(--muted); }
.err { color: var(--err); min-height: 1.4em; margin: 0; }
[hidden] { display: none !important; }

.login { min-height: 100%; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left)); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 24px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px;
}
.card h1 { font-size: 20px; margin: 0; }
.card p { margin: 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  background: var(--bg); font-size: 15px;
}
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; gap: 8px; justify-content: flex-end; }

.app { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
.side {
  background: var(--side); border-right: 1px solid var(--line); display: flex;
  flex-direction: column; gap: 12px; padding: 14px; min-height: 0;
}
.threads { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.thread { display: flex; align-items: center; border-radius: 8px; }
.thread.on { background: var(--panel); }
.thread .open {
  flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 8px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread .del { border: 0; background: none; color: var(--muted); padding: 6px 8px; visibility: hidden; }
.thread:hover .del, .thread.on .del { visibility: visible; }
.thread .del.armed { color: var(--err); visibility: visible; }
.me { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 13px; }
.me span { margin-right: auto; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.top { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.top h2 { font-size: 15px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#side-toggle { display: none; }
.log { flex: 1; overflow-y: auto; padding: 20px max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 72ch; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--me); padding: 9px 13px; border-radius: 12px; }
.msg.assistant { align-self: flex-start; }
.msg.note { align-self: center; color: var(--muted); font-size: 13px; }
.empty { margin: auto; color: var(--muted); }
.compose { display: flex; gap: 8px; padding: 10px max(16px, env(safe-area-inset-left)) 4px; align-items: flex-end; }
.compose textarea { flex: 1; resize: none; max-height: 40vh; min-width: 0; }
.hint { font-size: 12px; margin: 0; padding: 0 max(16px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-bottom)); }

.icon-btn { font-size: 20px; line-height: 1; padding: 8px 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px max(16px, env(safe-area-inset-left)) 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; font-size: 13px;
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 4px 3px 10px;
}
.chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.chip.err { color: var(--err); border-color: var(--err); padding-right: 10px; }
.chip.wait { color: var(--muted); padding-right: 10px; }
.chip button { border: 0; background: none; padding: 0 6px; color: var(--muted); }
.msg .files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg .files span { font-size: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; background: var(--panel); }
.main.drop .log { outline: 2px dashed var(--accent); outline-offset: -8px; }

.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / .35); display: grid; place-items: center; padding: 16px; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(300px, 85vw); z-index: 5; transform: translateX(-100%); transition: transform .2s; }
  .app.side-open .side { transform: none; box-shadow: 0 0 40px rgb(0 0 0 / .3); }
  #side-toggle { display: inline-block; }
}
