/* MLT Stats Portal
   Built for a trade business owner checking their phone, not an analyst at a
   desk. Figures use tabular numerals so columns line up; distributions are
   bars in rows rather than pie charts, which are unreadable at 380px. */

:root {
  --ink: #1b2027;
  --ink-soft: #55606b;
  --muted: #7c8791;
  --paper: #ffffff;
  --surface: #f4f6f5;
  --rule: #dce1de;
  --phone: #1f5c8b;
  --wa: #1e8e4e;
  --warn: #8a5a12;
  --bad: #9a3324;
  --measure: 62ch;

  /* Figures and charts. Kept separate from the interface colours so the
     dark theme can lift them without touching text contrast. */
  --stat-views: #3a5bd9;
  --stat-phone: #e53e3e;
  --stat-wa: #25d366;
  --grid: #eef1f0;
  --axis: #94a3b8;
  --topbar: #1b2027;
  --topbar-ink: #eef1ef;
  --topbar-link: #b9c6cf;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  --btn-bg: #1b2027;
  --btn-ink: #ffffff;
}

/* Dark theme. Applied by the toggle in the top bar; falls back to the
   operating system preference until someone chooses. */
[data-theme="dark"] {
  --ink: #e6ebe9;
  --ink-soft: #a3b0ba;
  --muted: #8b98a3;
  --paper: #1a1f26;
  --surface: #12161b;
  --rule: #2c343d;
  --phone: #6ea8dc;
  --wa: #3ecf7e;
  --warn: #d3a35e;
  --bad: #e08272;

  --stat-views: #7b95ec;
  --stat-phone: #ef7c72;
  --stat-wa: #3ecf7e;
  --grid: #232b33;
  --axis: #6f7d89;
  --topbar: #0d1116;
  --topbar-ink: #e6ebe9;
  --topbar-link: #9aa7b2;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  --btn-bg: #e6ebe9;
  --btn-ink: #12161b;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

a { color: var(--phone); }
a:hover { color: var(--ink); }

:focus-visible {
  outline: 3px solid var(--phone);
  outline-offset: 2px;
}

.wrap {
  max-width: 68rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Header */

.topbar {
  background: var(--topbar);
  color: var(--topbar-ink);
  padding: 0.9rem 0;
}
.topbar .wrap {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar-name {
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  margin-right: auto;
}
.topbar a { color: var(--topbar-link); text-decoration: none; font-size: 0.9rem; }
.topbar a:hover { color: var(--topbar-ink); text-decoration: underline; }

/* Controls */

.controls {
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: 0.75rem 0;
}
.controls .wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem 1.25rem;
  flex-wrap: wrap;
}
.periods { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.periods a {
  text-decoration: none;
  color: var(--ink-soft);
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  font-size: 0.875rem;
}
.periods a[aria-current="true"] {
  background: var(--btn-bg);
  border-color: var(--btn-bg);
  color: var(--btn-ink);
}
select, input[type="text"], input[type="password"], input[type="url"], input[type="email"] {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.45rem 0.6rem;
  max-width: 100%;
}

/* Stat cards — matching the Drupal admin dashboard */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 1rem;
  margin: 1.75rem 0 1.5rem;
}
.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.25rem 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.card .num {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1;
  color: var(--stat-views);
}
.card .num.small { font-size: 1.6rem; }
.card .num .of { font-size: 1rem; color: var(--muted); font-weight: 400; }
.card .num.phone { color: var(--stat-phone); }
.card .num.wa { color: var(--stat-wa); }
.card .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin-top: 0.5rem;
}
.card .sub {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* Charts */

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}
.charts > .panel { margin-bottom: 0; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .ylab {
  fill: var(--axis);
  font-size: 10px;
  text-anchor: end;
  font-family: system-ui, sans-serif;
}
.chart .xlab {
  fill: var(--axis);
  font-size: 10px;
  font-family: system-ui, sans-serif;
}

/* Overview */

.controls-inline { padding: 1.25rem 0 0; }
.overview-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}
.overview-head h1 {
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  margin: 0;
}
.overview-head h1 .note {
  display: block;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: 0.2rem;
}
.panel.attention { border-left: 3px solid var(--warn); }

/* Admin screens */

details.tuck {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  margin-bottom: 1.25rem;
}
details.tuck > summary {
  cursor: pointer;
  padding: 1rem 1.5rem;
  font-weight: 650;
  font-size: 1.05rem;
  list-style: none;
}
details.tuck > summary::-webkit-details-marker { display: none; }
details.tuck > summary::before { content: "+ "; color: var(--muted); }
details.tuck[open] > summary::before { content: "– "; }
details.tuck > summary:hover { background: var(--surface); }
details.tuck .tuck-body { padding: 0 1.5rem 1.5rem; }

.muted-row td { color: var(--muted); }
.pill {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  margin: 0 0.25rem 0.25rem 0;
  white-space: nowrap;
}

.btn.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn.danger-text { color: var(--bad); }
.btn.danger-text:hover { background: var(--bad); color: var(--paper); border-color: var(--bad); }
.row-actions { display: flex; gap: 0.4rem; justify-content: flex-end; flex-wrap: wrap; }
.row-actions form { margin: 0; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0 1.25rem;
}

/* Theme toggle */

.theme-toggle {
  background: none;
  border: 1px solid transparent;
  color: var(--topbar-link);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  line-height: 1.4;
}
.theme-toggle:hover { color: var(--topbar-ink); border-color: var(--topbar-link); }
.theme-toggle .on-light { display: inline; }
.theme-toggle .on-dark { display: none; }
[data-theme="dark"] .theme-toggle .on-light { display: none; }
[data-theme="dark"] .theme-toggle .on-dark { display: inline; }

/* Landing page */

.landing main { padding-bottom: 2rem; }
.hero { padding: 4rem 1.25rem 2.5rem; }
.hero h1 {
  font-size: clamp(2.1rem, 6vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin: 0 0 1.25rem;
  max-width: 18ch;
}
.lead {
  font-size: clamp(1.05rem, 2.4vw, 1.25rem);
  color: var(--ink-soft);
  max-width: var(--measure);
  margin: 0 0 2rem;
}
.cta-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0;
}
.cta-note { font-size: 0.9rem; color: var(--muted); }

.band { padding: 2.5rem 1.25rem; border-top: 1px solid var(--rule); }
.band h2 {
  font-size: clamp(1.3rem, 3vw, 1.7rem);
  letter-spacing: -0.02em;
  margin: 0 0 1.25rem;
}
.band.closing { border-bottom: 1px solid var(--rule); }

.prose {
  max-width: var(--measure);
  margin: 0 0 1rem;
  color: var(--ink-soft);
  font-size: 1.02rem;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1.5rem 2rem;
}
.feature h3 {
  font-size: 1.05rem;
  margin: 0 0 0.4rem;
  letter-spacing: -0.01em;
}
.feature p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

@media (max-width: 40rem) {
  .hero { padding: 2.5rem 1.25rem 1.75rem; }
  .band { padding: 2rem 1.25rem; }
}

/* Per-site report tabs */

.site-tabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin: 1.5rem 0 0.25rem;
  border-bottom: 1px solid var(--rule);
}
.site-tabs a {
  text-decoration: none;
  color: var(--ink-soft);
  padding: 0.55rem 0.9rem;
  font-size: 0.925rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.site-tabs a:hover { color: var(--ink); }
.site-tabs a[aria-current="page"] {
  color: var(--ink);
  font-weight: 650;
  border-bottom-color: var(--stat-views);
}

.bar-track.thin {
  display: block;
  height: 3px;
  margin-top: 0.35rem;
  max-width: 16rem;
}

/* Detail list filters and pager */

.list-filter {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.85rem 1rem;
  margin: 1.25rem 0 0.75rem;
}
.list-filter label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.list-filter input[type="date"],
.list-filter select {
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.35rem 0.5rem;
}

.pager {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.pager-count { font-size: 0.875rem; color: var(--muted); }
.pager-links { display: flex; gap: 0.35rem; margin-left: auto; flex-wrap: wrap; }

/* Enquiry cards */

.submission { padding: 1.15rem 1.5rem; }
.submission-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding-bottom: 0.6rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--rule);
}
.submission-meta { font-size: 0.85rem; color: var(--muted); }
.submission-fields {
  display: grid;
  grid-template-columns: minmax(7rem, 12rem) 1fr;
  gap: 0.5rem 1.25rem;
  margin: 0;
}
.submission-fields dt {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.submission-fields dd {
  margin: 0;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
@media (max-width: 34rem) {
  .submission-fields { grid-template-columns: 1fr; gap: 0.15rem; }
  .submission-fields dd { margin-bottom: 0.6rem; }
}

/* Sections */

.panel {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}
.panel h2 {
  margin: 0 0 1.1rem;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.panel h2 .note {
  display: block;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: 0.15rem;
}
.cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  gap: 1.25rem;
}
.cols > .panel { margin-bottom: 0; }

/* Bar rows */

.bars { display: grid; gap: 0.6rem; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 0.75rem; align-items: baseline; }
.bar-label { font-size: 0.925rem; overflow-wrap: anywhere; }
.bar-value { font-size: 0.925rem; color: var(--ink-soft); white-space: nowrap; }
.bar-track {
  grid-column: 1 / -1;
  height: 6px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill { height: 100%; background: var(--phone); border-radius: 999px; }
.bar-fill.wa { background: var(--wa); }
.bar-fill.neutral { background: var(--axis); }
.bar-fill.views { background: var(--stat-views); }

/* Daily columns */

.days {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 130px;
  padding-top: 0.5rem;
}
.day { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; min-width: 0; }
.day-seg { border-radius: 1px 1px 0 0; min-height: 0; }
.day-seg.phone { background: var(--phone); }
.day-seg.wa { background: var(--wa); }
.day-seg.views { background: var(--axis); }
.day-base { height: 2px; background: var(--rule); }
.day-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.4rem;
}

/* Tables */

table { width: 100%; border-collapse: collapse; font-size: 0.925rem; }
th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 0 0.6rem 0.5rem 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.85rem;
}
td { padding: 0.6rem 0.6rem 0.6rem 0; border-bottom: 1px solid var(--surface); overflow-wrap: anywhere; }
tr:last-child td { border-bottom: none; }
th:last-child, td:last-child { padding-right: 0; text-align: right; }

.enquiry { border-left: 3px solid var(--phone); padding-left: 0.75rem; }
.enquiry.wa { border-left-color: var(--wa); }

/* Messages */

.msg {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--muted);
  background: var(--paper);
  padding: 0.9rem 1.1rem;
  margin: 1.25rem 0;
  border-radius: 3px;
  font-size: 0.925rem;
}
.msg.bad { border-left-color: var(--bad); }
.msg.warn { border-left-color: var(--warn); }
.msg.good { border-left-color: var(--wa); }

