/* ── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d0f18;
  --surface:     #141722;
  --surface-2:   #1c2030;
  --surface-3:   #232840;
  --border:      #2a2f45;
  --border-soft: #1e2235;
  --text:        #e2e8f0;
  --text-muted:  #7c87a0;
  --text-dim:    #4a5268;
  --accent:      #6366f1;
  --accent-glow: rgba(99,102,241,0.18);
  --accent-2:    #818cf8;
  --green:       #22c55e;
  --green-glow:  rgba(34,197,94,0.15);
  --yellow:      #eab308;
  --yellow-glow: rgba(234,179,8,0.15);
  --red:         #ef4444;
  --red-glow:    rgba(239,68,68,0.15);
  --grey:        #4a5268;
  --font-mono:   'Fira Code', 'Cascadia Code', Consolas, 'Courier New', monospace;
  --radius:      8px;
  --radius-sm:   5px;
  --header-h:    54px;
  --meeting-h:   42px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Scrollbars ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--surface-3); }

/* ── Header ───────────────────────────────────────────────────────────── */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

#header-left {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
}

#company-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

#header-sub {
  font-size: 11px;
  color: var(--text-muted);
}

#ticker {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  font-size: 12px;
  min-width: 0;
}

.ticker-label {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ticker-item {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-2);
}

.ticker-item.positive { color: var(--green); }
.ticker-item.negative { color: var(--red); }
.ticker-sep { color: var(--border); }

#header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#flag-badge {
  background: var(--red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
}

#flag-badge.hidden { display: none; }

#live-dot {
  font-size: 11px;
  color: var(--green);
  animation: pulse 2s infinite;
}

#live-dot.disconnected { color: var(--grey); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

#clock {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  min-width: 60px;
  text-align: right;
}

/* ── Main Layout ──────────────────────────────────────────────────────── */
#main-layout {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  bottom: var(--meeting-h);
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 0;
  overflow: hidden;
}

/* ── Agent Floor ──────────────────────────────────────────────────────── */
#agent-floor {
  padding: 14px;
  overflow: hidden;
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.section-header .badge { flex-shrink: 0; }

/* Grid view scrolls normally */
#agent-grid { overflow-y: auto; flex: 1; }

/* Building view fills the remaining panel */
#building-view {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.section-header h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.badge {
  font-size: 10px;
  background: var(--surface-3);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
}

#agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 10px;
}

/* ── Agent Card ───────────────────────────────────────────────────────── */
.agent-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: default;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
  position: relative;
  overflow: hidden;
}

.agent-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow), 0 4px 16px rgba(0,0,0,0.3);
  transform: translateY(-1px);
}

.agent-card.skeleton {
  height: 110px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.agent-card.status-active  { border-left: 3px solid var(--green);  box-shadow: -2px 0 8px var(--green-glow); }
.agent-card.status-recent  { border-left: 3px solid var(--yellow); box-shadow: -2px 0 8px var(--yellow-glow); }
.agent-card.status-idle    { border-left: 3px solid var(--grey); }
.agent-card.status-error   { border-left: 3px solid var(--red);    box-shadow: -2px 0 8px var(--red-glow); }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 6px;
}

.agent-emoji {
  font-size: 22px;
  line-height: 1;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
}

.status-dot.active  { background: var(--green);  box-shadow: 0 0 6px var(--green); animation: pulse 1.5s infinite; }
.status-dot.recent  { background: var(--yellow); }
.status-dot.idle    { background: var(--grey); }
.status-dot.error   { background: var(--red);    box-shadow: 0 0 6px var(--red); }

.agent-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.agent-role {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.3;
  margin-bottom: 8px;
}

.agent-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
}

.agent-activity {
  font-size: 10px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.model-chip {
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.model-chip.opus   { border-color: var(--accent); color: var(--accent-2); }
.model-chip.sonnet { border-color: #3b82f6; color: #93c5fd; }
.model-chip.haiku  { border-color: var(--border); color: var(--text-dim); }

.agent-log-preview {
  font-size: 9px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-top: 1px solid var(--border-soft);
  padding-top: 5px;
}

/* ── Right Panel ──────────────────────────────────────────────────────── */
#right-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

/* ── Pending Panel ────────────────────────────────────────────────────── */
#pending-panel {
  padding: 14px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

#pending-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pending-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  transition: background 0.2s;
}

.pending-item.has-items {
  background: rgba(239,68,68,0.06);
  border-color: rgba(239,68,68,0.2);
}

.pend-icon { font-size: 13px; }

.pend-label {
  flex: 1;
  color: var(--text-muted);
  font-size: 11px;
}

.pend-count {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  min-width: 20px;
  text-align: right;
}

.pend-count.nonzero { color: var(--red); }

#flags-area {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.flag-chip {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--red);
}

/* ── Log Panel ────────────────────────────────────────────────────────── */
#log-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px 14px 8px;
}

#log-panel .section-header {
  margin-bottom: 8px;
}

#log-filter {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

#log-output {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.6;
  color: var(--text-muted);
}

.log-line {
  padding: 1px 0;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  gap: 6px;
  align-items: flex-start;
  word-break: break-all;
}

