/* ============================================================
   DunningBee Dashboard Styles
   Used by: dashboard.html
   Colors:
     Primary amber: #F59E0B
     Dark:          #1F2937
     Background:    #F9FAFB
     Success:       #10B981
     Danger:        #EF4444
     Border:        #E5E7EB
     Text muted:    #6B7280
   ============================================================ */

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

:root {
  --primary: #F59E0B;
  --primary-dark: #D97706;
  --primary-light: #FEF3C7;
  --dark: #1F2937;
  --dark-mid: #374151;
  --bg: #F9FAFB;
  --white: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --text-muted: #6B7280;
  --text-faint: #9CA3AF;
  --success: #10B981;
  --success-bg: #D1FAE5;
  --danger: #EF4444;
  --danger-bg: #FEE2E2;
  --warning: #F59E0B;
  --warning-bg: #FEF3C7;
  --info: #3B82F6;
  --info-bg: #DBEAFE;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────── */

.db-header {
  background: var(--dark);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.db-header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.db-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: white;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  flex-shrink: 0;
}

.db-logo-bee { font-size: 20px; line-height: 1; }
.db-logo-accent { color: var(--primary); }

.db-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.db-account-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 13px;
  color: rgba(255,255,255,0.8);
}

.db-account-badge .account-dot {
  width: 7px;
  height: 7px;
  background: var(--success);
  border-radius: 50%;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  line-height: 1;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
  background: transparent;
  color: rgba(255,255,255,0.75);
  border: 1px solid rgba(255,255,255,0.2);
}
.btn-outline:hover {
  background: rgba(255,255,255,0.07);
  color: white;
  border-color: rgba(255,255,255,0.35);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--white); color: var(--text); }

.btn-sm {
  font-size: 12px;
  padding: 5px 10px;
}

/* ── Demo banner ─────────────────────────────────────────── */

.demo-banner {
  background: linear-gradient(135deg, #D97706 0%, #F59E0B 60%, #FBBF24 100%);
  color: var(--dark);
  padding: 12px 24px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  border-bottom: 2px solid rgba(0,0,0,0.1);
}

.demo-banner-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.demo-banner-hint {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.75;
}

.demo-banner-cta {
  background: var(--dark) !important;
  color: var(--primary) !important;
  border: none;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  flex-shrink: 0;
}

.demo-banner-cta:hover {
  background: #111827 !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.demo-banner a {
  color: var(--dark);
  text-decoration: underline;
  font-weight: 700;
}

/* Demo account dot — amber instead of green */
.account-dot.demo-dot {
  background: var(--primary) !important;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Main layout ─────────────────────────────────────────── */

.db-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

/* Page title */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.4px;
}

.page-header p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Stats cards ─────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s;
}

.stat-card:hover { box-shadow: var(--shadow); }

.stat-card-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-card-icon {
  font-size: 14px;
}

.stat-card-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--text);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-card-value.success { color: var(--success); }
.stat-card-value.danger  { color: var(--danger); }
.stat-card-value.primary { color: var(--primary-dark); }

