:root {
  /* Northeast Essex Recovery College palette */
  --blue: #2f9e8f;        /* primary (teal) — name kept so existing rules recolour */
  --blue-dark: #1f7d78;
  --teal: #2f9e8f;
  --nerc-green: #76b84a;
  --nerc-lime: #aed136;
  --yellow: #ece708;
  --purple: #851873;
  --green: #bfc423;
  --dark-grey: #646464;
  --light-grey: #8a988f;
  --heading: #1f3b35;
  --ink: #1f3b35;
  --body: #55635d;
  --white: #ffffff;
  --off-white: #f3f6f3;
  --line: #e4ece7;
  --danger: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(31, 59, 53, 0.07), 0 1px 2px rgba(31, 59, 53, 0.05);
  --font: "Figtree", "Proxima Nova", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--body);
  background: var(--off-white);
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3 { color: var(--heading); margin: 0 0 0.4em; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
a { color: var(--blue-dark); }

.hidden { display: none !important; }

/* ---- Brand logo ---- */
.brand { display: inline-flex; align-items: center; gap: 12px; }
.brand .brand-logo { display: block; height: 30px; width: auto; flex: none; }
.brand .brand-sub {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--light-grey);
  padding-left: 12px;
  border-left: 1px solid var(--line);
  line-height: 1;
}
.brand-login { display: flex; justify-content: center; margin-bottom: 18px; }
.brand-login img { width: 150px; height: auto; display: block; }

/* ---- Buttons ---- */
button {
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: var(--white); color: var(--dark-grey); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--light-grey); }
.btn-danger { background: var(--white); color: var(--danger); border-color: #e6c9c7; }
.btn-danger:hover { background: #fbeceb; }
.btn-small { padding: 5px 10px; font-size: 0.82rem; }
.icon-btn { padding: 5px 8px; line-height: 1; min-width: 28px; font-size: 0.9rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Login ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 400px at 80% -10%, rgba(0, 184, 233, 0.10), transparent),
    var(--off-white);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  border-top: 4px solid var(--blue);
}
.login-card .brand { margin-bottom: 22px; }
.login-card h1 { font-size: 1.2rem; }
.login-card p.sub { margin-top: 0; color: var(--light-grey); font-size: 0.9rem; }

/* ---- Forms ---- */
label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--dark-grey); margin: 14px 0 5px; }
input[type="text"], input[type="password"], input[type="email"], input[type="date"], input[type="number"], select, textarea {
  width: 100%;
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--heading);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
  border-color: var(--blue);
}
textarea { resize: vertical; min-height: 58px; }

.form-error {
  background: #fbeceb;
  color: var(--danger);
  border: 1px solid #e6c9c7;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.88rem;
  margin-top: 14px;
}

/* ---- App shell ---- */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--line);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar { border-bottom: none; }
.banner-logo { height: 42px; width: auto; display: block; }
.banner-rule { height: 4px; background: linear-gradient(90deg, #aed136, #6cc3bf); }
.topbar .right { display: flex; align-items: center; gap: 14px; }
.role-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 4px 10px;
  border-radius: 20px;
}
.role-admin { background: rgba(0, 184, 233, 0.12); color: var(--blue-dark); }
.role-viewer { background: rgba(133, 24, 115, 0.10); color: var(--purple); }
.who { font-size: 0.85rem; color: var(--light-grey); }

.tabs {
  background: var(--white);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  display: flex;
  gap: 4px;
}
.tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  padding: 13px 14px;
  color: var(--dark-grey);
  font-weight: 600;
}
.tab:hover { color: var(--heading); }
.tab.active { color: var(--heading); border-bottom-color: var(--teal); }

.page { max-width: 1000px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.muted { color: var(--light-grey); font-size: 0.88rem; }

/* ---- Hero: total courses + delivery mix ---- */
.hero {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-top: 5px solid var(--blue);
  padding: 22px 26px;
  margin: 18px 0 14px;
  display: flex;
  align-items: center;
  gap: 26px;
  flex-wrap: wrap;
}
.hero-figure { text-align: center; min-width: 110px; flex: none; }
.hero-num {
  font-size: 3.8rem;
  font-weight: 800;
  line-height: 1;
  color: var(--blue-dark);
  letter-spacing: -1px;
}
.hero-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--dark-grey);
  margin-top: 6px;
}
.hero-mix { flex: 1; min-width: 240px; }
.mix-bar { display: flex; height: 16px; border-radius: 6px; overflow: hidden; background: var(--off-white); }
.mix-seg { height: 100%; transition: width 0.3s ease; }
.mix-legend { display: flex; gap: 14px 32px; margin-top: 12px; font-size: 1.1rem; color: var(--body); flex-wrap: wrap; }
.mix-item { display: inline-flex; align-items: center; gap: 10px; }
.mix-item b { color: var(--heading); font-size: 1.15em; }
.mix-dot { width: 13px; height: 13px; border-radius: 3px; display: inline-block; flex: none; }

/* ---- Referral legend (two columns under the bar) ---- */
.ref-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 28px;
  margin-top: 16px;
  font-size: 1.1rem;
  color: var(--body);
}
.ref-legend .mix-item b { color: var(--heading); }
@media (max-width: 600px) { .ref-legend { grid-template-columns: 1fr; } }

