@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Inter:wght@300;400;500;600&display=swap');

:root {
  --purple: #6B3FA0;
  --purple-light: #8B5FBF;
  --purple-dark: #4A2570;
  --purple-deep: #1A0A30;
  --purple-glow: rgba(107,63,160,0.15);
  --gold: #D4A843;
  --gold-light: #E8C76A;
  --gold-muted: rgba(212,168,67,0.2);
  --bg: #0D0A14;
  --bg-2: #141020;
  --bg-3: #1C1530;
  --bg-4: #251D3A;
  --card: #181228;
  --text: #E8E0F0;
  --text-2: #A89BB8;
  --text-3: #6B5F7A;
  --border: rgba(107,63,160,0.25);
  --success: #4ADE80;
  --danger: #F87171;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); overflow: hidden; height: 100vh; }

/* ── TOPBAR ── */
.topbar {
  height: 60px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem; background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.topbar-brand { display: flex; align-items: center; gap: 0.75rem; }
.topbar-logo {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--gold));
  display: flex; align-items: center; justify-content: center;
  font-family: 'Playfair Display', serif; font-size: 1.1rem; font-weight: 700; color: #fff;
}
.topbar-title { font-family: 'Playfair Display', serif; font-size: 1.1rem; font-weight: 600; color: var(--gold); }
.topbar-sub { font-size: 0.65rem; color: var(--text-3); letter-spacing: 2px; text-transform: uppercase; }

.topbar-nav { display: flex; gap: 0.25rem; }
.topbar-nav button {
  padding: 0.5rem 1rem; background: transparent; border: 1px solid transparent;
  color: var(--text-2); font-size: 0.75rem; letter-spacing: 1px; text-transform: uppercase;
  cursor: pointer; font-family: 'Inter', sans-serif; transition: all 0.3s; border-radius: 4px;
}
.topbar-nav button.active { background: var(--purple-glow); border-color: var(--border); color: var(--gold); }
.topbar-nav button:hover { color: var(--gold); }

.topbar-status { display: flex; align-items: center; gap: 0.5rem; font-size: 0.75rem; color: var(--text-2); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.status-dot.busy { background: var(--gold); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── LAYOUT ── */
.app-container { display: flex; height: calc(100vh - 60px); }

/* ── CHAT PANEL ── */
.chat-panel {
  width: 380px; min-width: 380px; display: flex; flex-direction: column;
  background: var(--bg-2); border-right: 1px solid var(--border);
}
.chat-header {
  padding: 1.2rem 1rem; border-bottom: 1px solid var(--border);
}
.chat-header h2 { font-family: 'Playfair Display', serif; font-size: 1rem; color: var(--gold); margin-bottom: 0.75rem; }

.ai-status { display: flex; align-items: center; gap: 0.5rem; }
.ai-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.ai-label { font-size: 0.7rem; color: var(--text-3); }
.ai-badge {
  font-size: 0.6rem; padding: 0.15rem 0.5rem; border-radius: 3px;
  background: rgba(74,222,128,0.1); color: var(--success); margin-left: auto;
  letter-spacing: 1px; text-transform: uppercase;
}

.chat-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--purple-dark); border-radius: 2px; }

.chat-msg {
  max-width: 90%; padding: 0.75rem 1rem; font-size: 0.85rem; line-height: 1.6; border-radius: 8px;
}
.chat-msg.assistant { background: var(--bg-3); color: var(--text); align-self: flex-start; border-bottom-left-radius: 2px; }
.chat-msg.user { background: var(--purple); color: #fff; align-self: flex-end; border-bottom-right-radius: 2px; }
.chat-msg.system { background: var(--gold-muted); color: var(--gold); align-self: center; font-size: 0.75rem; text-align: center; }
.chat-msg strong { color: var(--gold); }
.chat-msg code { background: rgba(0,0,0,0.3); padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.8rem; }

.typing-indicator { display: flex; gap: 4px; padding: 0.3rem 0; }
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--purple-light);
  animation: typing 1.4s infinite both;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%,80%,100% { transform: scale(0.6); opacity: 0.3; } 40% { transform: scale(1); opacity: 1; } }

.chat-quick { padding: 0.5rem 1rem; display: flex; gap: 0.4rem; flex-wrap: wrap; border-top: 1px solid var(--border); }
.chat-quick button {
  padding: 0.35rem 0.75rem; background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-2); font-size: 0.7rem; cursor: pointer; border-radius: 20px;
  font-family: 'Inter', sans-serif; transition: all 0.2s;
}
.chat-quick button:hover { border-color: var(--gold); color: var(--gold); }

