:root {
  --bg: #0c0e14;
  --bg-elevated: #12151f;
  --glass: rgba(22, 27, 40, 0.72);
  --glass-border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf4;
  --text-muted: #8b95a8;
  --accent: #7c9cff;
  --accent-glow: rgba(124, 156, 255, 0.25);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --font: 'Inter', system-ui, sans-serif;
  --font-display: 'Outfit', 'Inter', sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(124, 156, 255, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(32, 201, 151, 0.06), transparent);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.glass {
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1rem 1.25rem 0.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.brand-icon svg { width: 22px; height: 22px; }

.brand h1 {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.8125rem;
}

.office-mood {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  transition: background 0.4s, color 0.4s, box-shadow 0.4s;
}

.office-mood.mood-calm {
  background: rgba(139, 149, 168, 0.15);
  border: 1px solid rgba(139, 149, 168, 0.25);
  color: var(--text-muted);
}

.office-mood.mood-work {
  background: rgba(124, 156, 255, 0.15);
  border: 1px solid rgba(124, 156, 255, 0.35);
  color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
  animation: mood-pulse 2s ease-in-out infinite;
}

.office-mood.mood-hot {
  background: rgba(251, 146, 60, 0.18);
  border: 1px solid rgba(251, 146, 60, 0.4);
  color: #fb923c;
  box-shadow: 0 0 20px rgba(251, 146, 60, 0.25);
  animation: mood-pulse 0.8s ease-in-out infinite;
}

@keyframes mood-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.25);
  color: var(--success);
  font-weight: 500;
  font-size: 0.75rem;
}

.status-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-pill.offline {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.25);
  color: var(--danger);
}

.status-pill.offline .dot { background: var(--danger); animation: none; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

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

/* Status bar */
.status-bar {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 1fr;
  gap: 1.25rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
}

.meeting-banner {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #FFD93D;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  background: rgba(255, 217, 61, 0.12);
  border: 1px solid rgba(255, 217, 61, 0.35);
  animation: mood-pulse 1.2s ease-in-out infinite;
}

.pipeline-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  list-style: none;
  margin-bottom: 0.5rem;
  padding: 0;
}

.pipeline-step {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.625rem;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: all 0.3s;
}

.pipeline-step .step-icon { font-size: 0.7rem; }
.pipeline-step .step-label { white-space: nowrap; }

.pipeline-step.done {
  background: rgba(52, 211, 153, 0.12);
  color: var(--success);
}

.pipeline-step.current {
  background: rgba(124, 156, 255, 0.18);
  color: var(--accent);
  border-color: rgba(255, 217, 61, 0.5);
  box-shadow: 0 0 12px var(--accent-glow);
}

.minimap-wrap {
  position: absolute;
  bottom: 0.75rem;
  right: 0.75rem;
  padding: 0.35rem 0.45rem 0.4rem;
  border-radius: 10px;
  pointer-events: none;
}

.minimap-label {
  display: block;
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

#minimap-canvas {
  display: block;
  width: 240px;
  height: 140px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.status-bar .label {
  display: block;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.status-production strong {
  font-size: 0.9375rem;
  font-weight: 600;
  display: block;
  line-height: 1.35;
}

.pipeline-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.pipeline-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #6366f1);
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 12px var(--accent-glow);
}

.status-telegram p {
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text);
  opacity: 0.9;
}

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  min-height: 0;
}

.office-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 400px;
}

#office-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1024 / 580;
  cursor: default;
}

/* Three.js 3D viewport */
.layout-3d {
  grid-template-columns: 1fr 300px;
}

.office-3d-wrap {
  min-height: 520px;
}

.office-viewport {
  width: 100%;
  height: min(68vh, 620px);
  min-height: 420px;
  background: #0a0c10;
  cursor: grab;
}

.office-viewport:active {
  cursor: grabbing;
}

.office-viewport canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.zone-legend {
  position: absolute;
  bottom: 0.75rem;
  left: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  padding: 0.4rem 0.65rem;
  border-radius: 10px;
  font-size: 0.625rem;
  color: var(--text-muted);
  pointer-events: none;
}

.pipeline-steps li.active {
  background: rgba(124, 156, 255, 0.22);
  border-color: var(--accent);
  color: var(--accent);
}

.pipeline-steps li.done {
  color: var(--success);
  opacity: 0.85;
}

.roster-item.active strong {
  color: var(--accent);
}

.roster-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-pill.connected .dot {
  background: var(--success);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}

.canvas-tooltip {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  background: rgba(12, 14, 20, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.75rem;
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  max-width: 220px;
}

.agent-popup {
  position: fixed;
  z-index: 1001;
  width: 260px;
  padding: 1rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  pointer-events: auto;
}

.agent-popup .popup-close {
  position: absolute;
  top: 0.5rem;
  right: 0.6rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem;
}

.agent-popup .popup-close:hover { color: var(--text); }

.agent-popup .popup-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
  padding-right: 1.5rem;
}

.agent-popup .popup-role {
  font-size: 0.75rem;
  margin-bottom: 0.75rem;
}

.agent-popup .popup-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.8125rem;
}

.agent-popup .popup-details dt {
  color: var(--text-muted);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.agent-popup .popup-details dd {
  margin: 0;
  line-height: 1.4;
}

.office-overlay {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  pointer-events: none;
}

.office-badge {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
}

.panel {
  border-radius: var(--radius);
  padding: 1rem;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.panel h2 svg { width: 16px; height: 16px; opacity: 0.7; }

.feed, .roster {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.feed li {
  padding: 0.65rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.8125rem;
  line-height: 1.45;
  animation: feed-in 0.35s ease-out;
}

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

.feed .feed-time {
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.feed .feed-agent {
  font-weight: 600;
  color: var(--accent);
}

.roster li {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.35rem;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.roster li.active {
  background: rgba(124, 156, 255, 0.08);
}

.roster li:hover { background: rgba(255, 255, 255, 0.03); }

.roster-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.04);
  padding: 2px;
}

.roster-info { flex: 1; min-width: 0; }

.roster-name {
  font-size: 0.8125rem;
  font-weight: 600;
  display: block;
}

.roster-status {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.roster-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.4;
}

.roster li.active .roster-dot {
  opacity: 1;
  box-shadow: 0 0 10px currentColor;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

/* Footer */
.footer {
  text-align: center;
  padding: 0.75rem;
  font-size: 0.75rem;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover { text-decoration: underline; }

/* Confetti overlay */
#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}

/* Responsive */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .panel { flex: 1 1 280px; max-height: 280px; }
}

@media (max-width: 768px) {
  .status-bar {
    grid-template-columns: 1fr;
    gap: 0.875rem;
  }
  .app { padding: 0.75rem; }
  .topbar { padding: 0.875rem 1rem; }
}

/* Three.js load error */
.three-error {
  position: absolute;
  inset: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  border-radius: var(--radius);
  border: 1px solid var(--danger);
  z-index: 10;
  gap: 0.5rem;
}

.three-error strong { color: var(--danger); font-size: 1rem; }

/* Agent info panel (3D click) */
.office-3d-wrap { position: relative; }

.agent-panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 240px;
  padding: 1rem;
  border-radius: var(--radius-sm);
  z-index: 5;
  font-size: 0.8125rem;
  line-height: 1.5;
}

.agent-panel .agent-panel-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.agent-panel .agent-panel-close {
  position: absolute;
  top: 0.5rem;
  right: 0.6rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
}

.agent-panel .label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-right: 0.35rem;
}

.roster-item { cursor: pointer; }