/* ---- Attendee tiles ---- */
.tile-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.tile {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.tile-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
  flex: none;
}
.tile-icon-blue { background: rgba(0, 184, 233, 0.12); color: var(--blue-dark); }
.tile-icon-green { background: rgba(191, 196, 35, 0.18); color: #6c700d; }
.tile-num { font-size: 1.85rem; font-weight: 700; line-height: 1; color: var(--heading); }
.tile-lbl { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--light-grey); margin-top: 4px; }

/* ---- Card / section ---- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card .card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

/* ---- Course grid ---- */
.course-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.course-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 7px;
  padding: 15px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.course-card .title { font-weight: 600; color: var(--heading); font-size: 1.05rem; }
.course-card .note { font-size: 0.9rem; color: var(--light-grey); margin-top: 3px; }
.course-card .actions { display: flex; gap: 6px; flex: none; }

/* ---- Table ---- */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { flex: 1; min-width: 160px; }
.filters label { margin-top: 0; }
.table-scroll { overflow-x: auto; background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th {
  text-align: left;
  background: var(--off-white);
  color: var(--dark-grey);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--body); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafa; }
.tag {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 12px;
  background: rgba(0, 184, 233, 0.10);
  color: var(--blue-dark);
  white-space: nowrap;
}
.tag.done { background: rgba(191, 196, 35, 0.18); color: #6c700d; }
.row-actions { display: flex; gap: 6px; }
.count-note { font-size: 0.85rem; color: var(--light-grey); margin: 10px 2px 0; }

/* ---- Contact row status overlays ---- */
.tick-col { width: 36px; }
#contactBody td.tick-cell { width: 36px; text-align: center; padding-left: 6px; padding-right: 4px; }
.tick {
  display: inline-flex;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #6c700d;
  color: #ffffff;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
}
#contactBody td:first-child { border-left: 4px solid transparent; }
#contactBody tr.row-meeting { background: rgba(191, 196, 35, 0.28); }
#contactBody tr.row-notes   { background: rgba(0, 184, 233, 0.10); }
#contactBody tr.row-none    { background: rgba(166, 166, 153, 0.18); }
#contactBody tr.row-meeting td:first-child { border-left-color: #6c700d; }
#contactBody tr.row-notes   td:first-child { border-left-color: #0093ba; }
#contactBody tr.row-none    td:first-child { border-left-color: #8f8f86; }
#contactBody tr.row-meeting:hover { background: rgba(191, 196, 35, 0.40); }
#contactBody tr.row-notes:hover   { background: rgba(0, 184, 233, 0.16); }
#contactBody tr.row-none:hover    { background: rgba(166, 166, 153, 0.27); }
#contactBody tr.row-meeting .cn { font-weight: 700; color: var(--heading); }

/* ---- Ledger ---- */
.ledger-empty { color: var(--light-grey); font-size: 0.9rem; }
.pattern-a { color: var(--blue-dark); font-weight: 700; }
.pattern-b { color: var(--purple); font-weight: 700; }

/* ---- Admin grid ---- */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.toggle-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(41, 41, 41, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: 100%; max-width: 480px;
  padding: 24px;
  max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--heading); color: var(--white);
  padding: 11px 18px; border-radius: 8px; font-size: 0.9rem; font-weight: 600;
  box-shadow: var(--shadow); z-index: 60;
}
.toast.err { background: var(--danger); }

@media (max-width: 600px) {
  .page { padding: 16px; }
  .tile-row { grid-template-columns: 1fr; }
  .course-grid { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: 1fr; }
  .hero { gap: 16px; }
  .topbar, .tabs { padding-left: 14px; padding-right: 14px; }
  .banner-logo { height: 34px; }
  .who { display: none; }
}

/* ===== Recovery College dashboard components ===== */
.dash-sub { font-size: 0.9rem; color: var(--light-grey); margin: 4px 0 18px; }
.dash-sub .muted { color: var(--light-grey); }

.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 24px; }
.kpi {
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--teal);
  padding: 18px;
}
.kpi-lbl { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.6px; text-transform: uppercase; color: var(--light-grey); margin-bottom: 10px; }
.kpi-num { font-size: 2.6rem; font-weight: 800; line-height: 1; color: var(--ink); letter-spacing: -1px; }

.section-head { display: flex; align-items: flex-start; gap: 14px; margin: 0 0 14px; }
.sec-num { font-size: 2.1rem; font-weight: 800; color: #d7e3dc; line-height: 0.8; flex: none; }
.sec-title { flex: 1; }
.sec-title h2 { margin: 0; font-size: 1.1rem; color: var(--ink); font-weight: 700; }
.sec-rule { display: block; height: 3px; width: 40px; background: var(--teal); border-radius: 2px; margin-top: 6px; }
.section-head .btn-primary { align-self: center; flex: none; }

.donut-row { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.course-split { padding-bottom: 18px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.donut-wrap { flex: none; line-height: 0; }
.donut-num { font-size: 30px; font-weight: 800; fill: var(--ink); font-family: var(--font); }
.donut-lbl { font-size: 11px; fill: var(--light-grey); font-family: var(--font); }
.donut-row .mix-legend,
.donut-row .ref-legend { flex: 1; min-width: 200px; }
