/* ================================================================
   Contagem TerraNutri GTA — Design System (verde + creme)
   ================================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary:       #1E4D3D;
  --primary-dark:  #133528;
  --primary-light: #E8F0EC;
  --accent:        #E94F1D;
  --accent-light:  #FEEEE6;
  --cream:         #FAF7F2;
  --paper:         #FFFFFF;
  --ink:           #1A1F1D;
  --ink-soft:      #4A524E;
  --muted:         #8B918E;
  --line:          #E6E8E4;
  --success:       #2E8B57;
  --success-bg:    #E0F0E6;
  --warning:       #E8A020;
  --warning-bg:    #FDF1DC;
  --danger:        #D43F2A;
  --danger-bg:     #FCE6E3;
  --radius-sm:     8px;
  --radius:        12px;
  --radius-lg:     16px;
  --shadow:        0 1px 2px rgba(20,40,30,.05), 0 1px 3px rgba(20,40,30,.06);
  --shadow-md:     0 4px 12px rgba(20,40,30,.08);
  --topbar-h:      56px;
  --bottomnav-h:   60px;
  --transition:    .18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
[hidden] { display: none !important; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--cream);
  color: var(--ink);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--primary); text-decoration: none; }

/* ── Layout ── */
#app { min-height: 100vh; display: flex; flex-direction: column; }
#topbar {
  height: var(--topbar-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.topbar-brand { display: flex; flex-direction: column; }
.brand-title { font-weight: 700; font-size: 15px; line-height: 1; }
.brand-sub { font-size: 11px; opacity: .85; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.btn-ghost-sm {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,.4);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.btn-ghost-sm:hover { background: rgba(255,255,255,.15); }

#main {
  flex: 1;
  padding: 16px 16px calc(var(--bottomnav-h) + 16px);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.screen[hidden] { display: none; }

/* ── Bottom nav ── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottomnav-h);
  background: var(--paper);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 10;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
  position: relative;
}
.nav-item.active { color: var(--primary); }
.nav-item.active .nav-label { font-weight: 700; }
.nav-badge {
  position: absolute;
  top: 8px;
  right: 28%;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
}

/* ── Cards & forms ── */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
h1 { font-size: 22px; font-weight: 700; margin-bottom: 8px; color: var(--primary); }
h2 { font-size: 17px; font-weight: 700; margin-bottom: 10px; color: var(--primary); }
h3 { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
p { color: var(--ink-soft); margin-bottom: 8px; }

.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-row label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.form-row input, .form-row textarea, .form-row select {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--paper);
  outline: none;
  transition: var(--transition);
  width: 100%;
}
.form-row input:focus, .form-row textarea:focus, .form-row select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}
.form-row textarea { min-height: 64px; resize: vertical; }

.radio-group { display: flex; gap: 8px; }
.radio-group label {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: var(--transition);
}
.radio-group input { display: none; }
.radio-group input:checked + span,
.radio-group label.checked {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 12px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: var(--transition);
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { display: block; width: 100%; }
.btn-secondary {
  background: var(--paper);
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-secondary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: #C13F12; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #B0331F; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.btn-row > .btn { flex: 1; }

/* ── Listas & tabelas ── */
.list-item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; margin-bottom: 2px; }
.list-item-meta { font-size: 12px; color: var(--muted); }
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}
.tag-success { background: var(--success-bg); color: var(--success); }
.tag-warning { background: var(--warning-bg); color: var(--warning); }
.tag-danger  { background: var(--danger-bg); color: var(--danger); }
.tag-muted   { background: var(--line); color: var(--ink-soft); }

.diff-positive { color: var(--success); font-weight: 700; }
.diff-negative { color: var(--danger); font-weight: 700; }

/* ── Checkbox grid ── */
.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
}
.check-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
}
.check-grid label:hover { background: var(--primary-light); }

.filter-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--paper);
  outline: none;
  font-size: 13px;
}
.filter-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* ── Toast & Spinner ── */
#toast {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  max-width: 90vw;
  text-align: center;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); }
#toast.success { background: var(--success); }

#spinner {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
#spinner[hidden] { display: none; }
.spinner-ring {
  width: 40px; height: 40px;
  border: 4px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile ── */
@media (max-width: 480px) {
  #main { padding: 12px 12px calc(var(--bottomnav-h) + 12px); }
  .check-grid { grid-template-columns: 1fr; }
}

/* ── Sync info bar ── */
.sync-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary-light);
  border: 1px solid var(--primary);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 12px;
}
.sync-bar button {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
  font-size: 14px;
}

/* ── Scanner modal ── */
#scanner-modal {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scanner-frame {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scanner-overlay::before {
  content: '';
  position: absolute;
  top: 30%;
  left: 10%;
  right: 10%;
  bottom: 30%;
  border: 3px solid #E94F1D;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45);
}
.scanner-line {
  position: absolute;
  top: 50%;
  left: 12%;
  right: 12%;
  height: 2px;
  background: #E94F1D;
  box-shadow: 0 0 8px #E94F1D;
  animation: scanline 1.6s ease-in-out infinite;
}
@keyframes scanline {
  0%, 100% { top: 32%; }
  50% { top: 68%; }
}
.scanner-status {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  background: rgba(0,0,0,.6);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  max-width: 80vw;
  text-align: center;
}
.scanner-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255,255,255,.95);
  color: var(--ink);
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
