*, *::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;
  /* Notch / status-bar inset, readable from JS to keep the shell modal clear
     of the top chrome when pinned to the visual viewport. */
  --sat: env(safe-area-inset-top, 0px);
}

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%; min-width: 0; }
.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; }
.assistant-content { display: flex; flex-direction: column; gap: 10px; width: 100%; min-width: 0; }

/* ── Markdown in assistant ── */
/* Keep long URLs / tokens from blowing out the container.
   `overflow-wrap: anywhere` is the modern, smart "break only when needed" — it
   leaves normal prose alone and only intervenes when a word would overflow. */
.md-text { line-height: 1.6; min-width: 0; overflow-wrap: anywhere; }
.md-text p { margin-bottom: 8px; }
.md-text p:last-child { margin-bottom: 0; }
.md-text a { color: var(--accent); }
.md-text img, .md-text video { max-width: 100%; height: auto; }
.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); word-break: break-all; }
/* Code blocks: never wrap, scroll horizontally instead — preserves alignment. */
.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; max-width: 100%; }
.md-text pre code { background: none; padding: 0; color: var(--text); white-space: pre; word-break: normal; }
.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; }
/* Tables: turn into a scrollable strip when wider than container, no layout break. */
.md-text table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 8px 0; }
.md-text th, .md-text td { border: 1px solid var(--border); padding: 6px 10px; white-space: nowrap; }
.md-text th { background: var(--surface2); font-weight: 600; text-align: left; }

/* ── 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: 8px 16px 8px; background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0; position: relative; }
.image-previews { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.image-previews:empty { display: none; }   /* no dead space when nothing is attached */
.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; }
.image-previews .preview-file .file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 56px; padding: 0 10px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text);
  max-width: 220px;
}
.image-previews .preview-file .file-icon { font-size: 16px; flex-shrink: 0; }
.image-previews .preview-file .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.image-previews .preview-file .file-size { color: var(--text-muted); font-size: 11px; flex-shrink: 0; }
.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: 112px; 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; }

/* ── Split send button (Gmail-style): main = send now, ▾ = schedule ── */
.send-split { display: flex; flex-direction: column; gap: 2px; }
.send-split .btn-send { border-radius: var(--radius-sm) var(--radius-sm) 3px 3px; }
.btn-send-menu { width: 40px; height: 18px; border: none; border-radius: 3px 3px var(--radius-sm) var(--radius-sm); background: var(--accent); color: var(--bg); cursor: pointer; font-size: 10px; line-height: 1; display: flex; align-items: center; justify-content: center; opacity: .85; transition: opacity .15s; }
.btn-send-menu:hover { opacity: 1; }
.btn-send-menu:disabled { opacity: .4; cursor: not-allowed; }

/* Pull-up schedule menu */
#sendMenu { position: fixed; z-index: 500; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0,0,0,.45); padding: 6px; min-width: 230px; }
#sendMenu .send-menu-title { font-size: 11px; color: var(--text-muted); padding: 4px 8px 6px; }
#sendMenu .send-menu-item { display: flex; justify-content: space-between; gap: 12px; width: 100%; text-align: left; background: none; border: none; color: var(--text); font-size: 13px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
#sendMenu .send-menu-item:hover, #sendMenu .send-menu-item:active { background: var(--surface2); }
#sendMenu .send-menu-item .when { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
#sendMenu .send-menu-custom { display: flex; gap: 6px; padding: 6px 8px 4px; border-top: 1px solid var(--border); margin-top: 4px; }
#sendMenu .send-menu-custom input { flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; padding: 6px 8px; color-scheme: dark; }
#sendMenu .send-menu-custom button { background: var(--accent); border: none; color: var(--bg); border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer; }

/* Model/effort quick picker (pull-up on the model pill) */
#modelMenu { position: fixed; z-index: 500; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0,0,0,.45); padding: 6px; min-width: 220px; }
#modelMenu .mm-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 6px 8px; }
#modelMenu .mm-title { font-size: 11px; color: var(--text-muted); }
#modelMenu .mm-gear { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); font-size: 13px; line-height: 1; padding: 4px 8px; cursor: pointer; }
#modelMenu .mm-gear:hover { color: var(--text); background: var(--surface2); }
#modelMenu .mm-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: none; color: var(--text); font-size: 13px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
#modelMenu .mm-item:hover, #modelMenu .mm-item:active { background: var(--surface2); }
#modelMenu .mm-item .chk { color: var(--accent); width: 14px; flex-shrink: 0; text-align: center; }
#modelMenu .mm-effort { display: flex; align-items: center; gap: 8px; padding: 8px 8px 4px; border-top: 1px solid var(--border); margin-top: 4px; }
#modelMenu .mm-effort label { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
#modelMenu .mm-effort select { flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 13px; padding: 6px 8px; }

/* Scheduled (reserved) prompts badge + list */
.sched-badge { display: none; align-items: center; gap: 5px; padding: 4px 10px; background: transparent; border: 1px solid var(--accent); color: var(--accent); border-radius: var(--radius-sm); font-size: 12px; cursor: pointer; white-space: nowrap; }
.sched-badge.on { display: inline-flex; }
#schedList { position: fixed; z-index: 500; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0,0,0,.45); padding: 6px; min-width: 260px; max-width: 86vw; }
#schedList .sched-item { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; font-size: 13px; }
#schedList .sched-item + .sched-item { border-top: 1px solid var(--border); }
#schedList .sched-item .when { flex: none; color: var(--accent); font-size: 12px; white-space: nowrap; }
#schedList .sched-item .txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
#schedList .sched-item .x { flex: none; background: none; border: none; color: var(--text-muted); font-size: 14px; cursor: pointer; padding: 2px 6px; }
#schedList .sched-item .x:hover { color: var(--red, #f85149); }

/* ── Drag & drop overlay ── */
body.drag-over::after {
  content: 'Drop files to attach';
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: rgba(13, 17, 23, .82);
  border: 3px dashed var(--accent);
  color: var(--accent);
  font-size: 20px; font-weight: 600; letter-spacing: .02em;
  pointer-events: none;
  backdrop-filter: blur(2px);
}

/* ── 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%; }
}

/* ── 3-panel: desktop persistent sidebars ── */
/* Keep `position: relative` so the inner absolute-positioned resize handle
   (terminal.html: .side-resize-handle) anchors to the sidebar, not the viewport.
   Override only the mobile transform reset. */
@media (min-width: 768px) {
  .side { transform: none !important; }
  .side-left  { border-right-width: 1px; }
  .side-right { border-left-width: 1px; }
}
