:root {
  --color-primary: #8FBF9F;
  --color-primary-dark: #5B8F6D;
  --color-secondary: #EAF4EC;
  --color-bg: #F4F7F5;
  --color-card: #FFFFFF;
  --color-text: #3A4A40;
  --color-text-muted: #7C8C82;
  --color-border: #E1EAE3;
  --color-baixo: #7FB89A;
  --color-medio: #E8C468;
  --color-alto: #E39257;
  --color-critico: #D66B6B;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(60, 90, 70, 0.08);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

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

.app-shell {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 84px;
  background: var(--color-bg);
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; text-decoration: none; color: #fff; }
.topbar .brand img { height: 30px; border-radius: 8px; }
.topbar .actions { display: flex; align-items: center; gap: 10px; }
.topbar .back { color: #fff; text-decoration: none; font-size: 1.3rem; line-height: 1; }
.topbar .icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.18); color: #fff; display: flex; align-items: center; justify-content: center;
  text-decoration: none; font-size: .95rem; font-weight: 700; border: none; cursor: pointer;
}
.page-title { font-weight: 700; font-size: 1.05rem; }

main.content { padding: 16px; }

/* Flash messages */
.flash { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .92rem; }
.flash-success { background: #E4F5E9; color: #2F6B44; }
.flash-error { background: #FBE7E7; color: #9C3B3B; }
.flash-info { background: #E7F0FB; color: #2E5B8A; }

/* Dashboard tiles */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 6px;
}
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-text);
  font-size: .78rem;
  font-weight: 600;
  text-align: center;
  padding: 10px 6px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(0,0,0,.02);
}
.tile .emoji { font-size: 1.7rem; }
.tile-green   { background: #DCEFE1; }
.tile-blue    { background: #DCEAF5; }
.tile-yellow  { background: #FBF1D8; }
.tile-peach   { background: #FBE4DA; }
.tile-lilac   { background: #E9E1F5; }
.tile-pink    { background: #F8E1EA; }
.tile-mint    { background: #DFF3EE; }
.tile-sand    { background: #F1EADC; }

.section-title { font-size: .95rem; font-weight: 700; margin: 22px 0 10px; color: var(--color-text); }

/* Cards */
.card {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 4px; border-bottom: 1px solid var(--color-border); text-decoration: none; color: var(--color-text);
}
.list-item:last-child { border-bottom: none; }
.list-item .meta { font-size: .8rem; color: var(--color-text-muted); }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: .72rem; font-weight: 700; color: #fff; }
.badge-baixo { background: var(--color-baixo); }
.badge-medio { background: var(--color-medio); color: #5A4A16; }
.badge-alto { background: var(--color-alto); }
.badge-critico { background: var(--color-critico); }
.badge-outline { background: var(--color-secondary); color: var(--color-primary-dark); }
.badge-status-em_andamento { background: #E8C468; color: #5A4A16; }
.badge-status-concluida { background: #7FB89A; }
.badge-status-cancelada { background: #B9B9B9; }

/* Forms */
label { display: block; font-size: .85rem; font-weight: 600; margin: 14px 0 6px; color: var(--color-text); }
label:first-child { margin-top: 0; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], input[type=search], select, textarea {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--color-border);
  background: #fff; font-size: .95rem; color: var(--color-text); font-family: inherit;
}
textarea { min-height: 90px; resize: vertical; }
.field-help { font-size: .78rem; color: var(--color-text-muted); margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.checkbox-row input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px; border-radius: 12px; font-weight: 700; font-size: .92rem;
  border: none; cursor: pointer; text-decoration: none; width: 100%;
}
.btn-primary { background: var(--color-primary-dark); color: #fff; }
.btn-secondary { background: var(--color-secondary); color: var(--color-primary-dark); }
.btn-outline { background: transparent; border: 1.5px solid var(--color-primary-dark); color: var(--color-primary-dark); }
.btn-danger { background: #F1D6D6; color: #9C3B3B; }
.btn-sm { width: auto; padding: 8px 14px; font-size: .82rem; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn { flex: 1; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--color-border); text-align: left; }
th { font-size: .74rem; text-transform: uppercase; color: var(--color-text-muted); }
.table-wrap { overflow-x: auto; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 9px 16px; border-radius: 20px; background: var(--color-secondary); color: var(--color-primary-dark); font-size: .82rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.tab.active { background: var(--color-primary-dark); color: #fff; }

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  max-width: 640px; margin: 0 auto;
  background: #fff; box-shadow: 0 -2px 16px rgba(0,0,0,.08);
  display: flex; align-items: center; justify-content: space-around;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  border-top-left-radius: 18px; border-top-right-radius: 18px;
}
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 3px; text-decoration: none; color: var(--color-text-muted); font-size: .68rem; font-weight: 600; flex: 1; }
.nav-item.active { color: var(--color-primary-dark); }
.nav-item .ic { font-size: 1.25rem; }
.nav-fab {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--color-primary-dark); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; margin-top: -28px; box-shadow: 0 4px 14px rgba(91,143,109,.5); text-decoration: none;
}

/* Checklist item card */
.check-item { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.check-item .desc { font-size: .92rem; font-weight: 600; margin-bottom: 4px; }
.check-item .nr-tag { font-size: .72rem; color: var(--color-text-muted); margin-bottom: 10px; }
.status-toggle { display: flex; gap: 6px; }
.status-btn {
  flex: 1; padding: 10px 4px; border-radius: 10px; border: 1.5px solid var(--color-border);
  background: #fff; font-size: .78rem; font-weight: 700; cursor: pointer; text-align: center; color: var(--color-text-muted);
}
.status-btn.sel-conforme { background: var(--color-baixo); border-color: var(--color-baixo); color: #fff; }
.status-btn.sel-nao_conforme { background: var(--color-critico); border-color: var(--color-critico); color: #fff; }
.status-btn.sel-nao_aplica { background: #D9D9D9; border-color: #D9D9D9; color: #4A4A4A; }
.obs-box { margin-top: 10px; display: none; }
.obs-box.show { display: block; }
.photo-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.photo-thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; border: 1px solid var(--color-border); }
.photo-add-btn { width: 64px; height: 64px; border-radius: 10px; border: 1.5px dashed var(--color-border); background: var(--color-secondary); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; color: var(--color-primary-dark); cursor: pointer; }

.progress-bar { height: 8px; border-radius: 6px; background: var(--color-border); overflow: hidden; margin-top: 8px; }
.progress-bar .fill { height: 100%; background: var(--color-primary-dark); border-radius: 6px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--color-text-muted); }
.empty-state .emoji { font-size: 2.2rem; margin-bottom: 8px; }

.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border-radius: var(--radius-sm);
  box-shadow: var(--shadow); max-height: 220px; overflow-y: auto; z-index: 40; display: none;
}
.autocomplete-list.show { display: block; }
.autocomplete-list div { padding: 10px 14px; font-size: .9rem; cursor: pointer; border-bottom: 1px solid var(--color-border); }
.autocomplete-list div:last-child { border-bottom: none; }
.autocomplete-list div:hover, .autocomplete-list div.hi { background: var(--color-secondary); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: #fff; border-radius: 22px; box-shadow: var(--shadow); padding: 34px 26px; max-width: 380px; width: 100%; text-align: center; }
.login-card .app-emoji { font-size: 2.6rem; }
.login-card h1 { font-size: 1.25rem; margin: 8px 0 4px; }
.login-card p.subtitle { color: var(--color-text-muted); font-size: .85rem; margin-bottom: 24px; }
.login-card form { text-align: left; }

.sig-pad-wrap { background: #fff; border: 1.5px dashed var(--color-border); border-radius: var(--radius-sm); }
.sig-pad-wrap canvas { width: 100%; height: 200px; display: block; touch-action: none; border-radius: var(--radius-sm); }

.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.kpi { background: #fff; border-radius: var(--radius-sm); padding: 12px; text-align: center; box-shadow: var(--shadow); }
.kpi .num { font-size: 1.3rem; font-weight: 800; }
.kpi .lbl { font-size: .68rem; color: var(--color-text-muted); text-transform: uppercase; }

@media (min-width: 700px) {
  .tile-grid { grid-template-columns: repeat(4, 1fr); }
}
