:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --border: #e2e8f0;
  --border-dark: #cbd5e1;
  --text: #1e293b;
  --muted: #64748b;
  --muted-light: #94a3b8;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --code-bg: #1e293b;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px 0 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);
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--primary-hover); }

/* ===== Navbar ===== */
.navbar {
  background: #0f172a;
  color: #fff;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.navbar .brand {
  font-weight: 700;
  font-size: 1rem;
  margin-right: 2rem;
  color: #fff;
  letter-spacing: -0.02em;
}
.navbar .brand:hover { color: #c7d2fe; }
.navbar nav a {
  color: #94a3b8;
  margin-right: 0.1rem;
  padding: 0.5rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s;
}
.navbar nav a.active {
  color: #fff;
  background: rgba(255,255,255,0.1);
}
.navbar nav a:hover {
  color: #fff;
  text-decoration: none;
  background: rgba(255,255,255,0.08);
}
.navbar .compliance-badge {
  margin-left: auto;
  background: rgba(16,185,129,0.15);
  color: #6ee7b7;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
}
.navbar .nav-link {
  color: #64748b;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 6px;
  transition: all 0.15s;
}
.navbar .nav-link:hover { color: #e2e8f0; }

/* ===== Layout ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

/* ===== Stats grid ===== */
.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s;
}
.stat:hover { box-shadow: var(--shadow); }
.stat .label { color: var(--muted-light); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.stat .value { font-size: 1.75rem; font-weight: 700; margin-top: 0.2rem; color: var(--text); letter-spacing: -0.03em; }

/* ===== Typography ===== */
h1, h2, h3 { margin: 0 0 0.75rem; color: var(--text); }
h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.subtitle { color: var(--muted); margin-bottom: 1.25rem; font-size: 0.85rem; }

/* ===== Forms ===== */
.form-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.form-group { display: flex; flex-direction: column; }
.form-group label {
  font-size: 0.78rem;
  color: var(--text);
  margin-bottom: 0.3rem;
  font-weight: 600;
}

/* ALL input types get identical styling — including password and date */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
input[type="tel"],
input[type="url"],
select,
textarea {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  padding-right: 2rem;
}

textarea { min-height: 80px; resize: vertical; font-family: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace; }

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}

input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ===== Buttons ===== */
button, .btn {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  text-decoration: none;
  transition: all 0.15s;
  line-height: 1.4;
}
button:hover, .btn:hover {
  background: var(--primary-hover);
  text-decoration: none;
  color: #fff;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary, .btn.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border-dark);
}
button.secondary:hover, .btn.secondary:hover { background: #f8fafc; border-color: var(--muted-light); }
button.danger, .btn.danger { background: var(--danger); }
button.danger:hover, .btn.danger:hover { background: #b91c1c; }
button.success, .btn.success { background: var(--success); }
button.success:hover, .btn.success:hover { background: #047857; }

/* ===== Tables ===== */
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td {
  text-align: left;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  background: #f8fafc;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}
tbody tr { transition: background 0.1s; }
tbody tr:hover td { background: #f8fafc; }

/* ===== Badges ===== */
.checkbox-cell { width: 32px; text-align: center; }
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge.queued, .badge.draft { background: #fef3c7; color: #92400e; }
.badge.sent, .badge.paid { background: var(--success-light); color: #065f46; }
.badge.failed, .badge.overdue { background: var(--danger-light); color: #991b1b; }
.badge.new, .badge.new_lead { background: #dbeafe; color: #1e40af; }
.badge.drafted { background: #ede9fe; color: #5b21b6; }
.badge.replied, .badge.interested { background: #d1fae5; color: #065f46; }
.badge.converted { background: #fce7f3; color: #9d174d; }
.badge.bounced { background: var(--danger-light); color: #991b1b; }
.badge.modern { background: #e0e7ff; color: #3730a3; }
.badge.active { background: #d1fae5; color: #065f46; }
.badge.completed, .badge.archived { background: #f1f5f9; color: #475569; }
.badge.won { background: var(--success-light); color: #065f46; }
.badge.lost, .badge.cancelled { background: var(--danger-light); color: #991b1b; }

/* ===== Flash messages ===== */
.flash {
  padding: 0.7rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-weight: 500;
}
.flash.success { background: var(--success-light); color: #065f46; border: 1px solid #6ee7b7; }
.flash.error { background: var(--danger-light); color: #991b1b; border: 1px solid #fca5a5; }
.flash.info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }

/* ===== Preview blocks ===== */
pre.preview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  white-space: pre-wrap;
  font-family: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  max-height: 280px;
  overflow-y: auto;
  line-height: 1.6;
}

/* ===== Modals ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.6);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 10px;
  padding: 1.5rem;
  width: min(720px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
}
.modal h3 { margin-top: 0; }
.modal .actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* ===== Spinner ===== */
.spinner {
  border: 2px solid #e2e8f0;
  border-top: 2px solid var(--primary);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Notice boxes ===== */
.notice {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1e40af;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.82rem;
}
.notice strong { display: block; margin-bottom: 0.15rem; }

/* ===== Login page ===== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
}

/* ===== Kanban columns ===== */
.kanban-col {
  width: 240px;
  flex-shrink: 0;
}
.kanban-col h4 {
  text-transform: capitalize;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
}
.kanban-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem;
  margin-bottom: 0.4rem;
  cursor: pointer;
  transition: box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
}
.kanban-card:hover { box-shadow: var(--shadow-md); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .navbar { padding: 0 0.75rem; overflow-x: auto; }
  .navbar nav a { padding: 0.4rem 0.5rem; font-size: 0.78rem; }
  .container { padding: 1rem; }
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  .stat .value { font-size: 1.4rem; }
}
