:root {
  color-scheme: dark;
  --bg: #181818;
  --panel: #1f1f1f;
  --raised: #252526;
  --line: #2e2e2e;
  --line-soft: #262626;
  --text: #d6d6d6;
  --text-strong: #f2f2f2;
  --muted: #8b8b8b;
  --accent: #4c8dff;
  --ok: #4ec98a;
  --err: #f07178;
  --warn: #e2b341;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior-y: none;
}
#app {
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
#menu {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
}
#menu:active { background: var(--raised); }
#menu svg { width: 20px; height: 20px; }
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.titles { min-width: 0; }
.title { font-size: 14px; font-weight: 600; color: var(--text-strong); }
.sub {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 62vw;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #5a5a5a;
  flex: none;
  transition: background 160ms ease;
}
.dot.on { background: var(--ok); }
.dot.busy { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

#install {
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
}

#drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 29;
  background: rgba(0, 0, 0, 0.58);
}
#drawer {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  width: min(84vw, 330px);
  display: flex;
  flex-direction: column;
  background: #1b1b1b;
  border-right: 1px solid var(--line);
  transform: translateX(-102%);
  transition: transform 180ms ease;
  padding-top: env(safe-area-inset-top);
}
#drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--line);
}
.drawer-head strong { color: var(--text-strong); font-size: 16px; }
.drawer-head div div { color: var(--muted); font-size: 12px; margin-top: 2px; }
#drawer-close {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 25px;
  line-height: 1;
}
#project-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.project-item {
  width: 100%;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.project-item.active { background: var(--raised); color: var(--text-strong); }
.project-item:active { background: #2a2a2a; }
.project-icon { color: var(--muted); font-size: 16px; }
.project-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.project-state {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: transparent;
}
.project-state.busy { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
.drawer-foot {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

#sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
#sheet[hidden] { display: none; }
.sheet-card {
  width: 100%;
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 85vh;
  overflow-y: auto;
}
.sheet-card h2 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--text-strong);
}
.sheet-card ol { margin: 0 0 14px; padding-left: 20px; }
.sheet-card li { margin: 7px 0; color: var(--text); }
.sheet-card b { color: var(--text-strong); }
#sheet-checks {
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
  margin-bottom: 14px;
  font-size: 12.5px;
  color: var(--muted);
}
#sheet-checks .row { display: flex; gap: 8px; align-items: baseline; }
#sheet-checks .yes { color: var(--ok); }
#sheet-checks .no { color: var(--warn); }
#sheet-close {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  padding: 12px;
}

#progress { height: 2px; background: var(--line-soft); overflow: hidden; }
#progress span {
  display: block;
  height: 100%;
  width: 35%;
  background: var(--accent);
  animation: slide 1.2s ease-in-out infinite;
}
@keyframes slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(340%); }
}

#log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}

.msg { max-width: 100%; word-break: break-word; }
.msg.user {
  align-self: flex-end;
  max-width: 88%;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  color: var(--text-strong);
  white-space: pre-wrap;
}
.msg.bot { align-self: stretch; color: var(--text); }
.msg.sys {
  align-self: center;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  max-width: 90%;
}
.msg.err {
  align-self: stretch;
  color: var(--err);
  border: 1px solid #4a2b2d;
  background: #241a1b;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
}

.msg.bot p { margin: 0 0 10px; }
.msg.bot p:last-child { margin-bottom: 0; }
.msg.bot h3, .msg.bot h4, .msg.bot h5, .msg.bot h6 {
  margin: 14px 0 6px;
  font-size: 15px;
  color: var(--text-strong);
}
.msg.bot ul, .msg.bot ol { margin: 0 0 10px; padding-left: 20px; }
.msg.bot li { margin: 3px 0; }
.msg.bot code {
  font-family: var(--mono);
  font-size: 13px;
  background: #232323;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}
.msg.bot pre {
  margin: 0 0 10px;
  padding: 10px 12px;
  background: #141414;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
}
.msg.bot pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.5;
}
.caret {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.tool {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  padding: 7px 11px;
}
.tool .label {
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool.done { color: #7d7d7d; }
.tool .mark { flex: none; width: 13px; height: 13px; display: grid; place-items: center; }
.spinner {
  width: 11px;
  height: 11px;
  border: 1.6px solid #4a4a4a;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.check { color: var(--ok); font-size: 12px; line-height: 1; }

.meta {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  padding-top: 2px;
}
.meta::before,
.meta::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); }
.meta.finished { color: var(--ok); }

#composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}
textarea {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  max-height: 148px;
  border: 1px solid var(--line);
  background: #1a1a1a;
  color: var(--text-strong);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
}
textarea::placeholder { color: #6f6f6f; }
textarea:focus { outline: none; border-color: #3d3d3d; }
#composer button {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  padding: 0;
}
#composer button svg { width: 20px; height: 20px; display: block; }
button#send { background: var(--accent); color: #fff; }
button#stop { background: var(--raised); color: var(--err); border: 1px solid #4a2b2d; }
button:disabled { opacity: 0.4; }
