*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-dim: #1f3a5f;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --purple: #bc8cff;
  --user-bubble: #1f3a5f;
  --assistant-bg: #161b22;
  --tool-bg: #0d1117;
  --radius: 12px;
  --radius-sm: 6px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 15px; line-height: 1.5; }

a { color: var(--accent); text-decoration: none; }

/* ── Layout ── */
.page { display: flex; flex-direction: column; height: 100vh; }
.header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.header h1 { font-size: 16px; font-weight: 600; flex: 1; }
.header .avatar { width: 28px; height: 28px; border-radius: 50%; }

/* ── Login ── */
.login-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; gap: 24px; padding: 24px; }
.login-logo { font-size: 48px; }
.login-wrap h1 { font-size: 24px; font-weight: 600; }
.login-wrap p { color: var(--text-muted); text-align: center; max-width: 320px; }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 12px 24px; border-radius: var(--radius-sm); border: none; cursor: pointer; font-size: 15px; font-weight: 500; transition: opacity .15s; }
.btn:hover { opacity: .85; }
.btn-github { background: #238636; color: #fff; }
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--red); padding: 6px 12px; font-size: 13px; border-radius: var(--radius-sm); cursor: pointer; }
.btn-danger:hover { background: rgba(248,81,73,.15); }
.btn-sm { padding: 6px 14px; font-size: 13px; }

/* ── App (session list) ── */
.session-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.session-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; align-items: center; gap: 12px; }
.session-card .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
.session-card .dir { flex: 1; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-card .actions { display: flex; gap: 8px; flex-shrink: 0; }
.new-session { padding: 16px; border-top: 1px solid var(--border); background: var(--surface); display: flex; gap: 8px; }
.new-session input { flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); padding: 10px 12px; font-size: 14px; outline: none; }
.new-session input:focus { border-color: var(--accent); }
.empty-state { text-align: center; color: var(--text-muted); padding: 48px 16px; }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }

/* ── Terminal / Chat ── */
.chat-wrap { display: flex; flex-direction: column; height: 100vh; }
.chat-header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-header .back { color: var(--accent); font-size: 22px; line-height: 1; cursor: pointer; text-decoration: none; }
.chat-header .dir-label { flex: 1; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }

/* ── Message bubbles ── */
.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg-user { align-items: flex-end; }
.msg-user .bubble { background: var(--user-bubble); border-radius: var(--radius) var(--radius) var(--radius-sm) var(--radius); padding: 10px 14px; color: var(--text); max-width: 80%; white-space: pre-wrap; word-break: break-word; }
.msg-user .img-previews { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.msg-user .img-previews img { max-width: 120px; max-height: 120px; border-radius: var(--radius-sm); object-fit: cover; }

.msg-assistant { align-items: flex-start; }
.msg-assistant .label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.msg-assistant .label .claude-dot { width: 16px; height: 16px; border-radius: 50%; background: linear-gradient(135deg, #d97706, #b45309); flex-shrink: 0; }
.assistant-content { display: flex; flex-direction: column; gap: 10px; width: 100%; }

/* ── Markdown in assistant ── */
.md-text { line-height: 1.6; }
.md-text p { margin-bottom: 8px; }
.md-text p:last-child { margin-bottom: 0; }
.md-text code { background: var(--surface2); border-radius: 4px; padding: 2px 6px; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; color: var(--purple); }
.md-text pre { background: var(--tool-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; overflow-x: auto; margin: 8px 0; }
.md-text pre code { background: none; padding: 0; color: var(--text); }
.md-text ul, .md-text ol { padding-left: 20px; margin-bottom: 8px; }
.md-text li { margin-bottom: 4px; }
.md-text h1,.md-text h2,.md-text h3,.md-text h4 { margin: 12px 0 6px; font-weight: 600; }
.md-text strong { color: #fff; font-weight: 600; }
.md-text blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-muted); margin: 8px 0; }
.md-text hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* ── Tool use cards ── */
.tool-card { background: var(--tool-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.tool-card-header { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; user-select: none; }
.tool-card-header:hover { background: var(--surface2); }
.tool-badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; }
.badge-bash { background: rgba(59,130,246,.2); color: #93c5fd; }
.badge-read { background: rgba(34,197,94,.15); color: #86efac; }
.badge-write { background: rgba(234,179,8,.15); color: #fde68a; }
.badge-edit { background: rgba(234,179,8,.15); color: #fde68a; }
.badge-ls { background: rgba(139,92,246,.15); color: #c4b5fd; }
.badge-default { background: rgba(148,163,184,.1); color: var(--text-muted); }
.tool-card-title { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--text-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-card-chevron { color: var(--text-muted); font-size: 12px; transition: transform .2s; }
.tool-card.open .tool-card-chevron { transform: rotate(90deg); }
.tool-card-body { display: none; padding: 10px 12px; border-top: 1px solid var(--border); }
.tool-card.open .tool-card-body { display: block; }
.tool-card-body pre { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--text); white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow-y: auto; }

/* ── Thinking block ── */
.thinking-block { background: rgba(188,140,255,.05); border: 1px solid rgba(188,140,255,.2); border-radius: var(--radius-sm); padding: 10px 12px; }
.thinking-block .label { font-size: 11px; color: var(--purple); margin-bottom: 6px; font-weight: 600; }
.thinking-block pre { font-size: 12px; color: var(--text-muted); white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow-y: auto; }

/* ── Streaming cursor ── */
.cursor { display: inline-block; width: 2px; height: 1em; background: var(--accent); vertical-align: text-bottom; animation: blink .8s step-end infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }

/* ── Cost / usage pill ── */
.usage-pill { font-size: 11px; color: var(--text-muted); padding: 3px 8px; border-radius: 99px; background: var(--surface2); align-self: flex-start; }

/* ── Error message ── */
.msg-error .bubble { background: rgba(248,81,73,.15); border: 1px solid rgba(248,81,73,.3); color: var(--red); padding: 10px 14px; border-radius: var(--radius-sm); }

/* ── Input area ── */
.input-area { padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0; }
.image-previews { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.image-previews .preview-item { position: relative; }
.image-previews img { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius-sm); display: block; }
.image-previews .remove-img { position: absolute; top: -4px; right: -4px; width: 18px; height: 18px; background: var(--red); color: #fff; border-radius: 50%; border: none; cursor: pointer; font-size: 11px; display: flex; align-items: center; justify-content: center; line-height: 1; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.input-row textarea { flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); padding: 10px 12px; font-size: 15px; resize: none; outline: none; max-height: 180px; min-height: 44px; font-family: inherit; line-height: 1.5; }
.input-row textarea:focus { border-color: var(--accent); }
.input-row textarea::placeholder { color: var(--text-muted); }
.input-actions { display: flex; flex-direction: column; gap: 6px; }
.btn-icon { width: 40px; height: 40px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface2); color: var(--text-muted); cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; transition: background .15s, color .15s; }
.btn-icon:hover { background: var(--surface); color: var(--text); }
.btn-send { width: 40px; height: 40px; border-radius: var(--radius-sm); border: none; background: var(--accent); color: var(--bg); cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; transition: opacity .15s; }
.btn-send:hover { opacity: .85; }
.btn-send:disabled { opacity: .4; cursor: not-allowed; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ── */
@media (min-width: 768px) {
  .chat-messages { padding: 24px max(24px, calc(50% - 380px)); }
  .msg-user .bubble { max-width: 65%; }
}
