* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #131314; --panel: #1e1f20; --panel2: #282a2c; --line: #3c4043;
  --text: #e3e3e3; --dim: #9aa0a6; --accent: #8ab4f8; --accent2: #1f3a5f;
  --danger: #f28b82; --radius: 14px;
}
html, body { height: 100%; }
body { font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
.hidden { display: none !important; }
#app { display: flex; height: 100vh; height: 100dvh; }

/* Sidebar */
#sidebar { width: 272px; flex: 0 0 272px; background: var(--panel); display: flex; flex-direction: column; padding: 14px 12px; gap: 10px; border-right: 1px solid var(--line); z-index: 30; }
.brand { font-size: 20px; font-weight: 700; padding: 4px 6px 10px; }
.side-top { display: flex; flex-direction: column; gap: 8px; }
#searchInput { width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 8px 10px; font-size: 14px; outline: none; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-item { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.conv-item:hover { background: var(--panel2); }
.conv-item.active { background: var(--accent2); }
.conv-item .ct { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .ci { background: none; border: none; color: var(--dim); cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 6px; }
.conv-item .ci:hover { color: var(--text); background: var(--line); }
.side-bottom { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.badge { background: var(--accent2); color: var(--accent); border-radius: 999px; padding: 0 7px; font-size: 12px; }

/* Buttons */
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-size: 14px; cursor: pointer; }
.btn:hover { filter: brightness(1.2); }
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #d3e3fd; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.wfull { width: 100%; text-align: left; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel2); }
.icon-btn { background: none; border: none; color: var(--text); font-size: 17px; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--panel2); }

/* Main */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
#menuBtn { display: none; }
.top-title { font-weight: 600; flex: 1; }
#modelSelect { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; font-size: 13px; max-width: 55vw; }
.model-bar { display: flex; align-items: center; gap: 8px; width: 100%; max-width: 820px; margin: 0 auto; padding: 6px 16px 0; }
.model-bar label { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
#modelSelectChat { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 7px 11px; font-size: 13px; max-width: 65vw; cursor: pointer; }
.messages { flex: 1; overflow-y: auto; padding: 22px 16px 8px; width: 100%; max-width: 820px; margin: 0 auto; }
.empty { text-align: center; padding-top: 9vh; }
.empty h1 { font-size: 40px; font-weight: 700; margin-bottom: 8px; }
.empty-sub { color: var(--dim); margin-bottom: 26px; }
.sugg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 640px; margin: 0 auto; }
.sugg { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: var(--radius); padding: 14px; font-size: 14px; text-align: left; cursor: pointer; }
.sugg:hover { background: var(--panel2); }
.msg { display: flex; gap: 12px; margin-bottom: 22px; }
.msg .avatar { flex: 0 0 30px; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; background: var(--panel2); }
.msg.user .avatar { background: #4b3a5f; }
.msg .body { flex: 1; min-width: 0; }
.msg .who { font-size: 12px; color: var(--dim); margin-bottom: 4px; }
.msg .content { font-size: 15px; line-height: 1.6; overflow-wrap: break-word; }
.msg .content p { margin-bottom: 10px; }
.msg .content h1, .msg .content h2, .msg .content h3 { margin: 14px 0 8px; line-height: 1.3; }
.msg .content ul, .msg .content ol { margin: 6px 0 12px 20px; }
.msg .content a { text-decoration: underline; }
.msg .content code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.codeblock { background: #0d0d0e; border: 1px solid var(--line); border-radius: 10px; margin: 10px 0; overflow: hidden; }
.codeblock .cb-head { display: flex; justify-content: space-between; align-items: center; background: var(--panel2); padding: 5px 10px; font-size: 12px; color: var(--dim); }
.codeblock pre { overflow-x: auto; padding: 12px; }
.codeblock code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5; white-space: pre; }
.copy-code { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12px; }
.msg .meta { display: flex; gap: 6px; align-items: center; margin-top: 7px; }
.msg .meta .time { font-size: 11px; color: var(--dim); margin-right: 4px; }
.mini-btn { background: none; border: 1px solid var(--line); color: var(--dim); border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.mini-btn:hover { color: var(--text); background: var(--panel2); }
.msg.error .content { color: var(--danger); }
.typing { display: flex; gap: 5px; padding: 4px 16px 10px; max-width: 820px; margin: 0 auto; width: 100%; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { display: flex; gap: 10px; align-items: flex-end; width: 100%; max-width: 820px; margin: 0 auto; padding: 8px 16px 4px; }
#input { flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 24px; padding: 13px 18px; font-size: 15px; font-family: inherit; resize: none; max-height: 180px; outline: none; }
.send-btn { flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--accent); color: #0b1526; font-size: 19px; cursor: pointer; }
.send-btn:disabled { opacity: .4; cursor: default; }
.foot-note { text-align: center; font-size: 11px; color: var(--dim); padding: 4px 10px 10px; }

/* Artifacts pane */
.pane { width: 380px; flex: 0 0 380px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px; gap: 10px; overflow-y: auto; z-index: 30; }
.pane-head { display: flex; justify-content: space-between; align-items: center; }
.pane-title { font-weight: 700; font-size: 16px; }
.artifact-list { display: flex; flex-direction: column; gap: 6px; }
.artifact-item { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; cursor: pointer; font-size: 14px; }
.artifact-item:hover { filter: brightness(1.15); }
.artifact-item .at { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.artifact-item .ak { font-size: 11px; color: var(--dim); text-transform: uppercase; }
.artifact-editor { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.artifact-editor input, .artifact-editor select, .artifact-editor textarea { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 8px 10px; font-size: 14px; font-family: inherit; width: 100%; }
.artifact-editor textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; resize: vertical; }
.row { display: flex; gap: 8px; } .row.wrap { flex-wrap: wrap; }
.preview-label { font-size: 12px; color: var(--dim); margin: 4px 0; }
#artPreview { width: 100%; height: 260px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.empty-note { color: var(--dim); font-size: 13px; padding: 8px 2px; }

/* Settings modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 10px; max-height: 90vh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.lbl { font-size: 13px; color: var(--dim); }
.hint { font-size: 13px; color: var(--dim); line-height: 1.5; }
.modal-card hr { border: none; border-top: 1px solid var(--line); }

#scrim { display: none; }
@media (max-width: 860px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-105%); transition: transform .25s; }
  #sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  #menuBtn { display: block; }
  .pane { position: fixed; right: 0; top: 0; bottom: 0; width: min(92vw, 400px); box-shadow: 0 0 40px rgba(0,0,0,.5); }
  #scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }
  .sugg-grid { grid-template-columns: 1fr; }
  .empty h1 { font-size: 32px; }
}
