:root {
  --bg: #0b1222;
  --panel: #111a2e;
  --panel-2: #0f1729;
  --line: #1f2a44;
  --text: #e2e8f0;
  --muted: #8b97ad;
  --accent: #f5a524;
  --accent-2: #38bdf8;
  --working: #4ade80;
  --idle: #fbbf24;
  --off: #8b93a3;
  --meeting: #a78bfa;
  --danger: #f87171;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }

/* ---------- buttons */
.btn { border: 1px solid var(--line); background: #17223a; border-radius: 8px; padding: 7px 14px; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { background: #1d2a47; border-color: #2c3b5e; }
.btn:disabled { opacity: .6; cursor: default; }
.btn:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible, .team-row:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1b1203; font-weight: 600; }
.btn-primary:hover { background: #ffb53d; border-color: #ffb53d; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }

/* ---------- brand */
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-center { justify-content: center; }
.brand-logo { display: inline-flex; align-items: flex-end; gap: 2px; width: 26px; height: 26px; padding: 4px; border-radius: 6px; background: #13213f; border: 1px solid #23365f; }
.brand-logo i { display: block; width: 4px; background: var(--accent); }
.brand-logo i:nth-child(1) { height: 9px; }
.brand-logo i:nth-child(2) { height: 15px; background: var(--accent-2); }
.brand-logo i:nth-child(3) { height: 6px; background: var(--working); }

/* ---------- app shell */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.topbar { flex: 0 0 auto; height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 16px; margin: 0; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user { font-weight: 600; }
.conn { font: 11px var(--mono); padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); text-transform: uppercase; letter-spacing: .5px; }
.conn-on { color: var(--working); border-color: #1f5135; background: #0f2a1c; }
.conn-off { color: var(--muted); }
.my-status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border: 1px solid var(--line); border-radius: 8px; background: #121c31; }
.my-status select { background: transparent; border: 0; padding: 3px 2px; cursor: pointer; }
.my-status option { background: #121c31; }

.layout { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) clamp(300px, 25vw, 400px); }
.stage { position: relative; min-width: 0; min-height: 0; background: radial-gradient(ellipse at center, #121c33 0%, var(--bg) 70%); }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.legend { position: absolute; left: 12px; bottom: 10px; display: flex; gap: 12px; padding: 5px 10px; border-radius: 99px; background: rgba(11, 18, 34, .78); border: 1px solid var(--line); font: 11px var(--mono); color: var(--muted); pointer-events: none; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

.side { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--panel); }
.panel { display: flex; flex-direction: column; min-height: 0; }
.panel h2 { display: flex; align-items: center; gap: 8px; margin: 0; padding: 12px 14px 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.count { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; font-family: var(--mono); font-size: 11px; }
.badge { font: 10px var(--mono); padding: 1px 6px; border-radius: 99px; background: #2a1f4a; color: #c4b5fd; text-transform: none; letter-spacing: 0; }

/* ---------- status dots */
.dot { display: inline-block; flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; background: var(--off); box-shadow: 0 0 0 2px rgba(0, 0, 0, .25); }
.dot-working { background: var(--working); box-shadow: 0 0 0 2px rgba(74, 222, 128, .18), 0 0 8px rgba(74, 222, 128, .5); }
.dot-idle { background: var(--idle); }
.dot-off { background: var(--off); }
.dot-meeting { background: var(--meeting); box-shadow: 0 0 0 2px rgba(167, 139, 250, .2), 0 0 8px rgba(167, 139, 250, .55); }

/* ---------- team list */
.team { flex: 0 0 auto; max-height: 34%; border-bottom: 1px solid var(--line); }
.team-list { overflow-y: auto; padding: 0 8px 10px; }
.team-group { margin: 8px 6px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #64748b; }
.team-row { display: grid; grid-template-columns: 12px 92px minmax(0, 1fr); align-items: center; gap: 8px; width: 100%; padding: 4px 6px; border: 0; border-radius: 6px; background: transparent; text-align: left; cursor: pointer; }
.team-row:hover { background: #17223a; }
.team-row.selected { background: #1c2a4a; }
.team-row.is-off { opacity: .6; }
.team-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }
.team-name.is-bot { color: #a5d8ff; }
.team-text { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team-text.is-meeting { color: #c4b5fd; }
.online-pill { font: 9px var(--mono); color: var(--working); border: 1px solid #1f5135; border-radius: 99px; padding: 0 4px; }

/* ---------- meetings */
.meetings { flex: 0 0 auto; max-height: 27%; border-bottom: 1px solid var(--line); outline: none; transition: background .3s; }
.meetings.flash { animation: meetings-flash 1.4s ease-out; }
@keyframes meetings-flash { 0%, 30% { background: #241d45; } 100% { background: transparent; } }
.meeting-list { list-style: none; margin: 0; padding: 0 10px 10px; overflow-y: auto; }
.meeting { padding: 7px 9px; margin-bottom: 6px; border-radius: 8px; border: 1px solid var(--line); background: #0f1830; }
.meeting.is-live { border-color: #5b46a8; background: linear-gradient(180deg, #1d1840, #141a33); box-shadow: 0 0 0 1px rgba(167, 139, 250, .15), 0 0 14px rgba(139, 92, 246, .18); }
.meeting-head { display: flex; align-items: center; gap: 7px; min-width: 0; }
.meeting-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meeting-when { font-size: 12px; color: #b9c3d6; margin-top: 1px; }
.meeting-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.meeting-who { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-badge { flex: 0 0 auto; font: 700 10px var(--mono); letter-spacing: .6px; color: #fff; background: #dc2626; border-radius: 4px; padding: 1px 6px; animation: live-pulse 1.6s ease-in-out infinite; }
@keyframes live-pulse { 50% { opacity: .65; } }
.btn-join { flex: 0 0 auto; padding: 3px 12px; font-size: 12px; text-decoration: none; }
.meeting-empty { margin: 0; padding: 0 14px 12px; font-size: 12px; }
.card dd.is-meeting { color: #c4b5fd; }
@media (prefers-reduced-motion: reduce) { .live-badge, .meetings.flash { animation: none; } }

/* ---------- chat */
.chat { flex: 1 1 auto; }
.messages { flex: 1 1 auto; min-height: 120px; overflow-y: auto; list-style: none; margin: 0; padding: 4px 12px 8px; }
.msg { padding: 6px 8px; border-radius: 8px; margin-bottom: 4px; }
.msg:hover { background: #141f36; }
.msg-head { display: flex; align-items: baseline; gap: 6px; }
.msg-author { font-weight: 700; color: #fcd38d; }
.msg-bot .msg-author { color: #a5d8ff; }
.msg-slack .msg-author { color: #d8b4fe; }
.msg-mine .msg-author { color: var(--accent); }
.msg-time { margin-left: auto; font: 11px var(--mono); color: #64748b; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; color: #dbe3ef; }
.src { font: 9px var(--mono); text-transform: uppercase; padding: 0 5px; border-radius: 4px; letter-spacing: .5px; }
.src-bot { background: #0e2c45; color: #7dd3fc; }
.src-slack { background: #2a1f4a; color: #c4b5fd; }

.chat-form { padding: 10px 12px 12px; border-top: 1px solid var(--line); background: var(--panel-2); }
.chat-form textarea { width: 100%; resize: none; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: #0c1426; min-height: 44px; max-height: 140px; }
.chat-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.chat-actions .muted { font: 11px var(--mono); }
.chat-actions .error { flex: 1; }
.chat-actions .btn { margin-left: auto; }

/* ---------- info card */
.card { position: absolute; z-index: 5; width: 270px; padding: 12px 14px; border-radius: var(--radius); background: rgba(15, 23, 41, .97); border: 1px solid #2a3a60; box-shadow: 0 12px 32px rgba(0, 0, 0, .45); }
.card-head { display: flex; align-items: center; gap: 8px; padding-right: 18px; margin-bottom: 8px; }
.card-head strong { font-size: 16px; }
.card-close { position: absolute; top: 6px; right: 8px; border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 4px; }
.card-close:hover { color: var(--text); }
.card dl { display: grid; grid-template-columns: 88px 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
.card dt { color: var(--muted); }
.card dd { margin: 0; overflow-wrap: anywhere; }
.tag { font: 10px var(--mono); padding: 1px 6px; border-radius: 4px; letter-spacing: .5px; }
.tag-bot { background: #0e2c45; color: #7dd3fc; }
.tag-human { background: #3a2a10; color: #fcd38d; }

.fatal { position: fixed; inset: auto 16px 16px; padding: 12px; border-radius: 8px; background: #3b1d22; color: #fecaca; }

/* ---------- login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; background:
  linear-gradient(rgba(11, 18, 34, .92), rgba(11, 18, 34, .92)),
  repeating-linear-gradient(0deg, #1a2540 0 1px, transparent 1px 16px),
  repeating-linear-gradient(90deg, #1a2540 0 1px, transparent 1px 16px); }
.login-box { width: 100%; max-width: 360px; padding: 28px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(0, 0, 0, .4); }
.login-box h1 { font-size: 20px; text-align: center; margin: 12px 0 4px; }
.login-box > .muted { text-align: center; margin: 0 0 18px; }
.login-box label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.login-box input { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: #0c1426; color: var(--text); }
.login-box .error { margin-bottom: 10px; }

/* ---------- @mentions */
.mention { color: #7dd3fc; background: rgba(56, 189, 248, .12); border-radius: 4px; padding: 0 2px; font-weight: 600; }
.mention-me { color: #1b1203; background: var(--accent); }
.chat-form { position: relative; }
.mention-list { position: absolute; left: 12px; right: 12px; bottom: calc(100% - 4px); z-index: 6; list-style: none; margin: 0; padding: 4px; max-height: 240px; overflow-y: auto; border-radius: 8px; border: 1px solid #2a3a60; background: #0f1729; box-shadow: 0 -8px 24px rgba(0, 0, 0, .4); }
.mention-item { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.mention-item.active, .mention-item:hover { background: #1c2a4a; }
.mention-name { font-weight: 600; }
.mention-name.is-bot { color: #a5d8ff; }
.mention-sub { margin-left: auto; font-size: 11px; }

/* ---------- connect page */
.btn-connect { text-decoration: none; white-space: nowrap; }
.btn-danger { border-color: #5b2330; color: #fecaca; }
.btn-danger:hover { background: #3b1d22; border-color: #7f2a3a; }
.page { min-height: 100vh; }
.page .topbar a { text-decoration: none; }
.connect { max-width: 860px; margin: 0 auto; padding: 18px 16px 48px; }
.intro { margin: 4px 0 16px; }
.panel-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 16px; }
.panel-box h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.secret { border-color: #7a5a12; background: linear-gradient(180deg, #221a08, var(--panel)); }
.secret .warn { margin: 0 0 10px; color: #fcd38d; }
.secret-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.secret-actions .btn-ghost { margin-left: auto; }
.secret-text { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: #0a1020; font: 12px/1.5 var(--mono); resize: vertical; white-space: pre-wrap; overflow-wrap: anywhere; overflow: auto; }
.bot-list { list-style: none; margin: 0; padding: 0; }
.bot-item { display: flex; align-items: center; gap: 12px; padding: 8px 4px; border-top: 1px solid var(--line); }
.bot-item:first-child { border-top: 0; }
.bot-avatar { flex: 0 0 auto; width: 40px; height: 56px; image-rendering: pixelated; }
.bot-info { flex: 1; min-width: 0; }
.bot-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bot-name { color: #a5d8ff; }
.bot-id { font: 11px var(--mono); color: var(--muted); }
.bot-role, .bot-token { font-size: 12px; overflow-wrap: anywhere; }
.bot-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.tag-config { background: #2a2a2a; color: #cbd5e1; }
.add-form label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.add-form input:not([type=color]) { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: #0c1426; color: var(--text); }
.add-form small { display: block; margin-top: 3px; font-size: 11px; }
.colors { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; margin: 0 0 12px; }
.colors legend { color: var(--muted); font-size: 13px; padding: 0 4px; }
.palette { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; }
.swatch[aria-checked="true"] { outline: 2px solid #fff; outline-offset: 2px; }
.color-inputs { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.color-inputs label { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.color-inputs input[type=color] { width: 40px; height: 28px; border: 1px solid var(--line); border-radius: 6px; background: transparent; padding: 0; cursor: pointer; }
.preview { width: 60px; height: 84px; image-rendering: pixelated; margin-left: auto; background: #0c1426; border-radius: 8px; border: 1px solid var(--line); }

/* ---------- responsive */
@media (max-width: 980px) {
  .app { height: auto; min-height: 100vh; overflow: auto; }
  .layout { grid-template-columns: 1fr; }
  /* office keeps its 3:2 shape and fills the width; chat stacks below */
  .stage { height: auto; aspect-ratio: 3 / 2; max-height: 78vh; min-height: 260px; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .team { max-height: none; }
  .team-list { max-height: 40vh; }
  .meetings { max-height: none; }
  .meeting-list { max-height: 36vh; }
  .messages { max-height: 50vh; }
  .my-status select { max-width: 90px; }
}
@media (max-width: 560px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar h1 { font-size: 13px; }
  .topbar-right { gap: 6px; }
  .user { display: none; }
  .conn { display: none; }
  .bot-item { flex-wrap: wrap; }
  .topbar .btn { white-space: nowrap; padding: 6px 10px; }
  /* phones: render the office at a readable size and let it pan sideways */
  .stage { aspect-ratio: auto; max-height: none; min-height: 0; height: auto; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  .stage canvas { position: relative; inset: auto; width: 660px; height: 440px; }
  .legend { position: sticky; left: 8px; bottom: auto; margin: -34px 0 8px 8px; width: max-content; }
  .card { width: min(270px, calc(100vw - 24px)); }
  .team-row { grid-template-columns: 12px 84px minmax(0, 1fr); }
  .chat-form textarea { font-size: 16px; } /* avoid iOS zoom on focus */
}
