:root {
  --bg: #fffaf6;
  --bg-2: #fff1eb;
  --panel: rgba(255, 255, 255, 0.76);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --text: #34264f;
  --muted: #786d96;
  --line: rgba(124, 92, 255, 0.12);
  --shadow: 0 22px 60px rgba(127, 84, 180, 0.16);
  --cyan: #68d7ff;
  --blue: #5b7cff;
  --orange: #ff8a64;
  --purple: #8b6dff;
  --green: #47d7a9;
  --red: #ff648b;
  --yellow: #ffcf5c;
  --cream: #fffaf6;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, 'Segoe UI', Roboto, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(104, 215, 255, 0.35), transparent 30%),
    radial-gradient(circle at top right, rgba(255, 138, 100, 0.28), transparent 34%),
    radial-gradient(circle at bottom left, rgba(139, 109, 255, 0.2), transparent 28%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(124, 92, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 92, 255, 0.035) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  mask-image: radial-gradient(circle at center, black 62%, transparent 100%);
}

body.drawer-open { overflow: hidden; }

.app-shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-strong));
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px) saturate(1.3);
}

.sidebar {
  margin: 18px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.80), rgba(255,255,255,0.94)),
    radial-gradient(circle at top right, rgba(255, 138, 100, 0.2), transparent 42%);
}

.main-content {
  padding: 18px 18px 28px 0;
  display: grid;
  gap: 16px;
}

