:root {
  --purple: #A12885;
  --purple-dark: #5E1850;
  --ink: #1A0A16;
  --bg: #F4F1F3;
  --line: #E6DFE4;
  --muted: #7A6F76;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); height: 100vh;
  display: flex; flex-direction: column;
}

.top {
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  color: #fff; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between;
}
.brand { font-weight: 800; font-size: 1.15rem; }
.brand small { font-weight: 600; opacity: .8; font-size: .85rem; }
.brand .bot { font-size: 1.2rem; }
.meta { display: flex; align-items: center; gap: 10px; }
.pill {
  background: rgba(255,255,255,.16); padding: 4px 10px; border-radius: 999px;
  font-size: .76rem; font-weight: 700;
}
.conn-off { background: #C2410C; }
.conn-on { background: #15803D; }
.ghost {
  background: transparent; border: 1.5px solid rgba(255,255,255,.5); color: #fff;
  border-radius: 999px; padding: 5px 14px; font-weight: 700; cursor: pointer; font-size: .8rem;
}
.ghost:hover { background: rgba(255,255,255,.15); }

main { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 14px; min-height: 0; }

/* chat */
.chat { display: flex; flex-direction: column; background: #fff; border-radius: 14px;
  box-shadow: 0 4px 18px rgba(26,10,22,.08); overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { padding: 11px 14px; border-radius: 14px; font-size: .92rem; line-height: 1.5; max-width: 92%; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--purple), var(--purple-dark)); color: #fff; }
.msg.agent { align-self: flex-start; background: #F2EEF1; white-space: normal; }
.msg.system { align-self: center; background: #FFF6DD; color: #6b5300; font-size: .82rem; font-weight: 600; }
.msg.error { align-self: center; background: #FDECEC; color: #B3261E; font-size: .85rem; font-weight: 600; }
.msg.done { align-self: center; background: #E7F6E9; color: #1d6b2a; font-size: .86rem; font-weight: 700; }
.msg b { color: inherit; }

/* rendered markdown inside agent replies */
.msg.agent > b { display: block; font-weight: 800; margin-bottom: 5px; }
.msg.agent p { margin: 0 0 7px; }
.msg.agent p:last-child { margin-bottom: 0; }
.msg.agent h2, .msg.agent h3, .msg.agent h4, .msg.agent h5, .msg.agent h6 {
  margin: 9px 0 5px; font-size: 1rem; font-weight: 800; color: var(--ink);
}
.msg.agent ul, .msg.agent ol { margin: 5px 0 7px; padding-left: 20px; }
.msg.agent li { margin: 2px 0; }
.msg.agent code {
  background: #E6DFE4; padding: 1px 5px; border-radius: 4px;
  font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: .85em;
}
.msg.agent pre {
  background: #1A0A16; color: #F2EEF1; padding: 10px 12px;
  border-radius: 8px; overflow-x: auto; margin: 7px 0;
}
.msg.agent pre code { background: none; padding: 0; color: inherit; }
.msg.agent strong { font-weight: 800; }
.msg.agent em { font-style: italic; }
.msg.agent a { color: var(--purple); font-weight: 700; }

.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.composer input { flex: 1; padding: 12px 14px; border: 1.6px solid var(--line); border-radius: 999px; font-size: .92rem; }
.composer input:focus { outline: none; border-color: var(--purple); }
.composer button {
  background: linear-gradient(135deg, var(--purple), var(--purple-dark)); color: #fff;
  border: none; border-radius: 999px; padding: 0 22px; font-weight: 800; cursor: pointer;
}
.composer button:disabled { opacity: .5; cursor: not-allowed; }

/* side */
.side { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.panel { background: #fff; border-radius: 14px; box-shadow: 0 4px 18px rgba(26,10,22,.08);
  display: flex; flex-direction: column; overflow: hidden; }
.panel-head { padding: 9px 14px; font-weight: 800; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted); border-bottom: 1px solid var(--line); }
.browser { flex: 3; min-height: 0; }
.activity { flex: 2; min-height: 0; }
.screen { flex: 1; background: #1A0A16; display: grid; place-items: center; overflow: hidden; }
.screen img { width: 100%; height: 100%; object-fit: contain; display: none; }
#noframe { color: #8b7d85; font-size: .85rem; }

.log { flex: 1; overflow-y: auto; padding: 10px 14px; font-size: .82rem; line-height: 1.5;
  font-family: 'SF Mono', Menlo, Consolas, monospace; }
.log .row { padding: 3px 0; border-bottom: 1px solid #F2EEF1; }
.log .t-think { color: var(--muted); }
.log .t-tool { color: var(--purple); font-weight: 700; }
.log .t-ok { color: #1d6b2a; }
.log .t-err { color: #B3261E; }
.log .t-guard { color: #C2410C; font-weight: 700; }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; grid-auto-rows: minmax(280px, auto); }
}
