* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --terracotta: #d97757;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-family: "Instrument Sans", system-ui, sans-serif;
  transition: background-color 0.3s, color 0.3s;
}

.app.light {
  --bg: #ebe7db;
  --bg-panel: #f7f4ec;
  --bg-card: #fffdf8;
  --text: #26221c;
  --text-dim: #8a8272;
  --border: rgba(120, 90, 60, 0.16);
  background: var(--bg);
  color: var(--text);
}

.app.dark {
  --bg: #131009;
  --bg-panel: #1c1812;
  --bg-card: #242019;
  --text: #ece7dc;
  --text-dim: #8f8672;
  --border: rgba(255, 255, 255, 0.09);
  background: var(--bg);
  color: var(--text);
}

/* ── header ── */

.header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-mark {
  font-size: 30px;
  color: var(--terracotta);
  line-height: 1;
  animation: mark-spin 14s linear infinite;
  display: inline-block;
}

.header-brand h1 {
  font-family: "Fraunces", Georgia, serif;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.header-brand p {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 1px;
}

.header-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-left: auto;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-dim);
}

.legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.agent-count {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}

.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.btn:hover {
  border-color: var(--terracotta);
}

.btn:active {
  transform: scale(0.96);
}

.mode-btn.live-on {
  background: #d14343;
  color: #fff;
  border-color: transparent;
  animation: live-pulse 1.6s ease-in-out infinite;
}

@keyframes live-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(209, 67, 67, 0.4);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(209, 67, 67, 0);
  }
}

/* ── layout ── */

.main-row {
  display: flex;
  flex: 1;
  min-height: 0;
}

.floorplan-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.floorplan-svg {
  width: 100%;
  height: 100%;
}

/* ── side panel ── */

.side-panel {
  width: 300px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.agent-card {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  animation: card-in 0.25s ease-out;
}

.agent-card-head {
  display: flex;
  gap: 10px;
  align-items: center;
  position: relative;
}

.agent-card-head svg {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-shrink: 0;
}

.agent-card-head h2 {
  font-family: "Fraunces", Georgia, serif;
  font-size: 19px;
  font-weight: 600;
}

.agent-card-head .mark {
  color: var(--terracotta);
}

.role-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--terracotta);
  background: color-mix(in srgb, var(--terracotta) 14%, transparent);
  border-radius: 5px;
  padding: 1px 6px;
  margin: 3px 6px 0 0;
}

.model-tag {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  color: var(--text-dim);
}

.close-btn {
  position: absolute;
  top: 0;
  right: 0;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
}

.agent-stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.status-chip {
  font-size: 12px;
  font-weight: 700;
  border-radius: 7px;
  padding: 3px 9px;
}

.tool-now {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  color: var(--terracotta);
}