.chat-input-area {
  padding: 0.75rem 1rem; display: flex; gap: 0.5rem; align-items: flex-end;
  border-top: 1px solid var(--border); background: var(--bg-2);
}
.chat-input-area textarea {
  flex: 1; background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  padding: 0.6rem 0.8rem; font-size: 0.85rem; font-family: 'Inter', sans-serif;
  border-radius: 6px; resize: none; outline: none; min-height: 38px; max-height: 120px;
}
.chat-input-area textarea:focus { border-color: var(--purple-light); }
.chat-input-area textarea::placeholder { color: var(--text-3); }
.chat-send, .chat-voice {
  width: 38px; height: 38px; border-radius: 6px; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.chat-send { background: var(--purple); }
.chat-send:hover { background: var(--purple-light); }
.chat-send svg { width: 16px; height: 16px; fill: #fff; }
.chat-voice { background: var(--bg-3); border: 1px solid var(--border); }
.chat-voice:hover { border-color: var(--purple-light); }
.chat-voice svg { width: 16px; height: 16px; fill: var(--text-2); }
.chat-voice.recording { background: var(--danger); border-color: var(--danger); }
.chat-voice.recording svg { fill: #fff; }

/* ── MAIN CONTENT ── */
.main-content { flex: 1; overflow-y: auto; padding: 1.5rem 2rem; }
.main-content::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-thumb { background: var(--purple-dark); border-radius: 3px; }

/* ── STATS ── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 2rem; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); padding: 1.2rem;
  border-radius: 8px; position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(to right, var(--purple), var(--gold));
}
.stat-label { font-size: 0.65rem; letter-spacing: 2px; text-transform: uppercase; color: var(--text-3); }
.stat-value { font-family: 'Playfair Display', serif; font-size: 2rem; color: var(--gold); margin: 0.3rem 0; }
.stat-detail { font-size: 0.75rem; color: var(--text-2); }

/* ── SECTION HEADERS ── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.section-title { font-family: 'Playfair Display', serif; font-size: 1.3rem; color: var(--text); }
.section-sub { font-size: 0.75rem; color: var(--text-3); margin-top: 0.2rem; }

.refresh-btn {
  padding: 0.6rem 1.5rem; background: transparent; border: 1px solid var(--gold);
  color: var(--gold); font-size: 0.7rem; letter-spacing: 2px; text-transform: uppercase;
  cursor: pointer; font-family: 'Inter', sans-serif; transition: all 0.3s; border-radius: 4px;
}
.refresh-btn:hover { background: var(--gold); color: var(--bg); }
.refresh-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── FILTER ── */
.filter-bar { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; }
.filter-bar input {
  flex: 1; min-width: 200px; padding: 0.6rem 1rem; background: var(--card);
  border: 1px solid var(--border); color: var(--text); font-size: 0.85rem;
  font-family: 'Inter', sans-serif; border-radius: 4px; outline: none;
}
.filter-bar input:focus { border-color: var(--purple-light); }
.filter-bar input::placeholder { color: var(--text-3); }
.chip {
  padding: 0.4rem 1rem; background: transparent; border: 1px solid var(--border);
  color: var(--text-3); font-size: 0.7rem; letter-spacing: 1px; text-transform: uppercase;
  cursor: pointer; font-family: 'Inter', sans-serif; transition: all 0.2s; border-radius: 20px;
}
.chip.active { background: var(--purple); border-color: var(--purple); color: #fff; }
.chip:hover { border-color: var(--purple-light); color: var(--text); }

/* ── OPP CARDS ── */
.region-header {
  display: flex; align-items: center; gap: 0.5rem;
  margin: 1.5rem 0 1rem; padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.region-header h3 { font-family: 'Playfair Display', serif; font-size: 1.1rem; color: var(--text); }
.region-count {
  font-size: 0.65rem; padding: 0.15rem 0.5rem; background: var(--purple-glow);
  border: 1px solid var(--border); color: var(--purple-light); border-radius: 10px;
}

.opp-grid { display: flex; flex-direction: column; gap: 0.75rem; }
.opp-card {
  background: var(--card); border: 1px solid var(--border); padding: 1.2rem 1.5rem;
  border-radius: 8px; position: relative; transition: all 0.3s;
}
.opp-card:hover { border-color: var(--purple-light); background: var(--bg-3); }

.opp-source {
  font-size: 0.6rem; letter-spacing: 2px; text-transform: uppercase;
  color: var(--gold); margin-bottom: 0.5rem;
}
.opp-score {
  position: absolute; top: 1.2rem; right: 3.5rem;
  font-size: 0.75rem; font-weight: 600; color: var(--success);
  background: rgba(74,222,128,0.1); padding: 0.2rem 0.5rem; border-radius: 3px;
}
.bookmark-btn {
  position: absolute; top: 1rem; right: 1.2rem;
  background: none; border: none; font-size: 1.2rem; color: var(--text-3);
  cursor: pointer; transition: 0.2s;
}
.bookmark-btn:hover, .bookmark-btn.saved { color: var(--gold); }

.opp-title { font-family: 'Playfair Display', serif; font-size: 1.05rem; margin-bottom: 0.5rem; }
.opp-title a { color: var(--text); text-decoration: none; transition: color 0.2s; }
.opp-title a:hover { color: var(--gold); }
.opp-desc { font-size: 0.8rem; color: var(--text-2); line-height: 1.6; margin-bottom: 0.75rem; }
.opp-location { font-size: 0.75rem; color: var(--text-3); margin-bottom: 0.75rem; }

.opp-tags { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.opp-tag {
  font-size: 0.6rem; padding: 0.2rem 0.5rem; background: var(--purple-glow);
  border: 1px solid var(--border); color: var(--purple-light); border-radius: 3px;
  letter-spacing: 1px;
}

.opp-actions { display: flex; gap: 0.4rem; }
.opp-btn {
  padding: 0.4rem 0.8rem; font-size: 0.7rem; border: 1px solid var(--border);
  background: transparent; color: var(--text-2); cursor: pointer;
  font-family: 'Inter', sans-serif; transition: all 0.2s; border-radius: 4px;
}
.opp-btn:hover { border-color: var(--purple-light); color: var(--text); }
.opp-btn.primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.opp-btn.primary:hover { background: var(--purple-light); }

/* ── TAB PANELS ── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── EMPTY STATE ── */
.empty-state { text-align: center; padding: 3rem; color: var(--text-3); }
.empty-state h3 { font-family: 'Playfair Display', serif; color: var(--text-2); margin-bottom: 0.5rem; }

/* ── SENT TABLE ── */
.sent-table { width: 100%; border-collapse: collapse; }
.sent-table th {
  text-align: left; font-size: 0.65rem; letter-spacing: 2px; text-transform: uppercase;
  color: var(--text-3); padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
}
.sent-table td { padding: 0.75rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.03); font-size: 0.85rem; }

/* ── COMPOSE MODAL ── */
.compose-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 1000; align-items: center; justify-content: center;
  backdrop-filter: blur(5px);
}
.compose-overlay.show { display: flex; }
.compose-modal {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 2rem; width: 90%; max-width: 600px; max-height: 80vh; overflow-y: auto;
}
.compose-modal h3 { font-family: 'Playfair Display', serif; color: var(--gold); margin-bottom: 1.5rem; }
.compose-field { margin-bottom: 1rem; }
.compose-field label { display: block; font-size: 0.65rem; letter-spacing: 2px; text-transform: uppercase; color: var(--text-3); margin-bottom: 0.3rem; }
.compose-field input, .compose-field textarea {
  width: 100%; background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  padding: 0.7rem 1rem; font-size: 0.85rem; font-family: 'Inter', sans-serif;
  border-radius: 4px; outline: none;
}
.compose-field input:focus, .compose-field textarea:focus { border-color: var(--purple-light); }
.compose-field textarea { min-height: 200px; resize: vertical; }
.compose-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }
.compose-actions button { padding: 0.6rem 1.5rem; font-size: 0.75rem; letter-spacing: 1px; cursor: pointer; font-family: 'Inter', sans-serif; border-radius: 4px; }
.btn-save { background: var(--purple); border: none; color: #fff; }
.btn-save:hover { background: var(--purple-light); }
.btn-cancel { background: transparent; border: 1px solid var(--border); color: var(--text-2); }
.btn-cancel:hover { border-color: var(--text-2); }

/* ── OUTREACH TAB ── */
.template-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.template-card {
  background: var(--card); border: 1px solid var(--border); padding: 1.2rem;
  border-radius: 8px; cursor: pointer; transition: all 0.3s;
}
.template-card:hover { border-color: var(--purple-light); }
.template-card h4 { font-family: 'Playfair Display', serif; color: var(--gold); margin-bottom: 0.5rem; }
.template-card p { font-size: 0.8rem; color: var(--text-2); line-height: 1.5; }

/* ── MOBILE ── */
.mobile-chat-toggle {
  display: none; position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 999;
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--gold));
  border: none; cursor: pointer; color: #fff;
  box-shadow: 0 4px 20px rgba(107,63,160,0.4);
}
.mobile-chat-toggle svg { width: 24px; height: 24px; fill: currentColor; }

@media (max-width: 768px) {
  .topbar-nav { display: none; }
  .app-container { flex-direction: column; }
  .chat-panel {
    display: none; position: fixed; inset: 0; z-index: 998;
    width: 100%; min-width: 100%;
  }
  .chat-panel.mobile-open { display: flex; }
  .mobile-chat-toggle { display: flex; align-items: center; justify-content: center; }
  .main-content { padding: 1rem; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}
