/* NextAI web UI — layout and patterns follow the major chat apps (ChatGPT / Claude / Gemini):
   quiet neutral surfaces, history sidebar, centered thread, floating rounded composer. */
:root {
  --bg: #ffffff; --side: #f7f7f8; --panel: #ffffff; --panel-2: #f3f4f6; --hover: rgba(0,0,0,.05); --active: rgba(0,0,0,.08);
  --border: #e5e7eb; --border-strong: #d1d5db; --text: #111827; --muted: #6b7280; --faint: #9ca3af;
  --accent: #4f46e5; --accent-2: #6366f1; --accent-soft: #eef2ff; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --user-bubble: #f1f2f4; --code-bg: #0d1117; --code-head: #161b22; --code-text: #e6edf3;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05); --shadow: 0 2px 6px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --shadow-pop: 0 10px 38px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.08);
  --grad: linear-gradient(90deg, #4f46e5, #9333ea 45%, #db2777);
  --radius: 14px; --sidebar: 268px; --thread: 780px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #212121; --side: #171717; --panel: #2a2a2a; --panel-2: #303030; --hover: rgba(255,255,255,.06); --active: rgba(255,255,255,.1);
    --border: #3a3a3a; --border-strong: #4a4a4a; --text: #ececec; --muted: #a3a3a3; --faint: #737373;
    --accent: #8b8cf8; --accent-2: #a5b4fc; --accent-soft: rgba(129,140,248,.14); --user-bubble: #303030;
    --shadow-sm: none; --shadow: 0 2px 10px rgba(0,0,0,.3); --shadow-pop: 0 10px 38px rgba(0,0,0,.5);
    --grad: linear-gradient(90deg, #818cf8, #c084fc 45%, #f472b6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #212121; --side: #171717; --panel: #2a2a2a; --panel-2: #303030; --hover: rgba(255,255,255,.06); --active: rgba(255,255,255,.1);
  --border: #3a3a3a; --border-strong: #4a4a4a; --text: #ececec; --muted: #a3a3a3; --faint: #737373;
  --accent: #8b8cf8; --accent-2: #a5b4fc; --accent-soft: rgba(129,140,248,.14); --user-bubble: #303030;
  --shadow-sm: none; --shadow: 0 2px 10px rgba(0,0,0,.3); --shadow-pop: 0 10px 38px rgba(0,0,0,.5);
  --grad: linear-gradient(90deg, #818cf8, #c084fc 45%, #f472b6);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.7 "Inter", system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
#app { height: 100%; }
.boot { display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ic { flex: none; display: block; }
kbd { font: 11px ui-monospace, Consolas, monospace; color: var(--faint); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; }

/* buttons & inputs */
a.btn { text-decoration: none; color: inherit; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--panel); padding: 8px 14px;
  border-radius: 10px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.primary:hover { opacity: .88; background: var(--text); }
.btn.block { width: 100%; padding: 11px; font-weight: 600; margin-top: 6px; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); border-radius: 9px; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.done { color: var(--ok); }
.input, textarea.input, select.input { width: 100%; border: 1px solid var(--border); background: var(--panel); border-radius: 10px; padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 8px 10px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.4em; }
.notice { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.keybox { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; border: 1px solid var(--accent); }
.keybox .row { flex-wrap: nowrap; }
.keybox .input { flex: 1; width: auto; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.card code { font-family: ui-monospace, Consolas, monospace; word-break: break-all; background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); margin-bottom: 14px; }
.card h3 { margin-top: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grow { flex: 1; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.ok { color: var(--ok); } .chip.warn { color: var(--warn); } .chip.bad { color: var(--danger); }

/* auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 32px 16px; position: relative; overflow: hidden; }
.auth-glow { position: absolute; inset: -30% -10% auto; height: 70%; background: radial-gradient(closest-side, rgba(99,102,241,.22), transparent),
  radial-gradient(closest-side at 70% 40%, rgba(219,39,119,.16), transparent); filter: blur(20px); pointer-events: none; }
.auth-card { position: relative; width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 32px 28px 24px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 22px; text-align: center; margin: 12px 0 4px; letter-spacing: -.01em; }
.auth-card > p { text-align: center; margin: 0 0 12px; font-size: 14px; }
.auth-logo { display: grid; place-items: center; }
.auth-logo img { width: 52px; height: 52px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; min-width: 0; }
.brand img { width: 26px; height: 26px; flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* layout */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100%; transition: grid-template-columns .2s ease; }
.layout.collapsed { grid-template-columns: 0 1fr; }
.layout.collapsed .sidebar { visibility: hidden; }
.sidebar { background: var(--side); display: flex; flex-direction: column; min-height: 0; overflow: hidden; border-right: 1px solid var(--border); }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 6px 14px; }
.new-chat { display: flex; align-items: center; gap: 10px; margin: 6px 10px 4px; padding: 9px 12px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; text-align: left; font-weight: 500; }
.new-chat:hover { background: var(--hover); }
.new-chat span { flex: 1; }
.new-chat kbd { opacity: 0; transition: opacity .15s; }
.new-chat:hover kbd { opacity: 1; }
.search { display: flex; align-items: center; gap: 8px; margin: 2px 10px 6px; padding: 0 10px; border-radius: 10px; color: var(--muted); }
.search:focus-within { background: var(--panel); box-shadow: inset 0 0 0 1px var(--border); }
.search-input { flex: 1; border: 0; background: transparent; outline: none; padding: 8px 0; min-width: 0; }
.nav { display: flex; flex-direction: column; padding: 0 10px; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 8px 12px; border-radius: 10px; cursor: pointer; text-align: left; color: var(--text); }
.nav-item .ic { color: var(--muted); }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--active); font-weight: 500; }
.side-label { font-size: 12px; font-weight: 600; color: var(--faint); padding: 16px 22px 2px; }
.convs { flex: 1; overflow-y: auto; padding: 0 10px 10px; scrollbar-width: thin; }
.conv-group { margin-top: 8px; }
.group-label { font-size: 12px; color: var(--faint); padding: 6px 12px 3px; font-weight: 500; }
.conv { display: flex; align-items: center; gap: 2px; padding: 0 4px 0 12px; border-radius: 10px; cursor: pointer; font-size: 14px; height: 36px; position: relative; }
.conv:hover { background: var(--hover); }
.conv.active { background: var(--active); }
.conv .t { flex: 1; overflow: hidden; white-space: nowrap; -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
.conv .conv-more { width: 28px; height: 28px; opacity: 0; }
.conv:hover .conv-more, .conv.active .conv-more, .conv:focus-within .conv-more { opacity: 1; }
.me { display: flex; align-items: center; gap: 10px; margin: 6px 10px 10px; padding: 8px 10px; border-radius: 12px; cursor: pointer; border: 0; background: transparent; text-align: left; }
.me:hover { background: var(--hover); }
.me .name { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .muted { line-height: 1.3; }
.me > .ic { color: var(--muted); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; object-fit: cover; flex: none; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.hdr { display: flex; align-items: center; gap: 6px; height: 52px; padding: 0 12px; flex: none; }
.hdr-toggle { display: none; }
.layout.collapsed .hdr-toggle { display: inline-grid; }
.hdr-title { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 4px 8px; border-radius: 8px; }
.hdr-title:not(:empty):hover { background: var(--hover); cursor: pointer; }
.hdr-right { display: flex; gap: 4px; }
.view { flex: 1; overflow-y: auto; min-height: 0; }
.view-inner { max-width: 880px; margin: 0 auto; padding: 12px 20px 48px; }
h2 { font-size: 22px; margin: 6px 0 16px; letter-spacing: -.01em; }
h3 { font-size: 16px; margin: 22px 0 10px; }

/* popover menus */
.popover { position: fixed; z-index: 60; min-width: 200px; max-width: 320px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 6px; box-shadow: var(--shadow-pop); animation: pop .12s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
.pop-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; cursor: pointer; text-align: left; font-size: 14px; }
.pop-item:hover { background: var(--hover); }
.pop-item .ic { color: var(--muted); }
.pop-item.danger, .pop-item.danger .ic { color: var(--danger); }
.pop-item .desc { font-size: 12px; color: var(--muted); line-height: 1.4; }
.pop-item.active > .ic:last-child { color: var(--accent); }
.popover .sep { height: 1px; background: var(--border); margin: 5px 4px; }

/* chat */
.chat { display: flex; flex-direction: column; height: 100%; position: relative; }
.messages { flex: 1; overflow-y: auto; padding: 8px 20px 24px; scroll-behavior: auto; }
.thread { max-width: var(--thread); margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }
.msg { position: relative; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.msg.user .bubble { background: var(--user-bubble); padding: 10px 16px; border-radius: 22px; max-width: min(78%, 620px); white-space: pre-wrap; word-break: break-word; }
.msg.assistant { display: grid; grid-template-columns: 30px 1fr; gap: 14px; }
.ai-avatar { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--border); display: grid; place-items: center; background: var(--panel); margin-top: 2px; }
.ai-avatar img { width: 18px; height: 18px; }
.ai-avatar.spin img { animation: spin 2.4s linear infinite; }
.msg .body { min-width: 0; }
.msg-actions { display: flex; align-items: center; gap: 2px; margin-top: 6px; min-height: 32px; opacity: 0; transition: opacity .15s; }
.msg-actions .icon-btn { width: 30px; height: 30px; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .thread > .msg.assistant:last-child .msg-actions { opacity: 1; }
.msg.live .msg-actions { opacity: 1; }
.meta-info { font-size: 12px; color: var(--faint); margin-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.att-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 5px 8px 5px 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--border); max-width: 260px; }
.att-chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; margin-left: -4px; }
.att-chip .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip .x { border: 0; background: transparent; cursor: pointer; color: var(--muted); display: grid; place-items: center; padding: 2px; border-radius: 6px; }
.att-chip .x:hover { background: var(--hover); color: var(--text); }
.live-status { font-size: 14px; color: var(--muted); padding: 4px 0; }
.shimmer { background: linear-gradient(90deg, var(--muted) 30%, var(--text) 50%, var(--muted) 70%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text;
  color: transparent; animation: shimmer 1.8s linear infinite; }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.activity { margin: 2px 0 10px; font-size: 13px; color: var(--muted); }
.activity summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 4px; border-radius: 8px; user-select: none; }
.activity summary::-webkit-details-marker { display: none; }
.activity summary:hover { background: var(--hover); color: var(--text); }
.activity summary .ic { transform: rotate(-90deg); transition: transform .15s; }
.activity[open] summary .ic { transform: none; }
.activity .steps { border-left: 2px solid var(--border); margin: 6px 0 0 9px; padding: 2px 0 2px 14px; display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; }
.activity .step { white-space: pre-wrap; word-break: break-word; }

/* markdown */
.md { word-break: break-word; }
.md p { margin: 0 0 .85em; } .md > :last-child { margin-bottom: 0; }
.md ul, .md ol { padding-left: 1.5em; margin: .3em 0 .9em; }
.md li { margin: .2em 0; }
.md h2, .md h3, .md h4 { margin: 1.2em 0 .5em; line-height: 1.4; }
.md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; } .md h4 { font-size: 1em; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md blockquote { border-left: 3px solid var(--border-strong); margin: .6em 0; padding: 2px 14px; color: var(--muted); }
.md a { text-decoration: underline; text-underline-offset: 2px; }
.md code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; font-size: .88em; font-family: ui-monospace, "Cascadia Code", "Cascadia Mono", Consolas, monospace; }
.md .code { margin: .8em 0; border-radius: 12px; overflow: hidden; background: var(--code-bg); border: 1px solid rgba(255,255,255,.06); }
.md .code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 14px; font-size: 12px; color: #8b949e; background: var(--code-head); }
.md .code-head .copy { display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; color: #8b949e; cursor: pointer; font-size: 12px; padding: 3px 8px; border-radius: 6px; }
.md .code-head .copy:hover { color: #e6edf3; background: rgba(255,255,255,.08); }
.md .code-head .copy.done { color: #3fb950; }
.md pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.md pre code { background: none; color: var(--code-text); padding: 0; font-size: 13px; line-height: 1.6; }
.md .table-wrap { overflow-x: auto; margin: .7em 0; border: 1px solid var(--border); border-radius: 10px; }
.md table { border-collapse: collapse; font-size: 14px; width: 100%; }
.md th, .md td { border-bottom: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.md tr:last-child td { border-bottom: 0; }
.md th { background: var(--panel-2); font-weight: 600; }
.typing:empty::after, .typing > :last-child::after { content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 4px; border-radius: 50%; background: var(--text); vertical-align: middle; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.6); opacity: .5; } }
.assets { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.assets:empty { display: none; }
.asset-img img { max-width: min(100%, 440px); border-radius: 14px; display: block; box-shadow: var(--shadow); }
.assets audio { width: min(100%, 440px); }
.vid { max-width: min(100%, 520px); border-radius: 14px; }
.file-link { display: inline-flex; gap: 8px; align-items: center; padding: 8px 12px; border: 1px solid var(--border); border-radius: 12px; font-size: 13px; text-decoration: none; background: var(--panel); color: var(--text); }
.file-link:hover { background: var(--hover); }
.progress { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin: 6px 0; max-width: 420px; }
.progress > div { height: 100%; background: var(--grad); width: 0; transition: width .3s; }

/* composer */
.composer-wrap { padding: 0 20px calc(10px + env(safe-area-inset-bottom)); }
.composer { max-width: var(--thread); margin: 0 auto; }
.composer-box { background: var(--panel); border: 1px solid var(--border); border-radius: 26px; padding: 12px 12px 8px 16px; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
.composer-box:focus-within { border-color: var(--border-strong); }
.composer textarea { width: 100%; border: 0; outline: none; resize: none; background: transparent; max-height: 240px; padding: 4px 4px 2px; min-height: 28px; line-height: 1.6; display: block; }
.composer textarea::placeholder { color: var(--faint); }
.composer-row { display: flex; align-items: center; gap: 4px; margin-top: 6px; margin-left: -6px; }
.composer-status { font-size: 12px; color: var(--muted); margin-left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: transparent; border-radius: 99px; padding: 4px 10px 4px 9px; cursor: pointer; font-size: 13px; color: var(--muted); }
.pill:hover { background: var(--hover); color: var(--text); }
.send { width: 36px; height: 36px; border-radius: 50%; border: 0; display: grid; place-items: center; background: var(--text); color: var(--bg); cursor: pointer; flex: none; transition: opacity .15s, transform .1s; }
.send:hover { opacity: .85; }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .25; cursor: default; }
.send.busy { background: var(--text); }
.attached { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 8px -4px; }
.disclaimer { text-align: center; font-size: 12px; color: var(--faint); padding: 8px 0 0; }
.to-bottom { position: absolute; left: 50%; bottom: 150px; transform: translate(-50%, 10px); width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 5; }
.to-bottom.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.dropzone { position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 20px; background: color-mix(in srgb, var(--bg) 86%, transparent);
  display: none; place-items: center; align-content: center; gap: 10px; color: var(--accent); font-weight: 600; z-index: 20; pointer-events: none; }
.chat.dragging .dropzone { display: grid; }

/* welcome (new chat): greeting + centered composer, like Gemini / ChatGPT */
.chat.welcome { justify-content: center; }
.chat.welcome .messages { flex: 0 0 auto; overflow: visible; padding-bottom: 8px; }
.chat.welcome .disclaimer { display: none; }
.chat.welcome { padding-bottom: 8vh; }
.empty { text-align: center; color: var(--muted); padding: 24px 0 8px; }
.empty .greet { font-size: clamp(26px, 4.4vw, 38px); font-weight: 650; letter-spacing: -.02em; margin: 0 0 6px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1.25; }
.empty > p { margin: 0 0 4px; font-size: 17px; }
.greet .nb { display: inline-block; }
.below { padding: 0 20px; }
.suggest { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: var(--thread); margin: 18px auto 0; }
.suggest button { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; text-align: left; border: 1px solid var(--border); background: var(--panel);
  padding: 12px 14px; border-radius: 16px; cursor: pointer; color: var(--text); transition: background .15s, border-color .15s, transform .1s; }
.suggest button:hover { background: var(--hover); border-color: var(--border-strong); }
.suggest button:active { transform: scale(.99); }
.s-ic { grid-row: span 2; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.s-label { font-weight: 600; font-size: 13px; }
.s-text { font-size: 13px; color: var(--muted); line-height: 1.45; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* lists / other views */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; flex-wrap: wrap; }
.item .grow { flex: 1; min-width: 160px; }
.item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.live { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; align-items: start; }
.gallery .g { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: var(--panel); font-size: 12px; transition: box-shadow .15s; }
.gallery .g:hover { box-shadow: var(--shadow); }
.gallery .g img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.gallery .g audio { width: 100%; }
.gallery .g video { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #000; }
.gallery .g .cap { padding: 7px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.tabs { display: inline-flex; gap: 2px; margin-bottom: 16px; padding: 3px; background: var(--panel-2); border-radius: 12px; }
.tabs button { border: 0; background: transparent; padding: 6px 16px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }
.meter { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin: 4px 0 8px; }
.meter > div { height: 100%; background: var(--grad); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 80;
  font-size: 14px; max-width: calc(100% - 32px); box-shadow: var(--shadow-pop); animation: pop .15s ease-out; }
.overlay { display: none; }

@media (max-width: 860px) {
  .layout, .layout.collapsed { grid-template-columns: 1fr; }
  .layout.collapsed .sidebar { visibility: visible; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px); z-index: 30; transform: translateX(-102%); transition: transform .22s ease; }
  .layout.open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  .conv .conv-more { opacity: 1; }
  .layout.open .overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
  .hdr-toggle { display: inline-grid; }
  .side-top .icon-btn { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .messages { padding: 4px 14px 20px; }
  .composer-wrap { padding: 0 10px calc(8px + env(safe-area-inset-bottom)); }
  .msg.user .bubble { max-width: 88%; }
  .msg.assistant { grid-template-columns: 1fr; }
  .ai-avatar { display: none; }
  .suggest { grid-template-columns: 1fr 1fr; }
  .suggest button:nth-child(n+5) { display: none; }
  .msg-actions { opacity: 1; }
  .new-chat kbd { display: none; }
  .view-inner { padding: 8px 14px 40px; }
}
@media (max-width: 420px) {
  .suggest { grid-template-columns: 1fr; }
  .suggest button:nth-child(n+4) { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* file cards & previews */
.file-card { border: 1px solid var(--border); border-radius: 14px; background: var(--panel); width: min(100%, 560px); overflow: hidden; }
.fc-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 12px; }
.fc-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.fc-name { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-kind { font-size: 12px; color: var(--muted); }
.fc-body { border-top: 1px solid var(--border); padding: 10px 12px; max-height: 420px; overflow: auto; }
.fc-body .table-wrap { margin: 0; }
.fc-pre { margin: 0; font: 12.5px/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre; overflow-x: auto; }
.preview-frame { width: 100%; height: 420px; border: 1px solid var(--border); border-radius: 12px; background: #fff; display: block; margin: 8px 0; }
.fc-body .preview-frame { margin: 0; border: 0; border-radius: 0; }
/* thinking, sources, memory */
.thinking { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.thinking summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 4px; border-radius: 8px; user-select: none; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary:hover { background: var(--hover); color: var(--text); }
.think-text { border-left: 2px solid var(--border); margin: 6px 0 0 9px; padding: 2px 0 2px 14px; white-space: pre-wrap; max-height: 320px; overflow-y: auto; }
.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.src-label { font-size: 12px; color: var(--faint); margin-right: 2px; }
.src { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 10px 3px 4px; border-radius: 99px; background: var(--panel-2); color: var(--text); text-decoration: none; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src:hover { background: var(--active); }
.src .n { width: 18px; height: 18px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; font-size: 11px; color: var(--muted); flex: none; }
.mem-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); padding: 2px 8px; border-radius: 99px; background: var(--panel-2); margin-left: 4px; cursor: help; }
.md .code-head { gap: 4px; }
.md .code-head > span:first-child { flex: 1; }
.fc-body .preview-frame { height: 320px; }
