/* Community Candle Co CRM - Stylesheet */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #D97706;
  --primary-dark: #B45309;
  --primary-light: #FEF3C7;
  --bg: #F9FAFB;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --text-muted: #6B7280;
  --text-light: #9CA3AF;
  --success: #059669;
  --danger: #DC2626;
  --warning: #D97706;
  --info: #2563EB;
  --sidebar-w: 220px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}

/* ── Login ── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  box-shadow: var(--shadow-md);
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo svg { margin-bottom: 12px; }
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--text); }
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ── Layout ── */
#main-app {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: #1F2937;
  color: #E5E7EB;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid #374151;
  font-weight: 700;
  font-size: 15px;
  color: white;
}
.nav-links {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: #9CA3AF;
  text-decoration: none;
  border-radius: 6px;
  margin: 2px 8px;
  font-size: 13.5px;
  transition: all 0.15s;
  position: relative;
}
.nav-link svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.nav-link:hover { background: #374151; color: #F3F4F6; }
.nav-link.active { background: #D97706; color: white; }
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid #374151;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: #9CA3AF;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}
.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #D1D5DB; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #9CA3AF;
  display: flex;
  align-items: center;
}
.btn-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-icon:hover { color: white; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-muted); margin-bottom: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
input[type="text"], input[type="email"], input[type="tel"], input[type="password"],
input[type="search"], textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(217,119,6,0.1);
}
textarea { resize: vertical; }
.search-input { width: 240px; }
.select-input { width: auto; }

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.contacts-icon { background: #EFF6FF; color: #2563EB; }
.sms-icon { background: #F0FDF4; color: #059669; }
.calls-icon { background: #FFF7ED; color: #D97706; }
.activity-icon { background: #FDF4FF; color: #9333EA; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Dashboard Panels ── */
.dashboard-panels {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
}
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header h3 { font-size: 15px; font-weight: 600; }
.quick-sms { padding: 20px; }

/* ── Activity List ── */
.activity-list { overflow-y: auto; max-height: 400px; }
.activity-item {
  display: flex;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.activity-item:last-child { border-bottom: none; }
.activity-icon-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}
.activity-icon-sm svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ai-sms_in, .ai-sms_out { background: #F0FDF4; color: #059669; }
.ai-call_in, .ai-call_out { background: #FFF7ED; color: #D97706; }
.ai-call_missed { background: #FEF2F2; color: #DC2626; }
.ai-email_in, .ai-email_out { background: #EFF6FF; color: #2563EB; }
.ai-note { background: #F5F3FF; color: #7C3AED; }
.activity-content { flex: 1; min-width: 0; }
.activity-contact { font-weight: 600; font-size: 13px; }
.activity-body { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity-time { font-size: 11px; color: var(--text-light); white-space: nowrap; }

/* ── Data Table ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.data-table th {
  background: #F9FAFB;
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #FAFAFA; }
.data-table .loading { text-align: center; color: var(--text-muted); padding: 40px; }
.contact-name-link { color: var(--primary); cursor: pointer; font-weight: 500; text-decoration: none; }
.contact-name-link:hover { text-decoration: underline; }

/* ── Contact Detail ── */
.contact-detail-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
}
.contact-info-panel { padding: 20px; }
.contact-info-item { margin-bottom: 14px; }
.contact-info-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 3px; }
.contact-info-value { font-size: 14px; color: var(--text); }
.contact-timeline { min-height: 400px; }
.contact-timeline .activity-list { max-height: 600px; }

/* ── SMS View ── */
.sms-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: calc(100vh - 140px);
  overflow: hidden;
}
.sms-threads-panel {
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.sms-thread-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.sms-thread-item:hover { background: #F9FAFB; }
.sms-thread-item.active { background: var(--primary-light); }
.sms-thread-name { font-weight: 500; font-size: 13.5px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.sms-thread-unread { font-weight: 700; color: var(--text); }
.sms-thread-preview { color: var(--text-muted); font-size: 12.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sms-thread-time { font-size: 11px; color: var(--text-light); flex-shrink: 0; }
.sms-unread-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-top: 5px; }
.sms-thread-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sms-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
}
.sms-thread-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  flex-shrink: 0;
}
.sms-thread-header-info { display: flex; flex-direction: column; gap: 2px; }
.sms-thread-header-name { font-weight: 600; font-size: 15px; }
.sms-thread-header-phone { font-size: 12px; color: var(--text-muted); }
.sms-thread-header-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.sms-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sms-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
}
.sms-bubble.inbound {
  background: #F3F4F6;
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.sms-bubble.outbound {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.sms-bubble-time { font-size: 10px; opacity: 0.7; margin-top: 4px; }
.sms-date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
  flex-shrink: 0;
}
.sms-date-separator::before, .sms-date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.sms-date-separator span { font-size: 11px; color: var(--text-light); white-space: nowrap; }
.btn-success { background: #059669; color: white; border: none; }
.btn-success:hover { background: #047857; }
.sms-compose {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.sms-compose textarea {
  flex: 1;
  resize: none;
  max-height: 100px;
  min-height: 40px;
}

/* ── Activity Full List ── */
.activity-list-full {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ── Settings ── */
.settings-layout { display: flex; flex-direction: column; gap: 20px; max-width: 700px; }
.settings-form { padding: 20px; }
.settings-info { padding: 20px; }
.settings-info p { margin-bottom: 8px; font-size: 13.5px; }
.settings-info code {
  display: block;
  background: #F3F4F6;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 12.5px;
  margin-bottom: 8px;
  word-break: break-all;
}
.settings-info .hint { color: var(--text-muted); font-size: 12px; }

/* ── Modals ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--border); }
.modal form, .modal > .form-group { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ── Badges & Status ── */
.badge {
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  margin-left: auto;
}
.error-msg { color: var(--danger); font-size: 13px; padding: 8px 0; }
.status-msg { font-size: 13px; padding: 8px 0; }
.status-msg.success { color: var(--success); }
.status-msg.error { color: var(--danger); }
.loading { text-align: center; color: var(--text-muted); padding: 40px; }

/* ── Tags ── */
.tag {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 12px;
  margin: 2px;
}

/* ── Type Badges ── */
.type-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.type-sms_in { background: #F0FDF4; color: #059669; }
.type-sms_out { background: #ECFDF5; color: #047857; }
.type-call_in { background: #FFF7ED; color: #D97706; }
.type-call_out { background: #FFFBEB; color: #B45309; }
.type-call_missed { background: #FEF2F2; color: #DC2626; }
.type-email_in { background: #EFF6FF; color: #2563EB; }
.type-email_out { background: #EFF6FF; color: #1D4ED8; }
.type-note { background: #F5F3FF; color: #7C3AED; }

/* ── Utility ── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-panels { grid-template-columns: 1fr; }
  .contact-detail-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-header span, .nav-link span, .sidebar-footer span { display: none; }
  .nav-link { justify-content: center; padding: 12px; }
  .content { padding: 16px; }
  .sms-layout { grid-template-columns: 1fr; }
  .sms-threads-panel { display: none; }
}

/* ── Email Inbox ──────────────────────────────────────────────────── */
.email-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.email-message {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px 16px;
  max-width: 85%;
  background: #fff;
}

.email-message.inbound {
  align-self: flex-start;
  border-left: 3px solid #6b7280;
}

.email-message.outbound {
  align-self: flex-end;
  border-left: 3px solid #D97706;
  background: #fffbf0;
}

.email-message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 12px;
}

.email-direction {
  font-size: 11px;
  color: #6b7280;
  font-weight: 500;
}

.email-time {
  font-size: 11px;
  color: #9ca3af;
  white-space: nowrap;
}

.email-subject {
  font-weight: 600;
  font-size: 13px;
  color: #111827;
  margin-bottom: 6px;
}

.email-body {
  font-size: 13px;
  color: #374151;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
