/* ==========================================================
   Tema: base clara no estilo do MecanicaIgreja.
   A cor principal muda conforme o produto (body[data-mode]).
   ========================================================== */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e5e7eb;
  --field: #f1f3f5;
  --text: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

/* Placas solares: laranja */
body[data-mode="solar"] {
  --primary: #ea580c;
  --primary-dark: #c2410c;
  --primary-soft: #fff7ed;
  --primary-soft-2: #ffedd5;
  --primary-text: #9a3412;
}

/* Ar-condicionado: azul escuro */
body[data-mode="ar"] {
  --primary: #1e3a8a;
  --primary-dark: #172554;
  --primary-soft: #eff6ff;
  --primary-soft-2: #dbeafe;
  --primary-text: #1e3a8a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg.i { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 18px; height: 18px; }
svg.i.lg { width: 26px; height: 26px; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-t)) 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
  min-height: 100vh;
}
body.no-tabbar #app { padding-bottom: calc(110px + var(--safe-b)); }
body.no-tabbar .tabbar { display: none; }

/* ---------- Cabeçalhos ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { font-size: 24px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: 15px; margin-top: 2px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text);
}
.icon-btn:active { background: var(--field); }

.bar-head { display: flex; align-items: center; gap: 8px; margin: -4px 0 16px -8px; }
.bar-head h1 { font-size: 21px; margin: 0; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mode-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px; border-radius: 999px;
  background: var(--primary-soft-2); color: var(--primary-text);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.mode-chip svg.i { width: 16px; height: 16px; }

.section-title {
  font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); margin: 24px 4px 10px;
}

/* ---------- Seletor grande de produto ---------- */
.mode-switch {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  background: var(--card); border: 1px solid var(--border); border-radius: 20px;
  padding: 6px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.mode-switch .pill {
  position: absolute; top: 6px; bottom: 6px; left: 6px; width: calc(50% - 6px);
  border-radius: 15px; background: var(--primary);
  transition: transform .35s cubic-bezier(.4, 1.3, .5, 1), background-color .3s;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 40%, transparent);
}
body[data-mode="ar"] .mode-switch .pill { transform: translateX(100%); }
.mode-switch button {
  position: relative; z-index: 1; border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 16px 8px; border-radius: 15px; color: var(--muted); font-weight: 700; font-size: 16px;
  transition: color .25s;
}
.mode-switch button svg.i { width: 30px; height: 30px; }
.mode-switch button small { font-weight: 500; font-size: 12px; opacity: .85; }
.mode-switch button[aria-pressed="true"] { color: #fff; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-weight: 600; font-size: 16px; box-shadow: var(--shadow); width: 100%;
  transition: transform .08s, background-color .2s;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.big { min-height: 64px; font-size: 18px; border-radius: var(--radius); }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.soft { background: var(--primary-soft); border-color: var(--primary-soft-2); color: var(--primary-text); box-shadow: none; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack > * + * { margin-top: 10px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card + .card { margin-top: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-2 > .card { margin-top: 0; }
.stat { display: flex; gap: 12px; align-items: flex-start; padding: 14px; }
.stat .ico {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary);
}
.stat .ico.ok { background: var(--success-soft); color: var(--success); }
.stat .ico.warn { background: var(--warning-soft); color: var(--warning); }
.stat b { display: block; font-size: 20px; line-height: 1.15; letter-spacing: -.01em; word-break: break-word; }
.stat span { color: var(--muted); font-size: 13.5px; line-height: 1.3; }

.empty {
  display: flex; align-items: center; gap: 12px; color: var(--muted);
  padding: 18px 16px; font-size: 15px;
}
.empty svg.i { color: var(--faint); }

/* ---------- Listas ---------- */
.list { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; width: 100%;
  border: 0; background: transparent; text-align: left;
}
.list-item + .list-item { border-top: 1px solid var(--border); }
.list-item:active { background: var(--field); }
.list-item .avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 700;
}
.list-item .main { flex: 1; min-width: 0; }
.list-item .title, .list-item .meta { display: block; }
.list-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .meta { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .right { text-align: right; flex: none; }
.list-item .right b { display: block; font-size: 15px; }
.list-item > svg.i { color: var(--faint); }

.badge {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--field); color: var(--muted);
}
.badge.rascunho { background: var(--field); color: var(--muted); }
.badge.enviado { background: var(--warning-soft); color: var(--warning); }
.badge.aprovado { background: var(--success-soft); color: var(--success); }
.badge.recusado { background: var(--danger-soft); color: var(--danger); }

/* ---------- Busca e filtros ---------- */
.search {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 14px; height: 48px;
  margin-bottom: 12px; box-shadow: var(--shadow);
}
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; font-size: 16px; }
.search svg.i { color: var(--faint); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--border); background: var(--card); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; font-weight: 600; white-space: nowrap; color: var(--muted);
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Formulários ---------- */
.field { margin-bottom: 14px; }
.field label, .label { display: block; font-size: 14px; font-weight: 600; margin: 0 2px 6px; }
.field .hint { color: var(--muted); font-size: 13px; margin: 5px 2px 0; }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--field); font-size: 16px; outline: none;
  transition: border-color .15s, background-color .15s; -webkit-appearance: none; appearance: none;
}
select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px;
}
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { border-color: var(--primary); background: #fff; }
.input-suffix { position: relative; }
.input-suffix .input { padding-right: 64px; }
.input-suffix span {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 14px; pointer-events: none;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  background: var(--field); padding: 4px; border-radius: var(--radius-sm);
}
.segmented button {
  border: 0; background: transparent; border-radius: 9px; padding: 10px 6px;
  font-weight: 600; font-size: 14px; color: var(--muted);
}
.segmented button[aria-pressed="true"] { background: #fff; color: var(--primary-text); box-shadow: var(--shadow); }

.picker {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px;
  padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--field); text-align: left; font-size: 16px;
}
.picker .ph { color: var(--faint); flex: 1; }
.picker .val { flex: 1; font-weight: 600; }
.picker svg.i { color: var(--faint); }

/* ---------- Blocos de cálculo ---------- */
.calc-box {
  background: var(--primary-soft); border: 1px solid var(--primary-soft-2);
  border-radius: var(--radius); padding: 16px; margin-top: 4px;
}
.calc-box h3 { margin: 0 0 12px; font-size: 15px; color: var(--primary-text); display: flex; align-items: center; gap: 8px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.kv div span { display: block; color: var(--muted); font-size: 12.5px; }
.kv div b { font-size: 17px; }
.kv .full { grid-column: 1 / -1; }
.warn-note {
  display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; color: var(--warning);
  background: var(--warning-soft); border-radius: 10px; padding: 10px 12px; margin-top: 12px;
}

.ambiente { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: #fff; }
.ambiente + .ambiente { margin-top: 10px; }
.ambiente-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ambiente-head b { font-size: 15px; }
.ambiente-res {
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  background: var(--primary-soft); color: var(--primary-text); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; font-weight: 600; margin-top: 4px;
}

.item-row { display: grid; grid-template-columns: 1fr 64px 110px 36px; gap: 6px; align-items: center; }
.item-row + .item-row { margin-top: 8px; }
.item-row .input { min-height: 44px; padding: 10px; font-size: 15px; }
.item-auto { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; font-size: 15px; }
.item-auto + .item-auto { border-top: 1px dashed var(--border); }
.item-auto .d { color: var(--text); }
.item-auto .d small { display: block; color: var(--muted); }
.item-auto .v { font-weight: 600; white-space: nowrap; }

.total-line { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; color: var(--muted); }
.total-line.grand { color: var(--text); font-size: 20px; font-weight: 800; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; }

/* Barra fixa de salvar */
.save-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border); padding: 12px 16px calc(12px + var(--safe-b));
}
.save-bar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.save-bar .tot { flex: 1; }
.save-bar .tot span { display: block; font-size: 12px; color: var(--muted); }
.save-bar .tot b { font-size: 19px; }
.save-bar .btn { width: auto; min-width: 140px; }
.save-bar.above-tabbar { bottom: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: 12px; border-top: 1px solid var(--border); }

/* ---------- Barra de abas ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(6px + var(--safe-b));
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 12px; font-weight: 500; color: var(--muted); padding: 4px 0;
}
.tabbar a .ti { width: 52px; height: 30px; border-radius: 999px; display: flex; align-items: center; justify-content: center; transition: background-color .2s; }
.tabbar a.on { color: var(--primary); font-weight: 700; }
.tabbar a.on .ti { background: var(--primary-soft-2); }

/* ---------- Folha inferior (bottom sheet) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .45); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .2s;
}
.sheet {
  background: #fff; width: 100%; max-width: 640px; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + var(--safe-b)); max-height: 85vh; overflow-y: auto;
  animation: up .25s cubic-bezier(.2, .9, .3, 1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-size: 19px; margin: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

/* ---------- Avisos ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); transition: all .25s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--warning-soft); color: #92400e; font-size: 14px; margin-bottom: 14px;
}

.logo-preview { width: 72px; height: 72px; border-radius: 14px; background: var(--field); object-fit: contain; border: 1px solid var(--border); }
.muted { color: var(--muted); }
.center { text-align: center; }
.mt { margin-top: 14px; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; }
.login-logo {
  width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 16px;
  background: linear-gradient(135deg, #ea580c 0 50%, #1e3a8a 50% 100%);
  display: flex; align-items: center; justify-content: center; color: #fff;
}

/* ---------- Documento para PDF / impressão ---------- */
.print-root { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; }
  #app, .tabbar, .save-bar, #sheet-root, .toast { display: none !important; }
  .print-root { display: block; }
}
.doc { font-size: 12.5px; color: #111; line-height: 1.45; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 12px; border-bottom: 3px solid var(--primary); }
.doc-head img { max-height: 64px; max-width: 160px; object-fit: contain; }
.doc-head .emp b { font-size: 16px; display: block; }
.doc-head .num { text-align: right; }
.doc-head .num b { font-size: 18px; color: var(--primary); display: block; }
.doc h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--primary); margin: 18px 0 6px; }
.doc table { width: 100%; border-collapse: collapse; }
.doc th, .doc td { padding: 7px 6px; border-bottom: 1px solid #e5e7eb; text-align: left; vertical-align: top; }
.doc th { font-size: 11px; text-transform: uppercase; color: #555; background: #f6f7f9; }
.doc td.n, .doc th.n { text-align: right; white-space: nowrap; }
.doc .doc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.doc .doc-grid div { background: #f6f7f9; border-radius: 6px; padding: 8px; }
.doc .doc-grid span { display: block; font-size: 10.5px; color: #666; }
.doc .doc-grid b { font-size: 14px; }
.doc .doc-total { margin-left: auto; width: 260px; margin-top: 8px; }
.doc .doc-total div { display: flex; justify-content: space-between; padding: 3px 0; }
.doc .doc-total .g { font-size: 16px; font-weight: 800; border-top: 2px solid #111; margin-top: 4px; padding-top: 6px; }
.doc .doc-foot { margin-top: 28px; font-size: 11px; color: #555; }
.doc .sign { margin-top: 48px; display: grid; grid-template-columns: 1fr 1fr; gap: 40px; text-align: center; font-size: 11px; }
.doc .sign div { border-top: 1px solid #333; padding-top: 6px; }
