/* ================================================================
   App CdT Vendedor Campo — Design System
   Padrão visual do B2B TerraNutri adaptado à paleta Companhia da Terra
   ================================================================ */

:root {
  /* Paleta Companhia da Terra */
  --verde-cdt:    #43b32b;  /* primary — verde folha vibrante */
  --verde-escuro: #1d432e;  /* primary-dark — verde do logo */
  --verde-claro:  #7ed957;  /* light accent */
  --laranja-cdt:  #fea82f;  /* accent — CTAs de destaque */
  --cinza-cdt:    #c5cbc7;  /* neutro esverdeado — linhas */

  /* Semânticos (estilo b2b) */
  --primary: var(--verde-escuro);
  --accent: var(--laranja-cdt);
  --accent-dark: #e89421;
  --ink: #1A1F1C;
  --ink-soft: #4A554E;
  --ink-muted: #8A948D;
  --muted: #8A948D;
  --line: #E2E6E3;
  --line-soft: #EEF1EF;
  --bg: #F4F6F4;
  --danger: #C62828;
  --danger-bg: #FDECEA;
  --warning-vivid: #F9A825;
  --warning-bg-soft: #FFF7E0;
  --success-bg-soft: #E8F5E0;

  --terra: #6D4C41;
  --branco: #FAFAFA;
  --cinza: #F5F5F5;
  --cinza-md: #BDBDBD;
  --cinza-escuro: var(--ink-soft);
  --vermelho: var(--danger);
  --laranja: var(--laranja-cdt);
  --amarelo: #F9A825;
  --azul: #1565C0;

  --raio: 12px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --sombra: 0 1px 3px rgba(20, 40, 28, .07);
  --sombra-md: 0 6px 18px rgba(20, 40, 28, .12);

  --topbar-h: 54px;
  --bottomnav-h: 62px;
  --max-content: 760px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* [hidden] DEVE vencer regras de ID (#app-header/#bottom-nav usam display:flex).
   Sem isto, esconder via elemento.hidden=true não funciona — topbar/nav vazariam
   na tela de login. Armadilha clássica (skill pwa-shell-lifecycle). */
[hidden] { display: none !important; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}
img { max-width: 100%; height: auto; }

a { color: var(--verde-cdt); text-decoration: none; }
a:hover, a:focus { text-decoration: underline; }

button, .nav-item, .cart-item-remove, .qty-stepper button, .autocomplete-item {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ================================================================
   TOPBAR — branca minimalista (estilo b2b)
   ================================================================ */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  background: #fff;
  color: var(--ink);
  border-bottom: 1px solid var(--line-soft);
  padding: 0 14px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: var(--max-content);
  margin: 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.brand-wrap { display: flex; align-items: center; gap: .4rem; }
.brand { font-weight: 700; font-size: 1rem; display: flex; align-items: center; gap: .55rem; color: var(--verde-escuro); }
.brand img { height: 34px; width: auto; }
.btn-voltar {
  background: transparent;
  border: none;
  color: var(--verde-escuro);
  padding: .35rem .4rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-voltar:hover { background: var(--line-soft); }
.btn-voltar:active { transform: scale(.92); }
.topbar-actions { display: flex; gap: .4rem; }
.btn-ghost-sm {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  padding: .35rem .7rem;
  border-radius: 9px;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-ghost-sm:hover { background: var(--line-soft); color: var(--ink); }
.status-bar { display: none; }

/* ================================================================
   BOTTOM NAV — fixo, ícones SVG + label (estilo b2b)
   ================================================================ */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottomnav-h);
  background: #fff;
  border-top: 1px solid var(--line-soft);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-muted);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none !important;
  transition: color .15s ease;
}
.nav-item:hover { color: var(--ink-soft); }
.nav-item.active { color: var(--verde-cdt); }
.nav-item .nav-icon { position: relative; display: flex; }
.nav-item:active { transform: scale(.96); }

/* ================================================================
   LAYOUT / PAGE
   ================================================================ */
main {
  max-width: var(--max-content);
  margin: 0 auto;
  padding: 0 0 calc(var(--bottomnav-h) + 16px);
}
.page-header {
  background: #fff;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 12px;
}
.page-header h2 { font-size: 18px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.page-header p { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }

.padding-page { padding: 0 14px; }

/* Cards */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--sombra);
  padding: 16px;
  margin: 0 14px 12px;
}
.card h2 { font-size: 14.5px; margin-bottom: .8rem; color: var(--verde-escuro); font-weight: 700; }
.card-row { display: flex; justify-content: space-between; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line-soft); }
.card-row:last-child { border-bottom: none; }
.section-title { font-size: 13px; font-weight: 700; color: var(--verde-escuro); margin-bottom: 8px; }

