:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #1c2129;
  --muted: #6b7280;
  --primary: #2f5fd0;
  --primary-dark: #23479c;
  --danger: #c0362c;
  --danger-bg: #fdecea;
  --success: #1c7c3f;
  --success-bg: #e9f8ee;
  --warn-bg: #fff6e0;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

header.topbar .brand { font-weight: 700; font-size: 16px; }
header.topbar nav a { margin-right: 16px; color: var(--text); font-weight: 500; }
header.topbar nav a.active { color: var(--primary); }
header.topbar .user { color: var(--muted); font-size: 13px; }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
p.hint { color: var(--muted); margin: 0 0 16px; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f0f1f3; }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}
textarea { width: 100%; min-height: 160px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
label:first-child { margin-top: 0; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); z-index: 2; }
tbody tr:hover { background: #fafbfc; }
.table-scroll { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.yes, .badge.ok { background: var(--success-bg); color: var(--success); }
.badge.no { background: #eef0f3; color: var(--muted); }
.badge.bounced { background: var(--danger-bg); color: var(--danger); }
.badge.pending { background: var(--warn-bg); color: #8a6100; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.flash.success { background: var(--success-bg); color: var(--success); }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.flash.info { background: #eaf1ff; color: var(--primary-dark); }

.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

.stat-grid { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; min-width: 130px; }
.stat .num { font-size: 22px; font-weight: 700; }
.stat .label { color: var(--muted); font-size: 12px; }


.save-state { font-size: 11px; color: var(--muted); margin-left: 4px; }

/* ---- Full-width pages (leads table) ---- */
body.wide main { max-width: none; padding: 16px 24px; }
body.wide footer.pagefoot { padding: 12px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .hint { margin: 0; }
.page-head .stat-grid { margin-bottom: 0; gap: 10px; }
.page-head .stat { padding: 8px 14px; min-width: 110px; }
.page-head .stat .num { font-size: 18px; }

.card.compact { padding: 14px 16px; margin-bottom: 14px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .pagination { padding: 12px 16px; margin-top: 0; border-top: 1px solid var(--border); }
.row .push-right { margin-left: auto; }
.card.compact input[name=q] { width: 280px; }

label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-top: 12px; }

/* Leads table scrolls inside its own box, so the header row and the Email
   column stay visible while you scroll through the data. */
.table-scroll.tall { overflow: auto; max-height: calc(100vh - 290px); min-height: 300px; }
#leads-table th, #leads-table td { padding: 6px 10px; }
#leads-table th:first-child, #leads-table td:first-child {
  position: sticky; left: 0; background: var(--panel); z-index: 1;
  box-shadow: inset -1px 0 0 var(--border);
}
#leads-table th:first-child { z-index: 3; }
#leads-table tbody tr:hover td { background: #f5f7fb; }

/* Editable cells look like plain text until hovered/focused. The #id prefix is
   needed to beat the global input[type=text]/select styles above. */
#leads-table .inline-edit {
  font: inherit; color: var(--text);
  border: 1px solid transparent; background-color: transparent;
  padding: 3px 6px; border-radius: 4px; margin: -3px 0;
}
#leads-table .inline-edit:hover, #leads-table .inline-edit:focus {
  border-color: var(--border); background-color: #fff; outline: none;
}
#leads-table .inline-edit:focus { border-color: var(--primary); }
#leads-table select.inline-edit { cursor: pointer; }
#leads-table select.inline-edit.status { min-width: 170px; }
#leads-table select.inline-edit.yn { min-width: 64px; }
#leads-table input.inline-edit.cost { width: 90px; }
#leads-table .save-state { display: inline-block; min-width: 60px; }

footer.pagefoot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
