:root {
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --surface-2: #ECF1F7;
  --ink: #16202E;
  --ink-soft: #4C5B6D;
  --ink-faint: #8393A6;
  --line: #DCE3EC;
  --blue: #1E5F8C;
  --blue-deep: #123B57;
  --blue-tint: #E7F0F7;
  --safety: #E06A28;
  --safety-tint: #FCEBDF;
  --good: #2F8F5B;
  --good-tint: #E4F5EC;
  --danger: #C2452F;
  --radius: 14px;
  --radius-sm: 9px;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --shadow: 0 1px 2px rgba(18,59,87,.06), 0 6px 20px -8px rgba(18,59,87,.15);
}
:root:not([data-theme="light"]) {
  @media (prefers-color-scheme: dark) {
    --bg: #0E1620;
    --surface: #16202C;
    --surface-2: #1D2A38;
    --ink: #ECF1F7;
    --ink-soft: #A8B6C7;
    --ink-faint: #6C7C8F;
    --line: #2A3A4A;
    --blue: #4B9BCB;
    --blue-deep: #A9D3EC;
    --blue-tint: #17293A;
    --safety: #F08A4B;
    --safety-tint: #33241A;
    --good: #4FBE86;
    --good-tint: #16302380;
    --danger: #E17A63;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px -8px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --bg: #0E1620;
  --surface: #16202C;
  --surface-2: #1D2A38;
  --ink: #ECF1F7;
  --ink-soft: #A8B6C7;
  --ink-faint: #6C7C8F;
  --line: #2A3A4A;
  --blue: #4B9BCB;
  --blue-deep: #A9D3EC;
  --blue-tint: #17293A;
  --safety: #F08A4B;
  --safety-tint: #33241A;
  --good: #4FBE86;
  --good-tint: #16302380;
  --danger: #E17A63;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px -8px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--blue-deep);
  color: #fff;
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
}
.topbar .back {
  background: rgba(255,255,255,.12); border: none; color: #fff;
  width: 36px; height: 36px; border-radius: 10px; font-size: 18px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.topbar .title { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; flex: 1; }
.topbar .sub { font-size: 12px; color: rgba(255,255,255,.65); font-weight: 500; }

.content { flex: 1; padding: 16px 16px calc(96px + env(safe-area-inset-bottom, 0px)); }
.content.no-pad-bottom { padding-bottom: 16px; }

h1.page-h { font-size: 20px; font-weight: 800; margin: 4px 0 4px; letter-spacing: -0.02em; }
p.page-sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 18px; line-height: 1.5; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-flat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 10px; }
/* Campos do Portãozinho (ex.: batentes) — cartão externo discreto com
   células brancas bem definidas por campo, para não ficar tudo
   amontoado dentro de um único bloco azul-claro. */
.campo-card { background: rgba(207,231,245,.32); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; margin-top: 10px; }
.campo-card .campo-card-titulo { font-size: 12px; font-weight: 800; color: var(--blue-deep); display: block; margin-bottom: 10px; letter-spacing: .2px; }
.campo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.field-cell { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px 8px; }
.field-cell .field-cell-label { font-size: 10.5px; font-weight: 700; color: var(--ink-faint); display: block; margin-bottom: 3px; }
.field-cell input, .field-cell select { border: none; padding: 1px 0; background: transparent; font-size: 16px; width: 100%; }
.field-cell select { appearance: none; }

label.field-label {
  display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  margin: 14px 0 6px; text-transform: none;
}
label.field-label:first-child { margin-top: 0; }
input[type=text], input[type=tel], input[type=date], input[type=number], textarea, select {
  width: 100%; font-family: var(--font-ui); font-size: 16px; color: var(--ink);
  background: var(--surface-2); border: 1.5px solid transparent; border-radius: 10px;
  padding: 12px 13px; outline: none; transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); background: var(--surface); }
