:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1d2330; --muted: #6b7385; --line: #e2e5eb;
  --accent: #b5532c; --accent-2: #8f3f1f; --user: #eef3fb; --code: #f1f3f6; --warn: #a15c00; --err: #b3261e; --ok: #2e7d32;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c; --panel: #1d2027; --text: #e6e8ee; --muted: #9aa1b2; --line: #2d313b;
    --accent: #e07a4f; --accent-2: #f09a73; --user: #1f2a3a; --code: #252932; --warn: #f0b354; --err: #f2867e; --ok: #7bc47f;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: 190px; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-r { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); }
.pill { font-size: 12px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); white-space: nowrap; }
.pill.warn { color: var(--warn); border-color: var(--warn); }

.btn { font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 7px 12px;
  cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.ghost { padding: 5px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.icon { font-size: 18px; padding: 6px 10px; }
.link { font: inherit; font-size: 13px; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.link:disabled { opacity: .4; cursor: default; }

.log { max-width: 980px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; min-width: 0; }
.msg.user { background: var(--user); margin-left: 10%; }
.msg.assistant { margin-right: 4%; }
.meta { display: flex; gap: 10px; align-items: baseline; margin-bottom: 6px; flex-wrap: wrap; }
.body { overflow-wrap: anywhere; }
.msg.user .body { white-space: pre-wrap; }
.body p { margin: 0 0 .7em; }
.body p:last-child { margin-bottom: 0; }
.body h3, .body h4, .body h5, .body h6 { margin: 1em 0 .4em; line-height: 1.3; }
.body ul, .body ol { margin: .3em 0 .7em; padding-left: 1.4em; }
.body blockquote { margin: .5em 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.body hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.body code { background: var(--code); padding: 1px 5px; border-radius: 4px; font: 13px/1.5 ui-monospace, Consolas, "Cascadia Mono", monospace; }
.code { border: 1px solid var(--line); border-radius: 8px; margin: .6em 0; overflow: hidden; }
.code-h { display: flex; align-items: center; gap: 8px; padding: 4px 8px; background: var(--code); border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.code-h span { flex: 1; }
.code-h button { font: inherit; font-size: 12px; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; cursor: pointer; }
.code pre { margin: 0; padding: 10px 12px; overflow-x: auto; background: var(--code); }
.code pre code { background: none; padding: 0; white-space: pre; }
.tbl { overflow-x: auto; margin: .6em 0; }
.tbl table { border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.tbl th { background: var(--code); }
.note { margin-top: 8px; font-size: 13px; color: var(--warn); }
.note.err { color: var(--err); background: var(--panel); border: 1px solid var(--err); border-radius: 8px; padding: 8px 12px; }

.files { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.thumb img { max-width: 220px; max-height: 160px; border-radius: 6px; border: 1px solid var(--line); display: block; }
.fchip { font-size: 13px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; color: var(--text); background: var(--panel); }

.thinking { margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.thinking summary { cursor: pointer; }
.thinking .tbody { white-space: pre-wrap; padding: 6px 10px; border-left: 2px solid var(--line); margin-top: 4px; max-height: 260px; overflow: auto; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.composer { position: fixed; left: 0; right: 0; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: 8px 16px 10px; }
.composer > * { max-width: 980px; margin-left: auto; margin-right: auto; }
.row { display: flex; gap: 8px; align-items: flex-end; margin-top: 6px; }
.row.small { justify-content: space-between; align-items: center; font-size: 13px; }
.author { font: inherit; font-size: 13px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); width: 180px; }
.hint { flex: 1; }
textarea { flex: 1; font: inherit; resize: none; min-height: 42px; max-height: 40vh; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); }
textarea:focus, .author:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#status.err { color: var(--err); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); }
.chip.up { opacity: .7; }
.chip.bad { border-color: var(--err); color: var(--err); }
.chip .x { border: 0; background: none; color: inherit; cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.drop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; font-size: 22px; color: #fff; background: rgba(181, 83, 44, .75); pointer-events: none; }

/* login + admin */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: 100%; max-width: 380px; }
.card h1 { font-size: 20px; margin: 0 0 12px; }
.card input { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); margin: 8px 0 12px; }
.card .err { color: var(--err); font-size: 14px; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 12px 0 20px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.tile .v { font-size: 22px; font-weight: 600; }
.tile .k { font-size: 12px; color: var(--muted); }
.sect { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 16px; overflow-x: auto; }
.sect h2 { font-size: 16px; margin: 0 0 10px; }
.sect table { border-collapse: collapse; width: 100%; font-size: 13px; }
.sect th, .sect td { border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: right; white-space: nowrap; }
.sect th:first-child, .sect td:first-child, .sect td.l { text-align: left; }
.inv { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inv input { flex: 1; min-width: 200px; font: 13px ui-monospace, Consolas, monospace; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); }
.bar { height: 8px; background: var(--code); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); }

.bar i.hot { background: var(--err); }

.tools { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.tools summary { cursor: pointer; }
.tools .tl { padding: 1px 0 1px 10px; border-left: 2px solid var(--line); font-family: ui-monospace, Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
.tools .tl.err { color: var(--err); }
.tools.live:empty { display: none; }
.ver { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; padding: 8px 10px; border: 1px dashed var(--accent); border-radius: 8px; font-size: 14px; }
.ver span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.msg.summary { background: var(--code); border-style: dashed; }
.sumbody summary { cursor: pointer; color: var(--accent); font-size: 14px; margin-bottom: 6px; }

/* admin shell: left menu */
body.adm { padding-bottom: 0; display: flex; min-height: 100vh; }
.side { width: 200px; flex: none; background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; }
.side-h { font-weight: 600; padding: 4px 10px 12px; }
.side a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.side a:hover { background: var(--bg); }
.side a.on { background: var(--user); color: var(--accent); font-weight: 600; }
.side-f { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.side a.sub { font-size: 13px; color: var(--muted); }
.main { flex: 1; min-width: 0; }
.vh { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.vh h1 { font-size: 20px; margin: 4px 0; }
.st { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor; }
.st.ok { color: var(--ok); } .st.bad { color: var(--err); } .st.mid { color: var(--warn); }

@media (max-width: 720px) {
  body.adm { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; }
  .side-h { padding: 4px 8px; }
  .side-f { margin: 0 0 0 auto; flex-direction: row; }
}

@media (max-width: 640px) {
  .msg.user { margin-left: 0; } .msg.assistant { margin-right: 0; }
  .hint { display: none; } .author { width: 100%; }
  body { padding-bottom: 210px; }
}
