:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2024;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #c2372f;
  --fast: #1f8a4c;
  --ok: #b7791f;
  --slow: #c2372f;
  --waiting: #6b7280;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --panel: #1b1e22;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --border: #2c3036;
    --accent: #5b8ff0;
    --accent-text: #0d1117;
    --danger: #ef6b62;
    --fast: #4cc285;
    --ok: #e0a84a;
    --slow: #ef6b62;
    --waiting: #9aa1ab;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

a { color: var(--accent); }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem 1.25rem;
  padding: .75rem 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.backup { margin-left: auto; }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 16px 3rem;
}

button, .button {
  font: inherit;
  padding: .4rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover, .button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.tab { border-color: transparent; }
button.tab.active { background: var(--bg); border-color: var(--border); font-weight: 600; }
button.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  text-align: left;
}
button.link:hover { text-decoration: underline; }
button.icon {
  padding: 0 .4rem;
  border-color: transparent;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}
button.icon:hover { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: .4rem .55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}
input[type=checkbox] { width: auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  min-width: 0;
}
details.panel > summary { cursor: pointer; font-weight: 600; }
details.panel[open] > summary { margin-bottom: .75rem; }

.stack { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 1rem; align-items: start; }

.form { display: flex; flex-direction: column; gap: .75rem; }
.form.inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; margin-bottom: .75rem; }
.form.inline .field { flex: 1 1 140px; }
.field { display: flex; flex-direction: column; gap: .2rem; }
.field > span { font-size: .8rem; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem;
}
.panel .stat { background: var(--bg); }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .8rem; color: var(--muted); }

.list { list-style: none; margin: 0 0 .75rem; padding: 0; }
.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: 0; }
.tasks { list-style: none; margin: 0 0 .75rem; padding: 0; }
.task {
  padding: .6rem 0;
  border-bottom: 1px solid var(--border);
}
.task:last-child { border-bottom: 0; }
.task-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task.late .task-title { font-weight: 600; }
.check { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 0 1.6rem; }
.late-text { color: var(--slow); }

/* Chart series colours: validated categorical palette, fixed order per lead source. */
:root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --series-4: #eda100; --series-5: #e87ba4; --series-6: #008300;
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --series-4: #c98500; --series-5: #d55181; --series-6: #008300;
  }
}
.series-1 { --c: var(--series-1); } .series-2 { --c: var(--series-2); } .series-3 { --c: var(--series-3); }
.series-4 { --c: var(--series-4); } .series-5 { --c: var(--series-5); } .series-6 { --c: var(--series-6); }

.week { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; align-items: start; }
.donut { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; }
.donut svg { flex: none; }
.slice { fill: var(--c); stroke: var(--panel); stroke-width: 2; }
.slice:hover { opacity: .85; }
.donut-total { fill: var(--text); font-size: 20px; font-weight: 650; }
.legend { border-collapse: collapse; font-size: .9rem; }
.legend td { padding: .15rem .4rem; }
.legend .num { text-align: right; font-variant-numeric: tabular-nums; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--c); }

.stats.compact { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); margin-bottom: .75rem; }
.stats.compact .stat-value { font-size: 1.2rem; }

.checklist { list-style: none; margin: .25rem 0 .5rem; padding: 0; }
.checklist li { padding: .35rem 0; border-bottom: 1px solid var(--border); }
.checklist li:last-child { border-bottom: 0; }
.checklist li.done span { text-decoration: line-through; color: var(--muted); }

.after-job { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: .5rem; }
.after-job .text-preview, .after-job .actions { margin-left: 0; }

/* ---------- goals ---------- */
.goal-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin: .3rem 0 .2rem; }
.goal-bar span { display: block; height: 100%; border-radius: 3px; background: var(--ok); }
.goal-bar span.met { background: var(--fast); }
.goal-status { display: inline-block; font-size: .78rem; font-weight: 600; }
.goal-status.met { color: var(--fast); }
.goal-status.missed { color: var(--slow); }
.goal-status.behind { color: var(--muted); }

