:root {
  --bg: #0d1117; --panel: #161b22; --panel2: #1c2330; --line: #2a3140; --text: #e6edf3; --muted: #8b949e;
  --gold: #e3b341; --green: #3fb950; --red: #f85149; --blue: #58a6ff;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; overflow: hidden; position: fixed; inset: 0; -webkit-touch-callout: none; }
/* App chrome is not selectable (no accidental text highlight); content still is. */
#side, #tabs, .chat-head, .page-head, .btn, .member, .task { -webkit-user-select: none; user-select: none; }
#msgs, #modalBody, .appr pre { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }

.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #1a1300; }
.btn.danger { border-color: var(--red); color: var(--red); background: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.err { color: var(--red); font-size: 13px; min-height: 18px; }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; margin-left: 6px; font-weight: 700; }

/* login */
#login { height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; align-items: center; }
.login-card h1 { margin: 4px 0 0; font-size: 26px; }
.login-card p { margin: 0 0 8px; color: var(--muted); }
.login-card input { width: 100%; text-align: center; font-size: 22px; letter-spacing: 6px; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); }
.login-card .btn { width: 100%; padding: 14px; font-size: 16px; }

/* shell */
#app { height: 100%; display: grid; grid-template-columns: 300px 1fr; }
#side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow-y: auto; padding-top: var(--safe-t); }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px; font-weight: 700; font-size: 18px; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-left: auto; }
.live.on { background: var(--green); }
.side-label { padding: 12px 16px 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.member { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; background: none; border: 0; padding: 10px 16px; border-left: 3px solid transparent; }
.member:hover { background: var(--panel2); }
.member.active { background: var(--panel2); border-left-color: var(--gold); }
.member .meta { min-width: 0; flex: 1; }
.member .nm { font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.member .nm small { color: var(--muted); font-weight: 400; font-size: 12px; }
.member .ln { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member.busy .ln { color: var(--gold); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #0d1117; flex: none; position: relative; background: var(--gold); }
.avatar.busy::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); border: 2px solid var(--panel); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
#sideNav { display: flex; flex-direction: column; }
#sideNav button { text-align: left; background: none; border: 0; padding: 10px 16px; border-left: 3px solid transparent; }
#sideNav button:hover, #sideNav button.active { background: var(--panel2); }
#sideNav button.active { border-left-color: var(--gold); }
.side-foot { margin-top: auto; padding: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; }

#main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
body[data-view="chat"] #v-chat, body[data-view="tasks"] #v-tasks, body[data-view="schedules"] #v-schedules, body[data-view="approvals"] #v-approvals, body[data-view="connections"] #v-connections { display: flex; }
#tabs { display: none; }

/* chat */
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + var(--safe-t)); border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head .who { flex: 1; min-width: 0; font-weight: 600; }
.sub { color: var(--muted); font-size: 13px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; background: none; border: 0; font-size: 22px; padding: 4px 8px; }
.chat-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr; }
.chat-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.mrow { display: flex; gap: 8px; align-items: flex-start; max-width: min(800px, 94%); }
.mrow.me { align-self: flex-end; }
.mrow.relay { margin-left: 22px; }
.mrow.relay .msg { border-style: dashed; }
.mrow .avatar { width: 32px; height: 32px; font-size: 13px; margin-top: 2px; }
.msg .from .to { color: var(--muted); font-weight: 400; }
.msg { min-width: 0; padding: 10px 14px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: #2b2410; border-color: #5a4a17; }
.msg.sys { align-self: center; background: transparent; color: var(--muted); font-size: 13px; border-style: dashed; }
.msg .from { font-size: 12px; color: var(--gold); font-weight: 600; margin-bottom: 2px; }
.msg .at { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.msg pre { background: #0b0f14; border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 13px; white-space: pre-wrap; }
.msg code { background: #0b0f14; border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.msg h4 { margin: 8px 0 2px; }
.hello { margin: auto; text-align: center; color: var(--muted); max-width: 420px; }
.hello .chips { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.hello .chips button { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; color: var(--text); }
.activity { padding: 6px 16px; color: var(--gold); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); margin-right: 8px; animation: pulse 1.2s infinite; }
#composer { display: flex; gap: 8px; padding: 10px 16px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--panel); align-items: flex-end; }
#input { flex: 1; resize: none; max-height: 160px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 10px 12px; font-size: 16px; }

/* the bot's computer */
.pc-col { display: none; border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 12px 16px 24px; }
.pc-head { display: none; justify-content: space-between; align-items: center; font-weight: 700; padding-bottom: 8px; }
.pc-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 6px; display: flex; justify-content: space-between; align-items: center; }
.pc-label .btn { text-transform: none; letter-spacing: 0; color: var(--text); }
.screen { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #0b0f14; aspect-ratio: 16 / 10; display: grid; place-items: center; }
.screen img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.empty { color: var(--muted); font-size: 13px; padding: 12px; text-align: center; }
.file { display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 8px 0; }
.file span:last-child { color: var(--muted); font-size: 12px; flex: none; }
.mem { display: flex; gap: 8px; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 6px 0; font-size: 13px; }
.mem button { background: none; border: 0; color: var(--muted); }

/* pages */
.page-head { padding: 18px 20px 10px; padding-top: calc(18px + var(--safe-t)); border-bottom: 1px solid var(--line); background: var(--panel); }
.page-head { display: flex; align-items: center; gap: 12px; }
.page-head h2 { margin: 0; font-size: 20px; flex: 1; }
.back.show { display: block; }
#sideNav { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; max-width: 720px; }
.page-body { flex: 1; overflow-y: auto; padding: 16px 20px 32px; display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.task { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.task.child { margin-left: 28px; width: calc(100% - 28px); background: transparent; }
.task .t { flex: 1; min-width: 0; }
.task .t div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.task .t div:last-child { color: var(--muted); font-size: 13px; }
.pill { font-size: 12px; border-radius: 999px; padding: 2px 10px; border: 1px solid var(--line); flex: none; }
.pill.running { color: var(--gold); border-color: var(--gold); }
.pill.done { color: var(--green); border-color: var(--green); }
.pill.failed, .pill.stopped { color: var(--red); border-color: var(--red); }
.form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; align-items: end; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form .wide { grid-column: 1 / -1; }
.form select, .form input, .form textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 16px; color: var(--text); }
.sched { display: flex; gap: 12px; align-items: center; }
.sched .t { flex: 1; min-width: 0; }
.sched .when { color: var(--gold); font-size: 13px; font-weight: 600; }
.sched.off { opacity: .5; }
.appr h3 { margin: 0 0 4px; font-size: 16px; }
.appr .by { color: var(--muted); font-size: 13px; }
.appr pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font: inherit; font-size: 14px; max-height: 320px; overflow-y: auto; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 760px; max-height: 86vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
#modalBody { padding: 16px; overflow-y: auto; }
#modalBody pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; margin: 0; }
.log { color: var(--muted); font-size: 13px; padding: 3px 0; border-bottom: 1px solid var(--line); }

/* desktop: use the whole screen — the bot's computer sits beside the chat */
@media (min-width: 1100px) {
  .chat-body { grid-template-columns: 1fr 400px; }
  .pc-col { display: block; }
  #pcBtn { display: none; }
}

/* phone */
@media (max-width: 899px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #side { display: none; border-right: 0; }
  #main { display: none; }
  body[data-view="team"] #side { display: flex; }
  body:not([data-view="team"]) #main { display: flex; }
  #sideNav, .side-label.office { display: none; }
  .member { padding: 14px 16px; }
  .avatar { width: 46px; height: 46px; }
  .back { display: block; }
  #tabs { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
  #tabs button { background: none; border: 0; padding: 14px 2px; color: var(--muted); font-size: 12px; font-weight: 600; }
  #tabs button.active { color: var(--gold); }
  body[data-view="chat"] #tabs { display: none; }
  .form { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
}
@media (max-width: 1099px) {
  .pc-col.open { display: block; position: fixed; inset: 0; z-index: 10; padding-top: calc(12px + var(--safe-t)); border-left: 0; }
  .pc-col.open .pc-head { display: flex; }
}

/* connections */
.card h3 { margin: 0 0 4px; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; margin: 2px 0 10px; }
.card textarea, .card input[type="password"], .card input[type="text"] { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 16px; color: var(--text); margin-bottom: 10px; }
.card input[type="file"] { width: 100%; font-size: 14px; margin-bottom: 6px; }
.card ol { margin: 6px 0 10px; padding-left: 20px; color: var(--muted); font-size: 13px; }
.card ol code { color: var(--text); overflow-wrap: anywhere; }
.pill.bad { color: var(--red); border-color: var(--red); }
.pill.ok { color: var(--green); border-color: var(--green); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.switch { width: 50px; height: 30px; border-radius: 999px; border: 0; background: var(--line); position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(20px); }
.switch:disabled { opacity: .4; }
.reply { border-top: 1px solid var(--line); padding: 8px 0; font-size: 13px; }
.reply .q { color: var(--muted); }
.reply .a { white-space: pre-line; }

.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

/* live browser the owner can control */
.screen { cursor: pointer; }
.remote { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; padding-top: var(--safe-t); padding-bottom: var(--safe-b); outline: none; }
.remote-bar { display: flex; gap: 6px; padding: 8px; background: var(--panel); align-items: center; flex-wrap: wrap; }
.remote-bar input { flex: 1; min-width: 120px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; font-size: 16px; color: var(--text); }
.remote-view { flex: 1; min-height: 0; display: grid; place-items: center; background: #000; overflow: hidden; }
.remote-view img { max-width: 100%; max-height: 100%; display: block; cursor: crosshair; -webkit-user-drag: none; }
.remote .err { padding: 0 10px; background: var(--panel); }
.logo { border-radius: 22%; }
.row.budget { align-items: center; margin-bottom: 4px; }
.row.budget input { width: 90px; margin: 0; }
