:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2330;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #2456c9;
  --accent-text: #ffffff;
  --user: #e8eefb;
  --ok: #1f7a4a;
  --warn: #9a6200;
  --bad: #b42318;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --panel: #1a1f29;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --line: #2c3340;
    --accent: #6b93f2;
    --accent-text: #0d1117;
    --user: #22304d;
    --ok: #5fcf8f;
    --warn: #e6b04a;
    --bad: #f97066;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1 { font-size: 1.4rem; margin: 0 0 .5rem; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
     margin: 1.4rem 0 .4rem; display: flex; justify-content: space-between; align-items: center; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--bad); }
.ok { color: var(--ok); }

button { font: inherit; cursor: pointer; border-radius: var(--radius); border: 1px solid var(--line);
         background: var(--panel); color: var(--text); padding: .45rem .9rem; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; font-size: inherit;
              text-transform: none; letter-spacing: 0; text-align: left; }
button.wide { width: 100%; }
input, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
                  border-radius: var(--radius); padding: .5rem .6rem; width: 100%; }
textarea { resize: vertical; }
label { display: block; margin: .8rem 0; font-size: .9rem; }
label input { margin-top: .25rem; }

/* sign-in */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
              border-radius: 12px; padding: 2rem; }
.login-card h1 { margin-bottom: 0; }

/* app layout */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem;
          background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 1.1rem; }
.spacer { flex: 1; }
.status { font-size: .85rem; padding: .15rem .6rem; border-radius: 999px; border: 1px solid currentColor; }
.status.ready { color: var(--ok); }
.status.loading { color: var(--warn); }
.status.offline { color: var(--bad); }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 290px; flex-shrink: 0; overflow-y: auto; padding: 1rem;
           background: var(--panel); border-right: 1px solid var(--line); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; border-radius: 6px; padding: .1rem .3rem; }
.list li.active { background: var(--user); }
.list li.warn span:first-child { color: var(--warn); }
.list .item { flex: 1; border: 0; background: none; text-align: left; padding: .3rem 0;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .delete { border: 0; background: none; color: var(--muted); padding: 0 .3rem; visibility: hidden; }
.list li:hover .delete { visibility: visible; }
.list.small li { padding: .2rem .3rem; font-size: .88rem; display: block;
                 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chat */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.intro { max-width: 640px; margin: 2rem auto; }
.intro ul { padding-left: 1.2rem; }
.msg { max-width: 860px; width: 100%; margin: 0 auto; padding: .8rem 1rem; border-radius: 10px;
       overflow-wrap: anywhere; }
.msg.user { background: var(--user); white-space: pre-wrap; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); }
.msg.error { background: var(--panel); border: 1px solid var(--bad); color: var(--bad); }
.msg.pending .working { color: var(--muted); }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer table { border-collapse: collapse; margin: .6rem 0; display: block; overflow-x: auto; }
.answer th, .answer td { border: 1px solid var(--line); padding: .3rem .6rem; text-align: left; }
.answer pre { overflow-x: auto; background: var(--bg); padding: .6rem; border-radius: 6px; }
.answer code { font-size: .9em; }
.steps { margin-top: .6rem; font-size: .85rem; color: var(--muted); }
.steps summary { cursor: pointer; }
.live-steps { margin: .4rem 0 0; padding-left: 1.2rem; font-size: .85rem; color: var(--muted); }

.composer { display: flex; gap: .6rem; padding: .8rem 1.5rem 1.2rem; border-top: 1px solid var(--line);
            background: var(--panel); }
.composer textarea { flex: 1; }
.composer button { align-self: flex-end; }

/* upload */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text);
         width: min(520px, calc(100vw - 32px)); padding: 1.5rem; }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog h2 { font-size: 1.1rem; text-transform: none; letter-spacing: 0; color: var(--text); margin-top: 0; }
#upload-preview { max-height: 180px; overflow-y: auto; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }

@media (max-width: 760px) {
  .layout { flex-direction: column; overflow-y: auto; }
  .sidebar { width: auto; border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .messages { padding: 1rem 16px; }
  .composer { padding: .6rem 16px 1rem; }
  .topbar { padding: .6rem 16px; gap: .6rem; flex-wrap: wrap; }
}
