/* Dark-first, minimal: near-black canvas, flat sidebar, soft rounded cards, thin borders, white primary pill. */
:root {
  --bg: #0b0b0c; --side: #0f0f10; --panel: #151516; --panel2: #1b1b1d; --hover: #1d1d20; --line: #2a2a2e;
  --text: #ececee; --muted: #8b8b93; --faint: #5e5e66;
  --primary: #f4f4f5; --primary-text: #0b0b0c; --brand: #3b82f6;
  --ok: #3fb950; --warn: #d9a441; --bad: #f2555a; --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafafa; --side: #f3f3f4; --panel: #ffffff; --panel2: #f4f4f5; --hover: #ececee; --line: #e2e2e6;
    --text: #18181b; --muted: #6b6b73; --faint: #a1a1a9; --primary: #18181b; --primary-text: #fafafa;
    --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 18px; font-weight: 600; margin: 0 0 12px; } h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 22px 0 8px; } h3 { font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .right { margin-left: auto; }
svg.icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* layout */
.shell { display: grid; grid-template-columns: 264px 1fr; height: 100vh; }
.menu-btn { display: none; position: fixed; top: 8px; left: 8px; z-index: 12; background: var(--panel); border: 1px solid var(--line); }
.shell.collapsed { grid-template-columns: 0 1fr; } .shell.collapsed .menu-btn { display: inline-flex; } .shell.collapsed .chat-head { padding-left: 54px; } .shell.collapsed .side { display: none; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 10px 8px; }
.side-top { display: flex; align-items: center; gap: 4px; padding: 2px 4px 8px; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--muted); cursor: pointer; display: inline-flex; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.side-scroll { flex: 1; overflow: auto; min-height: 0; }
.side-label { font-size: 11.5px; color: var(--faint); padding: 14px 10px 4px; letter-spacing: .02em; }
.item { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 9px; color: var(--text); cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.item:hover { background: var(--hover); } .item.active { background: var(--panel2); }
.item.muted-item { color: var(--muted); }
.badge { margin-left: auto; background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; }
.side-bottom { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 6px; }
.userrow { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.userrow .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usagebar { height: 3px; background: var(--panel2); border-radius: 99px; overflow: hidden; margin: 4px 10px 8px; } .usagebar > span { display: block; height: 100%; background: var(--muted); }
.main { overflow: auto; min-width: 0; }
.page { padding: 24px 28px; max-width: 1100px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; min-height: 48px; }

/* controls */
input, select, textarea { width: 100%; padding: 8px 11px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--faint); }
input[type=checkbox] { width: auto; } input[type=color] { padding: 2px; height: 36px; }
textarea { min-height: 84px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
button { padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; }
button:hover { background: var(--hover); }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 500; }
button.primary:hover { opacity: .9; }
button.danger { color: var(--bad); background: none; }
button.ghost { background: none; border-color: transparent; color: var(--muted); } button.ghost:hover { color: var(--text); background: var(--hover); }
button:disabled { opacity: .45; cursor: not-allowed; }
.chip { padding: 5px 13px; border-radius: 99px; border: 1px solid transparent; background: none; color: var(--muted); } .chip:hover { background: var(--hover); color: var(--text); }
.chip.on { background: var(--primary); color: var(--primary-text); }
.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 11.5px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .col { display: flex; flex-direction: column; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; } th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; } th { color: var(--muted); font-weight: 500; }
.warnbox:empty { display: none; }
.editor { scroll-margin-top: 64px; }
.warnbox { border: 1px solid var(--line); border-left: 3px solid var(--warn); background: var(--panel); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.toast { position: fixed; bottom: 18px; right: 18px; background: var(--primary); color: var(--primary-text); padding: 9px 14px; border-radius: 12px; z-index: 50; max-width: 420px; box-shadow: 0 8px 30px rgba(0,0,0,.4); }

/* live browser view */
.shot { width: 100%; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; background: #111; cursor: crosshair; display: block; min-height: 120px; }
.empty { color: var(--muted); padding: 18px 8px; text-align: center; }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; font-size: 15px; }
.scrim { display: none; }
.editor-hint { border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px 18px; text-align: center; color: var(--muted); }

/* avatars & status */
.avatar { width: 24px; height: 24px; display: inline-block; flex: none; }
.avatar.circle { border-radius: 50%; } .avatar.square { border-radius: 6px; } .avatar.diamond { transform: rotate(45deg) scale(.75); border-radius: 4px; } .avatar.hex { border-radius: 40% 60% 55% 45%; }
.avatar.lg { width: 40px; height: 40px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); display: inline-block; flex: none; }
.dot.thinking, .dot.working { background: var(--brand); animation: pulse 1s infinite; } .dot.waiting { background: var(--warn); } .dot.blocked { background: var(--bad); } .dot.idle { background: var(--ok); }
@keyframes pulse { 50% { opacity: .25; } }
.initial { width: 28px; height: 28px; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); flex: none; }

