:root {
  --bg: #0e1116;
  --panel: #161b22;
  --border: #262d38;
  --text: #e6edf3;
  --muted: #8a95a5;
  --accent: #ff7a45;
  --user-bg: #1f2733;
  --assistant-bg: #12171f;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; background: transparent; border: 1px solid var(--border); color: var(--text); padding: 8px 14px; border-radius: 6px; font-size: 14px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { background: transparent; border: none; color: var(--muted); padding: 4px 6px; }
button.link:hover { color: var(--text); }
input, textarea, select { background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 8px 10px; font-size: 14px; font-family: inherit; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: #ff6a6a; margin-top: 8px; min-height: 1em; }

#app, .app-shell { height: 100vh; }

.login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--border); padding: 32px; border-radius: 10px; width: 360px; }
.login-card h1 { margin: 0 0 8px; font-size: 20px; }
.login-card input { width: 100%; margin: 12px 0; }
.login-card button { width: 100%; }

.app-shell { display: grid; grid-template-columns: 280px 1fr; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px; gap: 10px; overflow: hidden; }
.brand-title { font-weight: 600; }
.brand-sub { color: var(--muted); font-size: 12px; }
#new-chat { width: 100%; }
.chat-list { flex: 1; overflow-y: auto; margin-top: 6px; }
.chat-list .item { padding: 8px 10px; border-radius: 6px; cursor: pointer; margin-bottom: 4px; border: 1px solid transparent; }
.chat-list .item:hover { background: var(--bg); }
.chat-list .item.active { background: var(--bg); border-color: var(--border); }
.chat-list .item .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .item .date { font-size: 11px; color: var(--muted); }
.side-footer { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }

.chat { display: flex; flex-direction: column; overflow: hidden; height: 100vh; }
.chat-header { padding: 12px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.chat-title { font-weight: 600; }
.chat-actions { display: flex; align-items: center; gap: 8px; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 78%; padding: 12px 14px; border-radius: 10px; word-wrap: break-word; line-height: 1.55; }
.msg.user { background: var(--user-bg); align-self: flex-end; }
.msg.assistant { background: var(--assistant-bg); border: 1px solid var(--border); align-self: flex-start; }
.msg.error { border-color: #663333; color: #ffb3b3; align-self: center; }
.msg img { max-width: 100%; border-radius: 6px; margin-top: 6px; }

/* markdown typography inside messages */
.msg > *:first-child { margin-top: 0; }
.msg > *:last-child { margin-bottom: 0; }
.msg p { margin: 0.5em 0; }
.msg h1, .msg h2, .msg h3, .msg h4 { margin: 0.8em 0 0.4em; line-height: 1.3; }
.msg h1 { font-size: 1.35em; }
.msg h2 { font-size: 1.2em; }
.msg h3 { font-size: 1.1em; }
.msg h4 { font-size: 1em; }
.msg ul, .msg ol { margin: 0.5em 0; padding-left: 1.6em; }
.msg li { margin: 0.25em 0; }
.msg li > p { margin: 0.15em 0; }
.msg code { background: rgba(255,255,255,0.08); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 0.9em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.msg pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 0.6em 0; }
.msg pre code { background: none; border: none; padding: 0; font-size: 0.85em; line-height: 1.5; }
.msg blockquote { margin: 0.5em 0; padding: 2px 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.msg table { border-collapse: collapse; margin: 0.6em 0; font-size: 0.95em; display: block; overflow-x: auto; max-width: 100%; }
.msg th, .msg td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.msg th { background: rgba(255,255,255,0.05); font-weight: 600; }
.msg hr { border: none; border-top: 1px solid var(--border); margin: 0.8em 0; }
.msg strong { font-weight: 650; }
.input-form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.input-form textarea { flex: 1; resize: vertical; min-height: 44px; max-height: 200px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 20px; width: min(720px, 90vw); max-height: 80vh; overflow-y: auto; }
.modal-title { font-weight: 600; margin-bottom: 12px; }
.modal-body { white-space: pre-wrap; }
.modal-body .note { padding: 8px; border-bottom: 1px solid var(--border); }
.modal-body pre { background: var(--bg); padding: 12px; border-radius: 6px; overflow-x: auto; }

select { max-width: 260px; }
option.unhealthy { color: #ff8c8c; }

.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px; }
.attach-chips:empty { display: none; }
.chip { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 3px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.chip .x { cursor: pointer; color: var(--muted); }
.chip .x:hover { color: #ff8c8c; }
.chip.uploading { opacity: 0.6; }
.msg .att { display: inline-block; margin: 4px 6px 0 0; padding: 3px 10px; border: 1px solid var(--border); border-radius: 14px; font-size: 12px; }

.skill-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-bottom: 1px solid var(--border); }
.skill-row .info { flex: 1; min-width: 0; }
.skill-row .name { font-weight: 600; }
.skill-row .desc { color: var(--muted); font-size: 12px; }
.skill-row.disabled .info { opacity: 0.45; }
.skill-form { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.skill-form input, .skill-form textarea { width: 100%; }
.skill-form textarea { min-height: 140px; font-family: ui-monospace, monospace; font-size: 13px; }
