:root {
  --bg: #ffffff; --side: #f9f9f9; --text: #0d0d0d; --muted: #6b6b6b; --faint: #9a9a9a;
  --border: #e6e6e6; --hover: #ececec; --active: #e3e3e3; --bubble: #f2f2f2; --input: #ffffff;
  --primary: #0d0d0d; --on-primary: #ffffff; --accent: #2563eb; --ok: #15803d; --warn: #b45309; --bad: #b91c1c;
  --code: #f6f6f6; --shadow: 0 2px 10px rgba(0,0,0,.06), 0 0 0 1px rgba(0,0,0,.05);
  --r: 12px; --side-w: 264px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121; --side: #171717; --text: #ececec; --muted: #a3a3a3; --faint: #7a7a7a;
    --border: #343434; --hover: #2a2a2a; --active: #303030; --bubble: #303030; --input: #2b2b2b;
    --primary: #ececec; --on-primary: #171717; --accent: #7aa2ff; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
    --code: #171717; --shadow: 0 0 0 1px rgba(255,255,255,.08);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 ui-sans-serif, -apple-system, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.ic { width: 18px; height: 18px; flex: none; }
.ic.sm { width: 14px; height: 14px; }
.ic.lg { width: 22px; height: 22px; }

/* logo */
.logo-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--primary); display: inline-block; position: relative; flex: none; }
.logo-mark::after { content: ""; position: absolute; inset: 6px 7px 5px; background: var(--on-primary); border-radius: 50% 50% 3px 3px; }
.logo-mark.big { width: 52px; height: 52px; border-radius: 15px; }
.logo-mark.big::after { inset: 12px 14px 10px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--bad); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.login-card h1 { margin: 4px 0 0; font-size: 28px; font-weight: 600; }
.login-card p { margin: 0 0 12px; }
.login-card input { width: 100%; height: 48px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--input); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card .btn { width: 100%; height: 48px; justify-content: center; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; }