.topbar {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

h1, h2, h3, h4 {
  margin: 4px 0;
  letter-spacing: -0.03em;
}

h1 { font-size: clamp(1.8rem, 2.4vw, 2.6rem); }
h2 { font-size: clamp(1.25rem, 1.9vw, 1.7rem); }

.eyebrow,
.section-title,
.label {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 11px;
  font-weight: 800;
}

.eyebrow { color: #8e62ff; }
.section-title { margin-bottom: 10px; color: #ff7d8d; }
.muted, .small, .label { color: var(--muted); }
.small { font-size: 12px; line-height: 1.5; }

.hero-card {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 18px;
  border-radius: 24px;
  background:
    radial-gradient(circle at top right, rgba(104, 215, 255, 0.22), transparent 35%),
    linear-gradient(180deg, rgba(255,255,255,0.84), rgba(255,255,255,0.96));
  border: 1px solid rgba(124, 92, 255, 0.12);
}

.hero-copy p { margin: 6px 0 10px; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 8px; }

.avatar,
.hero-avatar,
.agent-avatar,
.chip-avatar,
.tooltip-avatar,
.drawer-avatar {
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid rgba(124, 92, 255, 0.14);
  background: linear-gradient(145deg, rgba(255,255,255,0.18), rgba(255,255,255,0.06));
  box-shadow: 0 14px 28px rgba(0,0,0,0.12);
  flex-shrink: 0;
}

.avatar img,
.hero-avatar img,
.agent-avatar img,
.chip-avatar img,
.tooltip-avatar img,
.drawer-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hero-avatar { width: 96px; height: 96px; }
.agent-avatar { width: 56px; height: 56px; border-radius: 18px; }
.chip-avatar { width: 40px; height: 40px; border-radius: 14px; }
.tooltip-avatar { width: 56px; height: 56px; border-radius: 16px; }
.drawer-avatar { width: 86px; height: 86px; }

.avatar--fallback,
.hero-avatar--fallback,
.agent-avatar--fallback,
.chip-avatar--fallback,
.tooltip-avatar--fallback,
.drawer-avatar--fallback {
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  background:
    radial-gradient(circle at top left, #68d7ff, transparent 45%),
    linear-gradient(145deg, #5b7cff, #8b6dff);
}

.mode-banner {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 20px;
  border-radius: 22px;
  border: 1px solid rgba(124, 92, 255, 0.16);
  box-shadow: var(--shadow);
}

.mode-banner--safe {
  background: linear-gradient(135deg, rgba(255, 244, 196, 0.88), rgba(255, 255, 255, 0.94));
}

.mode-banner--live {
  background: linear-gradient(135deg, rgba(255, 215, 215, 0.92), rgba(255, 255, 255, 0.94));
}

.mode-banner__label {
  font-size: 1rem;
  font-weight: 800;
}

.mode-banner__chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats-grid,
.detail-grid {
  display: grid;
  gap: 16px;
}

.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.detail-grid--system { align-items: start; }
.detail-grid--triple { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.stat-card {
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(255,255,255,0.94)),
    radial-gradient(circle at top right, rgba(104, 215, 255, 0.18), transparent 44%);
}

.stat-card strong { font-size: 30px; }
.factory-layout, .detail-card { padding: 20px; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.action-row { display: flex; flex-wrap: wrap; gap: 10px; }

.btn {
  border: 1px solid rgba(124, 92, 255, 0.16);
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(124, 92, 255, 0.08);
  transition: transform 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
}

.btn:hover {
  border-color: rgba(124, 92, 255, 0.34);
  transform: translateY(-1px) scale(1.01);
}

.btn.is-loading { opacity: 0.72; cursor: wait; }
.btn-primary { background: linear-gradient(135deg, rgba(104, 215, 255, 0.58), rgba(139, 109, 255, 0.28)); }
.btn-accent {
  background: linear-gradient(135deg, rgba(255, 138, 100, 0.5), rgba(255, 207, 92, 0.38));
  border-color: rgba(255, 138, 100, 0.24);
}

.health-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.health-card,
.activity-card,
.connector-row,
.timeline-card,
.recap-item,
.room-card,
.agent-item,
.bot-chip,
.stat-card,
.checklist-item {
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
}

.health-card,
.activity-card,
.connector-row,
.timeline-card,
.recap-item,
.agent-item,
.bot-chip,
.checklist-item {
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(124, 92, 255, 0.12);
}

.health-card strong,
.activity-card strong { display: block; margin-top: 6px; }
.health-footnote { margin-top: 12px; }
.health-footnote code,
#buildIdentity code {
  background: rgba(124, 92, 255, 0.12);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.connector-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.connector-row--success { border-left: 5px solid var(--green); }
.connector-row--warn { border-left: 5px solid var(--yellow); }
.connector-row--muted { border-left: 5px solid var(--purple); }

.activity-card--success,
.recap-item--success,
.timeline-card--success,
.checklist-item--ok { border-left: 5px solid var(--green); }
.activity-card--warn,
.recap-item--warn,
.timeline-card--warn,
.checklist-item--todo { border-left: 5px solid var(--yellow); }
.activity-card--danger,
.recap-item--danger,
.timeline-card--danger { border-left: 5px solid var(--red); }
.activity-card--info,
.timeline-card--info { border-left: 5px solid var(--blue); }

.agent-list,
.room-bots,
.timeline,
.recap-block,
.report-status { display: grid; gap: 10px; }
.report-status { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 14px; }
.report-row { margin-bottom: 12px; }

.agent-item,
.bot-chip,
.report-card,
.performance-card {
  position: relative;
  border-left: 5px solid var(--bot-color, var(--purple));
}

.agent-item,
.bot-chip { text-align: left; width: 100%; }
.agent-button,
.bot-button,
.room-card { cursor: pointer; }
.agent-item:hover,
.bot-chip:hover,
.room-card:hover,
.recap-item:hover,
.stat-card:hover,
.activity-card:hover,
.health-card:hover,
.timeline-card:hover,
.checklist-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 38px rgba(124, 92, 255, 0.14);
}

.agent-item[data-tone='recovery'],
.bot-chip[data-tone='recovery'],
.performance-card[data-tone='recovery'] {
  background: linear-gradient(180deg, rgba(255, 244, 246, 0.92), rgba(255, 255, 255, 0.88));
}
.agent-item[data-tone='elite'],
.bot-chip[data-tone='elite'],
.performance-card[data-tone='elite'] {
  background: linear-gradient(180deg, rgba(240, 255, 250, 0.92), rgba(255, 255, 255, 0.88));
}
.agent-item[data-tone='leader'],
.bot-chip[data-tone='leader'],
.performance-card[data-tone='leader'] {
  background: linear-gradient(180deg, rgba(255, 252, 238, 0.92), rgba(255, 255, 255, 0.88));
}

.agent-row,
.bot-chip__top,
.bot-chip__title,
.tooltip-hero,
.drawer-hero {
  display: flex;
  gap: 12px;
  align-items: center;
}

.agent-row { align-items: flex-start; }
.agent-body { flex: 1; min-width: 0; }
.agent-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.agent-meta-row { margin-top: 10px; display: grid; gap: 4px; }

.dot {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 8px;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.6), 0 0 16px currentColor;
}
.dot.active, .dot.online, .dot.watching { color: var(--green); background: var(--green); }
.dot.improving { color: var(--orange); background: var(--orange); }
.dot.idle, .dot.standby { color: var(--blue); background: var(--blue); }

.room-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.room-card {
  min-height: 170px;
  padding: 16px;
  border-radius: 24px;
  border: 1px solid rgba(124, 92, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.78), rgba(255,255,255,0.94)),
    radial-gradient(circle at top left, rgba(104, 215, 255, 0.22), transparent 50%),
    radial-gradient(circle at bottom right, rgba(255, 138, 100, 0.18), transparent 46%);
  position: relative;
  overflow: hidden;
  text-align: left;
}

.room-card::after {
  content: '';
  position: absolute;
  width: 120px;
  height: 120px;
  right: -28px;
  bottom: -42px;
  background: radial-gradient(circle, rgba(139, 109, 255, 0.24), transparent 62%);
}

.room-card.active {
  border-color: rgba(124, 92, 255, 0.44);
  box-shadow: 0 22px 44px rgba(124, 92, 255, 0.16);
}
.room-card h4 { margin: 10px 0 6px; }
.room-card p { font-size: 13px; line-height: 1.45; }

.room-badge,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(124, 92, 255, 0.12);
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
}
.score-pill { background: linear-gradient(135deg, rgba(255,255,255,0.7), rgba(104,215,255,0.28)); }

.room-mini-graphic {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 14px;
}
.room-mini-graphic span {
  height: 28px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(104, 215, 255, 0.5), rgba(139, 109, 255, 0.24));
  border: 1px solid rgba(124, 92, 255, 0.12);
}

.mini-stat-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 16px 0; }

