@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/fonts/roboto-400.woff2') format('woff2');
}

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/static/fonts/roboto-500.woff2') format('woff2');
}

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/static/fonts/roboto-700.woff2') format('woff2');
}

:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --text: #1c1f1d;
  --muted: #5f665f;
  --border: #dde1dc;
  --control-border: #7f867f;
  /* 3:1+ against white and canvas (WCAG 1.4.11) */
  --primary: #15803d;
  --primary-hover: #116632;
  --primary-text: #ffffff;
  --danger: #b42318;
  --ok-bg: #e6f4ea;
  --ok-text: #14532d;
  --warn-bg: #fdf3dc;
  --warn-text: #7a4a00;
  --error-bg: #fbe9e7;
  --error-text: #8a1c12;
  --info-bg: #e8f0fb;
  --info-text: #1d4380;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06);
  color-scheme: light;
}

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

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

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

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

h1 {
  font-size: 1.35rem;
  line-height: 1.25;
  margin: 0;
}

h3 {
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

code,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 12px;
  overflow-y: auto;
}

.shell .container {
  width: 100%;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  padding: 0 8px;
}

.brand-solo {
  display: flex;
  padding: 0;
  margin-bottom: 16px;
}

.logout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: auto 0 0;
  padding: 12px 8px 0;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-link {
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.side-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.side-link.active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  box-shadow: inset 3px 0 0 var(--primary);
}

@media (max-width: 760px) {
  .shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    z-index: 10;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 12px;
    padding: 10px 16px 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }

  .logout {
    margin: 0;
    padding: 0;
    border: 0;
  }

  .side-nav {
    order: 3;
    flex: 0 0 100%;
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -16px;
    padding: 0 8px;
  }

  .side-link {
    white-space: nowrap;
    border-radius: 0;
    padding: 10px;
  }

  .side-link.active {
    background: none;
    box-shadow: inset 0 -2px 0 var(--primary);
  }
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 8px 0 16px;
}

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 28px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count {
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 0.8rem;
  letter-spacing: 0;
}

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

.small {
  font-size: 0.85rem;
}

.nowrap {
  white-space: nowrap;
}

.empty {
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  margin: 0;
}

.stack {
  display: grid;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin: 0;
}

section.card+section.card {
  margin-top: 12px;
}

.contact-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.contact-head>div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.phone {
  font-size: 0.9rem;
  text-decoration: none;
}

.meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 4px 0 12px;
}

.actions {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 12px;
  align-items: start;
}

.actions form {
  margin: 0;
}

.actions>form>.btn,
details.sale>summary {
  width: 100%;
}

details.sale[open] {
  grid-column: 1 / -1;
}

