:root {
  color-scheme: light;
  --paper: #f3f4ee;
  --surface: #ffffff;
  --ink: #202923;
  --muted: #6d766f;
  --line: #dce1d9;
  --line-dark: #c8d0c6;
  --green: #365c34;
  --green-deep: #213d2e;
  --lime: #b7d95a;
  --lime-pale: #eaf3d2;
  --red: #a74431;
  --red-pale: #f9e8e2;
  --amber: #866221;
  --amber-pale: #f7efd9;
  --focus: #397a4d;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px max(24px, calc((100vw - 1380px) / 2));
  background: var(--green-deep);
  color: #f7f8f2;
}

.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--lime);
  color: var(--green-deep);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 800;
}
.brand-copy { display: grid; gap: 2px; }
.brand-copy strong { font-size: 13px; font-weight: 750; }
.brand-copy small { color: #bac8bc; font-size: 9px; font-weight: 700; letter-spacing: 1px; }
.topbar-tools { display: flex; align-items: center; gap: 10px; }
.local-indicator { display: inline-flex; align-items: center; gap: 7px; margin-right: 8px; color: #d7e2d6; font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--lime); }
.status-dot.is-offline { background: #f0a08b; }
.icon-button, .quiet-button, .secondary-button, .filter-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.topbar .icon-button { border-color: #5a7060; color: #f7f8f2; }
.topbar .icon-button:hover { background: #355443; }
.quiet-button:hover, .secondary-button:hover { border-color: var(--green); background: var(--lime-pale); }
.quiet-button span { margin-left: 5px; color: var(--muted); }

.page-shell { width: min(1380px, calc(100% - 48px)); margin: 0 auto; padding: 34px 0 64px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 7px; color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: 1px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: 32px; line-height: 1.1; font-weight: 650; }
h2 { margin: 0; font-size: 17px; line-height: 1.25; font-weight: 700; }
.heading-note, .section-note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 22px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
.metric { min-height: 84px; display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 12px 20px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric > span { font-size: 24px; line-height: 1; font-variant-numeric: tabular-nums; font-weight: 700; }
.metric small { color: var(--muted); font-size: 11px; }
.metric-progress > span { color: var(--green); }
.work-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; gap: 22px; }
.main-column, .side-column { min-width: 0; }
.main-column { display: grid; gap: 20px; }
.side-column { display: grid; gap: 16px; }
.main-column > *, .side-column > * { min-width: 0; }
.panel { border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
.scout-panel, .results-panel, .template-panel { padding: 20px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 15px; }
.section-heading .eyebrow { margin-bottom: 5px; }
.section-note { max-width: 340px; text-align: right; }
textarea, .text-field {
  display: block;
  width: 100%;
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}
textarea { min-height: 112px; resize: vertical; padding: 12px 13px; line-height: 1.5; }
textarea::placeholder { color: #9aa29b; }
.text-field { min-height: 40px; padding: 9px 11px; }
.input-summary { display: flex; flex-wrap: wrap; gap: 16px; padding: 10px 0 14px; color: var(--muted); font-size: 11px; }
.input-summary strong { margin-left: 4px; color: var(--ink); font-variant-numeric: tabular-nums; }
.import-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.import-button { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.import-state { flex: 1 1 100%; color: var(--muted); font-size: 10px; }
.scan-tools { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.scan-tools summary { width: fit-content; color: var(--green); cursor: pointer; font-size: 11px; font-weight: 700; }
.scan-tools[open] summary { margin-bottom: 12px; }
.controls-row { display: flex; align-items: end; flex-wrap: wrap; gap: 18px; padding: 14px 0; border-top: 1px solid var(--line); }
.check-control { display: inline-flex; align-items: center; gap: 8px; margin-right: auto; min-height: 36px; color: var(--ink); font-size: 12px; }
.check-control input { width: 16px; height: 16px; accent-color: var(--green); }
.number-control { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 700; }
.number-control input { width: 112px; height: 34px; padding: 0 9px; border: 1px solid var(--line-dark); border-radius: 4px; background: var(--surface); color: var(--ink); font-size: 12px; }
.button-row { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.primary-button { min-height: 39px; padding: 0 16px; border: 1px solid var(--green); border-radius: 4px; background: var(--green); color: #fff; cursor: pointer; font-size: 12px; font-weight: 700; transition: background-color 120ms ease; }
.primary-button:hover:not(:disabled) { background: var(--green-deep); }
.secondary-button { background: var(--surface); }
button:disabled { cursor: not-allowed; opacity: .48; }
.scan-state { min-height: 18px; margin-left: 4px; color: var(--muted); font-size: 11px; }
.export-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.export-tools .quiet-button { min-height: 32px; padding-inline: 9px; }
.filter-row { display: flex; gap: 6px; margin: 2px 0 12px; }
.filter-button { min-height: 31px; border-color: transparent; color: var(--muted); font-size: 11px; }
.filter-button span { margin-left: 5px; }
.filter-button.is-active { border-color: var(--line); background: var(--paper); color: var(--ink); }
.table-wrap { min-height: 92px; overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { height: 36px; color: var(--muted); font-size: 10px; font-weight: 700; }
td { min-height: 56px; padding: 10px 8px 10px 0; border-top: 1px solid #edf0eb; vertical-align: middle; font-size: 12px; }
th:last-child, td:last-child { text-align: right; }
.store-cell { min-width: 180px; }
.store-title { display: block; max-width: 290px; overflow: hidden; color: var(--ink); font-weight: 700; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.store-domain { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.email-list { display: grid; justify-items: start; gap: 3px; }
.email-list a { max-width: 220px; overflow: hidden; color: var(--green); text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.email-list a:hover { text-decoration: underline; }
.phone-link { color: var(--green); font-size: 11px; text-decoration: none; white-space: nowrap; }
.phone-link:hover { text-decoration: underline; }
.no-email { color: #89928b; font-size: 11px; }
.status-tag { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border-radius: 3px; background: var(--paper); color: var(--muted); font-size: 10px; font-weight: 700; white-space: nowrap; }
.status-tag.queued { background: var(--amber-pale); color: var(--amber); }
.status-tag.scanning { background: var(--lime-pale); color: var(--green); }
.status-tag.scouted { background: var(--lime-pale); color: var(--green); }
.status-tag.imported { background: var(--lime-pale); color: var(--green); }
.status-tag.sent { background: var(--green); color: #fff; }
.status-tag.error { background: var(--red-pale); color: var(--red); }
.row-actions { display: flex; justify-content: end; gap: 5px; }
.row-action { min-height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); cursor: pointer; font-size: 10px; font-weight: 650; white-space: nowrap; }
.row-action:hover { border-color: var(--green); background: var(--lime-pale); }
.empty-state { display: grid; justify-items: center; gap: 6px; padding: 25px 10px; color: var(--muted); text-align: center; }
.empty-state[hidden] { display: none; }
.empty-state strong { color: var(--ink); font-size: 12px; }
.empty-state span { font-size: 11px; }
.activity-panel { min-width: 0; padding: 2px 4px 0; }
.activity-list { display: grid; width: 100%; min-width: 0; gap: 0; margin: 0; padding: 0; list-style: none; }
.activity-list li { display: flex; min-width: 0; justify-content: space-between; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.activity-list li > span { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
.activity-list time { flex-shrink: 0; font-size: 10px; }
.activity-list .empty-activity { justify-content: start; }
.template-panel .section-heading { margin-bottom: 18px; }
.field-label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: 10px; font-weight: 750; }
.template-panel textarea { min-height: 172px; }
.template-panel .text-field { font-size: 13px; }
.token-note { margin: 8px 0 16px; color: var(--muted); font-size: 10px; }
.preview-block { display: grid; gap: 8px; padding: 14px; border-left: 3px solid var(--lime); background: var(--paper); }
.preview-block .eyebrow { margin-bottom: 0; font-size: 9px; }
.preview-block strong { font-size: 12px; line-height: 1.4; }
.preview-block p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.variant-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.variant-tabs { display: flex; flex-wrap: wrap; gap: 5px; }
.variant-tab { min-width: 34px; min-height: 32px; padding: 0 9px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); cursor: pointer; font-size: 12px; font-weight: 750; transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease; }
.variant-tab:hover { border-color: var(--green); background: var(--lime-pale); }
.variant-tab.is-active { border-color: var(--green); background: var(--green); color: #fff; }
body[data-theme="dark"] .variant-tab.is-active { color: var(--green-deep); }
.variant-add { min-height: 32px; color: var(--green); }
.variant-note { margin: 9px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.variant-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.variant-actions .quiet-button { min-height: 30px; padding-inline: 9px; font-size: 11px; }
.danger-button:hover:not(:disabled) { border-color: var(--red); background: var(--red-pale); color: var(--red); }
.variant-tag { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.contact-list { display: grid; justify-items: start; gap: 3px; }
.privacy-note { margin: 15px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.side-note { display: flex; gap: 10px; padding: 13px 14px; border-top: 1px solid var(--line-dark); border-bottom: 1px solid var(--line-dark); color: var(--muted); }
.note-mark { flex: 0 0 19px; width: 19px; height: 19px; display: grid; place-items: center; border-radius: 50%; background: var(--lime-pale); color: var(--green); font-family: Georgia, serif; font-weight: 700; }
.side-note p { margin: 0; font-size: 11px; line-height: 1.55; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 5; max-width: min(380px, calc(100vw - 40px)); padding: 11px 15px; border: 1px solid #5d755f; border-radius: 4px; background: var(--green-deep); color: #fff; box-shadow: 0 8px 28px #1d2c2430; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 150ms ease, transform 150ms ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

body[data-theme="dark"] {
  color-scheme: dark;
  --paper: #202923;
  --surface: #29342d;
  --ink: #edf1e9;
  --muted: #a8b2a8;
  --line: #46534a;
  --line-dark: #59675d;
  --green: #a9d36a;
  --green-deep: #19251d;
  --lime: #a7cc58;
  --lime-pale: #35452e;
  --red: #f09a82;
  --red-pale: #50322d;
  --amber: #e2c277;
  --amber-pale: #493e28;
  --focus: #b7d95a;
}
body[data-theme="dark"] .topbar { background: #151e18; }
body[data-theme="dark"] .topbar .icon-button { border-color: #4d5b50; }
body[data-theme="dark"] td { border-top-color: #39453c; }
body[data-theme="dark"] .filter-button.is-active { background: #344138; }

@media (max-width: 900px) {
  .work-grid { grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; }
  .scout-panel, .results-panel, .template-panel { padding: 16px; }
  .section-heading { align-items: start; }
  .results-heading { flex-direction: column; }
  .section-note { max-width: 260px; }
}

@media (max-width: 720px) {
  .topbar { min-height: 64px; padding: 10px 16px; }
  .topbar-tools { gap: 6px; }
  .local-indicator { margin-right: 2px; font-size: 10px; }
  .topbar .icon-button { min-height: 33px; padding: 0 8px; font-size: 10px; }
  .page-shell { width: calc(100% - 32px); padding-top: 24px; }
  .page-heading { align-items: start; flex-direction: column; gap: 12px; }
  h1 { font-size: 28px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .work-grid { grid-template-columns: minmax(0, 1fr); }
  .side-column { grid-row: 1; }
  .template-panel { display: grid; grid-template-columns: 1fr; }
  .section-heading { align-items: start; flex-direction: column; }
  .section-note { max-width: none; text-align: left; }
  .results-heading { gap: 12px; }
  .export-tools { width: 100%; }
  .controls-row { gap: 12px; }
  .check-control { flex: 1 1 100%; }
  .number-control input { width: 104px; }
  .store-cell { min-width: 150px; }
  td { padding-right: 6px; }
  .row-actions { flex-direction: column; align-items: end; }
}

@media (max-width: 520px) {
  .table-wrap { overflow: visible; }
  table, tbody { display: block; width: 100%; }
  thead { display: none; }
  tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; padding: 12px 0; border-top: 1px solid var(--line); }
  tbody td { display: block; min-width: 0; min-height: 0; padding: 0; border: 0; }
  tbody td:first-child { grid-column: 1 / -1; }
  tbody td:nth-child(2) { grid-column: 1; grid-row: 2; }
  tbody td:nth-child(3) { grid-column: 2; grid-row: 2; justify-self: end; }
  tbody td:last-child { grid-column: 1 / -1; text-align: left; }
  .store-cell { min-width: 0; }
  .store-title { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
  .store-domain { overflow-wrap: anywhere; }
  .email-list a { max-width: 100%; overflow-wrap: anywhere; white-space: normal; }
  .import-state { flex-basis: 100%; }
  .row-actions { flex-direction: row; flex-wrap: wrap; justify-content: flex-start; }
}

@media (max-width: 420px) {
  .topbar { gap: 8px; padding-inline: 12px; }
  .brand { gap: 8px; }
  .brand-mark { width: 33px; height: 33px; }
  .local-indicator { max-width: 94px; }
  .local-indicator #connection-state { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .icon-button { padding-inline: 5px; }
  .input-summary { gap: 9px; }
  .metric { padding-inline: 14px; }
  .quiet-button { padding-inline: 9px; }
}

/* Account: sign-in screen, account panel, and hiding the workspace until signed in */
body[data-auth="loading"] .page-shell, body[data-auth="loading"] .auth-shell,
body[data-auth="out"] .page-shell, body[data-auth="in"] .auth-shell,
body:not([data-auth="in"]) .signed-in-only { display: none; }
.auth-shell { display: grid; place-items: start center; min-height: calc(100vh - 72px); padding: 56px 16px 64px; }
.auth-card { width: min(420px, 100%); padding: 28px; }
.auth-card h1 { margin-bottom: 8px; font-size: 26px; }
.auth-intro { margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 4px; }
.auth-tabs[hidden], .auth-form [hidden], .auth-links [hidden], .auth-tabs [hidden] { display: none; }
.auth-form .field-label { margin-top: 12px; }
.auth-form .text-field { font-size: 14px; }
.auth-error { min-height: 18px; margin: 10px 0 0; color: var(--red); font-size: 12px; line-height: 1.45; }
.auth-error:empty { min-height: 0; }
.auth-submit { width: 100%; margin-top: 14px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 14px; }
.link-button { padding: 0; border: 0; background: none; color: var(--green); cursor: pointer; font-size: 12px; font-weight: 650; }
.link-button:hover { text-decoration: underline; }
.account-dialog { width: min(400px, calc(100vw - 32px)); padding: 22px; color: var(--ink); }
.account-dialog::backdrop { background: #10181399; }
.dialog-close-row { display: flex; justify-content: end; margin: -6px 0 4px; }
.account-dialog h2 { margin-bottom: 6px; }
.account-email { margin: 0 0 4px; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.account-sync { margin: 0 0 16px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.account-dialog > .primary-button { width: 100%; }
.account-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.account-section summary { width: fit-content; color: var(--green); cursor: pointer; font-size: 12px; font-weight: 700; }
.account-section form { display: grid; }
.account-section .secondary-button { justify-self: start; margin-top: 12px; }
.account-warning { margin: 10px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
@media (max-width: 720px) {
  .auth-shell { min-height: calc(100vh - 64px); padding-top: 32px; }
  .auth-card { padding: 22px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}