/* mopi — minimal light theme, dense & typographic */
:root {
  --bg: #fdfdfc;
  --panel: #f6f6f4;
  --panel-2: #efefec;
  --border: #e3e3de;
  --border-strong: #cfcec7;
  --text: #1c1c1a;
  --muted: #82817b;
  --faint: #a8a7a0;
  --accent: #2f6fdb;
  --accent-soft: #e8effb;
  --danger: #c0392b;
  --user-bubble: #eef2f8;
  --code-bg: #f4f4f1;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: -apple-system, "Segoe UI", "Inter", Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 13.5px/1.55 var(--sans);
  font-feature-settings: "kern", "liga";
  text-rendering: optimizeLegibility;
}

/* thin, unobtrusive scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
*::-webkit-scrollbar-thumb:hover { background: var(--faint); }
*::-webkit-scrollbar-corner { background: transparent; }

.layout { display: flex; height: 100vh; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 268px; min-width: 268px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto; padding: 10px 8px 20px;
}
.project { margin-bottom: 14px; }
.project-name {
  font-size: 10.5px; font-weight: 600; color: var(--faint);
  text-transform: uppercase; letter-spacing: .1em;
  padding: 0 8px; margin-bottom: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.session {
  padding: 5px 8px; border-radius: 6px; cursor: pointer;
  display: flex; flex-direction: column; gap: 1px;
  border-left: 2px solid transparent;
}
.session:hover { background: var(--panel-2); }
.session.active { background: var(--accent-soft); border-left-color: var(--accent); }
.session .title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session .meta { font-size: 11px; color: var(--muted); }
.empty { color: var(--muted); padding: 12px; }

/* ---------- main ---------- */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.session-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: 12.5px;
  background: var(--bg);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.dot.running { background: #34a853; }

.transcript { flex: 1; overflow-y: auto; padding: 18px 24px 28px; }
.msg { margin-bottom: 18px; max-width: 860px; }
.msg .role {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .09em; color: var(--faint); margin-bottom: 3px;
}
.msg.user {
  background: var(--user-bubble);
  border-radius: 10px; padding: 9px 14px;
}
.msg.user .plain { white-space: pre-wrap; font-family: var(--sans); font-size: 13.5px; }
.msg.toolresult {
  border-left: 2px solid var(--border);
  padding: 2px 0 2px 12px; color: var(--muted);
  font-size: 12.5px;
}
.msg.toolresult.iserror { border-left-color: var(--danger); }
.msg.toolresult .role { color: var(--danger); }
.msg.toolresult .plain { max-height: 240px; overflow-y: auto; }

/* markdown */
.md { font-size: 13.5px; }
.md p { margin: 0 0 9px; }
.md :is(h1,h2,h3,h4) { margin: 16px 0 6px; line-height: 1.3; font-weight: 600; }
.md h1 { font-size: 17px; } .md h2 { font-size: 15px; } .md h3 { font-size: 14px; }
.md ul, .md ol { margin: 0 0 9px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md blockquote { margin: 0 0 9px; padding: 2px 0 2px 12px; border-left: 2px solid var(--border-strong); color: var(--muted); }
.md pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 7px;
  padding: 9px 12px; overflow-x: auto; font-size: 12.5px; line-height: 1.45;
  margin: 0 0 9px;
}
.md code { background: var(--code-bg); border-radius: 4px; padding: 1px 4px; font-family: var(--mono); font-size: 12px; }
.md pre code { padding: 0; background: none; font-size: inherit; }
.md table { border-collapse: collapse; margin: 0 0 9px; font-size: 12.5px; }
.md th, .md td { border: 1px solid var(--border); padding: 3px 10px; text-align: left; }
.md th { background: var(--panel); font-weight: 600; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md hr { border: none; border-top: 1px solid var(--border); }
.plain { white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 12.5px; }

.thinking { color: var(--muted); font-size: 12.5px; margin-bottom: 8px; }
.thinking summary {
  cursor: pointer; font-style: italic; user-select: none;
  color: var(--faint); font-size: 12px;
}
.thinking summary:hover { color: var(--muted); }
.thinking .plain { border-left: 2px solid var(--border); padding-left: 10px; margin-top: 6px; max-height: 300px; overflow-y: auto; }

.toolcall {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 11px; margin-bottom: 8px; font-size: 12.5px;
}
.toolcall .toolname { color: var(--accent); font-weight: 600; font-family: var(--mono); font-size: 12px; margin-bottom: 3px; }
.toolcall pre {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font-family: var(--mono); font-size: 12px; line-height: 1.45;
}

.typing { color: var(--faint); font-size: 11px; letter-spacing: 3px; }

/* ---------- composer ---------- */
.composer {
  border-top: 1px solid var(--border);
  padding: 10px 24px 12px;
  background: var(--panel);
}
.composer textarea {
  width: 100%; resize: vertical; min-height: 44px; max-height: 200px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 9px 12px; font: inherit; line-height: 1.5;
}
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.composer textarea::placeholder { color: var(--faint); }
.composer-actions { display: flex; justify-content: flex-end; margin-top: 7px; }

/* ---------- buttons ---------- */
.btn {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 7px; padding: 5px 14px;
  cursor: pointer; font: inherit; font-size: 13px;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2a62c4; }
.btn.danger { background: none; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: #fdf0ee; }
.btn.small { padding: 2px 10px; font-size: 12px; margin-left: auto; }
.new-chat {
  width: 100%; margin-bottom: 6px; font-size: 12px;
  color: var(--muted); background: none;
  border: 1px dashed var(--border-strong);
}
.new-chat:hover { color: var(--text); background: var(--panel-2); }

/* ---------- login ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px; width: 320px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.login-card h1 { font-size: 18px; margin: 0 0 16px; text-align: center; }
.login-card input {
  width: 100%; padding: 9px 12px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px;
  font: inherit; margin-bottom: 12px;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.login-card button { width: 100%; }

/* ---------- composer bar ---------- */
.composer-bar { display: flex; align-items: center; gap: 8px; }
.composer-bar .btn.primary { margin-left: auto; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 28px; border-radius: 6px; cursor: pointer;
  color: var(--muted); background: none; border: none; font-size: 14px;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.attach-count { font-size: 12px; color: var(--muted); }
.ctl {
  font: inherit; font-size: 12.5px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 3px 6px; max-width: 260px;
  cursor: pointer;
}
.ctl:focus { outline: none; border-color: var(--accent); }
.msg-img img {
  max-width: 320px; max-height: 240px; border-radius: 8px;
  border: 1px solid var(--border); display: block; margin: 6px 0;
}

/* ---------- steer box ---------- */
.steer-box {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 20px; border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
}
.steer-box input {
  flex: 1; padding: 6px 12px; font: inherit; font-size: 13px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--accent); border-radius: 7px;
}
.steer-box input:focus { outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }
.steer-box .btn.small { padding: 5px 12px; margin-left: 0; font-size: 12.5px; }
.btn.outline { background: none; border-color: var(--accent); color: var(--accent); }
.btn.outline:hover { background: var(--accent-soft); }
.status-line { display: flex; align-items: center; gap: 8px; width: 100%; }
.session-header { flex-wrap: wrap; }

/* ---------- collapsible tool blocks ---------- */
details.collapsible { margin-bottom: 8px; }
details.collapsible > summary {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none; list-style: none;
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary .chev {
  color: var(--faint); font-size: 10px; transition: transform .12s;
  flex-shrink: 0;
}
details.collapsible[open] > summary .chev { transform: rotate(90deg); }
details.collapsible > summary:hover { filter: brightness(.97); }

.toolcall {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 7px; padding: 6px 10px;
}
.toolcall > summary .toolname {
  color: var(--accent); font-weight: 600; font-family: var(--mono);
  font-size: 12px; flex-shrink: 0;
}
.toolcall > summary .argline {
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
  direction: rtl; text-align: left;
}
.toolcall > pre {
  margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-word;
  font-family: var(--mono); font-size: 12px; line-height: 1.45;
  max-height: 320px; overflow-y: auto;
}

.msg.toolresult { border-left: 2px solid var(--border); padding-left: 12px; }
.toolresult > summary {
  font-size: 12px; color: var(--faint); font-family: var(--mono);
}
.toolresult > summary .tname { color: var(--accent); font-weight: 600; }
.toolresult > summary .tdur { color: var(--border-strong); }
.toolresult > summary:hover { color: var(--muted); }
.toolresult > summary .errtag {
  color: var(--danger); border: 1px solid var(--danger);
  border-radius: 4px; padding: 0 5px; font-size: 10.5px;
}
.toolresult .plain {
  margin-top: 6px; max-height: 320px; overflow-y: auto;
  background: var(--code-bg); border-radius: 6px; padding: 8px 10px;
}
.toolresult .plain.iserr { color: var(--danger); }

.thinking { color: var(--muted); font-size: 12.5px; }
.thinking > summary { font-style: italic; color: var(--faint); font-size: 12px; }
.thinking > summary:hover { color: var(--muted); }
.thinking .plain {
  border-left: 2px solid var(--border); padding-left: 10px; margin-top: 6px;
  max-height: 300px; overflow-y: auto;
}

/* ---------- mobile ---------- */
.hamburger {
  display: none;
  position: fixed; top: 8px; left: 8px; z-index: 60;
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border-strong);
  align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.35);
}

@media (max-width: 768px) {
  .hamburger { display: flex; }
  .layout { position: relative; }
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%);
    transition: transform .18s ease;
    width: 280px; min-width: 280px;
    box-shadow: 2px 0 12px rgba(0,0,0,.12);
    padding-top: 56px;
  }
  body.sidebar-open #sidebar { transform: translateX(0); }
  body.sidebar-open .backdrop { display: block; }
  #main { width: 100%; }
  .transcript { padding: 56px 12px 16px; }
  .session-header { padding: 8px 12px; font-size: 12px; }
  .steer-box { padding: 8px 12px; flex-wrap: wrap; }
  .composer { padding: 8px 12px 10px; }
  .composer-bar { flex-wrap: wrap; gap: 6px; }
  .composer-bar .ctl { max-width: 46vw; }
  .composer-bar .btn.primary { margin-left: auto; }
  .msg { max-width: 100%; }
  .msg-img img { max-width: 100%; }
}

/* ---------- engine switch + permission bar ---------- */
.engine-ctl { margin-left: auto; display: flex; gap: 4px; }
.engine-btn { opacity: .55; }
.engine-btn.engine-active { opacity: 1; border-color: var(--accent); color: var(--accent); }
.yolo-btn.yolo-on { border-color: #d9534f; color: #d9534f; }
.perm-bar {
  display: flex; flex-direction: column; gap: 6px;
  margin: 8px 20px; padding: 10px 14px;
  border: 1px solid #d9534f; border-radius: 8px;
  background: #fff6f5;
}
.perm-title { font-size: 13px; font-weight: 600; }
.perm-args { font-size: 11.5px; white-space: pre-wrap; word-break: break-word; max-height: 120px; overflow: auto; background: var(--bg); padding: 6px 8px; border-radius: 6px; }
.perm-actions { display: flex; gap: 8px; }
