/* Vet · FaleAgro — mobile-first (celular / iPad / desktop) */
:root {
  --green: #1b4332;
  --green-mid: #2d6a4f;
  --green-light: #d8f3dc;
  --green-soft: #95d5b2;
  --amber: #e9c46a;
  --amber-bg: #fff6df;
  --orange: #d95d39;
  --orange-bg: #fff0ea;
  --red: #c1121f;
  --red-bg: #fde8ea;
  --blue: #1d6a8a;
  --blue-bg: #e6f4fa;
  --bg: #f3f1ea;
  --card: #ffffff;
  --text: #14201a;
  --muted: #5a655e;
  --border: #ddd8cc;
  --shadow: 0 2px 10px rgba(27, 67, 50, 0.08);
  --radius: 14px;
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --max: 780px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }

button, a, input, select, textarea {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: radial-gradient(900px 420px at 10% -20%, #2d6a4f26, transparent), var(--bg);
  min-height: 100dvh;
  padding-bottom: calc(24px + var(--safe-bottom));
}

body.mode-login .header,
body.mode-login .tabs,
body.mode-login .main,
body.mode-login .offline-banner { display: none !important; }
body.mode-app #login-app { display: none !important; }

/* Login */
#login-app {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 22px;
  box-shadow: 0 8px 28px rgba(27, 67, 50, 0.12);
}
.login-brand {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green-mid);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.login-card h1 {
  margin: 0 0 18px;
  font-size: 1.45rem;
  color: var(--green);
}
.login-field {
  display: block;
  margin-bottom: 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}