/* ================================================================
   FORM
   ================================================================ */
form label, .card label {
  display: block;
  font-size: .8rem;
  color: var(--ink-soft);
  margin: .6rem 0 .25rem;
  font-weight: 600;
}
input, select, textarea {
  width: 100%;
  padding: .68rem .8rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--verde-cdt);
  box-shadow: 0 0 0 3px rgba(67, 179, 43, .14);
}
.hint { font-size: .76rem; color: var(--ink-muted); margin-top: .25rem; }

/* ================================================================
   BOTÕES
   ================================================================ */
button, .btn {
  font: inherit;
  padding: .68rem 1.2rem;
  border-radius: 12px;
  border: none;
  background: var(--verde-cdt);
  color: white;
  cursor: pointer;
  font-weight: 700;
  font-size: .92rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  text-decoration: none !important;
  transition: transform .12s ease, opacity .12s ease, background .15s ease;
}
button:hover, .btn:hover { background: var(--verde-escuro); }
button:active, .btn:active { transform: scale(.98); opacity: .92; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--line-soft); color: var(--ink-soft); }
.btn-secondary:hover { background: var(--line); color: var(--ink); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8E1818; }
.btn-laranja, .btn-accent { background: var(--accent); color: var(--verde-escuro); }
.btn-laranja:hover, .btn-accent:hover { background: var(--accent-dark); }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--line);
  color: var(--ink-soft);
}
.btn-outline:hover { background: var(--line-soft); color: var(--ink); }
.btn-full { width: 100%; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

/* ================================================================
   LISTAS (cards clicáveis)
   ================================================================ */
.lista { list-style: none; padding: 0 14px; }
.card .lista, .card .autocomplete-dropdown { padding: 0; }
.lista li {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--sombra);
  margin-bottom: 10px;
  padding: 14px 16px;
  cursor: pointer;
  transition: box-shadow .15s ease, transform .12s ease;
}
.lista li:hover { box-shadow: var(--sombra-md); }
.lista li:active { transform: scale(.99); }
.lista li .meta { font-size: .78rem; color: var(--ink-soft); margin-top: .3rem; }

/* Search */
.search {
  width: calc(100% - 28px);
  margin: 0 14px 12px;
  padding: .8rem 1rem;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  font-size: 1rem;
  background: #fff;
}
.card .search { width: 100%; margin: 0 0 .6rem; }

/* ================================================================
   BADGES
   ================================================================ */
