/* ═══════════════════════════════════════════════════════════════
   Building Analysis Panel — Enterprise Building Intelligence
   ═══════════════════════════════════════════════════════════════ */

/* ── Backdrop ── */
.ba-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}
.ba-backdrop.active { display: block; }

/* ── Popup container ── */
.ba-popup {
  display: none;
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 91;
  width: min(960px, 95vw);
  height: 88vh;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25), 0 0 0 1px rgba(0,0,0,0.05);
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.ba-popup.active { display: flex; }

/* ── Header ── */
.ba-header {
  display: flex;
  align-items: center;
  padding: 16px 20px 12px;
  border-bottom: 1px solid #e2e8f0;
  gap: 12px;
  flex-shrink: 0;
}
.ba-header-info { flex: 1; min-width: 0; }
.ba-title {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ba-subtitle {
  font-size: 12px;
  color: #64748b;
  margin-top: 2px;
}
.ba-close {
  width: 32px; height: 32px;
  border: none; background: none;
  font-size: 20px; color: #94a3b8;
  cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ba-close:hover { background: #f1f5f9; color: #475569; }

/* ── KPI bar ── */
.ba-kpi-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}
.ba-kpi-card {
  padding: 10px 14px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  text-align: center;
}
.ba-kpi-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #94a3b8;
  margin-bottom: 4px;
}
.ba-kpi-value {
  font-size: 22px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.1;
}
.ba-kpi-sub {
  font-size: 10px;
  color: #64748b;
  margin-top: 2px;
}

/* ── Tabs ── */
.ba-tabs {
  display: flex;
  border-bottom: 1px solid #e2e8f0;
  padding: 0 20px;
  gap: 0;
  flex-shrink: 0;
  background: #ffffff;
}
.ba-tab {
  padding: 10px 18px;
  border: none;
  background: none;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #94a3b8;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.ba-tab:hover { color: #475569; }
.ba-tab.active {
  color: #0f172a;
  border-bottom-color: #0f172a;
}

/* ── Body (scrollable) ── */
.ba-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* ── Tab panels ── */
.ba-panel { display: none; }
.ba-panel.active { display: block; }

/* ── Section headers ── */
.ba-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #64748b;
  margin: 0 0 12px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ba-section-title::before {
  content: "";
  width: 3px;
  height: 14px;
  background: #0f172a;
  border-radius: 2px;
  flex-shrink: 0;
}
.ba-section { margin-bottom: 24px; }

/* ── Donut chart area ── */
.ba-donut-wrap {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 8px 0;
}
.ba-donut-legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ba-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #334155;
}
.ba-legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ba-legend-label { flex: 1; }
.ba-legend-count {
  font-weight: 700;
  color: #0f172a;
  min-width: 28px;
  text-align: right;
}

/* ── Unit table ── */
.ba-table-wrap {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}
.ba-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.ba-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}
.ba-table th {
  padding: 8px 10px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #64748b;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}
.ba-table td {
  padding: 7px 10px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
  vertical-align: middle;
}
.ba-table tbody tr:hover { background: #f8fafc; }
.ba-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Category badges ── */
.ba-cat-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}
.ba-cat-residenziale { background: #dbeafe; color: #1e40af; }
.ba-cat-commerciale  { background: #d1fae5; color: #065f46; }
.ba-cat-pertinenze   { background: #f1f5f9; color: #475569; }
.ba-cat-uffici       { background: #ede9fe; color: #5b21b6; }
.ba-cat-altro        { background: #fef3c7; color: #92400e; }

/* ── OMI / Market cards ── */
.ba-market-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.ba-market-card {
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}
.ba-market-card-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: #94a3b8;
  margin-bottom: 4px;
}
.ba-market-card-value {
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
}
.ba-market-card-sub {
  font-size: 11px;
  color: #64748b;
  margin-top: 2px;
}

/* ── Trend indicator ── */
.ba-trend-up { color: #16a34a; }
.ba-trend-down { color: #dc2626; }
.ba-trend-flat { color: #64748b; }

/* ── Risk indicators ── */
.ba-risk-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.ba-risk-card {
  padding: 16px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  text-align: center;
}
.ba-risk-card-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 8px;
}
.ba-risk-indicator {
  width: 48px; height: 48px;
  border-radius: 50%;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}
.ba-risk-low    { background: #22c55e; }
.ba-risk-medium { background: #f59e0b; }
.ba-risk-high   { background: #ef4444; }
.ba-risk-info {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

/* ── Report actions ── */
.ba-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.ba-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #ffffff;
  font-size: 13px;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s;
}
.ba-action-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}
.ba-action-btn-primary {
  background: #0f172a;
  color: #ffffff;
  border-color: #0f172a;
}
.ba-action-btn-primary:hover {
  background: #1e293b;
}

/* ── Catasto immobili list ── */
.ba-immobile-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  margin-bottom: 8px;
  transition: background 0.1s;
}
.ba-immobile-row:hover { background: #f8fafc; }
.ba-immobile-info { flex: 1; }
.ba-immobile-title { font-size: 13px; font-weight: 600; color: #0f172a; }
.ba-immobile-meta { font-size: 11px; color: #64748b; margin-top: 2px; }
.ba-immobile-badges { display: flex; gap: 4px; }
.ba-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}
.ba-badge-ok { background: #dcfce7; color: #166534; }
.ba-badge-pending { background: #fef3c7; color: #92400e; }

/* ── Loading / empty states ── */
.ba-loading {
  text-align: center;
  padding: 40px 20px;
  color: #94a3b8;
  font-size: 13px;
}
.ba-empty {
  text-align: center;
  padding: 32px 20px;
  color: #94a3b8;
  font-size: 13px;
  font-style: italic;
}
.ba-error {
  padding: 12px 16px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  font-size: 13px;
}

/* ── SVG Chart container ── */
.ba-chart-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 8px 0;
}
.ba-chart-wrap svg { display: block; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .ba-kpi-bar { grid-template-columns: repeat(2, 1fr); }
  .ba-market-grid { grid-template-columns: 1fr; }
  .ba-risk-grid { grid-template-columns: 1fr; }
  .ba-donut-wrap { flex-direction: column; }
}
