:root {
  --bg: #f3f6f8;
  --ink: #14212b;
  --muted: #5c6b76;
  --card: #ffffff;
  --line: #d5dee5;
  --accent: #0b6e4f;
  --accent-ink: #ffffff;
  --warn: #8a5a00;
  --danger: #9b1c1c;
  --ok: #0b6e4f;
  --shadow: 0 10px 30px rgba(20, 33, 43, 0.06);
  --font: "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9e8ef 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #e7f2ec 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; letter-spacing: 0.02em; }
.brand a { color: var(--ink); text-decoration: none; font-size: 1.1rem; }
.tag {
  font-size: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  color: var(--muted);
  font-weight: 600;
}
nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
nav a { color: var(--ink); font-weight: 600; font-size: 0.95rem; }
.inline { display: inline; margin: 0; }
.linkish {
  background: none; border: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; padding: 0;
}
.linkish:hover { color: var(--ink); }

.wrap { width: min(1100px, calc(100% - 2rem)); margin: 1.5rem auto 3rem; }
.wrap-wide { width: min(1800px, calc(100% - 2rem)); }
.wrap-full { width: calc(100% - 2rem); max-width: none; }
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.4rem 1.5rem;
}
h1 { margin: 0 0 0.4rem; font-size: 1.7rem; }
h2 { margin: 0 0 0.75rem; font-size: 1.2rem; }
.lede { color: var(--muted); margin: 0 0 1.25rem; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}
.page-head h1 { margin: 0; }
.page-head-actions {
  margin: 0;
  align-items: end;
}
.meeting-outside td {
  border-top: 2px solid var(--line);
  background: #f7faf8;
}

.bulk-dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  width: min(1100px, calc(100vw - 2rem));
  max-width: 1100px;
  box-shadow: var(--shadow);
  background: var(--card);
  color: var(--ink);
}
.bulk-dialog::backdrop {
  background: rgba(20, 33, 43, 0.45);
}
.bulk-dialog-inner {
  padding: 1.1rem 1.25rem 1.25rem;
}
.bulk-dialog-scroll {
  max-height: min(55vh, 520px);
  margin-top: 0.75rem;
}
.bulk-dialog select,
.bulk-dialog input[type="text"],
.bulk-dialog input[type="number"] {
  min-width: 6rem;
  width: 100%;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}
table.table-compact tfoot td {
  border-top: 2px solid var(--line);
  font-weight: 700;
  padding-top: 0.75rem;
}
.page-head-actions label { margin-bottom: 0; }

.stack { display: grid; gap: 1rem; }
/* Ensure [hidden] wins over utility display classes like .stack */
[hidden] { display: none !important; }
.is-hidden { display: none !important; }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.auth {
  width: min(460px, 100%);
  margin: 2rem auto;
}

label { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.92rem; margin-bottom: 0.85rem; }
input, select, textarea, button, .btn {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  background: #fff;
  color: var(--ink);
}
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  cursor: pointer;
}
button.secondary, .btn.secondary {
  background: #e8eef2;
  color: var(--ink);
}
button.danger { background: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.75rem; }