.stat-card-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-card-sub .tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.tag.success { background: var(--success-bg); color: #065F46; }
.tag.danger  { background: var(--danger-bg);  color: #991B1B; }
.tag.warning { background: var(--warning-bg); color: #92400E; }
.tag.info    { background: var(--info-bg);    color: #1E40AF; }

/* ── Two-column layout (chart + email preview) ───────────── */

.content-grid {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 20px;
  margin-bottom: 20px;
}

/* ── Panel base ──────────────────────────────────────────── */

.panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.panel-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.panel-body {
  padding: 20px;
}

/* ── Chart panel ─────────────────────────────────────────── */

.chart-panel { min-height: 300px; }

.chart-wrapper {
  position: relative;
  height: 260px;
}

/* ── Email preview panel ─────────────────────────────────── */

.email-preview-panel {
  display: flex;
  flex-direction: column;
}

.email-preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  flex: 1;
  min-height: 240px;
}

.email-preview-empty-icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.email-preview-empty p {
  font-size: 13px;
  max-width: 200px;
}

.email-preview-content { display: none; }

.email-preview-content.active { display: block; }

/* Demo-mode callout note above email preview */
.preview-template-note {
  display: none;
  background: #FEF3C7;
  border-left: 3px solid var(--primary);
  color: #92400E;
  font-size: 11.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 12px 20px 0;
  line-height: 1.4;
}

.email-preview-meta {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.email-meta-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 12px;
}

.email-meta-row:last-child { margin-bottom: 0; }

.email-meta-label {
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  min-width: 36px;
  flex-shrink: 0;
}

.email-meta-value {
  color: var(--text);
  font-weight: 500;
}

.email-subject-line {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.email-body {
  padding: 16px 20px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.65;
  max-height: 360px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ── Demo panel CTA ──────────────────────────────────────── */

.demo-panel-cta {
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  background: linear-gradient(135deg, #FFFBEB 0%, #FEF3C7 100%);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.demo-panel-cta-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.demo-panel-cta-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--dark);
}

.demo-panel-cta-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Failed payments table ───────────────────────────────── */

.table-panel {
  margin-bottom: 20px;
}

.table-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 160px;
  max-width: 280px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 10px 0 30px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E") no-repeat 10px center;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--primary); }

.filter-select {
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--primary); }

.table-container { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

thead th:hover { color: var(--text); }

thead th.sorted { color: var(--primary-dark); }

thead th .sort-icon {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.4;
  font-size: 9px;
}

thead th.sorted .sort-icon { opacity: 1; }

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }

tbody tr:hover { background: #FAFBFD; }

tbody tr.selected { background: var(--primary-light) !important; }

tbody td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text);
  vertical-align: middle;
}

.td-date { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.td-email { font-weight: 500; }
.td-email .email-sub { font-weight: 400; font-size: 12px; color: var(--text-muted); }
.td-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.td-action { font-size: 12px; color: var(--text-muted); max-width: 160px; }

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 100px;
  text-transform: capitalize;
  white-space: nowrap;
}

.status-badge::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.pending  { background: #FEF3C7; color: #92400E; }
.status-badge.emailing { background: #DBEAFE; color: #1E40AF; }
.status-badge.recovered { background: var(--success-bg); color: #065F46; }
.status-badge.expired  { background: #F3F4F6; color: #6B7280; }
.status-badge.cancelled { background: #F3F4F6; color: #6B7280; }
.status-badge.lost     { background: var(--danger-bg); color: #991B1B; }

/* Failure reason pill */
.failure-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

/* Empty table state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13px;
  max-width: 300px;
  margin: 0 auto;
}

/* ── Loading state ───────────────────────────────────────── */

.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(249,250,251,0.8);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

.loading-overlay.active { display: flex; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Error state ─────────────────────────────────────────── */

.error-banner {
  display: none;
  background: var(--danger-bg);
  border: 1px solid #FECACA;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  color: #991B1B;
  align-items: center;
  gap: 10px;
}
.error-banner.active { display: flex; }
.error-banner-icon { font-size: 16px; flex-shrink: 0; }
.error-banner-close {
  margin-left: auto;
  cursor: pointer;
  opacity: 0.6;
  font-size: 16px;
  line-height: 1;
  background: none;
  border: none;
  color: inherit;
}

/* ── Pagination ──────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 10px;
}

.pagination-buttons {
  display: flex;
  gap: 6px;
}

.page-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  color: var(--text);
}

.page-btn:hover:not(:disabled) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Connect Stripe empty state (no account_id) ──────────── */

.connect-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 120px);
  padding: 40px 24px;
  text-align: center;
}

.connect-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-md);
}

.connect-bee { font-size: 56px; margin-bottom: 20px; display: block; }

.connect-card h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
  margin-bottom: 12px;
}

.connect-card p {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 28px;
}

.btn-connect {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--primary);
  color: white;
  font-size: 15px;
  font-weight: 700;
  padding: 13px 24px;
  border-radius: var(--radius-lg);
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 4px 14px rgba(245,158,11,0.35);
  width: 100%;
  justify-content: center;
  margin-bottom: 14px;
}

.btn-connect:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.connect-note {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 12px;
}

.connect-features {
  list-style: none;
  text-align: left;
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.connect-features li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 5px 0;
}

.connect-features li::before {
  content: '✓';
  color: var(--success);
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .content-grid { grid-template-columns: 1fr; }
  .email-preview-panel { min-height: 300px; }
}

@media (max-width: 700px) {
  .db-main { padding: 20px 16px 40px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .db-account-badge { display: none; }
  .table-controls { flex-direction: column; align-items: stretch; }
  .search-input { max-width: 100%; }
  thead th:nth-child(4),
  tbody td:nth-child(4) { display: none; }  /* hide action taken on mobile */
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .connect-card { padding: 28px 20px; }
}

/* Inline email preview below selected row */
.inline-preview-row td {
  background: transparent !important;
}
.inline-preview-row:hover td {
  background: transparent !important;
}
tr.selected {
  background: #FFF7ED !important;
}
tr.selected td {
  border-color: #F59E0B !important;
}

/* Responsive inline preview grid */
@media (max-width: 768px) {
  .inline-preview-row [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
}
