/* ===== Visual Panel ===== */
.visual-panel {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  padding: 24px;
  order: 2; /* Right on desktop */
  min-height: 0; /* Required for flex children to scroll */
  position: relative;
}

/* ===== Fullscreen Toggle ===== */
.fullscreen-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  opacity: 0.7;
}

.fullscreen-btn:hover {
  opacity: 1;
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.fullscreen-btn .icon-collapse { display: none; }

.visual-panel.fullscreen .fullscreen-btn .icon-expand { display: none; }
.visual-panel.fullscreen .fullscreen-btn .icon-collapse { display: block; }

/* Fullscreen state */
.visual-panel.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  flex: none;
  width: 100%;
  height: 100%;
  padding-top: 16px;
}

.visual-panel.fullscreen ~ .chat-panel {
  display: none;
}

.visual-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 900px;
  margin: 0 auto;
}

.visual-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 400px;
  color: var(--text-muted);
  text-align: center;
  gap: 12px;
}

.visual-empty svg { opacity: 0.3; }
.visual-empty p { font-size: 16px; }
.visual-empty span { font-size: 13px; }

/* ===== Skeleton Loading ===== */
.skeleton-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.skeleton {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.04) 50%, transparent 100%);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.skeleton-bar {
  height: 14px;
  background: var(--bg-elevated);
  border-radius: 4px;
}

/* KPI skeleton */
.skeleton-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.skeleton-kpi {
  padding: 16px;
  display: flex;
  gap: 12px;
}

.skeleton-kpi-accent {
  width: 4px;
  border-radius: 2px;
  background: var(--bg-elevated);
}

.skeleton-kpi-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-kpi-label {
  width: 60%;
  height: 10px;
}

.skeleton-kpi-value {
  width: 80%;
  height: 22px;
}

/* Pipeline skeleton */
.skeleton-pipeline {
  padding: 16px;
  display: flex;
  gap: 12px;
  overflow: hidden;
}