.bot-tooltip-card {
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  width: min(360px, 78vw);
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.995);
  border: 2px solid color-mix(in srgb, var(--bot-color, var(--purple)) 48%, white 30%);
  box-shadow: 0 22px 54px rgba(51, 33, 94, 0.20);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 30;
}

.bot-tooltip-card::before {
  content: '';
  position: absolute;
  left: -8px;
  top: calc(50% - 8px);
  width: 16px;
  height: 16px;
  transform: rotate(45deg);
  background: rgba(255, 255, 255, 0.995);
  border-left: 2px solid color-mix(in srgb, var(--bot-color, var(--purple)) 48%, white 30%);
  border-bottom: 2px solid color-mix(in srgb, var(--bot-color, var(--purple)) 48%, white 30%);
}

.agent-item:hover .bot-tooltip-card,
.bot-chip:hover .bot-tooltip-card {
  opacity: 1;
  transform: translateY(-50%) translateX(2px);
}

.tooltip-title { color: var(--text); font-weight: 800; margin-bottom: 4px; }
.tooltip-grid { display: grid; gap: 6px; margin-top: 12px; }
.tooltip-foot { margin-top: 10px; }

.form-stack { display: grid; gap: 8px; margin-bottom: 12px; }
.form-stack input,
.form-stack textarea,
.form-stack select {
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(124,92,255,.18);
  background: rgba(255,255,255,.82);
  font-family: inherit;
  font-size: 14px;
}
.form-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.voice-row select { min-width: min(420px, 100%); flex: 1; }
.revenue-ladder { display: grid; gap: 12px; }
.revenue-card { border-left: 5px solid var(--purple); }
.revenue-card[data-rank='1'] { border-left-color: var(--green); }
.revenue-card[data-rank='2'] { border-left-color: var(--blue); }
.revenue-card[data-rank='3'] { border-left-color: var(--orange); }
.revenue-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.rank-badge { min-width: 40px; justify-content: center; }
.revenue-meta, .revenue-plan-grid { display: grid; gap: 8px; }
.revenue-plan-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 10px; }
.revenue-plan-card { padding: 12px; border-radius: 16px; border: 1px solid rgba(124, 92, 255, 0.12); background: rgba(255,255,255,0.72); }
.revenue-footnote { margin-top: 10px; }
.voice-status-card { border-left: 5px solid var(--blue); }
.voice-status-card--premium { border-left-color: var(--green); }
.voice-status-card--fallback { border-left-color: var(--yellow); }
.voice-status-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }

