/* MatrixMedia Federation Simulator -- Styles */

:root {
  --mm-color-primary: #6366f1;
  --mm-color-primary-hover: #4f46e5;
  --mm-color-live: #ef4444;
  --mm-color-surface: #1e1e2e;
  --mm-color-surface-elevated: #2a2a3e;
  --mm-color-text: #e2e8f0;
  --mm-color-text-secondary: #94a3b8;
  --mm-color-success: #22c55e;
  --mm-color-warning: #f59e0b;
  --mm-color-error: #ef4444;
  --mm-color-bg: #0f0f1a;
  --mm-color-sidebar: #161625;
  --mm-color-border: #2e2e44;
  --mm-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  --mm-radius: 0.5rem;
  --mm-radius-lg: 0.75rem;
  --mm-space-xs: 0.25rem;
  --mm-space-sm: 0.5rem;
  --mm-space-md: 1rem;
  --mm-space-lg: 1.5rem;
  --mm-space-xl: 2rem;
  --mm-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --mm-shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);
  --mm-transition: 150ms ease;
  --server-a-color: #60a5fa;
  --server-b-color: #a78bfa;
}

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

body {
  font-family: var(--mm-font-family);
  background: var(--mm-color-bg);
  color: var(--mm-color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ============ Demo Banner ============ */
.demo-banner {
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--mm-color-warning);
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  text-align: center;
}

.banner-link {
  color: var(--mm-color-primary);
  cursor: default;
  margin-left: 0.5rem;
}

/* ============ Header ============ */
.app-header {
  display: flex;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--mm-color-sidebar);
  border-bottom: 1px solid var(--mm-color-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--mm-color-primary);
}

.brand-logo {
  font-size: 1.5rem;
}

.brand-name {
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.header-links {
  margin-left: auto;
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
}

.header-links a {
  color: var(--mm-color-text-secondary);
  text-decoration: none;
  transition: color var(--mm-transition);
}

.header-links a:hover {
  color: var(--mm-color-primary);
}

/* ============ Main Layout ============ */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ============ Controls Bar ============ */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--mm-color-surface);
  border: 1px solid var(--mm-color-border);
  border-radius: var(--mm-radius-lg);
  padding: 0.75rem 1rem;
  box-shadow: var(--mm-shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--mm-font-family);
  border: none;
  border-radius: var(--mm-radius);
  cursor: pointer;
  transition: all var(--mm-transition);
}

.btn-primary {
  background: var(--mm-color-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--mm-color-primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--mm-color-surface-elevated);
  color: var(--mm-color-text);
  border: 1px solid var(--mm-color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.1);
  border-color: var(--mm-color-primary);
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-icon {
  font-size: 0.75rem;
  line-height: 1;
}

.btn-small {
  background: transparent;
  color: var(--mm-color-text-secondary);
  border: none;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  border-radius: var(--mm-radius);
  font-family: var(--mm-font-family);
}

.btn-small:hover {
  background: var(--mm-color-surface-elevated);
  color: var(--mm-color-text);
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--mm-color-text-secondary);
}

.speed-control select {
  background: var(--mm-color-surface-elevated);
  color: var(--mm-color-text);
  border: 1px solid var(--mm-color-border);
  border-radius: var(--mm-radius);
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  font-family: var(--mm-font-family);
  cursor: pointer;
}

.step-indicator {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--mm-color-text-secondary);
  padding: 0.25rem 0.75rem;
  background: var(--mm-color-surface-elevated);
  border-radius: var(--mm-radius);
  font-variant-numeric: tabular-nums;
}

.step-indicator span {
  color: var(--mm-color-primary);
}

/* ============ Steps Timeline ============ */
.steps-timeline {
  display: flex;
  gap: 0.5rem;
  background: var(--mm-color-surface);
  border: 1px solid var(--mm-color-border);
  border-radius: var(--mm-radius-lg);
  padding: 0.75rem;
  overflow-x: auto;
  box-shadow: var(--mm-shadow);
}

.step-item {
  flex: 1;
  min-width: 100px;
  padding: 0.5rem 0.75rem;
  border-radius: var(--mm-radius);
  border: 2px solid var(--mm-color-border);
  text-align: center;
  transition: all var(--mm-transition);
  cursor: default;
}

.step-item.active {
  border-color: var(--mm-color-primary);
  background: rgba(99, 102, 241, 0.12);
  transform: scale(1.03);
}