/* layout */
.app { display: flex; height: 100%; overflow: hidden; }
.side { width: var(--side-w); flex: none; background: var(--side); display: flex; flex-direction: column; border-right: 1px solid var(--border); transition: margin .2s ease; }
.app.collapsed .side { margin-left: calc(-1 * var(--side-w)); }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 6px 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }
.ver { font-size: 11px; font-weight: 500; color: var(--muted); background: var(--hover); padding: 1px 7px; border-radius: 999px; }
.side-nav { padding: 4px 8px; display: flex; flex-direction: column; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 10px; border-radius: 10px; cursor: pointer; font-size: 14.5px; }
.nav-item:hover, .nav-item.on { background: var(--hover); }
.nav-item .count { margin-left: auto; font-size: 12px; background: var(--primary); color: var(--on-primary); border-radius: 999px; padding: 0 7px; line-height: 19px; font-weight: 600; }
.nav-item .count.soft { background: var(--active); color: var(--text); }
.search-row input { border: 0; background: transparent; outline: none; width: 100%; height: 100%; }
.side-scroll { flex: 1; overflow-y: auto; padding: 8px 8px 12px; }
.side-group { margin-top: 14px; }
.side-label { display: flex; align-items: center; justify-content: space-between; padding: 0 10px; height: 28px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.side-label .icon-btn { width: 26px; height: 26px; }
.s-item { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 6px 0 10px; border-radius: 10px; font-size: 14px; cursor: pointer; position: relative; }
.s-item:hover, .s-item.on { background: var(--hover); }
.s-item.on { background: var(--active); }
.s-item .t { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.s-item .more { opacity: 0; width: 28px; height: 28px; }
.s-item:hover .more, .s-item.on .more { opacity: 1; }
.s-item.sub { padding-left: 34px; height: 32px; font-size: 13.5px; }
.s-item .badge-auto { font-size: 10.5px; color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.run { background: var(--ok); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.side-bottom { border-top: 1px solid var(--border); padding: 8px; }
.neuron { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding: 4px 10px 8px; min-height: 26px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 8px; font-size: 14px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 600; flex: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 6px; padding: 0 12px; }
#openSide { display: none; }
.app.collapsed #openSide { display: inline-flex; }
.model-chip { white-space: nowrap; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px; font-size: 17px; font-weight: 500; cursor: pointer; }
.model-chip:hover { background: var(--hover); }
.model-chip .sub { color: var(--muted); font-weight: 400; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); font-size: 13.5px; cursor: pointer; background: var(--bg); white-space: nowrap; max-width: 260px; }
.chip:hover { background: var(--hover); }
.chip span { overflow: hidden; text-overflow: ellipsis; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* chat */
.thread { flex: 1; overflow-y: auto; }
.col { max-width: 780px; margin: 0 auto; padding: 0 20px; }
.msgs { padding: 12px 0 32px; display: flex; flex-direction: column; gap: 26px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bub { background: var(--bubble); padding: 10px 18px; border-radius: 22px; max-width: 78%; white-space: pre-wrap; word-wrap: break-word; }
.msg.ai { display: flex; flex-direction: column; gap: 6px; }
.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; } .md ul, .md ol { padding-left: 24px; margin: 0 0 12px; } .md li { margin: 3px 0; }
.md h1, .md h2, .md h3 { line-height: 1.3; margin: 20px 0 10px; font-weight: 600; } .md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; }
.md code { font: 13.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bubble); padding: 1px 5px; border-radius: 5px; }
.md pre { position: relative; background: var(--code); border: 1px solid var(--border); border-radius: var(--r); margin: 0 0 14px; overflow: hidden; }
.md pre code { display: block; padding: 14px 16px; overflow-x: auto; background: none; border-radius: 0; }
.md pre .code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.md pre .code-head button { border: 0; background: none; cursor: pointer; color: var(--muted); display: flex; gap: 5px; align-items: center; font-size: 12px; padding: 3px 6px; border-radius: 6px; }
.md pre .code-head button:hover { background: var(--hover); color: var(--text); }
.md table { border-collapse: collapse; margin: 0 0 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md blockquote { margin: 0 0 12px; padding-left: 14px; border-left: 3px solid var(--border); color: var(--muted); }
.md a { color: var(--accent); text-decoration: underline; }
.actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.msg.ai:hover .actions, .msg.ai:last-child .actions { opacity: 1; }
.actions .icon-btn { width: 30px; height: 30px; }
.caret::after { content: ""; display: inline-block; width: 9px; height: 9px; margin-left: 4px; border-radius: 50%; background: var(--text); vertical-align: middle; animation: pulse 1s infinite; }
.thinking { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.tool { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; color: var(--muted); border: 1px solid var(--border); border-radius: var(--r); padding: 9px 12px; }
.tool .ic { margin-top: 2px; }
.tool b { color: var(--text); font-weight: 500; }
.tool a { color: var(--accent); }
.tool pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; font: 12.5px/1.5 ui-monospace, Menlo, Consolas, monospace; max-height: 220px; overflow: auto; color: var(--text); }
.tool details summary { cursor: pointer; list-style: none; }
.tool details summary::-webkit-details-marker { display: none; }
.event { align-self: center; font-size: 13px; color: var(--muted); background: var(--bubble); padding: 6px 14px; border-radius: 999px; display: flex; gap: 8px; align-items: center; max-width: 100%; }
.event a { color: var(--accent); }
.thought { color: var(--muted); font-size: 14px; font-style: italic; }
.err-msg { color: var(--bad); }

/* composer */
.composer-wrap { flex: none; padding: 0 0 14px; background: var(--bg); }
.composer { border: 1px solid var(--border); background: var(--input); border-radius: 28px; padding: 10px 10px 10px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.composer textarea { border: 0; outline: none; resize: none; background: transparent; max-height: 240px; min-height: 26px; padding: 4px 4px 0; line-height: 1.5; }
.composer-row { display: flex; align-items: center; gap: 6px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: transparent; cursor: pointer; font-size: 13.5px; color: var(--muted); }
.toggle:hover { background: var(--hover); }
.toggle.on { background: color-mix(in srgb, var(--accent) 14%, transparent); border-color: var(--accent); color: var(--accent); }
.send { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; cursor: pointer; margin-left: auto; }
.send:disabled { opacity: .3; cursor: default; }
.hint { text-align: center; font-size: 12px; color: var(--muted); padding-top: 8px; }

/* home */
.home { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-bottom: 8vh; }
.home h2 { text-align: center; font-size: 28px; font-weight: 500; margin: 0 0 26px; letter-spacing: -.01em; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }

/* pages */
.page { flex: 1; overflow-y: auto; }
.page .col { max-width: 900px; padding-top: 8px; padding-bottom: 40px; }
.page h1 { font-size: 24px; font-weight: 600; margin: 4px 0 4px; }
.page .lead { color: var(--muted); margin: 0 0 20px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.field { height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--input); outline: none; min-width: 0; }
.field:focus, .area:focus { border-color: var(--accent); }
.area { width: 100%; min-height: 90px; padding: 12px 14px; border-radius: var(--r); border: 1px solid var(--border); background: var(--input); outline: none; resize: vertical; }
.list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.row { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row:hover { background: color-mix(in srgb, var(--hover) 50%, transparent); }
.row .meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.row .acts { display: flex; gap: 4px; flex: none; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--hover); color: var(--muted); font-weight: 500; }
.tag.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.tag.run { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.tag.bad { background: color-mix(in srgb, var(--bad) 13%, transparent); color: var(--bad); }
.tag.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.diff { font: 12.5px/1.5 ui-monospace, Menlo, Consolas, monospace; background: var(--code); border: 1px solid var(--border); border-radius: var(--r); padding: 10px 0; overflow-x: auto; margin-top: 10px; max-height: 420px; overflow-y: auto; }
.diff div { padding: 0 14px; white-space: pre; }
.diff .a { background: color-mix(in srgb, var(--ok) 14%, transparent); }
.diff .d { background: color-mix(in srgb, var(--bad) 13%, transparent); }
.diff .h { color: var(--accent); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 22px; }
.card { border: 1px solid var(--border); border-radius: var(--r); padding: 14px 16px; }
.card .n { font-size: 24px; font-weight: 600; }
.card .l { font-size: 13px; color: var(--muted); }
.form { display: flex; flex-direction: column; gap: 14px; max-width: 520px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
.form label small { font-weight: 400; color: var(--muted); }
.form select, .form input[type=text], .form input[type=number] { height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--input); padding: 0 12px; }
.switch { display: flex !important; flex-direction: row !important; align-items: center; gap: 10px !important; }
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--r); background: var(--bubble); margin: 8px 0 16px; font-size: 14px; }

/* menus, modal, toast */
.menu { position: fixed; z-index: 50; background: var(--bg); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.14); padding: 6px; min-width: 200px; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border: 0; background: none; border-radius: 9px; cursor: pointer; font-size: 14px; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--bad); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 2px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 60; padding: 16px; }
.dialog { background: var(--bg); border-radius: 18px; padding: 22px; width: 100%; max-width: 440px; box-shadow: 0 20px 60px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 14px; }
.dialog h3 { margin: 0; font-size: 18px; font-weight: 600; }
.dialog .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dialog .field { border-radius: 10px; width: 100%; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); background: var(--primary); color: var(--on-primary); padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 70; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.scrim { display: none; }

@media (max-width: 820px) {
  .side { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; margin-left: calc(-1 * var(--side-w)); }
  .app.side-open .side { margin-left: 0; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .model-chip .sub { display: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 39; }
  #openSide { display: inline-flex !important; }
  #collapse { display: none; }
  .col { padding: 0 16px; }
  .msg.user .bub { max-width: 88%; }
  .home h2 { font-size: 23px; }
  .chip { max-width: 150px; }
}