.log-line.historical { opacity: 0.5; }
.log-line.new        { animation: fadein 0.3s ease; }

@keyframes fadein {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: none; }
}

.log-agent {
  flex-shrink: 0;
  min-width: 90px;
  font-weight: 600;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.8;
}

.log-text { flex: 1; }
.log-text .ERROR, .log-text .CRITICAL { color: var(--red); font-weight: 700; }

/* ── Meeting Room ─────────────────────────────────────────────────────── */
#meeting-room {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 200;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

#meeting-header {
  height: var(--meeting-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  cursor: pointer;
  user-select: none;
}

#meeting-header:hover { background: var(--surface-2); }

#meeting-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

#room-name-display {
  font-weight: 400;
  color: var(--accent-2);
  font-size: 11px;
}

#meeting-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

button {
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 11px;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
  background: var(--surface-2);
  color: var(--text);
}

button:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--accent);
  color: var(--accent-2);
}

button:disabled { opacity: 0.4; cursor: not-allowed; }

#new-room-btn { font-size: 11px; }

#toggle-meeting-btn { font-size: 11px; }

#meeting-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  display: flex;
  flex-direction: column;
}

#meeting-body.open {
  max-height: 460px;
}

#meeting-content {
  display: flex;
  flex-direction: column;
  height: 460px;
  padding: 12px 16px;
  gap: 10px;
}

#transcript {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

/* ── Chat Messages ────────────────────────────────────────────────────── */
.chat-msg {
  display: flex;
  gap: 10px;
  animation: fadein 0.25s ease;
}

.chat-msg.user-msg {
  flex-direction: row-reverse;
}

.chat-avatar {
  font-size: 22px;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border);
}

.chat-bubble {
  max-width: 75%;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.55;
}

.agent-bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.user-bubble {
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  color: var(--accent-2);
}

.bubble-header {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-2);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.bubble-header .agent-role-tag {
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}

.bubble-text {
  color: var(--text);
}

.cursor {
  display: inline-block;
  width: 8px; height: 12px;
  background: var(--accent);
  animation: blink 0.8s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 1px;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Chat Input Bar ───────────────────────────────────────────────────── */
#chat-input-bar {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

#chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

#send-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  padding: 8px 16px;
  font-weight: 600;
}

#send-btn:hover:not(:disabled) {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: white;
}

/* ── Agent colour palette for log lines ──────────────────────────────── */
.log-agent[data-agent="orchestrator"]    { color: #818cf8; }
.log-agent[data-agent="trading-bot"]     { color: #34d399; }
.log-agent[data-agent="etsy-manager"]    { color: #fb923c; }
.log-agent[data-agent="market-research"] { color: #38bdf8; }
.log-agent[data-agent="accountant"]      { color: #a78bfa; }
.log-agent[data-agent="sales-agent"]     { color: #f472b6; }
.log-agent[data-agent="phone-ai"]        { color: #4ade80; }
.log-agent[data-agent="growth-scout"]    { color: #fbbf24; }
.log-agent[data-agent="security"]        { color: #f87171; }
.log-agent[data-agent="secretary"]       { color: #67e8f9; }
.log-agent[data-agent="lawyer"]          { color: #c4b5fd; }
.log-agent[data-agent="artist"]          { color: #f9a8d4; }

/* ── View Toggle ──────────────────────────────────────────────────────── */
.view-toggle {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.view-btn {
  font-size: 10px;
  padding: 2px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.view-btn.active,
.view-btn:hover {
  background: var(--surface-3);
  border-color: var(--accent);
  color: var(--accent-2);
}

/* ── Pixel Building View ──────────────────────────────────────────────── */
#building-view {
  position: relative;
}

#pixel-office {
  display: block;
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #07090f;
}

#room-tooltip {
  display: none;
  position: fixed;
  z-index: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 11px;
  color: var(--text);
  pointer-events: none;
  max-width: 220px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  line-height: 1.5;
}

#room-tooltip strong { display: block; margin-bottom: 2px; }

.tt-status {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 99px;
  margin-left: 6px;
  vertical-align: middle;
}

.tt-active { background: rgba(34,197,94,0.15);  color: #22c55e; border: 1px solid rgba(34,197,94,0.3); }
.tt-recent { background: rgba(234,179,8,0.15);  color: #eab308; border: 1px solid rgba(234,179,8,0.3); }
.tt-idle   { background: rgba(74,82,104,0.15);  color: #6b7280; border: 1px solid rgba(74,82,104,0.3); }
.tt-error  { background: rgba(239,68,68,0.15);  color: #ef4444; border: 1px solid rgba(239,68,68,0.3); }

.tt-role { color: var(--text-muted); font-size: 10px; margin-top: 2px; }
.tt-log  { color: var(--text-dim);   font-size: 9px;  font-family: var(--font-mono); margin-top: 4px; border-top: 1px solid var(--border-soft); padding-top: 3px; }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  #main-layout { grid-template-columns: 1fr; }
  #right-panel { display: none; }
}

@media (max-width: 600px) {
  #ticker { display: none; }
  #agent-grid { grid-template-columns: repeat(2, 1fr); }
}