.step-item.complete {
  border-color: var(--mm-color-success);
  background: rgba(34, 197, 94, 0.08);
}

.step-num {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--mm-color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.step-item.active .step-num {
  color: var(--mm-color-primary);
}

.step-item.complete .step-num {
  color: var(--mm-color-success);
}

.step-title {
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 0.15rem;
  white-space: nowrap;
}

/* ============ Visualization Container ============ */
.viz-container {
  display: grid;
  grid-template-columns: 1fr 200px 1fr;
  gap: 1rem;
  background: var(--mm-color-surface);
  border: 1px solid var(--mm-color-border);
  border-radius: var(--mm-radius-lg);
  padding: 2rem;
  min-height: 420px;
  box-shadow: var(--mm-shadow);
  position: relative;
}

/* ============ Server Cards ============ */
.server {
  background: var(--mm-color-surface-elevated);
  border: 2px solid var(--mm-color-border);
  border-radius: var(--mm-radius-lg);
  padding: 1.25rem;
  transition: all var(--mm-transition);
}

.server-a {
  border-color: var(--server-a-color);
  box-shadow: 0 0 20px rgba(96, 165, 250, 0.08);
}

.server-b {
  border-color: var(--server-b-color);
  box-shadow: 0 0 20px rgba(167, 139, 250, 0.08);
}

.server.highlight {
  transform: translateY(-2px);
  box-shadow: 0 0 32px rgba(99, 102, 241, 0.35);
}

.server-header {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mm-color-text-secondary);
  text-align: center;
  margin-bottom: 0.25rem;
}

.server-a .server-header { color: var(--server-a-color); }
.server-b .server-header { color: var(--server-b-color); }

.server-name {
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.services {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.service {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: var(--mm-color-surface);
  border: 1px solid var(--mm-color-border);
  border-radius: var(--mm-radius);
  border-left: 3px solid var(--mm-color-border);
  font-size: 0.8rem;
  transition: all var(--mm-transition);
}

.service.active {
  border-left-color: var(--mm-color-success);
}

.service.highlight {
  border-color: var(--mm-color-primary);
  border-left-color: var(--mm-color-primary);
  background: rgba(99, 102, 241, 0.08);
  transform: translateX(3px);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.25);
}

.service-icon {
  width: 24px;
  height: 24px;
  border-radius: var(--mm-radius);
  background: var(--mm-color-surface-elevated);
  color: var(--mm-color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

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

.service-name {
  font-weight: 600;
  font-size: 0.8rem;
}

.service-port {
  font-family: 'SF Mono', monospace;
  font-size: 0.65rem;
  color: var(--mm-color-text-secondary);
}

.service-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mm-color-border);
  flex-shrink: 0;
  transition: all var(--mm-transition);
}

.service.active .service-status {
  background: var(--mm-color-success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.service.highlight .service-status {
  background: var(--mm-color-primary);
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
}

/* ============ User Cards ============ */
.user-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  background: var(--mm-color-surface);
  border: 1px solid var(--mm-color-border);
  border-radius: var(--mm-radius);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-card-a .user-avatar {
  background: linear-gradient(135deg, #3b82f6, #1e40af);
}

.user-card-b .user-avatar {
  background: linear-gradient(135deg, #a855f7, #6b21a8);
}

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

.user-name {
  font-size: 0.8rem;
  font-weight: 600;
  font-family: 'SF Mono', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.7rem;
  color: var(--mm-color-text-secondary);
  margin-top: 0.1rem;
}

/* ============ Federation Channel ============ */
.federation-channel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 160px;
}

.channel-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mm-color-text-secondary);
  margin-bottom: 0.5rem;
}

.channel-svg {
  width: 100%;
  height: 300px;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.channel-note {
  font-size: 0.65rem;
  color: var(--mm-color-text-secondary);
  font-family: 'SF Mono', monospace;
  margin-top: auto;
}

.packet-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

/* Packet animations */
.packet {
  position: absolute;
  top: 50%;
  padding: 0.35rem 0.6rem;
  background: var(--mm-color-primary);
  color: #fff;
  border-radius: var(--mm-radius);
  font-size: 0.65rem;
  font-weight: 600;
  font-family: 'SF Mono', monospace;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
  white-space: nowrap;
  transform: translateY(-50%);
}

.packet.a-to-b {
  left: 0;
  animation: packet-a-to-b 1.2s ease-in-out forwards;
}

.packet.b-to-a {
  right: 0;
  animation: packet-b-to-a 1.2s ease-in-out forwards;
}

.packet.openid {
  background: var(--mm-color-warning);
  box-shadow: 0 4px 16px rgba(245, 158, 11, 0.4);
}

.packet.stream-event {
  background: var(--mm-color-success);
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.4);
}

@keyframes packet-a-to-b {
  0% {
    left: -5%;
    opacity: 0;
    transform: translateY(-50%) scale(0.8);
  }
  15% {
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }
  85% {
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }
  100% {
    left: 100%;
    opacity: 0;
    transform: translateY(-50%) scale(0.8);
  }
}

@keyframes packet-b-to-a {
  0% {
    right: -5%;
    opacity: 0;
    transform: translateY(-50%) scale(0.8);
  }
  15% {
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }
  85% {
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }
  100% {
    right: 100%;
    opacity: 0;
    transform: translateY(-50%) scale(0.8);
  }
}

/* ============ Step Description ============ */
.step-description {
  background: var(--mm-color-surface);
  border: 1px solid var(--mm-color-border);
  border-radius: var(--mm-radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--mm-shadow);
  transition: all var(--mm-transition);
}

.step-description.active {
  border-color: var(--mm-color-primary);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.15);
}

.step-description-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--mm-color-primary);
  margin-bottom: 0.25rem;
}