.flash {
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  font-weight: 600;
}
.flash.ok { background: #e7f6ef; color: var(--ok); }
.flash.err { background: #fdecec; color: var(--danger); }
.flash.warn { background: #fff6e5; color: var(--warn); }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.65rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable:hover { color: var(--ink); }
th.sortable::after {
  content: " ↕";
  font-size: 0.75em;
  opacity: 0.45;
}
th.sortable.sorted-asc::after { content: " ↑"; opacity: 0.9; color: var(--accent); }
th.sortable.sorted-desc::after { content: " ↓"; opacity: 0.9; color: var(--accent); }
.muted { color: var(--muted); }
.cardish {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  background: #fbfcfd;
}
.user-row { margin-bottom: 1rem; }
.user-row form { margin-top: 0.6rem; }
.small { font-size: 0.85rem; }
.status {
  display: inline-block;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
  background: #e8eef2;
}
.status.pending { background: #fff6e5; color: var(--warn); }
.status.approved { background: #e7f6ef; color: var(--ok); }
.status.rejected, .status.disabled { background: #fdecec; color: var(--danger); }

.status-chip {
  display: inline-block;
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  background: #e8eef2;
  color: var(--ink);
}
.status-chip-new { background: #e8eef2; color: #3d4f5c; }
.status-chip-contacted { background: #e7f0fb; color: #1d4f91; }
.status-chip-followup { background: #fff6e5; color: var(--warn); }
.status-chip-won { background: #e7f6ef; color: var(--ok); }
.status-chip-lost { background: #fdecec; color: var(--danger); }
.status-chip-other { background: #eef1f4; color: var(--muted); }
.status-chip-tyfcb {
  background: #0b6e4f;
  color: #ffffff;
  letter-spacing: 0.04em;
}

.detail-grid {
  display: grid;
  gap: 1rem 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.detail-span { grid-column: 1 / -1; }
.detail-value {
  margin-top: 0.25rem;
  font-weight: 600;
  word-break: break-word;
}
.detail-value.comments {
  font-weight: 500;
  white-space: pre-wrap;
  line-height: 1.45;
  min-height: 3rem;
}

.filter-bar { margin-bottom: 1rem; }
.filter-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.filter-chip input { width: auto; margin: 0; }
.filter-chip:has(input:not(:checked)) {
  opacity: 0.55;
  background: #f3f6f8;
}

.admin-table { margin-top: 0.5rem; }
.admin-table td { vertical-align: middle; }
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.btn-small,
button.btn-small,
a.btn-small {
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
}
.impersonation-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.65rem 1.5rem;
  background: #143d2b;
  color: #f3faf6;
  font-weight: 600;
}
.impersonation-banner button {
  background: #fff;
  color: #143d2b;
}

.referral-columns {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}
.referral-column {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.referral-column h2 {
  margin: 0 0 0.35rem;
}
.referral-column .filter-bar {
  padding: 0.75rem;
}
.referral-column table {
  font-size: 0.82rem;
  width: 100%;
}
.table-scroll {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.table-scroll table,
.table-compact {
  width: max-content;
  max-width: 100%;
  min-width: 0;
  table-layout: auto;
}
.table-compact th,
.table-compact td {
  padding: 0.5rem 0.65rem;
  white-space: nowrap;
  vertical-align: middle;
}
.table-compact th.col-check,
.table-compact td.col-check {
  width: 2rem;
  padding-right: 0.25rem;
}
.table-compact td.cell-email {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 16rem;
}
.cell-email {
  word-break: break-word;
  overflow-wrap: anywhere;
}
@media (max-width: 1100px) {
  .referral-columns { grid-template-columns: 1fr; }
}

.dash-greeting {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.25rem;
}
.dash-greeting-text { min-width: 0; flex: 1; }
.dash-greeting-text .lede { margin-bottom: 0; }
.headshot {
  flex: 0 0 auto;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #e7f2ec 0%, #d9e8ef 100%);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}
.headshot-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.headshot-fallback {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  line-height: 1;
}
@media (max-width: 640px) {
  .dash-greeting { align-items: flex-start; }
  .headshot { width: 3.25rem; height: 3.25rem; }
  .headshot-fallback { font-size: 1rem; }
}

.summary-cards {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.summary-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f7faf8 100%);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}
.summary-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.summary-value {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.1;
  margin: 0.35rem 0 0.4rem;
  color: var(--accent);
}
.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-weight: 600;
}
.check-inline input { width: auto; margin: 0; }

.sm8-top {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  margin-bottom: 1.25rem;
}
.sm8-top .cardish { padding: 1rem; }
.sm8-top h2,
.sm8-jobs h2 { margin: 0 0 0.35rem; }
.sm8-jobs { min-width: 0; }
.sm8-schedule-form {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: end;
  margin-top: 0.75rem;
}
.sm8-schedule-form .check-inline { grid-column: 1 / -1; }
.sm8-schedule-form .actions { margin-top: 0; }
.referrer-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}
.referrer-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}
.referrer-list li:last-child { border-bottom: 0; }
.referrer-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.55rem;
  min-width: 0;
}
.referrer-email {
  font-weight: 600;
  word-break: break-all;
}
.referrer-count {
  font-weight: 800;
  color: var(--accent);
}
.referrer-count::before { content: "| "; color: var(--muted); font-weight: 600; }
@media (max-width: 980px) {
  .sm8-top { grid-template-columns: 1fr; }
}

