@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* the `hidden` attribute must always win over the display rules below */
[hidden] { display: none !important; }

:root {
  --bg: #ffffff; --surface: #f6f7f9; --surface-2: #eceef1; --border: #e2e5e9;
  --fg: #1a1d21; --fg-dim: #6b7280; --accent: #2563eb; --accent-fg: #ffffff;
  --user-bg: #2563eb; --user-fg: #ffffff; --tool-bg: #f6f7f9; --code-bg: #f3f4f6;
  --red: #cf222e; --green: #1a7f37;
  --diff-add-bg: #e6ffec; --diff-add-fg: #1a7f37; --diff-del-bg: #ffebe9; --diff-del-fg: #cf222e;
  --radius: 16px;
}
html, body { height: 100%; font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--fg); overflow: hidden; overscroll-behavior: none; }

/* Login */
#login-screen { display: flex; align-items: center; justify-content: center; height: 100dvh; padding: 24px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 32px 28px; }
.login-card h1 { font-size: 1.4rem; margin-bottom: 4px; } .login-card p { color: var(--fg-dim); font-size: .9rem; margin-bottom: 22px; }
.form-group { margin-bottom: 14px; } .form-group label { display: block; font-size: .8rem; color: var(--fg-dim); margin-bottom: 6px; }
.form-group input, .form-group select { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; font-size: 1rem; background: var(--bg); color: var(--fg); font-family: inherit; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent); }
.login-btn { width: 100%; padding: 12px; margin-top: 6px; border: none; border-radius: 12px; background: var(--accent); color: var(--accent-fg); font-size: 1rem; font-weight: 600; cursor: pointer; }
.login-error { color: var(--red); font-size: .85rem; margin-top: 12px; min-height: 1em; text-align: center; }

/* Chat shell */
#chat-screen { display: none; flex-direction: column; height: 100dvh; }
#chat-header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--border); background: var(--surface); flex: 0 0 auto; }
#chat-header .title { font-weight: 600; font-size: 1rem; } #chat-header .title .muted { color: var(--fg-dim); font-weight: 400; }
#chat-header .status { margin-left: 6px; display: flex; align-items: center; gap: 6px; font-size: .76rem; color: var(--fg-dim); }
#chat-header .status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); } #chat-header .status .dot.off { background: var(--red); }
#chat-header #new-btn { margin-left: auto; }
.ghost-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--fg); border-radius: 10px; padding: 6px 11px; font-size: .82rem; cursor: pointer; white-space: nowrap; }

/* Messages */
#messages { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 90%; display: flex; flex-direction: column; gap: 8px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: stretch; max-width: 96%; width: 96%; }
.bubble { padding: 11px 15px; border-radius: var(--radius); font-size: .98rem; line-height: 1.5; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user-bg); color: var(--user-fg); border-bottom-right-radius: 5px; }
.msg.user img { max-width: 220px; border-radius: 12px; display: block; }
.msg.assistant .text { color: var(--fg); font-size: .98rem; line-height: 1.55; }
.text.empty::after { content: '▍'; color: var(--fg-dim); animation: blink 1s step-start infinite; } @keyframes blink { 50% { opacity: 0; } }
.text p { margin: 0 0 .6em; } .text p:last-child { margin-bottom: 0; }
.text ul, .text ol { margin: 0 0 .6em 1.2em; } .text li { margin: .2em 0; }
.text h1, .text h2, .text h3 { font-size: 1.05rem; margin: .6em 0 .3em; }
.text code { font-family: 'JetBrains Mono', monospace; font-size: .86em; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.text pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow-x: auto; margin: .5em 0; }
.text pre code { background: none; padding: 0; font-size: .82rem; } .text a { color: var(--accent); }

/* Thinking */
.think { border-left: 3px solid var(--border); }
.think summary { list-style: none; cursor: pointer; color: var(--fg-dim); font-size: .82rem; padding: 2px 0 2px 10px; font-style: italic; }
.think summary::-webkit-details-marker { display: none; }
.think .body { padding: 4px 0 4px 10px; color: var(--fg-dim); font-size: .85rem; white-space: pre-wrap; font-style: italic; }

/* Tool cards */
.tool { background: var(--tool-bg); border: 1px solid var(--border); border-radius: 12px; font-size: .85rem; overflow: hidden; }
.tool summary { list-style: none; cursor: pointer; padding: 9px 12px; display: flex; align-items: center; gap: 8px; font-family: 'JetBrains Mono', monospace; color: var(--fg-dim); }
.tool summary::-webkit-details-marker { display: none; }
.tool summary .tname { color: var(--accent); font-weight: 500; } .tool.err summary .tname { color: var(--red); }
.tool summary .targ { color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tool summary .spin { margin-left: auto; }
.tool .body { border-top: 1px solid var(--border); padding: 10px 12px; }
.tool pre { font-family: 'JetBrains Mono', monospace; font-size: .78rem; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow-y: auto; color: var(--fg); }
.tool.err { border-color: var(--red); }

/* Diffs */
.diff { font-family: 'JetBrains Mono', monospace; font-size: .78rem; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.diff .line { padding: 1px 10px; white-space: pre-wrap; word-break: break-word; }
.diff .add { background: var(--diff-add-bg); color: var(--diff-add-fg); } .diff .add::before { content: '+ '; }
.diff .del { background: var(--diff-del-bg); color: var(--diff-del-fg); } .diff .del::before { content: '- '; }
.diff .ctx { color: var(--fg-dim); } .diff .ctx::before { content: '  '; }
.diff .path { background: var(--surface-2); color: var(--fg-dim); padding: 4px 10px; border-bottom: 1px solid var(--border); }

/* Composer */
#composer-wrap { flex: 0 0 auto; border-top: 1px solid var(--border); background: var(--bg); position: relative; }
#file-menu { position: absolute; bottom: 100%; left: 12px; right: 12px; max-height: 240px; overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 6px; box-shadow: 0 -4px 20px rgba(0,0,0,.08); z-index: 5; }
#file-menu .fitem { padding: 9px 14px; font-family: 'JetBrains Mono', monospace; font-size: .82rem; cursor: pointer; border-bottom: 1px solid var(--border); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#file-menu .fitem:last-child { border-bottom: none; } #file-menu .fitem.sel, #file-menu .fitem:hover { background: var(--surface); }
#attachments { display: flex; gap: 8px; padding: 10px 12px 0; flex-wrap: wrap; }
#attachments .chip { position: relative; } #attachments img { width: 54px; height: 54px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
#attachments .x { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: .8rem; cursor: pointer; line-height: 1; }
#composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
#attach-btn { flex: 0 0 auto; width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 50%; background: var(--surface); font-size: 1.1rem; cursor: pointer; }
#input { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 22px; padding: 11px 16px; font-family: inherit; font-size: 1rem; line-height: 1.4; max-height: 40vh; background: var(--surface); color: var(--fg); }
#input:focus { outline: none; border-color: var(--accent); }
#send-btn, #stop-btn { flex: 0 0 auto; width: 42px; height: 42px; border: none; border-radius: 50%; background: var(--accent); color: var(--accent-fg); font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }
#send-btn:disabled { background: var(--surface-2); color: var(--fg-dim); } #stop-btn { background: var(--red); }

/* Settings modal */
#settings-modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 10; }
.modal-card { width: 100%; max-width: 360px; background: var(--bg); border: 1px solid var(--border); border-radius: 18px; padding: 24px; }
.modal-card h2 { font-size: 1.15rem; margin-bottom: 16px; } .modal-card .hint { color: var(--fg-dim); font-size: .8rem; margin: 4px 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
