:root {
  --bg: #f6f6f4; --card: #ffffff; --text: #1d1d1b; --muted: #6b6b66; --line: #e2e2dd;
  --accent: #1f5f4a; --accent-text: #ffffff; --user: #e8f0ec; --warn: #8a5a00; --warnbg: #fff6e0;
  --err: #a12a2a; --errbg: #fdecec; --add: #e6f4ea; --del: #fbe9e9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161716; --card: #1f201f; --text: #ececea; --muted: #a3a39d; --line: #333431;
    --accent: #5fb394; --accent-text: #0d1a14; --user: #23332c; --warn: #f2c66d; --warnbg: #3a2f17;
    --err: #ff9b9b; --errbg: #3b1f1f; --add: #1d3324; --del: #3b2222;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 16px 0 6px; }
button { font: inherit; border: 0; border-radius: 8px; padding: 9px 14px; background: var(--accent); color: var(--accent-text); cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--err); color: #fff; }
button.wide { width: 100%; }
input, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%; }
label { display: block; margin: 0 0 12px; font-size: 14px; color: var(--muted); }
label input { margin-top: 4px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.narrow { max-width: 380px; margin: 12vh auto 0; }
.msg { min-height: 1.4em; color: var(--err); margin: 10px 0 0; }
.screen { height: 100%; }
#app { display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--card); }
header .title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menu-btn { display: none; }
.layout { flex: 1; display: flex; min-height: 0; }
aside { width: 260px; border-right: 1px solid var(--line); padding: 12px; overflow-y: auto; background: var(--card); }
aside ul { list-style: none; margin: 12px 0 0; padding: 0; }
aside li { padding: 8px 10px; border-radius: 8px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
aside li.active { background: var(--user); }
aside li .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 6px; }
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 760px; padding: 10px 13px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.user { align-self: flex-end; background: var(--user); }
.bubble.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); }
.bubble.notice { align-self: center; background: transparent; color: var(--muted); font-size: 13px; text-align: center; }
.bubble.proposal { align-self: stretch; max-width: 760px; background: var(--card); border: 2px solid var(--accent); }
.bubble.proposal .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.empty { color: var(--muted); text-align: center; margin-top: 15vh; padding: 0 16px; }
.status { display: flex; align-items: center; gap: 10px; padding: 6px 16px; color: var(--muted); font-size: 13px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
#composer { display: flex; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--line); background: var(--card); align-items: flex-end; }
#composer textarea { resize: vertical; min-height: 44px; max-height: 40vh; }
.bar { padding: 10px 16px; background: var(--warnbg); color: var(--warn); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.bar button { padding: 5px 10px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 16px; z-index: 10; }
.modal-card { width: 100%; max-width: 820px; max-height: 92vh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.conv { padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; cursor: pointer; }
.conv:hover { border-color: var(--accent); }
.line { padding: 6px 10px; border-radius: 8px; margin: 4px 0; white-space: pre-wrap; max-width: 85%; }
.line.lead { background: var(--bg); }
.line.ai { background: var(--user); margin-left: auto; }
.diff { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border-radius: 8px; padding: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
.diff .add { background: var(--add); display: block; }
.diff .del { background: var(--del); display: block; text-decoration: line-through; text-decoration-color: var(--muted); }
.test { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 8px 0; }
.test .tag { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.test .reply { background: var(--user); border-radius: 8px; padding: 6px 9px; margin: 4px 0; white-space: pre-wrap; }
.warning { background: var(--warnbg); color: var(--warn); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.error { background: var(--errbg); color: var(--err); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.ver { padding: 8px 0; border-bottom: 1px solid var(--line); }
@media (max-width: 760px) {
  #menu-btn { display: inline-block; }
  aside { position: fixed; top: 54px; bottom: 0; left: 0; z-index: 5; transform: translateX(-100%); transition: transform .15s; box-shadow: 2px 0 12px rgba(0,0,0,.15); }
  aside.open { transform: none; }
  #quota { display: none; }
  #composer { flex-wrap: wrap; }
  #pick-btn { order: 3; }
  .bubble { max-width: 92%; }
}
