:root {
  --green: #1f7a3d;
  --green-dark: #165c2d;
  --green-soft: #e6f2e9;
  --bg: #f5f7f5;
  --surface: #ffffff;
  --text: #1b261e;
  --muted: #5d6b61;
  --line: #dde4de;
  --danger: #b3261e;
  --danger-soft: #fbeaea;
  --warn: #8a5a00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 8px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --green: #3fa862;
    --green-dark: #5cc07d;
    --green-soft: #18301f;
    --bg: #111613;
    --surface: #1a211c;
    --text: #e6ece7;
    --muted: #9aa89e;
    --line: #2c3730;
    --danger: #ff8a80;
    --danger-soft: #3a1d1b;
    --warn: #e0b45a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
a { color: var(--green); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 0.75rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.error-text { color: var(--danger); }
.warn-text { color: var(--warn); }

/* ---------- Forms & buttons ---------- */
input, textarea, select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--green); outline-offset: 0; border-color: transparent; }
label { display: block; font-weight: 600; font-size: 0.9rem; }
label > input, label > textarea, label > select { margin-top: 0.3rem; font-weight: 400; }
label.check { display: flex; gap: 0.5rem; align-items: flex-start; font-weight: 400; }
label.check input { width: auto; margin-top: 0.3rem; }
label.inline { display: flex; align-items: center; justify-content: space-between; gap: 1rem; font-weight: 400; margin: 0.3rem 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem 1rem; }
legend { font-weight: 600; font-size: 0.9rem; padding: 0 0.25rem; }
input.tiny { width: 6rem; }
input.short { width: 10rem; }
.grow { flex: 1 1 16rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 0.6rem 1rem; min-height: 44px; white-space: nowrap;
}
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0.35rem 0.7rem; font-size: 0.875rem; }
.btn.danger, .link.danger { color: var(--danger); }
.btn.danger:not(.ghost) { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.6; cursor: wait; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--green); cursor: pointer; text-decoration: underline; }

.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: 0.6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.flash { background: var(--green-soft); border-radius: 8px; padding: 0.75rem 1rem; margin: 0 0 1rem; }
.flash.error { background: var(--danger-soft); }
.busy { color: var(--muted); font-style: italic; }

.logo { display: inline-flex; align-items: center; gap: 0.6rem; color: var(--text); text-decoration: none; }
.logo img { border-radius: 8px; }
.logo span { display: flex; flex-direction: column; line-height: 1.15; }
.logo small { color: var(--muted); font-size: 0.8rem; }