.step-description-body {
  font-size: 0.85rem;
  color: var(--mm-color-text-secondary);
  line-height: 1.6;
}

/* ============ Log Section ============ */
.log-section {
  background: var(--mm-color-surface);
  border: 1px solid var(--mm-color-border);
  border-radius: var(--mm-radius-lg);
  overflow: hidden;
  box-shadow: var(--mm-shadow);
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--mm-color-surface-elevated);
  border-bottom: 1px solid var(--mm-color-border);
}

.log-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--mm-color-text-secondary);
}

.event-log {
  max-height: 280px;
  overflow-y: auto;
  padding: 0.5rem 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.72rem;
  line-height: 1.6;
}

.log-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--mm-color-text-secondary);
  font-style: italic;
}

.log-entry {
  padding: 0.4rem 1rem;
  display: flex;
  gap: 0.6rem;
  align-items: center;
  border-bottom: 1px solid rgba(46, 46, 68, 0.3);
  cursor: pointer;
  transition: background var(--mm-transition);
}

.log-entry:hover {
  background: rgba(99, 102, 241, 0.06);
}

.log-entry .log-time {
  color: var(--mm-color-text-secondary);
  font-size: 0.68rem;
  min-width: 50px;
}

.log-entry .log-source {
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 3px;
  min-width: 80px;
  text-align: center;
  font-size: 0.65rem;
}

.log-entry .log-source.a { background: rgba(96, 165, 250, 0.15); color: var(--server-a-color); }
.log-entry .log-source.b { background: rgba(167, 139, 250, 0.15); color: var(--server-b-color); }
.log-entry .log-source.system { background: rgba(148, 163, 184, 0.15); color: var(--mm-color-text-secondary); }

.log-entry .log-method {
  font-weight: 700;
  min-width: 44px;
  font-size: 0.65rem;
}

.log-method.GET { color: var(--mm-color-success); }
.log-method.POST { color: var(--mm-color-primary); }
.log-method.PUT { color: var(--mm-color-warning); }

.log-entry .log-text {
  flex: 1;
  color: var(--mm-color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-entry .log-status {
  font-weight: 700;
  font-size: 0.65rem;
}

.log-status.s2xx { color: var(--mm-color-success); }
.log-status.s4xx { color: var(--mm-color-warning); }
.log-status.s5xx { color: var(--mm-color-error); }

/* ============ Details Panel ============ */
.details-panel {
  background: var(--mm-color-surface);
  border: 1px solid var(--mm-color-border);
  border-radius: var(--mm-radius-lg);
  overflow: hidden;
  box-shadow: var(--mm-shadow);
}

.details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--mm-color-surface-elevated);
  border-bottom: 1px solid var(--mm-color-border);
}

.details-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--mm-color-text);
}

.details-body {
  padding: 1rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--mm-color-text);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--mm-color-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--mm-color-text-secondary); }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .viz-container {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .federation-channel {
    min-height: 80px;
  }

  .channel-svg {
    height: 80px;
  }

  .steps-timeline {
    overflow-x: auto;
  }

  .step-item {
    min-width: 90px;
  }
}