.skeleton-column {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-column-header {
  height: 36px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
}

.skeleton-card {
  height: 64px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  opacity: 0.6;
}

.skeleton-card:nth-child(3) { opacity: 0.3; }

/* Table skeleton */
.skeleton-table {
  padding: 0;
}

.skeleton-table-header {
  height: 38px;
  background: var(--bg-elevated);
}

.skeleton-table-row {
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.skeleton-table-row:last-child { border-bottom: none; }

.skeleton-table-cell {
  height: 12px;
  background: var(--bg-elevated);
  border-radius: 4px;
  flex: 1;
}

.skeleton-table-cell:first-child { flex: 2; }
.skeleton-table-cell:last-child { flex: 0.5; }

.visual-block {
  width: 100%;
}

.visual-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}

/* ===== Animation System ===== */

/* Base: hidden before animation */
.anim-ready {
  opacity: 0;
}

.anim-ready.anim-visible {
  opacity: 1;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Fade in */
.anim-fade-in { opacity: 0; }
.anim-fade-in.anim-visible { opacity: 1; }

/* Slide in from left */
.anim-slide-in { opacity: 0; transform: translateX(-20px); }
.anim-slide-in.anim-visible { opacity: 1; transform: translateX(0); }

/* Fade rows — handled via stagger */
.anim-fade-rows { opacity: 0; }
.anim-fade-rows.anim-visible { opacity: 1; }

/* Stagger children */
.stagger-item {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  transition-delay: calc(var(--i, 0) * 80ms);
}

.stagger-item.stagger-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Pipeline ===== */
.pipeline-summary {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.pipeline-stat {
  flex: 1;
  min-width: 120px;
  text-align: center;
}

.pipeline-stat-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.pipeline-stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.pipeline-board {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

.pipeline-column {
  flex: 1;
  min-width: 180px;
  max-width: 260px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.pipeline-column-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 3px solid;
  background: var(--bg-elevated);
}

.pipeline-stage-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pipeline-stage-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.pipeline-stage-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 1px 8px;
  border-radius: 10px;
}

.pipeline-cards {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pipeline-card {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: default;
  transition: border-color var(--transition);
}

.pipeline-card:hover {
  border-color: var(--border-light);
}

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

.pipeline-card-company {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.pipeline-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.pipeline-card-next {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--accent);
}

/* ===== KPI Cards ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
}

.kpi-card-accent {
  width: 4px;
  flex-shrink: 0;
}

.kpi-card-body {
  padding: 16px;
  flex: 1;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.kpi-trend {
  font-size: 12px;
  font-weight: 600;
}

.kpi-trend-up { color: var(--green); }
.kpi-trend-down { color: var(--red); }

.kpi-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== Data Table ===== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 14px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: var(--bg-hover);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green  { background: var(--green-soft);  color: var(--green); }
.badge-red    { background: var(--red-soft);    color: var(--red); }
.badge-yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge-blue   { background: var(--blue-soft);   color: var(--blue); }
.badge-orange { background: var(--orange-soft); color: var(--orange); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }

/* ===== Timeline ===== */
.timeline {
  position: relative;
  padding-left: 32px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 14px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  padding-bottom: 20px;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-dot {
  position: absolute;
  left: -26px;
  top: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  border: 2px solid var(--bg);
}

.timeline-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.timeline-date {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.timeline-type {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.timeline-desc {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

.timeline-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Bar Chart ===== */
.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bar-label {
  width: 120px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: right;
  flex-shrink: 0;
}

.bar-track {
  flex: 1;
  height: 24px;
  background: var(--bg-elevated);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 4px;
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.bar-value {
  width: 60px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

/* ===== Donut Chart ===== */
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 32px;
  flex-wrap: wrap;
}

.donut-chart {
  position: relative;
}

.donut-chart svg {
  transform: rotate(-90deg);
}

.donut-segment {
  opacity: 0;
  animation: donutReveal 0.6s ease forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes donutReveal {
  from { opacity: 0; stroke-dashoffset: 50; }
  to { opacity: 1; stroke-dashoffset: 0; }
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.donut-center-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.donut-center-label {
  font-size: 11px;
  color: var(--text-muted);
}

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

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

.donut-legend-label {
  color: var(--text-secondary);
  flex: 1;
}

.donut-legend-value {
  font-weight: 600;
  color: var(--text);
}

/* ===== Progress Bars ===== */
.progress-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.progress-label {
  font-size: 13px;
  color: var(--text);
}

.progress-pct {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.progress-track {
  height: 8px;
  background: var(--bg-elevated);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 4px;
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ===== Mobile Visuals ===== */
@media (max-width: 768px) {
  .visual-panel {
    padding: 12px 10px;
    border-right: none;
  }

  .visual-content {
    gap: 14px;
  }

  .fullscreen-btn {
    top: 6px;
    right: 6px;
    width: 32px;
    height: 32px;
    opacity: 0.85;
  }

  .visual-panel.fullscreen {
    padding-top: 12px;
  }

  .visual-empty {
    min-height: 120px;
    gap: 8px;
  }

  .visual-empty svg {
    width: 36px;
    height: 36px;
  }

  .visual-empty p { font-size: 14px; }
  .visual-empty span { font-size: 11px; }

  .skeleton-kpi-row { grid-template-columns: repeat(2, 1fr); }
  .skeleton-pipeline { gap: 8px; }
  .skeleton-column { min-width: 100px; }

  .visual-title {
    font-size: 14px;
    margin-bottom: 12px;
  }

  /* Pipeline: horizontal scroll */
  .pipeline-summary {
    gap: 8px;
    padding: 12px;
  }

  .pipeline-stat {
    min-width: 80px;
  }

  .pipeline-stat-value {
    font-size: 16px;
  }

  .pipeline-board {
    gap: 8px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .pipeline-column {
    min-width: 200px;
    max-width: 80vw;
    flex-shrink: 0;
    scroll-snap-align: start;
  }

  /* KPI: 2 columns on mobile */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .kpi-card-body {
    padding: 12px;
  }

  .kpi-value {
    font-size: 18px;
  }

  .kpi-label {
    font-size: 10px;
  }

  /* Table: compact */
  .data-table th,
  .data-table td {
    padding: 8px 10px;
    font-size: 12px;
  }

  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }

  /* Timeline: compact */
  .timeline {
    padding-left: 28px;
  }

  .timeline-dot {
    left: -22px;
    width: 20px;
    height: 20px;
    font-size: 10px;
  }

  .timeline-content {
    padding: 10px 12px;
  }

  /* Bar chart: stack label above */
  .bar-label {
    width: 80px;
    font-size: 11px;
  }

  .bar-value {
    width: 50px;
    font-size: 12px;
  }

  /* Donut: stack vertically */
  .donut-wrap {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }

  .donut-legend {
    width: 100%;
  }

  .donut-legend-item {
    font-size: 12px;
  }
}