.badge {
  display: inline-block;
  padding: .16rem .55rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  background: var(--line-soft);
  color: var(--ink-soft);
  vertical-align: middle;
}
.badge.verde { background: #E4F6DC; color: var(--verde-escuro); }
.badge.amarelo { background: var(--warning-bg-soft); color: #8a5a00; }
.badge.vermelho { background: var(--danger-bg); color: var(--danger); }
.badge.azul { background: #E3F0FD; color: var(--azul); }
.badge.laranja { background: #FFEFD6; color: #9a5f00; }

/* ================================================================
   TOAST + SKELETON
   ================================================================ */
#toast-host { position: fixed; bottom: calc(var(--bottomnav-h) + 12px); left: 50%; transform: translateX(-50%); z-index: 9999; max-width: calc(100% - 2rem); }
.toast { background: var(--ink); color: white; padding: .8rem 1.2rem; border-radius: 12px; margin-top: .5rem; box-shadow: var(--sombra-md); font-size: .9rem; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--verde-cdt); }
.toast.warn { background: var(--accent); color: var(--verde-escuro); }

.skeleton { background: linear-gradient(90deg, #e8ebe8, #f4f6f4, #e8ebe8); background-size: 200% 100%; animation: shimmer 1.4s infinite; height: 3.4rem; border-radius: var(--radius-lg); margin: .5rem 14px; }
@keyframes shimmer { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

/* ================================================================
   LOGIN / 2FA
   ================================================================ */
.login-card { max-width: 380px; margin: 3.2rem auto; border-top: 4px solid var(--verde-cdt); }
.login-card h1 { text-align: center; color: var(--verde-escuro); margin-bottom: 1rem; font-size: 1.3rem; }
.login-card .login-logo { text-align: center; margin-bottom: 1rem; }
.login-card .login-logo img { max-width: 150px; height: auto; }

.secret-box {
  background: var(--line-soft);
  padding: 1rem;
  border-radius: var(--raio);
  font-family: "Consolas", "Courier New", monospace;
  font-size: 1.05rem;
  word-break: break-all;
  user-select: all;
  margin: 1rem 0;
  border: 1px dashed var(--cinza-cdt);
}
.qr-toggle { font-size: .85rem; color: var(--azul); cursor: pointer; }

/* ================================================================
   TABELAS
   ================================================================ */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .55rem .4rem; border-bottom: 1px solid var(--line-soft); text-align: left; }
th { background: var(--success-bg-soft); color: var(--verde-escuro); font-size: .78rem; font-weight: 700; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ================================================================
   EMPTY STATE
   ================================================================ */
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--ink-soft); }
.empty-state .empty-icon { font-size: 2.8rem; margin-bottom: .7rem; }
.empty-state p { font-size: .92rem; line-height: 1.5; }

/* ================================================================
   GEO
   ================================================================ */
.geo-info { font-size: .78rem; color: var(--ink-soft); }
.geo-ok, .geo-info.ok { color: var(--verde-cdt); }
.geo-fail, .geo-info.fail { color: var(--danger); }

/* ================================================================
   CARRINHO DE ORÇAMENTO (padrão b2b)
   ================================================================ */
.cart-item {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  padding: 14px 16px;
  margin: 0 14px 10px;
  box-shadow: var(--sombra);
}
.cart-item-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.cart-item-desc { font-weight: 600; font-size: 13.5px; flex: 1; line-height: 1.3; }
.cart-item-code {
  font-size: 10.5px;
  color: var(--ink-muted);
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.cart-item-remove {
  color: var(--ink-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 8px;
}
.cart-item-remove:hover { background: var(--danger-bg); color: var(--danger); }

.qty-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.qty-stepper {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.qty-stepper button {
  background: var(--line-soft);
  border: none;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  font-weight: 700;
  color: var(--verde-escuro);
  padding: 0;
  border-radius: 0;
  display: flex; align-items: center; justify-content: center;
}
.qty-stepper button:hover { background: var(--line); }
.qty-stepper button:active { transform: scale(.96); }
.qty-stepper span {
  width: 48px;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.qty-preco-un { flex: 1; text-align: right; font-size: 11.5px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.discount-row { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.discount-label { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-soft); margin-bottom: 6px; font-weight: 600; }
.discount-row input[type="number"] { width: 90px; }

.price-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}
.price-row .label { font-size: 12px; color: var(--ink-soft); }
.price-row .value { font-size: 16px; font-weight: 800; color: var(--verde-cdt); font-variant-numeric: tabular-nums; }
.price-riscado { text-decoration: line-through; color: var(--ink-muted); margin-right: 6px; font-variant-numeric: tabular-nums; }

/* Totals card sticky */
.totals-card {
  background: var(--verde-escuro);
  color: #fff;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 14px 18px 16px;
  margin: 1rem 0 0;
  box-shadow: 0 -8px 20px rgba(0,0,0,.12);
  position: sticky;
  bottom: var(--bottomnav-h);
  z-index: 6;
  overflow: hidden;
}
.totals-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 85% 0%, rgba(254,168,47,.22) 0, transparent 55%);
  pointer-events: none;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  margin-bottom: 4px;
  opacity: .85;
  position: relative;
  font-variant-numeric: tabular-nums;
}
.totals-row.destaque { color: var(--verde-claro); opacity: 1; }
.totals-row.total {
  margin-bottom: 0;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,.22);
  opacity: 1;
  align-items: center;
  gap: 12px;
}
.total-label-block { flex: 1; min-width: 0; }
.total-label {
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; opacity: .72; display: block; margin-bottom: 2px;
}
.total-value {
  font-variant-numeric: tabular-nums;
  font-size: 28px; font-weight: 800; letter-spacing: -0.02em;
  line-height: 1.05; display: block;
}
.total-parcelas { font-size: 10.5px; color: #FFE2BD; margin-top: 3px; display: block; }
.totals-card .btn-enviar {
  background: var(--accent);
  color: var(--verde-escuro);
  min-height: 52px;
  min-width: 120px;
  padding: 0 18px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(254,168,47,.35);
  border: none;
  cursor: pointer;
}
.totals-card .btn-enviar:hover { background: var(--accent-dark); }
.totals-card .btn-enviar:disabled { background: rgba(255,255,255,.2); color: rgba(255,255,255,.6); box-shadow: none; }

/* Autocomplete */
.autocomplete-dropdown {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--raio);
  box-shadow: var(--sombra-md);
  max-height: 290px;
  overflow-y: auto;
  margin-bottom: .8rem;
}
.autocomplete-item {
  padding: .65rem .85rem;
  cursor: pointer;
  border-bottom: 1px solid var(--line-soft);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--line-soft); }
.autocomplete-item small { display: block; color: var(--ink-soft); font-size: .76rem; margin-top: 2px; }

/* ================================================================
   RESPONSIVO
   ================================================================ */
@media (min-width: 761px) {
  /* desktop: bottom-nav vira barra fina ainda no rodapé (mantém consistência) */
  #bottom-nav { max-width: var(--max-content); left: 50%; transform: translateX(-50%); border-radius: 14px 14px 0 0; border: 1px solid var(--line-soft); border-bottom: none; }
}
@media (max-width: 480px) {
  .card { padding: 14px; }
}

/* ================================================================
   MODAL (detalhe de visita etc.)
   ================================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(20, 40, 28, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: modal-fade .15s ease;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-sheet {
  background: var(--bg, #fff); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; padding: 18px 16px 24px;
  max-height: 85vh; overflow-y: auto;
  box-shadow: var(--sombra-md);
  animation: modal-up .2s ease;
}
@keyframes modal-up { from { transform: translateY(40px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
@media (min-width: 761px) {
  .modal-overlay { align-items: center; }
  .modal-sheet { border-radius: 18px; }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-header h3 { font-size: 15px; color: var(--verde-escuro); font-weight: 700; }
.modal-close {
  background: var(--cinza); color: var(--ink); border: none;
  width: 32px; height: 32px; border-radius: 50%; font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.modal-close:hover { background: var(--cinza-md); }
.modal-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: .88rem; }
.modal-row:last-of-type { border-bottom: none; }
.modal-row .k { color: var(--ink-soft); flex-shrink: 0; }
.modal-row .v { font-weight: 600; text-align: right; word-break: break-word; }

/* ================================================================
   TOAST "Nova versão disponível" (sw_update.js) + botão atualizar
   ================================================================ */
#sw-update-toast {
  position: fixed; left: 12px; right: 12px; top: 12px;
  max-width: 560px; margin: 0 auto;
  background: var(--verde-escuro); color: #fff;
  border-radius: var(--raio); padding: 12px 14px;
  z-index: 9100; box-shadow: var(--sombra-md);
  animation: modal-fade .15s ease;
}
.sw-update-inner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sw-update-text { flex: 1; font-size: 13px; line-height: 1.3; min-width: 0; }
.sw-update-text strong { display: block; }
.sw-update-text small { color: rgba(255,255,255,.85); }
.sw-update-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.sw-update-actions button {
  width: auto; padding: 8px 14px; font-size: 13px;
  background: #fff; color: var(--verde-escuro); border: none;
}
.sw-update-actions button:hover { background: var(--verde-claro); }
.sw-update-actions button.ghost {
  background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4);
}
.sw-update-actions button.ghost:hover { background: rgba(255,255,255,.12); }

/* Card discreto do botão manual "Atualizar sistema" (home/admin) */
.update-card {
  text-align: center; background: transparent;
  border: 1px dashed var(--cinza-cdt); box-shadow: none;
}
.update-card .hint { margin-bottom: 6px; }

/* Mensagem de erro inline por campo (form de cliente) */
.campo-erro {
  color: var(--vermelho); font-size: .78rem; min-height: 0;
  margin: 2px 0 6px;
}
.campo-erro:empty { display: none; }