.identity-grid { display: grid; gap: 8px; }
.identity-grid > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.identity-grid span,
.identity-grid code { text-align: right; }

.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(460px, 100vw);
  height: 100vh;
  padding: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,249,245,0.98));
  box-shadow: -10px 0 40px rgba(44, 27, 85, 0.18);
  border-left: 1px solid rgba(124, 92, 255, 0.12);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 120;
  overflow-y: auto;
}
.detail-drawer.is-open { transform: translateX(0); }
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(36, 20, 62, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 110;
}
.drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }
.detail-drawer__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}
.drawer-hero {
  padding: 16px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(247,243,255,0.95));
  border: 1px solid rgba(124, 92, 255, 0.12);
}
.drawer-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.drawer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.drawer-card,
.drawer-section,
.drawer-empty {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255,255,255,0.82);
  border: 1px solid rgba(124, 92, 255, 0.12);
  margin-bottom: 10px;
}
.drawer-section p { margin: 8px 0 0; line-height: 1.5; }

.footer-stamp {
  margin-top: 8px;
  padding: 14px 18px;
  text-align: center;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(255, 215, 209, 0.5));
  border: 1px dashed rgba(124, 92, 255, 0.25);
}

ul { margin: 8px 0 0 16px; padding: 0; }
li + li { margin-top: 6px; }

@media (max-width: 1450px) {
  .room-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bot-tooltip-card {
    left: auto;
    right: 0;
    top: calc(100% + 10px);
    transform: translateY(0);
  }
  .bot-tooltip-card::before {
    left: auto;
    right: 18px;
    top: -8px;
    border-left: 2px solid color-mix(in srgb, var(--bot-color, var(--purple)) 48%, white 30%);
    border-bottom: none;
    border-top: 2px solid color-mix(in srgb, var(--bot-color, var(--purple)) 48%, white 30%);
    border-right: 2px solid color-mix(in srgb, var(--bot-color, var(--purple)) 48%, white 30%);
  }
  .agent-item:hover .bot-tooltip-card,
  .bot-chip:hover .bot-tooltip-card { transform: translateY(0); }
}

@media (max-width: 1280px) {
  .app-shell { grid-template-columns: 1fr; }
  .main-content { padding: 0 18px 28px 18px; }
  .sidebar { margin-bottom: 0; }
}

@media (max-width: 1180px) {
  .detail-grid--triple { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 1100px) {
  .stats-grid,
  .detail-grid,
  .health-grid,
  .report-status { grid-template-columns: 1fr 1fr; }
  .room-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .stats-grid,
  .detail-grid,
  .room-grid,
  .mini-stat-row,
  .report-status,
  .health-grid,
  .drawer-grid,
  .voice-status-grid,
  .revenue-plan-grid,
  .detail-grid--triple { grid-template-columns: 1fr; }
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .mode-banner {
    flex-direction: column;
    align-items: stretch;
  }
  .bot-tooltip-card {
    width: calc(100vw - 72px);
    right: -4px;
  }
  .hero-card,
  .drawer-hero,
  .agent-row,
  .bot-chip__top { align-items: flex-start; }
}