.actions.resolved {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

details.sale>summary {
  list-style: none;
}

details.sale>summary::-webkit-details-marker {
  display: none;
}

details.sale[open]>summary {
  display: none;
}

.sale-form {
  display: grid;
  gap: 6px;
}

.sale-form label {
  font-size: 0.85rem;
  color: var(--muted);
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row input {
  flex: 1 1 140px;
}

.origem-edit {
  margin-top: 4px;
  /* border-top: 1px solid var(--border); */
}

.origem-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  color: var(--primary);
  font-size: 0.9rem;
  cursor: pointer;
  list-style: none;
}

.origem-summary::-webkit-details-marker {
  display: none;
}

.origem-summary:hover {
  text-decoration: underline;
}

.origem {
  padding-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.origem label {
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
}

.btn:active:not(:disabled) {
  filter: brightness(0.93);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: #b9beb8;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  background: none;
  border: 0;
  padding: 0 8px;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.htmx-request .btn,
.htmx-request.btn {
  opacity: 0.6;
  pointer-events: none;
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: 10px;
  min-height: 44px;
  padding: 0 12px;
  max-width: 100%;
}

input:focus-visible,
select:focus-visible,
a:focus-visible,
.btn:focus-visible,
.btn-link:focus-visible,
summary:focus-visible,
.aviso:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent);
  outline-offset: 2px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge-anuncio,
.badge-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.badge-site,
.badge-maps,
.badge-indicacao,
.badge-passou_na_frente {
  background: var(--info-bg);
  color: var(--info-text);
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.badge-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.status {
  font-weight: 600;
}

.status-ok {
  color: var(--ok-text);
}

.status-no {
  color: var(--text);
}

.flash {
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 12px;
}

.flash-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.flash-erro {
  background: var(--error-bg);
  color: var(--error-text);
}

.auth {
  max-width: 380px;
  margin: 40px auto;
  display: grid;
  gap: 14px;
  padding: 24px;
}

.auth label,
.grid-form label {
  display: grid;
  gap: 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 16px 0 0;
}

@media (min-width: 720px) {
  .tiles {
    grid-template-columns: repeat(3, 1fr);
  }
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  gap: 2px;
}

.tile-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.tile-value {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.facts {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
}

.facts>div {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
  font-weight: 600;
}

.week-nav {
  display: flex;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
}

.segmented a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.segmented a.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.inline {
  display: flex;
  gap: 6px;
  margin: 0;
}

.inline select,
.inline .btn {
  min-height: 36px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.sale-edit {
  display: grid;
  gap: 10px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.code {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

.list {
  padding-left: 20px;
}

.qr {
  max-width: 280px;
  margin: 16px auto;
  padding: 12px;
  background: #fff;
  /* a QR code only scans dark-on-light */
  border-radius: var(--radius);
}

.qr svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Header connection chip: the product stops silently if WhatsApp drops, so it is always visible. */
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
}

.chip-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.chip-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.chip-error {
  background: var(--error-bg);
  color: var(--error-text);
}

.aviso:focus-visible {
  outline-offset: 2px;
}

/* Sale amount: the "R$" sits inside the field so "150" reads as money. */
.money {
  position: relative;
  display: flex;
  flex: 1 1 140px;
}

.money input {
  flex: 1;
  width: 100%;
  padding-left: 40px;
  font-variant-numeric: tabular-nums;
}

.money-sign {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.sale-form .btn-link {
  justify-self: start;
}

/* The one authored moment: the card that was just marked lands in its new list. */
@keyframes moved-in {
  from {
    opacity: 0.35;
    transform: translateY(-10px);
    background: var(--ok-bg);
  }

  to {
    opacity: 1;
    transform: none;
    background: var(--surface);
  }
}

.card.moved {
  animation: moved-in 480ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@media (prefers-reduced-motion: reduce) {
  .card.moved {
    animation: none;
  }
}

/* Toast: fixed so a confirmation is seen from anywhere in a long list. */
.aviso {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid currentColor;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.12);
}

.aviso[hidden] {
  display: none;
}

.aviso-undo {
  color: inherit;
  font-weight: 600;
}

.expiry {
  color: var(--warn-text);
  font-weight: 600;
}

.qr-hint {
  display: none;
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 12px 0 0;
}

@media (pointer: coarse) and (max-width: 900px) {
  .qr-hint {
    display: block;
  }
}

/* The day's ledger: one ruled line per marked contact, amounts in a tabular column, a double rule above the total. */
.ledger {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ledger-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 4px 12px;
  padding: 2px 14px;
  border-bottom: 1px solid var(--border);
}

.ledger-who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ledger-error {
  grid-column: 1 / -1;
  margin: 0 0 8px;
}

.ledger-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 14px;
  border-top: 3px double var(--control-border);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ledger-row.moved {
  animation: moved-in 480ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@media (prefers-reduced-motion: reduce) {
  .ledger-row.moved {
    animation: none;
  }
}

.panel-col {
  max-width: 880px;
  margin: 0 auto;
}

/* Pending contacts: a low-density table, one roomy row per contact. */
.contacts {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.contacts th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.contacts td {
  padding: 18px 16px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

.contacts tr:last-child td {
  border-bottom: 0;
}

.contacts td:first-child {
  display: table-cell;
}

.contacts td:first-child .phone {
  display: block;
}

.contacts .meta {
  margin: 0;
}

.contacts .actions {
  grid-template-columns: auto auto;
  justify-content: end;
  align-items: center;
}

.contacts details.sale[open] {
  grid-column: 1 / -1;
}

.contacts .origem-edit {
  margin-top: 6px;
}

.contact-row.moved {
  animation: moved-in 480ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@media (max-width: 640px) {
  .contacts thead {
    position: absolute;
    left: -9999px;
  }

  .contacts,
  .contacts tbody,
  .contacts tr,
  .contacts td {
    display: block;
  }

  .contacts td {
    border-bottom: 0;
    padding: 4px 16px;
  }

  .contacts tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }

  .contacts tr:last-child {
    border-bottom: 0;
  }

  .contacts .actions {
    justify-content: stretch;
    grid-template-columns: 3fr 2fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .contact-row.moved {
    animation: none;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Desktop widths: compact action buttons in the contacts table. Phones keep the 44px target. */
@media (min-width: 641px) {
  .contacts .actions .btn {
    min-height: 32px;
    padding: 0 12px;
    font-size: 0.875rem;
    border-radius: 8px;
  }

  .contacts .actions .btn-link {
    min-height: 32px;
  }

  .contacts .actions>form>.btn,
  .contacts details.sale>summary {
    width: auto;
  }
}
/* Modal dialog (origem edit). */
.origem-open {
  min-height: 0;
  padding: 0;
  margin-top: 6px;
  font-size: 0.85rem;
}

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: min(380px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.18);
}

.modal::backdrop {
  background: rgb(0 0 0 / 0.4);
}

.modal .origem {
  display: grid;
  gap: 8px;
  padding: 0;
}

.modal h3 {
  margin: 0;
}

.modal select {
  width: 100%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.modal .sale-form {
  gap: 8px;
}

.modal .money {
  width: 100%;
}

/* Search and pagination of the contacts list. */
.search {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 0 16px;
}

.search input {
  flex: 1;
  min-width: 0;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.pager-size {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.pager-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pager-page {
  min-width: 56px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 641px) {
  .pager .btn-icon {
    width: 32px;
    min-height: 32px;
  }
}

.pager [aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-icon {
  padding: 0;
  width: 44px;
  flex: none;
}

.search select {
  flex: none;
  max-width: 11rem;
}