.login-field input {
  width: 100%;
  margin-top: 6px;
  min-height: var(--tap);
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #faf9f5;
  color: var(--text);
}
.login-go { width: 100%; margin-top: 6px; }
.login-msg {
  margin: 8px 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 600;
}
.login-msg.bad { background: var(--red-bg); color: var(--red); }
.login-msg.warn { background: var(--amber-bg); color: #7c5800; }
.login-hint { margin: 14px 0 0; font-size: 0.82rem; color: var(--muted); text-align: center; }

/* Offline banner */
.offline-banner {
  background: #7c5800;
  color: #fff;
  text-align: center;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Header */
.header {
  background: linear-gradient(145deg, var(--green) 0%, #245c42 55%, var(--green-mid) 100%);
  color: #fff;
  padding: 14px 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.14);
}
.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 1.35rem;
  flex-shrink: 0;
}
.header h1 { margin: 0; font-size: 1.25rem; font-weight: 750; line-height: 1.15; }
.brand-dot { opacity: 0.7; font-weight: 400; }
.subtitle { margin: 2px 0 0; font-size: 0.8rem; opacity: 0.88; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.btn-header {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-header:active { background: rgba(255, 255, 255, 0.24); }

/* Tabs */
.tabs {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(243, 241, 234, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
}
.tab {
  flex: 1;
  max-width: 190px;
  min-height: 44px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 11px;
  padding: 6px 8px;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}
.tab.active {
  background: var(--card);
  color: var(--green);
  border-color: var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}
.tab-badge.info { background: var(--green-light); color: var(--green); }
.tab-badge.warn { background: var(--red); color: #fff; }

/* Main & Cards */
.main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 14px 12px 24px;
}
.panel { display: none; }
.panel.active { display: block; }

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

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-size: 0.96rem;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.06s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-xl { width: 100%; min-height: 56px; font-size: 1.06rem; border-radius: 13px; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 0.86rem; border-radius: 9px; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-mid); }
.btn-ghost { background: #f6f4ee; color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--red); color: #fff; }
.btn-warn { background: var(--orange); color: #fff; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-mini {
  min-height: 34px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-mini.active { background: var(--amber); border-color: #c79a2b; }

input[type="text"],
input[type="search"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fcfbf8;
  color: var(--text);
}
textarea { min-height: 76px; resize: vertical; }

/* Segmented control */
.farm-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.farm-bar-label { font-size: 0.88rem; font-weight: 650; color: var(--muted); }
.segmented {
  display: inline-flex;
  background: #efece3;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
  flex-wrap: wrap;
}
.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  min-height: 38px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 650;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--green);
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

/* Scanner */
.scan-hero { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.scan-secondary-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-photo { width: 100%; }

.scanner-box {
  margin: 12px 0;
  border: 2px solid var(--green-mid);
  border-radius: 14px;
  padding: 10px;
  background: #0d1611;
  color: #fff;
}
.scanner-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}
.scanner-tools { display: flex; gap: 6px; }
.scanner-viewport {
  position: relative;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  min-height: 220px;
}
#scan-video, #scan-reader { width: 100%; }
#scan-reader video { width: 100% !important; border-radius: 10px; }
.scanner-box .hint { color: #c7d4cd; margin: 8px 0 0; }

.barcode-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.quick-matches {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #faf9f5;
}
.quick-match-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.94rem;
}
.quick-match-item:last-child { border-bottom: 0; }
.quick-match-item:hover { background: var(--green-light); }

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: center;
}
.stat-val { font-size: 1.3rem; font-weight: 800; color: var(--green); }
.stat-lbl { font-size: 0.76rem; color: var(--muted); font-weight: 600; }

/* Product / Result Card */
.prod-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: var(--shadow);
}
.prod-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.prod-title { margin: 0; font-size: 1.12rem; font-weight: 750; color: var(--text); }
.prod-sub { margin: 2px 0 0; font-size: 0.85rem; color: var(--muted); }
.badges-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
  background: #efece3;
  color: var(--text);
}
.badge.green { background: var(--green-light); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.amber { background: var(--amber-bg); color: #7c5800; }
.badge.blue { background: var(--blue-bg); color: var(--blue); }

.farm-saldos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}
.saldo-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  background: #faf9f5;
}
.saldo-box.active-farm { border-color: var(--green-mid); background: #f2f9f4; }
.saldo-box .lbl { font-size: 0.76rem; color: var(--muted); font-weight: 650; }
.saldo-box .val { font-size: 1.2rem; font-weight: 800; color: var(--green); }

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.action-grid .btn { min-height: 44px; padding: 8px 6px; font-size: 0.88rem; }

.lotes-list {
  margin-top: 12px;
  border-top: 1px dashed var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.lote-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 9px;
  background: #faf9f5;
  border: 1px solid #eae6da;
  font-size: 0.88rem;
  flex-wrap: wrap;
}
.lote-main { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.lote-actions { display: flex; gap: 6px; align-items: center; }

/* Toolbars & lists */
.toolbar-card { display: flex; flex-direction: column; gap: 10px; }
.toolbar-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 8px; }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #faf9f5;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 650;
  cursor: pointer;
}
.chip.active { background: var(--green); color: #fff; border-color: var(--green); }

.list-stack { display: flex; flex-direction: column; gap: 10px; }
.empty-state {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
}

/* Alerts */
.alert-section-title {
  margin: 6px 0 2px;
  font-size: 0.95rem;
  font-weight: 750;
  color: var(--text);
}
.alert-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 5px solid var(--amber);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.alert-item.red { border-left-color: var(--red); background: #fffafa; }
.alert-item.orange { border-left-color: var(--orange); }

/* Movimentos */
.mov-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.mov-item.estornado { opacity: 0.58; }
.mov-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.mov-meta { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 25, 19, 0.56);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-backdrop[hidden] { display: none !important; }
.modal-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -6px 32px rgba(0, 0, 0, 0.25);
}
@media (min-width: 620px) {
  .modal-backdrop { align-items: center; padding: 18px; }
  .modal-sheet { border-radius: 18px; max-height: 88dvh; }
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: #faf9f5;
}
.modal-head h2 { margin: 0; font-size: 1.08rem; color: var(--green); }
.modal-close {
  border: 0;
  background: #eae6da;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  font-size: 1rem;
  cursor: pointer;
}
.modal-body {
  padding: 16px;
  overflow-y: auto;
  padding-bottom: calc(20px + var(--safe-bottom));
}
.form-grid { display: flex; flex-direction: column; gap: 12px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-lbl { display: block; font-size: 0.85rem; font-weight: 650; color: var(--muted); }
.field-lbl > input,
.field-lbl > select,
.field-lbl > textarea { margin-top: 5px; }
.shortcut-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.hint { font-size: 0.84rem; color: var(--muted); margin: 0; }
.hint.small { font-size: 0.78rem; }
.form-error {
  background: var(--red-bg);
  color: var(--red);
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 0.88rem;
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 200;
  background: #14201a;
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  max-width: 92vw;
  text-align: center;
}

@media (max-width: 520px) {
  .search-row { grid-template-columns: 1fr; }
  .form-row-2 { grid-template-columns: 1fr; }
  .action-grid { grid-template-columns: 1fr; }
}

/* Home Expiry Alerts */
.home-alerts {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.home-alerts.has-red { border-color: #eab3b7; background: #fff9f9; }
.home-alerts-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.home-alerts-head h3 { margin: 0; font-size: 0.98rem; font-weight: 750; color: var(--text); }
.home-alert-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.home-alert-list { display: flex; flex-direction: column; gap: 6px; }
.home-alert-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 9px;
  background: #ffffff;
  border: 1px solid #eadfe0;
  font-size: 0.86rem;
  cursor: pointer;
}
.home-alert-row:hover { background: #fdf4f4; }
.val-input-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
}
.val-date-picker {
  width: 46px !important;
  min-width: 46px;
  padding: 6px !important;
  cursor: pointer;
}
.lote-expiry-strong {
  font-weight: 750;
  padding: 3px 9px;
  border-radius: 7px;
  font-size: 0.82rem;
}
.lote-expiry-strong.red { background: var(--red-bg); color: var(--red); border: 1px solid #f5c2c6; }
.lote-expiry-strong.orange { background: var(--orange-bg); color: #b53f1e; border: 1px solid #f7cbbd; }
.lote-expiry-strong.amber { background: var(--amber-bg); color: #7c5800; border: 1px solid #f0da9a; }
.lote-expiry-strong.green { background: var(--green-light); color: var(--green); border: 1px solid #bce4c5; }
.fefo-tag {
  background: #e6f4fa;
  color: var(--blue);
  border: 1px solid #b8dfef;
  font-size: 0.74rem;
  font-weight: 750;
  padding: 2px 7px;
  border-radius: 999px;
}