.agent-facts {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.agent-facts dt {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.agent-facts dd {
  font-size: 13px;
  font-weight: 600;
  margin-top: 1px;
}

.link-btn {
  border: none;
  background: none;
  color: var(--terracotta);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-right: 8px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tool-history {
  margin-top: 12px;
}

.tool-history h3,
.event-feed h3 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.tool-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tool-chips code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
}

.assign-btn {
  width: 100%;
  margin-top: 14px;
  background: var(--terracotta);
  color: #fff;
  border-color: transparent;
}

.assign-btn:hover {
  filter: brightness(1.06);
  border-color: transparent;
}

.chat-panel {
  margin-top: 14px;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.chat-head h3 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-head .link-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── full-screen chat overlay ── */

.chat-full-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: card-in 0.2s ease-out;
}

.chat-full-card {
  width: min(860px, 100%);
  height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  padding: 18px 20px 20px;
}

.chat-full-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.chat-full-who {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-full-who svg {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  flex-shrink: 0;
}

.chat-full-who h2 {
  font-family: "Fraunces", Georgia, serif;
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.chat-full-who .model-tag {
  margin-left: 8px;
}

/* the shared conversation fills the full-screen card */
.chat-panel-full {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 14px;
}

.chat-panel-full .chat-list {
  flex: 1;
  max-height: none;
}

.chat-panel-full .chat-msg {
  max-width: 74%;
  font-size: 13.5px;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.chat-msg {
  max-width: 88%;
  font-size: 12px;
  line-height: 1.5;
  padding: 6px 10px;
  border-radius: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: card-in 0.2s ease-out;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--terracotta);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.chat-msg.system {
  align-self: center;
  color: var(--text-dim);
  font-size: 11px;
  font-style: italic;
  background: none;
  padding: 2px 6px;
}

.chat-msg.pending {
  align-self: flex-start;
  color: var(--text-dim);
  font-size: 11px;
  background: none;
  animation: emote-bob 1.6s ease-in-out infinite;
}

.chat-panel textarea {
  width: 100%;
  resize: vertical;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.chat-panel textarea:focus {
  outline: none;
  border-color: var(--terracotta);
}

.chat-hint {
  font-size: 11px;
  color: var(--text-dim);
}

.task-composer {
  margin-top: 14px;
}

.task-composer textarea {
  width: 100%;
  resize: vertical;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.task-composer textarea:focus {
  outline: none;
  border-color: var(--terracotta);
}

.task-composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

.task-composer-row label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
}

/* hover tooltip bubble (data-tip) */
.tip {
  position: relative;
}

.tip::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 24px;
  border: 6px solid transparent;
  border-top-color: var(--text);
  opacity: 0;
  transition: opacity 0.15s ease 0.15s;
  pointer-events: none;
}

.tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 13px);
  left: 0;
  width: 230px;
  background: var(--text);
  color: var(--bg-panel);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.55;
  padding: 8px 10px;
  border-radius: 9px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transition: opacity 0.15s ease 0.15s;
  pointer-events: none;
  white-space: normal;
  text-align: left;
  z-index: 20;
}

.tip:hover::before,
.tip:hover::after {
  opacity: 1;
}

.task-composer-row .tip::after {
  left: auto;
  right: 0;
}

.task-composer-row label.tip::after {
  left: 0;
  right: auto;
}

.task-composer-row .assign-btn {
  width: auto;
  margin-top: 0;
}

.task-composer-row .assign-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.panel-hint {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
}

.event-feed {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
}

.event-feed ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.event-feed li {
  font-size: 12px;
  line-height: 1.45;
  display: flex;
  gap: 7px;
  animation: card-in 0.25s ease-out;
}

.event-icon {
  flex-shrink: 0;
}

/* ── keyframes: pawn ── */

@keyframes pawn-breathe {
  0%,
  100% {
    transform: scaleY(1);
  }
  50% {
    transform: scaleY(1.035);
  }
}

@keyframes pawn-swing {
  from {
    transform: rotate(-24deg);
  }
  to {
    transform: rotate(24deg);
  }
}

@keyframes pawn-type {
  0%,
  100% {
    transform: rotate(0deg) translateY(0);
  }
  50% {
    transform: rotate(4deg) translateY(1.4px);
  }
}

@keyframes pawn-blink {
  0%,
  93%,
  100% {
    transform: scaleY(1);
  }
  95%,
  97% {
    transform: scaleY(0.08);
  }
}

@keyframes pawn-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-1.6px) rotate(-2deg);
  }
  75% {
    transform: translateX(1.6px) rotate(2deg);
  }
}

@keyframes pawn-mouth {
  0%,
  100% {
    transform: scaleY(1);
  }
  50% {
    transform: scaleY(0.4);
  }
}

/* ── keyframes: emotes ── */

@keyframes emote-pop {
  from {
    transform: scale(0);
  }
  70% {
    transform: scale(1.15);
  }
  to {
    transform: scale(1);
  }
}

@keyframes emote-bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2.5px);
  }
}

@keyframes emote-bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

@keyframes thinking-dots {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 1;
  }
}

@keyframes gear-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes zzz-float {
  0% {
    opacity: 0;
    transform: translate(0, 0);
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(5px, -9px);
  }
}

@keyframes sparkle-twinkle {
  0%,
  100% {
    opacity: 0.2;
    transform: scale(0.6) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.1) rotate(45deg);
  }
}

@keyframes selection-ring {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.12);
    opacity: 0.7;
  }
}

@keyframes agent-spawn {
  from {
    transform: scale(0.2);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes dash-flow {
  to {
    stroke-dashoffset: -32;
  }
}

@keyframes mark-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── RWD ──
   Portrait / narrow screens: stack vertically. The office locks to its
   1200:700 aspect ratio at full width (maximum size, no letterboxing),
   and the panel moves below it. */
@media (orientation: portrait) {
  .app {
    height: 100dvh;
  }

  .main-row {
    flex-direction: column;
    overflow-y: auto;
  }

  .floorplan-wrap {
    flex: none;
    width: 100%;
    aspect-ratio: 1200 / 700;
    padding: 2px;
  }

  .side-panel {
    width: 100%;
    flex: 1 0 auto;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .event-feed {
    max-height: 40vh;
  }
}

/* Narrow landscape: keep the row, slim the panel */
@media (max-width: 900px) and (orientation: landscape) {
  .side-panel {
    width: 232px;
  }
}

/* Compact chrome on any narrow screen */
@media (max-width: 900px) {
  .header {
    gap: 10px;
    padding: 6px 10px;
    flex-wrap: wrap;
  }

  .header-legend,
  .header-brand p,
  .agent-count {
    display: none;
  }

  .header-mark {
    font-size: 22px;
  }

  .header-brand h1 {
    font-size: 17px;
  }

  .header-controls {
    margin-left: auto;
    gap: 5px;
  }

  .btn {
    padding: 5px 9px;
    font-size: 12px;
  }
}

/* Very tight screens: shave header further */
@media (max-width: 480px) {
  .header-brand h1 {
    font-size: 15px;
  }
  .btn {
    padding: 4px 7px;
    font-size: 11px;
  }
}