.empty { color: var(--muted); }

/* Buttons */

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  background: var(--btn-bg);
  color: var(--btn-ink);
  border: 1px solid var(--btn-bg);
  border-radius: 2px;
  padding: 0.55rem 1.1rem;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { opacity: 0.88; }
.btn.quiet { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn.quiet:hover { background: var(--surface); color: var(--ink); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }

/* Login */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-box {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 2rem;
  width: 100%;
  max-width: 24rem;
}
.login-box h1 { font-size: 1.3rem; margin: 0 0 0.35rem; letter-spacing: -0.02em; }
.login-box p.sub { margin: 0 0 1.5rem; color: var(--muted); font-size: 0.925rem; }

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 0.3rem; }
.field input:not([type="checkbox"]):not([type="radio"]), .field select { width: 100%; }
.field .hint { font-size: 0.825rem; color: var(--muted); margin-top: 0.3rem; }

/* Admin */

.admin-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
code.key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  background: var(--surface);
  padding: 0.15rem 0.35rem;
  border-radius: 2px;
  overflow-wrap: anywhere;
}
.status-dot { display: inline-block; width: 0.55rem; height: 0.55rem; border-radius: 50%; margin-right: 0.4rem; }
.status-ok { background: var(--wa); }
.status-stale { background: var(--warn); }
.status-bad { background: var(--bad); }

footer.site {
  padding: 2rem 0 3rem;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 40rem) {
  .panel { padding: 1.15rem; }
  .cards { gap: 0.75rem; }
  th, td { font-size: 0.875rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Checklists — used for assigning site access */

.checklist-tools {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.checklist-tools input[type="search"] {
  flex: 1 1 12rem;
  min-width: 0;
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
}
.checklist-count { font-size: 0.85rem; color: var(--muted); margin-left: auto; }

.checklist {
  border: 1px solid var(--rule);
  border-radius: 3px;
  max-height: 20rem;
  overflow-y: auto;
  background: var(--paper);
}
.check {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--surface);
  line-height: 1.3;
}
.check:last-child { border-bottom: none; }
.check:hover { background: var(--surface); }
.check input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--phone);
  cursor: pointer;
}
.check .name {
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
.check .cust {
  margin-left: auto;
  padding-left: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
  white-space: nowrap;
}
.check.hidden { display: none; }
.checklist-empty { padding: 0.9rem; color: var(--muted); font-size: 0.9rem; }

.steps { margin: 0; padding-left: 1.2rem; }
.steps li { margin-bottom: 0.4rem; }