/* ---------- on site ---------- */
.steps { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .6rem; }
.step { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem; display: flex; flex-direction: column; gap: .35rem; }
.step.sent { border-color: var(--fast); }
.step.sent strong { color: var(--fast); }
.step-text { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.step .actions { margin: 0; }
.field.eta { flex-direction: row; align-items: center; gap: .5rem; }
.field.eta select { width: auto; }
.clock { font-size: 2.4rem; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: .02em; margin: .25rem 0; }
.clock.ringing { color: var(--slow); }
input.mins { width: 5rem; }

/* ---------- calendar ---------- */
.cal-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
.cal { display: grid; grid-template-columns: 52px repeat(7, minmax(120px, 1fr)); min-width: 900px; }
.cal-head {
  height: 56px; padding: .35rem .5rem; border-bottom: 1px solid var(--border); overflow: hidden;
  font-size: .9rem; line-height: 1.25; position: sticky; top: 0; background: var(--panel);
}
.cal-day { border-left: 1px solid var(--border); min-width: 0; }
.cal-day.today .cal-head { color: var(--accent); }
.cal-day.today .cal-head strong { text-decoration: underline; text-underline-offset: 3px; }
.cal-day.off .cal-body { background: repeating-linear-gradient(135deg, transparent 0 8px, var(--bg) 8px 16px); }
.cal-body { position: relative; }
.cal-hour { position: absolute; right: 6px; transform: translateY(-50%); font-size: .72rem; color: var(--muted); }
.cal-hour:first-child { transform: none; }
.cal-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); }
.cal-open, .cal-item {
  position: absolute; left: 3px; right: 3px; display: flex; flex-direction: column; align-items: flex-start;
  gap: 1px; padding: 3px 6px; border-radius: 6px; text-align: left; overflow: hidden; font-size: .8rem; line-height: 1.2;
}
.cal-open {
  border: 1px dashed var(--fast); background: color-mix(in srgb, var(--fast) 8%, transparent); color: var(--fast);
}
.cal-open:hover { background: color-mix(in srgb, var(--fast) 16%, transparent); border-color: var(--fast); }
.cal-item.job { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.cal-item.job.done { background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.cal-item.block { background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.cal-item.selected { outline: 2px solid var(--text); outline-offset: 1px; }
.cal-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.slots { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .35rem; }
.warn { color: var(--slow); margin: .25rem 0; }
.days { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .5rem 1rem; }
.days legend { font-size: .8rem; color: var(--muted); margin-bottom: .25rem; padding: 0; }
.text-preview {
  margin: .5rem 0 0 1.6rem;
  padding: .45rem .7rem;
  border-left: 3px solid var(--accent);
  background: var(--bg);
  border-radius: 0 var(--radius) var(--radius) 0;
  overflow-wrap: anywhere;
}
.text-preview p { margin: 0 0 .2rem; }
.template-field .text-preview { margin: .35rem 0 0; color: var(--muted); }

a.button { display: inline-block; text-decoration: none; }
button.small, .button.small, .small { font-size: .82rem; }
button.small, .button.small { padding: .2rem .55rem; }
button.stat { text-align: left; }

#alerts:empty { display: none; }
.alerts {
  max-width: 1200px;
  margin: .75rem auto 0;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  align-items: flex-start;
}
.alert {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem .5rem;
  padding: .55rem .75rem;
  border-radius: var(--radius);
  border: 1px solid var(--ok);
  background: var(--panel);
}
.alert.overdue { border-color: var(--slow); border-left-width: 5px; }
.alert.overdue strong { color: var(--slow); }
.alert.due { border-left-width: 5px; }
.alert .button { margin-left: auto; }
.hint { padding: .6rem 1rem; }

.badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .78rem;
  white-space: nowrap;
  border: 1px solid currentColor;
}
.badge.fast { color: var(--fast); }
.badge.ok { color: var(--ok); }
.badge.slow { color: var(--slow); }
.badge.waiting { color: var(--waiting); }

.tag {
  display: inline-block;
  min-width: 4.5rem;
  margin-right: .5rem;
  padding: .05rem .45rem;
  border-radius: 4px;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--bg);
  border: 1px solid var(--border);
  text-align: center;
}

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative;
  padding: .5rem 2rem .5rem 0;
  border-bottom: 1px solid var(--border);
}
.timeline li:last-child { border-bottom: 0; }
.timeline li > div { margin-top: .2rem; }
.timeline button.icon { position: absolute; right: 0; top: .5rem; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: .5rem 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; color: var(--muted); }

/* Seven stage columns; the board scrolls sideways on its own when the screen is narrow. */
.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(210px, 1fr);
  gap: .75rem;
  align-items: start;
  overflow-x: auto;
  padding-bottom: .5rem;
}
.column {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.column header { display: flex; flex-direction: column; }
.stage-new-lead { border-top-color: var(--ok); }
.stage-booked, .stage-completed { border-top-color: var(--fast); }
.stage-inactive, .stage-closed-lost { border-top-color: var(--muted); }
.card-name { font-weight: 600; }
.stage-pick { min-width: 170px; }
.quick-log { margin-bottom: .75rem; }
.narrow { max-width: 760px; }
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  overflow-wrap: anywhere;
}

.muted { color: var(--muted); }
.empty { color: var(--muted); margin: .25rem 0 .75rem; }
.intro p { margin: 0 0 .75rem; }

@media (max-width: 900px) {
  .split, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .backup { margin-left: 0; }
  .actions, .text-preview { margin-left: 0; }
  .week, .after-job { grid-template-columns: minmax(0, 1fr); }
}

/* Online version */
.sync { font-size: .82rem; color: var(--muted); }
.sync.error, .error-text { color: var(--danger); }
.error-text:empty { display: none; }
input.code { flex: 1 1 18rem; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: .82rem; }
pre.code {
  overflow-x: auto;
  padding: .6rem .75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .8rem;
}
details summary { cursor: pointer; margin-bottom: .5rem; }