textarea { resize: vertical; min-height: 70px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%); background-position: calc(100% - 20px) center, calc(100% - 15px) center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-ui); font-weight: 700; font-size: 15px; cursor: pointer;
  border-radius: 12px; border: none; padding: 14px 18px; width: 100%;
  transition: transform .05s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-safety { background: var(--safety); color: #fff; }
.btn-ghost { background: var(--surface-2); color: var(--ink); }
.btn-outline { background: transparent; color: var(--blue); border: 1.5px solid var(--blue); }
.btn-danger-outline { background: transparent; color: var(--danger); border: 1.5px solid var(--danger); }
.btn-sm { padding: 9px 14px; font-size: 13.5px; width: auto; border-radius: 9px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn[disabled] { opacity: .4; pointer-events: none; }

.home-hero {
  background: linear-gradient(160deg, var(--blue-deep), var(--blue));
  color: #fff; border-radius: 18px; padding: 22px 20px; margin-bottom: 20px;
}
.home-hero .eyebrow { font-size: 13px; color: rgba(255,255,255,.7); font-weight: 600; margin-bottom: 4px; }
.home-hero h2 { margin: 0 0 4px; font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.home-hero p { margin: 0; font-size: 13.5px; color: rgba(255,255,255,.75); }

.action-tile {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 16px; margin-bottom: 12px; box-shadow: var(--shadow); cursor: pointer;
}
.action-tile .icon {
  width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.action-tile .icon.blue { background: var(--blue-tint); color: var(--blue); }
.action-tile .icon.safety { background: var(--safety-tint); color: var(--safety); }
.action-tile .txt strong { display: block; font-size: 15.5px; font-weight: 700; }
.action-tile .txt span { font-size: 12.5px; color: var(--ink-faint); }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg-opt {
  flex: 1; min-width: 90px; text-align: center; padding: 12px 10px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface-2); font-weight: 600; font-size: 14px; color: var(--ink-soft);
  cursor: pointer;
}
.seg-opt.active { background: var(--blue); border-color: var(--blue); color: #fff; }

.env-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
.env-card .env-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; }
.env-card .env-head strong { font-size: 15px; }
.env-card .env-head .badge { font-size: 11px; }
.env-card .env-body { padding: 0 16px 14px; }

.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge-pending { background: var(--safety-tint); color: var(--safety); }
.badge-done { background: var(--good-tint); color: var(--good); }

.bar-row {
  display: grid; grid-template-columns: 46px 1fr; gap: 12px; align-items: start;
  background: var(--surface-2); border-radius: 12px; padding: 12px; margin-bottom: 10px;
}
.bar-row .tag {
  background: var(--blue); color: #fff; font-family: var(--font-mono); font-weight: 600; font-size: 12.5px;
  border-radius: 8px; height: 30px; display: flex; align-items: center; justify-content: center;
}
.bar-row .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bar-row .grid2 > div { grid-column: span 1; }
.bar-row .mini-label { font-size: 11px; color: var(--ink-faint); font-weight: 600; margin-bottom: 3px; display:block; }
.bar-row select, .bar-row input { padding: 8px 9px; font-size: 16px; }
.bar-row .remove-bar { grid-column: 1 / -1; text-align: right; }
.bar-row .remove-bar button { background: none; border: none; color: var(--danger); font-size: 12.5px; font-weight: 700; cursor: pointer; padding: 4px; }

.acc-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.acc-row:last-child { border-bottom: none; }
.acc-row .name { font-size: 14.5px; font-weight: 600; flex: 1; }
.acc-row .qty-input { width: 56px; text-align: center; padding: 8px 4px; }
.acc-row .qty-input:disabled { opacity: .4; background: var(--surface-2); color: var(--ink-faint); }
.acc-thumb {
  width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); color: var(--blue);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer;
}
.acc-preview-backdrop {
  position: fixed; inset: 0; background: rgba(10,20,30,.55); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.acc-preview-box {
  background: var(--surface); border-radius: 16px; padding: 28px 24px; text-align: center;
  box-shadow: var(--shadow); max-width: 260px; width: 100%;
}
.acc-preview-icon { color: var(--blue); display: flex; justify-content: center; margin-bottom: 14px; }
.acc-preview-box p { font-size: 14.5px; font-weight: 700; margin: 0 0 16px; }
.toggle { position: relative; width: 46px; height: 27px; flex-shrink: 0; }
.toggle input { display:none; }
.toggle .track { position: absolute; inset: 0; background: var(--line); border-radius: 20px; transition: .15s; }
.toggle .track::after { content:''; position: absolute; width: 21px; height: 21px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.toggle input:checked + .track { background: var(--good); }
.toggle input:checked + .track::after { left: 22px; }

.summary-block { margin-bottom: 16px; }
.summary-block h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 700; margin: 0 0 8px; }
.summary-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14.5px; }
.summary-line:last-child { border-bottom: none; }
.summary-line .k { color: var(--ink-soft); }
.summary-line .v { font-weight: 700; text-align: right; }
.empty-note { color: var(--ink-faint); font-size: 13.5px; font-style: italic; padding: 6px 0; }

.search-box { position: relative; margin-bottom: 16px; }
.search-box input { padding-left: 40px; }
.search-box .ic { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-faint); }

.visit-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); cursor: pointer; }
.visit-item .top-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.visit-item strong { font-size: 15.5px; }
.visit-item .meta { font-size: 12.5px; color: var(--ink-faint); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-faint); }
.empty-state .ic { font-size: 40px; margin-bottom: 10px; }
.empty-state p { font-size: 14px; margin: 0; }