/* ---------- Sign-in ---------- */
body.auth { min-height: 100vh; }
.auth-wrap { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.auth-pitch { background: var(--green); color: #fff; padding: 2rem 1.25rem; }
.auth-pitch .logo, .auth-pitch .logo small { color: #fff; }
.auth-pitch h2 { font-size: 1.5rem; margin: 1.5rem 0 0.75rem; }
.auth-pitch ul { padding-left: 1.2rem; }
.auth-pitch li { margin: 0.3rem 0; }
.auth-card { padding: 2rem 1.25rem; max-width: 440px; width: 100%; margin: 0 auto; }
@media (min-width: 860px) {
  .auth-wrap { grid-template-columns: 1fr 1fr; }
  .auth-pitch { padding: 4rem; display: flex; flex-direction: column; justify-content: center; }
  .auth-pitch h2 { font-size: 2rem; }
  .auth-card { align-self: center; }
}
.terms { max-width: 720px; margin: 0 auto; padding: 2rem 1rem 4rem; }
.terms-body { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; max-height: 55vh; overflow: auto; }

/* ---------- Customer chat ---------- */
body.chat { padding-bottom: 12rem; }
.chat-header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.chat-header .home { text-decoration: none; }
.chat-header nav { display: flex; gap: 0.25rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.chat-header form { margin: 0; }
@media (max-width: 520px) { .chat-header .logo strong { display: none; } }

.chat-main { max-width: 760px; margin: 0 auto; padding: 1rem; }
.welcome { padding: 1.5rem 0; }
.welcome h1 { font-size: 1.8rem; }
.suggestions { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-top: 1.25rem; }
.suggestion {
  text-align: left; font: inherit; color: var(--text); cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.8rem 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 0.2rem;
}
.suggestion small { color: var(--green); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.suggestion:hover { border-color: var(--green); }

.msg { margin: 1rem 0; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user p { background: var(--green); color: #fff; border-radius: 16px 16px 4px 16px; padding: 0.6rem 0.9rem; margin: 0; max-width: 85%; }
.msg.assistant { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1.1rem; box-shadow: var(--shadow); }
.photos { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.photos img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; }
.status { color: var(--muted); font-size: 0.9rem; display: flex; align-items: center; gap: 0.5rem; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol { margin: 0.6rem 0; }
.prose li { margin: 0.3rem 0; }
.prose h2, .prose h3, .prose h4 { margin: 1rem 0 0.4rem; font-size: 1.02rem; }
.prose code { background: var(--green-soft); padding: 0.05rem 0.3rem; border-radius: 4px; }
.prose .table { overflow-x: auto; }
.prose table { border-collapse: collapse; font-size: 0.9rem; }
.prose th, .prose td { border: 1px solid var(--line); padding: 0.35rem 0.6rem; text-align: left; }
sup.cite, span.cite {
  display: inline-block; font-size: 0.7rem; font-weight: 700; line-height: 1;
  background: var(--green-soft); color: var(--green); border-radius: 4px; padding: 0.15rem 0.3rem; margin-left: 0.1rem; vertical-align: super;
}
span.cite { vertical-align: baseline; }
.sources { margin-top: 0.8rem; font-size: 0.9rem; border-top: 1px solid var(--line); padding-top: 0.6rem; }
.sources summary { cursor: pointer; color: var(--muted); }
.sources ul { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.sources li { margin: 0.3rem 0; }
.feedback { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.8rem; }
.fb { font-size: 1.1rem; background: none; border: 1px solid var(--line); border-radius: 8px; width: 40px; height: 36px; cursor: pointer; }
.fb.on { background: var(--green-soft); border-color: var(--green); }
.fb-comment { display: flex; gap: 0.4rem; flex: 1 1 100%; }
.fb-comment input { padding: 0.4rem 0.6rem; }

.composer-wrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: linear-gradient(to top, var(--bg) 75%, transparent);
  padding: 0.75rem 1rem calc(0.5rem + env(safe-area-inset-bottom));
}
.composer-wrap > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.call-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.4rem; width: fit-content;
  margin-bottom: 0.5rem; padding: 0.45rem 0.9rem; border-radius: 999px; font-weight: 600; font-size: 0.9rem;
  background: var(--surface); border: 1px solid var(--green); color: var(--green); text-decoration: none; box-shadow: var(--shadow);
}
.composer { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 0.4rem; }
.composer-row { display: flex; align-items: flex-end; gap: 0.25rem; }
.composer textarea { border: 0; resize: none; padding: 0.6rem 0.4rem; max-height: 180px; background: transparent; }
.composer textarea:focus { outline: none; }
.icon-btn, .send-btn {
  flex: none; width: 44px; height: 44px; border-radius: 12px; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; background: transparent; color: var(--muted);
}
.icon-btn:hover { color: var(--green); }
.icon-btn.listening { color: #fff; background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.7; } }
.send-btn { background: var(--green); color: #fff; }
.send-btn:disabled { opacity: 0.5; }
.composer-note { font-size: 0.75rem; color: var(--muted); text-align: center; margin: 0.4rem auto 0; }
.photo-previews { display: flex; gap: 0.4rem; }
.photo-previews:empty { display: none; }
.thumb { position: relative; padding: 0.3rem; }
.thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.thumb.uploading img { opacity: 0.4; }
.thumb button { position: absolute; top: 0; right: 0; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); cursor: pointer; line-height: 1; }

.dialog { border: 0; border-radius: var(--radius); padding: 1.25rem; max-width: 560px; width: calc(100% - 2rem); background: var(--surface); color: var(--text); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog .prose { max-height: 60vh; overflow: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

.history { max-width: 760px; margin: 0 auto; padding: 1.5rem 1rem; }
.history-list { list-style: none; padding: 0; }
.history-list a { display: flex; flex-direction: column; padding: 0.8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 0.5rem; text-decoration: none; color: var(--text); }

/* ---------- Admin ---------- */
.admin-shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-bottom: 1px solid var(--line); padding: 0.75rem; display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; }
.sidebar a { text-decoration: none; color: var(--text); padding: 0.45rem 0.7rem; border-radius: 8px; font-size: 0.92rem; }
.sidebar a.active { background: var(--green-soft); color: var(--green); font-weight: 600; }
.sidebar-brand { width: 100%; }
.nav-group { display: none; }
.sidebar-foot { width: 100%; display: flex; gap: 1rem; align-items: center; font-size: 0.85rem; }
.sidebar-foot form { margin: 0; }
@media (min-width: 900px) {
  .admin-shell { grid-template-columns: 230px 1fr; }
  .sidebar { flex-direction: column; flex-wrap: nowrap; align-items: stretch; border-bottom: 0; border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; padding: 1rem 0.75rem; }
  .sidebar-brand { margin-bottom: 1rem; }
  .nav-group { display: block; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 1rem 0.7rem 0.25rem; }
  .sidebar-foot { margin-top: auto; flex-direction: column; align-items: flex-start; gap: 0.5rem; }
}
.admin-main { padding: 1.25rem 1rem 4rem; min-width: 0; }
@media (min-width: 900px) { .admin-main { padding: 2rem 2.5rem 4rem; } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.success { border-color: var(--green); }
.card.narrow { max-width: 560px; }
.danger-zone { border-color: var(--danger); }
.cards-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 1100px) { .cards-2 { grid-template-columns: 1fr 1fr; } }
.stats { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem; display: flex; flex-direction: column; }
.stat span { color: var(--muted); font-size: 0.85rem; }
.stat strong { font-size: 1.6rem; }
.stat small { color: var(--muted); }

.table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 0.92rem; }
.table th, .table td { text-align: left; padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.admin-main > .table, .card > .table { display: block; overflow-x: auto; }
.pill { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--green-soft); color: var(--green); margin-left: 0.25rem; }
.pill.down, .pill.deactivated, .pill.error { background: var(--danger-soft); color: var(--danger); }
.pill.invited, .pill.pending, .pill.skipped { background: #fff4d6; color: #7a5200; }
@media (prefers-color-scheme: dark) { .pill.invited, .pill.pending, .pill.skipped { background: #3a2f12; color: #e0b45a; } }
.filters { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip { padding: 0.35rem 0.8rem; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--text); font-size: 0.9rem; background: var(--surface); }
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }
.toolbar { display: flex; gap: 0.75rem; justify-content: space-between; flex-wrap: wrap; margin-bottom: 1rem; }
.search { display: flex; gap: 0.5rem; flex: 1 1 20rem; max-width: 32rem; }
.pager { display: flex; gap: 1rem; justify-content: center; margin-top: 1rem; }
.plain { list-style: none; padding: 0; margin: 0 0 0.75rem; }
.plain li { padding: 0.35rem 0; }
.checklist { list-style: none; padding: 0; max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.75rem; }
.question { font-size: 1.1rem; font-weight: 600; }
blockquote { margin: 0; padding: 0.5rem 0.9rem; border-left: 3px solid var(--line); color: var(--muted); }
.btn.dictate { margin-top: 0.4rem; }
.btn.dictate.listening { color: #fff; background: var(--danger); border-color: var(--danger); animation: pulse 1.2s infinite; }
.doc-preview { border: 1px solid var(--line); border-radius: 8px; padding: 1rem; max-height: 70vh; overflow: auto; }
.transcript .msg.user { align-items: stretch; }
.transcript .msg.user p { max-width: none; border-radius: 12px; }
.transcript .msg { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8rem 1rem; }
.transcript .msg.user { background: var(--green-soft); }
.transcript .msg.user p { background: none; color: var(--text); padding: 0; }
.msg-meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; }
.bar { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.bar i { display: block; width: 100%; background: var(--green); border-radius: 3px 3px 0 0; min-height: 2px; }
.hbar { display: grid; grid-template-columns: 8rem 1fr 3rem; align-items: center; gap: 0.6rem; margin: 0.4rem 0; font-size: 0.9rem; }
.hbar i { display: block; height: 14px; background: var(--green); border-radius: 3px; }
.hbar b { text-align: right; }

/* Keep the white-and-green Oztech mark legible. */
.logo img { object-fit: contain; background: #11161a; border-radius: 6px; }

.swath-chart { margin:0.85rem 0; }
.swath-chart img { max-width:100%; height:auto; display:block; border:1px solid var(--line); border-radius:8px; }
.swath-chart figcaption { font-size:0.82rem; color:var(--muted); margin-top:0.35rem; }

.tutorial-link { margin:0.75rem 0 0; white-space:normal; text-align:left; }