/* chat */
.chat { display: flex; flex-direction: column; height: 100vh; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid transparent; min-height: 52px; }
.msgs { flex: 1; overflow: auto; padding: 8px 18px 16px; }
.col-center { max-width: 760px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 14px; }
.msg { white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.msg.user { align-self: flex-end; background: var(--panel2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 18px 18px 4px 18px; max-width: 85%; }
.msg.bot { display: flex; gap: 10px; align-items: flex-start; } .msg.bot .body { flex: 1; min-width: 0; } .msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg.system { align-self: center; color: var(--muted); font-size: 12.5px; background: var(--panel); border: 1px solid var(--line); padding: 5px 12px; border-radius: 99px; max-width: 90%; text-align: center; }
.composer-wrap { padding: 8px 18px 18px; }
.composer { max-width: 760px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 10px 10px 10px 18px; display: flex; align-items: flex-end; gap: 8px; }
.composer:focus-within { border-color: var(--faint); }
.composer textarea { border: 0; background: none; min-height: 28px; max-height: 200px; padding: 6px 0; resize: none; flex: 1; border-radius: 0; }
.send { width: 34px; height: 34px; padding: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--primary); color: var(--primary-text); border: 0; flex: none; }
.send.stop { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.home { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; }
.home h1 { font-size: 26px; font-weight: 500; text-align: center; margin: 0; }
.home .composer { width: min(720px, 100%); }
.suggest .chip { border-color: var(--line); }
.suggest { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 720px; }

/* modal (settings) */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: min(980px, 100%); height: min(680px, 90vh); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; display: grid; grid-template-columns: 210px 1fr; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.modal-nav { background: var(--side); border-right: 1px solid var(--line); padding: 12px 8px; overflow: auto; display: flex; flex-direction: column; gap: 1px; }
.modal-nav input { margin-bottom: 8px; border-radius: 9px; padding: 7px 10px; }
.modal-body { overflow: auto; padding: 20px 24px; position: relative; }
.modal-close { position: absolute; top: 10px; right: 10px; }
.modal-body .row > .pill.right { margin-right: 34px; }

/* "Connect apps" style grid */
.app-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 24px; }
.app { min-width: 0; }
.app { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.app .tile { width: 36px; height: 36px; border-radius: 9px; background: var(--panel2); border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; color: var(--muted); flex: none; }
.app .info { flex: 1; min-width: 0; } .app .info .t { font-weight: 500; } .app .info .d { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app button { padding: 5px 14px; }
.sub { grid-column: 1 / -1; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }

.login { max-width: 360px; margin: 14vh auto; }

@media (max-width: 800px) {
  body { font-size: 15px; }
  input, select, textarea { font-size: 16px; }              /* stops iPhones zooming in when a field is tapped */
  button { min-height: 40px; }
  .shell { grid-template-columns: 1fr; height: auto; min-height: 100dvh; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 15; transform: translateX(-100%); transition: transform .15s; box-shadow: 0 0 40px rgba(0,0,0,.5); padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .shell.open .side { transform: none; }
  .shell.collapsed .side { display: flex; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 14; }
  .shell.open .scrim { display: block; }
  .menu-btn { display: inline-flex; top: calc(8px + env(safe-area-inset-top)); left: 8px; }
  .shell.open .menu-btn { display: none; }
  .page { padding: calc(58px + env(safe-area-inset-top)) 16px 24px; }
  .chat { height: 100dvh; }
  .chat-head { padding: calc(8px + env(safe-area-inset-top)) 12px 8px 58px; flex-wrap: wrap; row-gap: 2px; }
  .chat-head .role-text { display: none; }
  .msgs { padding: 8px 12px 12px; }
  .composer-wrap { padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); }
  .home { justify-content: flex-start; padding-top: 22vh; }
  .home h1 { font-size: 22px; }
  .grid2, .app-grid { grid-template-columns: minmax(0, 1fr); }
  .card { overflow-x: auto; }
  .card table { min-width: 560px; }
  .backdrop { padding: 0; align-items: stretch; }
  .modal { width: 100%; height: 100dvh; border-radius: 0; border: 0; grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .modal-nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: calc(8px + env(safe-area-inset-top)) 8px 8px; gap: 4px; }
  .modal-nav input { display: none; }
  .modal-nav .item { white-space: nowrap; width: auto; flex: none; }
  .modal-body { padding: 16px 16px 28px; }
  .modal-close { position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 10px; z-index: 22; background: var(--panel2); border: 1px solid var(--line); }
  .modal-body .row > .pill.right { margin-right: 0; }
  .app { flex-wrap: wrap; }
}