.fixed-cta { position: sticky; bottom: 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); background: linear-gradient(0deg, var(--bg) 60%, transparent); }

.croqui-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow); margin-bottom: 14px; }
.croqui-wrap svg { width: 100%; height: auto; display: block; border-radius: 10px; background: var(--blue-deep); }
#croqui3dSvgHost { touch-action: none; -webkit-user-select: none; user-select: none; cursor: grab; }
#croqui3dSvgHost:active { cursor: grabbing; }
.croqui-legend { display: flex; gap: 7px 14px; flex-wrap: wrap; padding: 12px 8px 4px; font-size: 10.5px; color: var(--ink-soft); line-height: 1.4; }
.croqui-legend span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.step-progress { display: flex; gap: 6px; margin-bottom: 18px; }
.step-progress div { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.step-progress div.done { background: var(--blue); }

.section-nav { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.section-nav button { flex-shrink: 0; padding: 9px 14px 9px 10px; border-radius: 20px; border: 1.5px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--ink-soft); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.section-nav button.active { background: var(--blue-deep); border-color: var(--blue-deep); color: #fff; }
.step-num { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; border-radius: 50%; background: var(--surface-2); color: var(--ink-faint); font-size: 10.5px; font-weight: 700; flex-shrink: 0; }
.section-nav button.active .step-num { background: rgba(255,255,255,.25); color: #fff; }
.step-dots { display: flex; gap: 5px; justify-content: center; margin-bottom: 10px; }
.step-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--line); transition: .15s; }
.step-dots span.active { background: var(--blue); width: 16px; border-radius: 4px; }

.login-wrap { display: flex; flex-direction: column; justify-content: center; min-height: 100vh; padding: 32px 26px; }
.login-logo-badge {
  display: inline-flex; align-items: center; background: #fff; border-radius: 16px;
  padding: 14px 20px; margin-bottom: 26px; box-shadow: var(--shadow); border: 1px solid var(--line);
  align-self: flex-start;
}
.login-logo-badge img { display: block; height: 46px; width: auto; }
.login-wrap .kicker { color: var(--blue); font-size: 13px; font-weight: 600; margin: 0 0 4px; }
.login-wrap h1 { font-size: 26px; margin: 0 0 8px; font-weight: 800; letter-spacing: -0.02em; }
.login-wrap p.tag { color: var(--ink-soft); font-size: 14.5px; margin: 0 0 30px; line-height: 1.5; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 11px 20px; border-radius: 30px; font-size: 13.5px; font-weight: 600; z-index: 999; box-shadow: var(--shadow); opacity:0; pointer-events:none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

.link-btn { background:none;border:none;color:var(--blue);font-weight:700;font-size:14px;cursor:pointer;padding:8px 0; }

/* Documento técnico (pré-visualização / impressão) */
.doc-page { background: #fff; color: #16202E; border-radius: var(--radius); padding: 22px 18px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.doc-header { border-bottom: 2px solid var(--blue-deep); padding-bottom: 14px; margin-bottom: 18px; }
.doc-eyebrow { font-size: 12px; font-weight: 700; color: var(--blue); text-transform: none; margin-bottom: 2px; }
.doc-header h1 { font-size: 22px; margin: 0 0 8px; font-weight: 800; letter-spacing: -0.02em; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: #4C5B6D; }
.doc-obs { font-size: 13px; color: #4C5B6D; margin: 10px 0 0; font-style: italic; }
.doc-ambiente { margin-bottom: 26px; padding-bottom: 18px; border-bottom: 1px dashed #DCE3EC; }
.doc-ambiente:last-child { border-bottom: none; }
.doc-ambiente h2 { font-size: 16px; margin: 0 0 2px; font-weight: 700; color: var(--blue-deep); }
.doc-produto { font-family: var(--font-mono); font-size: 12px; color: #4C5B6D; margin-bottom: 10px; }
.doc-bloco { margin-bottom: 12px; }
.doc-bloco h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: #8393A6; margin: 0 0 5px; font-weight: 700; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc-table td { padding: 4px 0; border-bottom: 1px dashed #ECF1F7; }
.doc-table td:last-child { text-align: right; font-weight: 600; }
.doc-bloco p { font-size: 13px; margin: 0; line-height: 1.5; }
.doc-croqui svg { width: 100%; height: auto; border-radius: 10px; background: var(--blue-deep); }

/* ============================= RESPONSIVIDADE (tablet / notebook / desktop) =============================
   Estratégia de breakpoints:
     - mobile   : padrão (< 768px) — layout já validado no iPhone, não é tocado por estas regras.
     - tablet   : >= 768px  — mais largura e listas em 2 colunas quando fizer sentido.
     - desktop  : >= 1024px — layout "de verdade" (painel largo, formulário + croqui lado a lado nas
                  etapas de estrutura, etapas sempre em uma linha).
     - desktop grande : >= 1440px — limite de largura máxima para não esticar demais em monitores grandes.
   Cada regra REORGANIZA os mesmos componentes (grid/flex), nunca só aumenta fonte/tamanho proporcionalmente. */

/* Colunas usadas em telas de lista (Ambientes, Visitas salvas, ações da Home).
   No mobile ficam em coluna única (comportamento atual, inalterado). */
.home-actions, .list-grid { display: block; }
.home-actions .action-tile, .list-grid > * { margin-bottom: 12px; }

/* Painel de formulário + preview do croqui nas etapas Superior/Inferior/Vertical.
   No mobile o preview fica oculto — o fluxo continua 100% vertical, como já validado. */
.checklist-layout { display: block; }
.checklist-preview { display: none; }

@media (min-width: 768px) {
  #app { max-width: 760px; }
  .content { padding: 20px 28px 44px; }
  .home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .list-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
  .home-actions .action-tile, .list-grid > * { margin-bottom: 0; }
  .login-wrap { max-width: 420px; margin: 0 auto; width: 100%; }
}

@media (min-width: 1024px) {
  body { background: var(--surface-2); }
  #app { max-width: 1120px; background: var(--bg); box-shadow: 0 0 32px rgba(18,32,46,.07); }
  .content { padding: 30px 44px 52px; }
  .list-grid { grid-template-columns: 1fr 1fr 1fr; }
  .checklist-layout { display: grid; grid-template-columns: minmax(0,1fr) minmax(280px, 420px); gap: 30px; align-items: start; }
  .checklist-preview { display: block; position: sticky; top: 18px; }
  .form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
  .form-row-2 > * { margin-top: 0 !important; }
  /* Campos "soltos" (não dentro de grades como .bar-row/.grid2/.acc-row)
     não devem esticar até a largura toda do painel — mantém leitura
     confortável em telas largas sem virar duas aplicações diferentes. */
  .content > input[type=text], .content > input[type=date], .content > input[type=tel],
  .content > input[type=number], .content > textarea, .content > select {
    max-width: 480px;
  }
}

/* Orçamento salvo: dados à esquerda, negociação e proposta à direita (só em tela larga). */
@media (min-width: 1024px) {
  .orc-colunas { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 24px; align-items: start; }
  .orc-colunas > * > .campo-card:first-child { margin-top: 0; }
  .orc-par .field-cell { grid-column: auto !important; }
}

@media (min-width: 1440px) {
  #app { max-width: 1280px; }
}

@media print {
  body { background: #fff; }
  .topbar, .fixed-cta, .toast, .section-nav { display: none !important; }
  #app { max-width: 100%; }
  .content { padding: 0; }
  .doc-page { box-shadow: none; border: none; padding: 0; }
  .doc-ambiente { break-inside: avoid; }
}
