/* ════════════════════ AreaPulse Civic AI Widget ═════════════════════ */

#ai-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #C84B31 0%, #B73A22 100%);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(200, 75, 49, 0.35);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
#ai-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 26px rgba(200, 75, 49, 0.5);
}
#ai-fab-pulse {
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid rgba(200, 75, 49, 0.6);
  animation: ai-pulse 2s ease-out infinite;
  pointer-events: none;
}
@keyframes ai-pulse {
  0%   { transform: scale(0.95); opacity: 0.8; }
  100% { transform: scale(1.4);  opacity: 0; }
}

.ai-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 36px);
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  transform-origin: bottom right;
  animation: ai-pop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.ai-panel.hidden { display: none; }
@keyframes ai-pop {
  from { opacity: 0; transform: scale(0.92) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(200,75,49,0.07), rgba(200,75,49,0.02));
}
.ai-header-left { display: flex; align-items: center; gap: 10px; }
.ai-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #C84B31, #1B4F72);
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
}
.ai-title { font-family: 'DM Serif Display', serif; font-size: 16px; line-height: 1.1; }
.ai-status { font-size: 11px; color: var(--text2); display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.ai-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #2D6A4F;
  box-shadow: 0 0 8px #2D6A4F;
  display: inline-block;
}
.ai-close {
  background: transparent; border: none; cursor: pointer; font-size: 24px;
  color: var(--text2); padding: 0 6px; line-height: 1;
}
.ai-close:hover { color: var(--text); }

.ai-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-tab {
  flex: 1; padding: 10px; text-align: center; font-size: 12.5px;
  font-weight: 500; cursor: pointer; color: var(--text2);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.ai-tab:hover { color: var(--text); }
.ai-tab.active { color: #C84B31; border-bottom-color: #C84B31; }

.ai-tab-panel { flex: 1; overflow: hidden; display: none; flex-direction: column; }
.ai-tab-panel.active { display: flex; }

/* FIX: Insights and Copilot tab content needs to scroll when it overflows.
   Chat already has its own scrollable .ai-messages — these don't, so the
   inner div was clipped. Take over the scroll on the inner content. */
#ai-tab-insights, #ai-tab-copilot {
  overflow: hidden;
}
#ai-insights-content,
#ai-tab-copilot > div:first-child {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;   /* smooth momentum scroll on iOS */
}

