:root {
  color-scheme: dark;
  --bg: #101413;
  --panel: #171c1a;
  --panel-2: #202825;
  --border: #2c3733;
  --text: #edf4f0;
  --muted: #91a09a;
  --accent: #10a37f;
  --accent-2: #0c8d6d;
  --danger: #ef8078;
}
* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.center-view { height: 100%; overflow: auto; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 32px; box-shadow: 0 24px 80px #0005; }
.auth-card h1 { margin: 18px 0 8px; font-size: 25px; }
.auth-card p { color: var(--muted); line-height: 1.55; }
.auth-card form { display: flex; gap: 10px; margin-top: 24px; }
.auth-card input { min-width: 0; flex: 1; border: 1px solid var(--border); border-radius: 10px; padding: 12px 13px; color: var(--text); background: var(--bg); }
.auth-card button, .new-chat { border: 0; border-radius: 10px; color: white; background: var(--accent); padding: 11px 16px; font-weight: 650; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px; color: #051a14; background: var(--accent); font-weight: 900; font-size: 24px; }
.brand-mark.small { width: 28px; height: 28px; border-radius: 8px; font-size: 16px; }
.error-text { min-height: 20px; color: var(--danger) !important; font-size: 13px; }
.app-shell { height: 100vh; height: 100dvh; height: var(--app-height, 100dvh); min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.topbar { height: 60px; flex-shrink: 0; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; border-bottom: 1px solid var(--border); background: #121716e8; backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.connection { color: var(--muted); font-size: 12px; }
.connection.online { color: #67d7b5; }
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar { width: 270px; display: flex; flex-direction: column; gap: 16px; padding: 20px 14px; border-right: 1px solid var(--border); background: #141a18; }
.new-chat { width: 100%; text-align: left; }
.sidebar-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; padding: 4px 10px; }
.session-list { display: flex; flex-direction: column; gap: 4px; overflow: auto; }
.session-item { border: 1px solid transparent; color: var(--text); text-align: left; background: transparent; border-radius: 10px; padding: 11px 10px; }
.session-item:hover, .session-item.active { background: var(--panel-2); border-color: var(--border); }
.session-item-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.session-item-meta { color: var(--muted); font-size: 11px; margin-top: 4px; }
.sidebar-footer { color: #63716b; font-size: 11px; margin-top: auto; padding: 6px 10px; }
.chat-panel { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; position: relative; }
.chat-toolbar { display: flex; align-items: center; justify-content: space-between; min-height: 66px; padding: 12px 28px; border-bottom: 1px solid var(--border); }
.chat-toolbar > div:first-child { min-width: 0; flex: 1; }
.chat-toolbar { flex-shrink: 0; gap: 8px; }
.session-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.session-select { display: none; min-width: 0; max-width: 48vw; color: var(--text); border: 1px solid var(--border); background: var(--bg); border-radius: 7px; padding: 6px 8px; }
.refresh-button { color: var(--muted); border: 1px solid var(--border); background: transparent; border-radius: 8px; padding: 7px 10px; }
.stop-button { color: var(--danger); border: 1px solid #713d3c; background: transparent; border-radius: 8px; padding: 7px 12px; }
.stop-button:disabled { opacity: .35; cursor: default; }
.messages { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; overflow-anchor: none; padding: 30px max(20px, calc((100% - 850px) / 2)); }
.empty-state { color: var(--muted); text-align: center; margin: 15vh auto 0; max-width: 420px; }
.empty-state h2 { color: var(--text); font-size: 22px; margin: 18px 0 8px; }
.empty-state p { line-height: 1.55; }
.empty-icon { color: var(--accent); font-size: 32px; }
.message { display: flex; gap: 13px; margin: 0 auto 25px; max-width: 850px; line-height: 1.65; align-items: flex-start; }
.message.user { flex-direction: row-reverse; }
.message-avatar { flex: 0 0 30px; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; color: #061711; background: var(--accent); font-size: 13px; font-weight: 850; }
.message.user .message-avatar { background: #34413c; color: var(--text); }
.message-content { min-width: 0; max-width: calc(100% - 43px); overflow-wrap: anywhere; padding-top: 3px; }
.message.user .message-content { text-align: right; background: #202825; border-radius: 14px 4px 14px 14px; padding: 9px 12px; }
.message-content > div { min-height: 1.65em; }
.message-content > br + br { display: none; }
.message-content h1, .message-content h2, .message-content h3, .message-content h4, .message-content h5, .message-content h6 { margin: 0 0 8px; line-height: 1.3; }
.message-content a { color: #67d7b5; text-decoration: underline; }
.message-content .attachment { max-width: min(100%, 560px); margin: 8px 0; }
.message-content img { display: block; max-width: 100%; max-height: 520px; height: auto; margin: 0; border-radius: 10px; object-fit: contain; background: #0b0e0d; }
.message-content .image-error { display: block; color: var(--muted); border: 1px dashed var(--border); border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 13px; }
.message.user .message-content .attachment { margin-left: auto; }
.download-link { display: inline-block; margin-top: 5px; color: #67d7b5; font-size: 13px; text-decoration: underline; }
.message-content code { padding: 2px 5px; border-radius: 5px; background: #0b0e0d; color: #b7e8d6; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
.message-content pre { max-width: 100%; overflow: auto; margin: 8px 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: #0b0e0d; text-align: left; white-space: pre; }
.message-content pre code { padding: 0; background: transparent; color: var(--text); font-size: .86em; }
.message.system { color: var(--muted); font-size: 12px; margin-bottom: 9px; }
.message.system .message-avatar { background: transparent; color: var(--muted); }
.composer-wrap { flex-shrink: 0; border-top: 1px solid var(--border); padding: 14px max(20px, calc((100% - 850px) / 2)) max(20px, env(safe-area-inset-bottom)); background: #141a18; }
.selectors { display: flex; gap: 10px; margin-bottom: 10px; }
.selectors label { color: var(--muted); display: flex; align-items: center; gap: 7px; font-size: 12px; }
.selectors select { color: var(--text); border: 1px solid var(--border); background: var(--bg); border-radius: 7px; padding: 6px 8px; max-width: 210px; }
.composer { display: flex; align-items: flex-end; gap: 9px; padding: 10px 10px 10px 14px; border: 1px solid var(--border); border-radius: 15px; background: var(--bg); }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 170px; border: 0; outline: 0; color: var(--text); background: transparent; line-height: 1.5; font-size: 16px; }
.composer button { width: 34px; height: 34px; border: 0; border-radius: 10px; background: var(--accent); color: #04150f; font-size: 20px; font-weight: 800; }
.composer button:disabled { opacity: .35; }
.composer-note { color: #68756f; font-size: 11px; margin-top: 8px; text-align: center; }
.composer-wrap { position: relative; }
.latest-button { position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%); white-space: nowrap; padding: 8px 14px; border: 1px solid var(--border); border-radius: 20px; background: var(--panel-2); color: var(--text); box-shadow: 0 3px 12px #0005; }
.send-error { color: var(--danger); border: 1px solid #713d3c; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 8px; max-height: 90px; overflow: auto; overflow-wrap: anywhere; }
.session-item { flex-shrink: 0; }
@media (max-width: 700px) {
  .topbar { padding: 0 14px; }
  .sidebar { display: none; }
  .chat-toolbar { padding: 10px 12px; flex-wrap: wrap; }
  .chat-toolbar > div:first-child { flex-basis: 100%; }
  .session-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .session-select { display: block; flex: 1; max-width: none; }
  .refresh-button { padding: 7px 8px; }
  .messages { padding: 22px 15px; }
  .composer-wrap { padding: 10px 12px max(12px, env(safe-area-inset-bottom)); }
  .selectors { overflow-x: auto; }
  .selectors label { flex: 0 0 auto; }
}
