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

:root {
  --bg: #fafafa;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1a1a1a;
  --text-secondary: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #059669;
  --orange: #d97706;
  --red: #dc2626;
  --purple: #7c3aed;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Login screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.login-box h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
}

.login-box p {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px;
}

.login-box input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}

.login-box input:focus {
  border-color: var(--accent);
}

.login-box button {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.login-box button:hover {
  background: var(--accent-hover);
}

.login-error {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
  display: none;
}

/* Dashboard */
.dashboard {
  display: none;
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 40px;
}

.dashboard.active {
  display: block;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.header h1 {
  font-size: 24px;
  font-weight: 600;
}

.header-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

/* Stats cards */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
}

.stat-card .label {
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
}

.stat-card .value.green { color: var(--green); }
.stat-card .value.orange { color: var(--orange); }
.stat-card .value.blue { color: var(--accent); }
.stat-card .value.purple { color: var(--purple); }

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  align-items: center;
}

.filters select,
.filters input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--card);
  outline: none;
  min-width: 160px;
}

.filters select:focus,
.filters input:focus {
  border-color: var(--accent);
}

/* Table */
.table-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 1100px;
}

/* Column widths — fixed so nothing gets squeezed */
th:nth-child(1), td:nth-child(1) { width: 22%; }   /* Entreprise */
th:nth-child(2), td:nth-child(2) { width: 10%; }   /* Type */
th:nth-child(3), td:nth-child(3) { width: 10%; }   /* Ville */
th:nth-child(4), td:nth-child(4) { width: 12%; }   /* Dirigeant */
th:nth-child(5), td:nth-child(5) { width: 16%; }   /* Email */
th:nth-child(6), td:nth-child(6) { width: 10%; }   /* Téléphone */
th:nth-child(7), td:nth-child(7) { width: 5%; text-align: center; }  /* Note */
th:nth-child(8), td:nth-child(8) { width: 7%; }    /* Statut */
th:nth-child(9), td:nth-child(9) { width: 5%; text-align: center; }  /* Relances */
th:nth-child(10), td:nth-child(10) { width: 3%; text-align: center; } /* Contenu */

thead {
  background: #f9fafb;
}

th {
  text-align: left;
  padding: 12px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 14px 14px;
  font-size: 13px;
  border-bottom: 1px solid #f3f4f6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

tr:hover {
  background: #f9fafb;
  cursor: pointer;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.badge-pending { background: #f3f4f6; color: var(--text-secondary); }
.badge-sent { background: #dbeafe; color: #1e40af; }
.badge-opened { background: #fef3c7; color: #92400e; }
.badge-replied { background: #d1fae5; color: #065f46; }
.badge-bounced { background: #fee2e2; color: #991b1b; }

/* Type badges */
.type-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}

.type-fo { background: #ede9fe; color: #5b21b6; }
.type-cgp { background: #dbeafe; color: #1e40af; }
.type-banque { background: #fef3c7; color: #92400e; }

/* Slide-over panel */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 100;
}

.overlay.active {
  display: block;
}

.slide-over {
  position: fixed;
  top: 0;
  right: -600px;
  width: 600px;
  max-width: 90vw;
  height: 100vh;
  background: var(--card);
  z-index: 101;
  transition: right 0.3s ease;
  overflow-y: auto;
  box-shadow: -4px 0 24px rgba(0,0,0,0.1);
}

.slide-over.active {
  right: 0;
}

.slide-over-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
}

.slide-over-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.close-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.close-btn:hover {
  background: #f3f4f6;
}

.slide-over-body {
  padding: 32px;
}

.detail-section {
  margin-bottom: 32px;
}

.detail-section h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.detail-row {
  display: flex;
  padding: 10px 0;
  gap: 16px;
}

.detail-label {
  min-width: 140px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.detail-value {
  font-size: 14px;
  word-break: break-word;
}

/* Rendered markdown for letters */
.letter-content {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 32px;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
}

.letter-content strong {
  font-weight: 600;
}

/* Email content */
.email-content {
  background: #f0f7ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 24px 28px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* Tabs in slide-over */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.pagination button {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer;
  font-size: 13px;
}

.pagination button:hover {
  background: #f3f4f6;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination-info {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 900px) {
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .dashboard {
    padding: 20px 16px;
  }
  td, th {
    padding: 12px 14px;
  }
}