/* Chat */
.ai-messages {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.ai-msg { display: flex; }
.ai-msg-bot { justify-content: flex-start; }
.ai-msg-user { justify-content: flex-end; }
.ai-msg-bubble {
  max-width: 85%; padding: 10px 13px; border-radius: 14px;
  font-size: 13.5px; line-height: 1.5;
  background: var(--surface2); color: var(--text);
}
.ai-msg-user .ai-msg-bubble {
  background: #C84B31; color: white;
  border-bottom-right-radius: 4px;
}
.ai-msg-bot .ai-msg-bubble { border-bottom-left-radius: 4px; }
.ai-msg-bubble b { font-weight: 600; }

.ai-suggested {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px;
}
.ai-chip {
  padding: 6px 11px; border-radius: 14px; font-size: 12px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; color: var(--text); font-family: inherit;
  transition: all 0.15s;
}
.ai-chip:hover { background: #C84B31; color: white; border-color: #C84B31; }

.ai-input-row {
  display: flex; gap: 8px; padding: 12px;
  border-top: 1px solid var(--border); flex-shrink: 0;
  background: var(--surface);
}
#ai-input {
  flex: 1; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 18px; font-family: inherit; font-size: 13px;
  background: var(--bg); color: var(--text); outline: none;
}
#ai-input:focus { border-color: #C84B31; }

/* AI table renderer */
.ai-table-wrap {
  margin-top: 8px; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; background: var(--bg);
}
.ai-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ai-table th, .ai-table td {
  padding: 7px 10px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.ai-table th {
  background: var(--surface2); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.ai-table tr:last-child td { border-bottom: none; }

/* Insight cards */
.ai-insight-card {
  display: flex; gap: 10px; padding: 12px;
  border: 1px solid var(--border); border-left-width: 3px;
  border-radius: 8px; margin-bottom: 10px;
  background: var(--surface);
}
.ai-insight-card.priority-high   { border-left-color: #C84B31; }
.ai-insight-card.priority-medium { border-left-color: #B7770D; }
.ai-insight-card.priority-low    { border-left-color: #2D6A4F; }
.ai-insight-icon { font-size: 18px; flex-shrink: 0; }
.ai-insight-msg { font-size: 12.5px; line-height: 1.5; }

/* Copilot result */
.copilot-result {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; background: var(--surface);
}
.copilot-row {
  display: flex; justify-content: space-between;
  font-size: 12.5px; padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.copilot-row:last-child { border-bottom: none; }
.copilot-key { color: var(--text2); }
.copilot-val { font-weight: 600; }

/* Moderation banner */
.ai-mod-banner {
  margin-top: 8px; padding: 8px 11px; border-radius: 8px;
  font-size: 12px; display: flex; align-items: center; gap: 8px;
}
.ai-mod-allow  { background: rgba(45,106,79,0.1);  color: #2D6A4F; border: 1px solid rgba(45,106,79,0.25); }
.ai-mod-review { background: rgba(183,119,13,0.12); color: #B7770D; border: 1px solid rgba(183,119,13,0.3); }
.ai-mod-block  { background: rgba(200,75,49,0.12); color: #C84B31; border: 1px solid rgba(200,75,49,0.3); }

.ai-loading {
  display: flex; flex-direction: column; align-items: center;
  padding: 30px 0; gap: 10px; color: var(--text2); font-size: 13px;
}

/* Map markers list (when AI returns map_markers) */
.ai-marker-list {
  margin-top: 8px; max-height: 180px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px;
}
.ai-marker-row {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  font-size: 12px; cursor: pointer; transition: background 0.12s;
}
.ai-marker-row:hover { background: var(--surface2); }
.ai-marker-row:last-child { border-bottom: none; }
.ai-marker-row .marker-sev {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  margin-right: 6px;
}
.marker-sev.high   { background: #C84B31; }
.marker-sev.medium { background: #B7770D; }
.marker-sev.low    { background: #2D6A4F; }

/* Mobile */
@media (max-width: 600px) {
  .ai-panel {
    bottom: 80px; right: 12px; left: 12px; width: auto;
    height: 70vh;
  }
  #ai-fab { right: 16px; bottom: 16px; }
}

/* Dark mode tweaks */
body.dark .ai-msg-bubble { background: rgba(255,255,255,0.06); }
body.dark .ai-panel { box-shadow: 0 24px 60px rgba(0,0,0,0.5); }

/* ════════════════════════════════════════════════════════════
   AreaPulse Dashboard Modal — single-area + 2-area compare
   ══════════════════════════════════════════════════════════ */

/* Inline preview card (in chat bubble) */
.ai-dash-preview {
  margin-top: 10px;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(200,75,49,0.08), rgba(27,79,114,0.08));
  border: 1px solid rgba(200,75,49,0.20);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.ai-dash-preview:hover { border-color: var(--accent); transform: translateY(-1px); }
.ai-dash-preview-title {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 14px; color: var(--text);
}
.ai-dash-preview-sub { font-size: 12px; color: var(--text2); margin-top: 4px; }
.ai-dash-preview-cta { font-size: 11px; color: var(--accent); margin-top: 6px; font-weight: 500; }

/* Modal backdrop */
.ai-dash-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,13,11,0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  padding: 20px;
  animation: aiDashFadeIn 0.2s ease;
}
.ai-dash-modal-backdrop.hidden { display: none; }
@keyframes aiDashFadeIn { from { opacity: 0; } to { opacity: 1; } }

.ai-dash-modal-card {
  background: var(--bg, #F5F3EE);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 16px;
  width: min(960px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 28px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.30);
  animation: aiDashSlideUp 0.25s ease;
}
@keyframes aiDashSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
body.dark .ai-dash-modal-card {
  background: #1A1714;
  border-color: rgba(255,255,255,0.08);
}

.ai-dash-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px;
  background: rgba(0,0,0,0.05); border: none; border-radius: 50%;
  cursor: pointer; font-size: 16px; color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
}
.ai-dash-close:hover { background: rgba(0,0,0,0.10); color: var(--text); }
body.dark .ai-dash-close { background: rgba(255,255,255,0.08); }
body.dark .ai-dash-close:hover { background: rgba(255,255,255,0.16); }

/* Header */
.ai-dash-header {
  padding-bottom: 14px; margin-bottom: 16px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
body.dark .ai-dash-header { border-color: rgba(255,255,255,0.08); }
.ai-dash-kicker {
  font-size: 11px; letter-spacing: 0.08em; color: var(--text2);
  font-weight: 600; text-transform: uppercase;
}
.ai-dash-title {
  font-size: 22px; font-weight: 600; color: var(--text);
  margin-top: 2px; font-family: Georgia, serif;
}

/* Success banner */
.ai-dash-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 10px; margin-bottom: 16px;
  font-size: 13px;
}
.ai-dash-banner-success {
  background: rgba(45,106,79,0.12); color: #1F4D38; border: 1px solid rgba(45,106,79,0.20);
}
.ai-dash-banner-icon {
  width: 24px; height: 24px; border-radius: 50%; background: #2D6A4F; color: #FFF;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px;
  flex-shrink: 0;
}
body.dark .ai-dash-banner-success { color: #98D9B4; }

/* Stats row */
.ai-dash-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  margin-bottom: 16px;
}
.ai-dash-stat {
  background: rgba(0,0,0,0.03); padding: 12px 14px; border-radius: 10px;
}
body.dark .ai-dash-stat { background: rgba(255,255,255,0.04); }
.ai-dash-stat-label { font-size: 11px; color: var(--text2); }
.ai-dash-stat-num { font-size: 24px; font-weight: 600; margin-top: 4px; font-family: Georgia, serif; }

/* Panels (categories, severity, trend, NGOs) */
.ai-dash-panel {
  background: rgba(0,0,0,0.03); padding: 14px 16px; border-radius: 10px;
  margin-bottom: 12px;
}
body.dark .ai-dash-panel { background: rgba(255,255,255,0.04); }
.ai-dash-panel-title {
  font-size: 11px; letter-spacing: 0.06em; color: var(--text2);
  text-transform: uppercase; font-weight: 600; margin-bottom: 10px;
}

.ai-dash-grid-2 {
  display: grid; grid-template-columns: 1.3fr 1fr; gap: 12px;
  margin-bottom: 12px;
}

/* Category bars */
.ai-dash-bar-row {
  display: grid; grid-template-columns: 80px 1fr 30px;
  align-items: center; gap: 10px;
  font-size: 12.5px;
  margin-bottom: 6px;
}
.ai-dash-bar-label { color: var(--text2); }
.ai-dash-bar {
  height: 8px; background: rgba(0,0,0,0.08); border-radius: 4px; overflow: hidden;
}
body.dark .ai-dash-bar { background: rgba(255,255,255,0.10); }
.ai-dash-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s ease; }
.ai-dash-bar-num { font-weight: 600; text-align: right; }

/* Severity donut */
.ai-dash-severity {
  display: flex; align-items: center; gap: 14px;
}
.ai-dash-donut {
  width: 80px; height: 80px; border-radius: 50%;
  position: relative; flex-shrink: 0;
}
.ai-dash-donut-hole {
  position: absolute; inset: 18px;
  background: var(--bg, #F5F3EE);
  border-radius: 50%;
}
body.dark .ai-dash-donut-hole { background: #1A1714; }
.ai-dash-sev-legend { font-size: 12px; color: var(--text2); display: flex; flex-direction: column; gap: 4px; }
.ai-dash-sev-legend .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px;
}
.ai-dash-sev-legend b { color: var(--text); margin-left: 4px; }

/* NGO list */
.ai-dash-ngo-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-top: 1px solid rgba(0,0,0,0.06);
  font-size: 13px;
}
body.dark .ai-dash-ngo-row { border-color: rgba(255,255,255,0.06); }
.ai-dash-ngo-row:first-child { border-top: none; }
.ai-dash-ngo-name { font-weight: 500; color: var(--text); }
.ai-dash-ngo-meta { font-size: 11px; color: var(--text2); margin-top: 2px; }
.ai-dash-ngo-rating { color: #B7770D; font-weight: 600; font-size: 13px; }

.ai-dash-empty {
  font-size: 12px; color: var(--text3); padding: 8px 0; font-style: italic;
}

/* Verdict box */
.ai-dash-verdict {
  margin-top: 16px; padding: 12px 14px;
  background: rgba(27,79,114,0.08);
  border: 1px solid rgba(27,79,114,0.18);
  border-radius: 10px; font-size: 13px; color: var(--text);
  line-height: 1.5;
}
.ai-dash-verdict b { color: #1B4F72; }
body.dark .ai-dash-verdict { background: rgba(85,183,234,0.10); border-color: rgba(85,183,234,0.20); }
body.dark .ai-dash-verdict b { color: #85B7EA; }

/* Compare mode */
.ai-dash-compare-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 12px;
}
.ai-dash-mini {
  background: rgba(0,0,0,0.03); padding: 16px; border-radius: 10px;
}
body.dark .ai-dash-mini { background: rgba(255,255,255,0.04); }
.ai-dash-mini-header {
  font-size: 14px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase;
}
.ai-dash-mini-num {
  font-size: 36px; font-weight: 600; font-family: Georgia, serif;
  margin: 4px 0 8px;
}
.ai-dash-mini-stats {
  display: flex; gap: 12px; font-size: 12px; color: var(--text2);
  padding-bottom: 12px; border-bottom: 1px solid rgba(0,0,0,0.08); margin-bottom: 12px;
}
body.dark .ai-dash-mini-stats { border-color: rgba(255,255,255,0.08); }
.ai-dash-mini-stats b { color: var(--text); }
.ai-dash-mini-section-title {
  font-size: 10.5px; letter-spacing: 0.06em; color: var(--text3);
  text-transform: uppercase; font-weight: 600; margin: 12px 0 6px;
}
.ai-dash-mini-sev {
  font-size: 12.5px; color: var(--text2);
}
.ai-dash-mini-sev b { color: var(--text); }
.ai-dash-ngo-mini {
  font-size: 12px; color: var(--text2); padding: 3px 0;
}

/* Mobile */
@media (max-width: 720px) {
  .ai-dash-modal-card { padding: 18px 16px; max-height: 95vh; }
  .ai-dash-stats { grid-template-columns: repeat(2, 1fr); }
  .ai-dash-grid-2 { grid-template-columns: 1fr; }
  .ai-dash-compare-grid { grid-template-columns: 1fr; }
  .ai-dash-title { font-size: 18px; }
  .ai-dash-stat-num { font-size: 20px; }
  .ai-dash-mini-num { font-size: 28px; }
  .ai-dash-bar-row { grid-template-columns: 70px 1fr 30px; font-size: 12px; }
}