:root {
  --bg: #f7f7f5; --panel: #ffffff; --side: #efeee9; --text: #1d1d1b; --muted: #6b6a66;
  --border: #e2e0da; --accent: #c2603c; --accent-text: #fff; --user: #ece9e2; --code: #f1efea;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1a; --panel: #252523; --side: #161615; --text: #ecebe7; --muted: #9a9892;
    --border: #353532; --accent: #d9774f; --accent-text: #111; --user: #2f2e2b; --code: #2b2b28;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; display: flex; }
button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); }
.muted { color: var(--muted); }
.logo { font-size: 28px; color: var(--accent); }

/* login */
body.login { align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 32px; width: 100%; max-width: 360px; text-align: center; display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card input { font: inherit; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); margin-top: 12px; }
.err { color: #d0473a; min-height: 1.2em; font-size: 14px; }

/* layout */
#sidebar { width: 270px; background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 12px; gap: 10px; }
#chat-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
#chat-list li { display: flex; align-items: center; border-radius: 8px; }
#chat-list li span { flex: 1; padding: 8px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; font-size: 14px; }
#chat-list li.active, #chat-list li:hover { background: var(--border); }
#chat-list .del { border: 0; background: transparent; color: var(--muted); padding: 4px 8px; visibility: hidden; }
#chat-list li:hover .del, #chat-list li.active .del { visibility: visible; }
main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
header { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
#toggle { display: none; }
#title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#messages { flex: 1; overflow-y: auto; padding: 24px 16px; display: flex; flex-direction: column; gap: 18px; }
.msg { max-width: 760px; width: 100%; margin: 0 auto; }
.msg.user .body { background: var(--user); padding: 10px 14px; border-radius: 14px; margin-left: auto; width: fit-content; max-width: 85%; white-space: pre-wrap; }
.msg.assistant .body { overflow-wrap: anywhere; }
.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }
.msg pre { background: var(--code); padding: 12px; border-radius: 10px; overflow-x: auto; }
.msg code { background: var(--code); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.msg pre code { padding: 0; background: none; }
.msg table { border-collapse: collapse; display: block; overflow-x: auto; }
.msg th, .msg td { border: 1px solid var(--border); padding: 6px 10px; }
.msg blockquote { border-left: 3px solid var(--accent); margin: 8px 0; padding-left: 12px; color: var(--muted); }
.msg a { color: var(--accent); }
.copy { font-size: 13px; padding: 2px 6px; margin-top: 4px; }
.typing { color: var(--muted); font-style: italic; }
.empty { margin: auto; text-align: center; max-width: 620px; }
.empty h2 { font-weight: 600; }
.chips { display: flex; flex-direction: column; gap: 8px; }
.chips button { text-align: left; color: var(--muted); }
.chips button:hover { color: var(--text); border-color: var(--accent); }
#composer { display: flex; gap: 8px; padding: 12px 16px 16px; max-width: 792px; width: 100%; margin: 0 auto; align-items: flex-end; }
#input { flex: 1; resize: none; font: inherit; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--panel); color: var(--text); max-height: 220px; }
#input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

[hidden] { display: none !important; }
#plano-view { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.plano-bar { display: flex; gap: 8px; flex-wrap: wrap; max-width: 760px; width: 100%; margin: 0 auto; }
#plano-text { flex: 1; min-height: 70vh; width: 100%; max-width: 760px; margin: 0 auto; font: 14px/1.5 ui-monospace, Consolas, monospace; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); color: var(--text); }
.msg input[type="checkbox"] { margin-right: 6px; }

@media (max-width: 760px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.25); }
  body.nav-open #sidebar { transform: none; }
  #toggle { display: inline-block; }
}
