/* =====================================================================
   Celular (iPhone/Android): base de toque, menu lateral, itens da
   cotação em cartões, janelas em tela cheia e app instalado (PWA).
   No computador nada muda: tudo aqui depende de toque ou tela estreita.
   ===================================================================== */

/* ---------- Base de toque ---------- */
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
button, a, [role="button"], .btn, .s-tile, .kc, .chip, .tabs button, .nav-top, .tile, .login-btn { touch-action: manipulation; }
button, [role="button"], .btn, .s-tile, .chip, .tabs button, .nav-top, .tile, .login-btn, .statusbar span {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
/* iOS dá zoom em campos com fonte menor que 16px e não volta. */
@media (pointer: coarse) {
  input, textarea, select, .inp, [contenteditable="true"] { font-size: 16px !important; }
}
/* Em toque não existe "passar o mouse": o efeito ficava preso depois do toque. Resposta no aperto. */
@media (hover: none) {
  .s-tile:hover, .theme-solar .kc:hover, .theme-solar .btn-primary:hover, .login-btn:hover { transform: none; box-shadow: inherit; }
  .s-tile:hover .s-ico { transform: none; }
  .s-tile:active { transform: scale(.96); }
  .theme-solar .kc:active { transform: scale(.985); }
  .btn:active, .login-btn:active { transform: scale(.97); }
}
.s-tile, .kc, .btn { transition: transform .12s ease-out, box-shadow .2s, background .2s; }

/* ---------- Entalhe (notch) e barra inferior do iPhone ---------- */
#nav { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
@supports (padding-top: env(safe-area-inset-top)) {
  #nav { height: calc(46px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
}
.ls-foot { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
#toast { bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }

/* ---------- Menu lateral (☰) ---------- */
.pk-ftoggle { display: none; }
@media (max-width: 760px) { .pk-ftoggle { display: inline-flex; } }
.nav-burger { display: none; width: 38px; height: 38px; border: 0; background: none; color: #fff; border-radius: 8px; place-items: center; cursor: pointer; flex: none; }
.nav-burger svg { width: 22px; height: 22px; }
.drawer-bg { position: fixed; inset: 0; z-index: 80; background: rgba(5, 20, 35, .45); backdrop-filter: blur(3px); opacity: 0; transition: opacity .2s; }
.drawer-bg.open { opacity: 1; }
.drawer { position: absolute; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); background: #fff; display: flex; flex-direction: column; box-shadow: 8px 0 30px rgba(0,0,0,.2); transform: translateX(-100%); transition: transform .26s cubic-bezier(.2,.8,.2,1); padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); overscroll-behavior: contain; }
.drawer-bg.open .drawer { transform: none; }
.drawer-h { display: flex; align-items: center; gap: 12px; padding: 16px 18px; color: #fff; background: linear-gradient(120deg, #083f68, #0d72b9 70%, #1a9dd8); }
.drawer-h .s-ico { width: 40px; height: 40px; border-radius: 13px; }
.drawer-h .s-ico svg { width: 22px; height: 22px; }
.drawer-h b { font: 600 18px 'Quicksand', sans-serif; }
.drawer-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 0 16px; }
.drawer-body .dg { padding: 12px 18px 4px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #6b8796; }
.drawer-body a { display: flex; align-items: center; min-height: 46px; padding: 0 18px 0 26px; color: #1d3747; text-decoration: none; font-size: 15.5px; border-left: 3px solid transparent; }
.drawer-body a.top { padding-left: 18px; font-weight: 600; }
.drawer-body a.active { color: #0d72b9; background: #eaf5fb; border-left-color: #0d72b9; font-weight: 600; }
.drawer-body a:active { background: #f1f7fb; }
.drawer-foot { border-top: 1px solid var(--border); padding: 10px 18px; display: flex; gap: 10px; }
.drawer-foot a { flex: 1; text-align: center; padding: 10px; border-radius: 10px; background: #f3f7fa; color: #1d3747; text-decoration: none; font-weight: 600; font-size: 14px; }

@media (max-width: 760px) {
  .nav-burger { display: grid; }
  .nav-menu, .nav-company { display: none !important; }
  #nav .nav-app { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
  #nav .nav-home { display: none; }
  .nav-right { gap: 8px; padding-left: 4px; }
  .nav-sub { top: calc(46px + env(safe-area-inset-top, 0px)); }

  /* ---------- Barras de controle e de ações ---------- */
  .cp { padding: 8px 12px; }
  .cp-search { min-width: 0; max-width: none; flex-basis: 100%; order: 3; }
  .actionbar { padding: 8px 12px; gap: 8px; }
  .actionbar .acts { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; width: 100%; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
  .actionbar .acts::-webkit-scrollbar { display: none; }
  .actionbar .acts .btn { flex: none; min-height: 40px; }
  .statusbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; width: 100%; }
  .statusbar::-webkit-scrollbar { display: none; }
  .btn { min-height: 38px; }
  .sheet-wrap { padding: 8px; }
  .sheet { padding: 14px; border-radius: 14px; }

  /* ---------- Itens da cotação/fatura em cartões ---------- */
  .lines-wrap { overflow: visible; }
  table.lines, table.lines.pick { min-width: 0; display: block; }
  table.lines thead { display: none; }
  table.lines tbody { display: flex; flex-direction: column; gap: 10px; }
  table.lines tr { display: grid; grid-template-columns: 1fr 1fr 1fr 40px; gap: 4px 10px; padding: 10px 10px 12px; border: 1px solid var(--border); border-radius: 14px; background: #fff; box-shadow: 0 1px 3px rgba(13,114,185,.05); }
  table.lines td { display: block; padding: 0; border: 0; min-width: 0; width: auto !important; text-align: left; }
  table.lines .desc-cell { grid-column: 1 / 4; grid-row: 1 / 3; min-width: 0; }
  table.lines td:last-child { grid-column: 4; grid-row: 1; justify-self: end; }
  table.lines td.mv { grid-column: 4; grid-row: 2; display: flex; flex-direction: column; align-items: flex-end; width: auto; }
  table.lines tr > td:nth-child(3) { grid-column: 1; grid-row: 3; }
  table.lines tr > td:nth-child(4) { grid-column: 2; grid-row: 3; }
  table.lines tr > td:nth-child(6) { grid-column: 3 / 5; grid-row: 3; }
  table.lines tr > td:nth-child(5) { grid-column: 1 / 3; grid-row: 4; }
  table.lines tr > td:nth-child(7) { grid-column: 3 / 5; grid-row: 4; text-align: right; font-weight: 700; font-size: 16px; align-self: end; }
  table.lines tr > td:nth-child(3)::before { content: 'Quantidade'; }
  table.lines tr > td:nth-child(4)::before { content: 'Preço unit.'; }
  table.lines tr > td:nth-child(5)::before { content: 'Impostos'; }
  table.lines tr > td:nth-child(6)::before { content: '% desconto'; }
  table.lines tr > td:nth-child(7)::before { content: 'Valor'; }
  table.lines tr > td:nth-child(n+3):nth-child(-n+7)::before { display: block; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; text-align: left; }
  table.lines input.inp.n, table.lines input.inp.n.s { width: 100%; text-align: left; border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; background: #f8fbfd; }
  table.lines .tax-cell .m2m { justify-content: flex-start; border: 1px solid var(--border); border-radius: 9px; padding: 4px 6px; min-height: 40px; }
  table.lines .desc-cell .m2o input { font-size: 16px; }
  table.lines textarea.desc { border: 1px solid transparent; border-radius: 8px; }
  table.lines textarea.desc:focus { border-color: var(--brand); }
  table.lines .ln-src { margin-top: 4px; }
  /* Seções e notas: uma linha simples (sem os rótulos dos campos) */
  table.lines tr.ln-sec, table.lines tr.ln-note { display: flex; align-items: center; gap: 8px; background: #eef3f6; }
  table.lines tr.ln-sec > td, table.lines tr.ln-note > td { grid-column: auto !important; grid-row: auto !important; }
  table.lines tr.ln-sec > td::before, table.lines tr.ln-note > td::before { content: none !important; display: none !important; }
  table.lines tr.ln-sec > td:nth-child(2), table.lines tr.ln-note > td:nth-child(2) { flex: 1; min-width: 0; }
  table.lines tr.ln-sec > td:nth-child(3) { font-weight: 700; white-space: nowrap; text-align: right !important; font-size: 15px; }
  table.lines tr.ln-sec > td.mv, table.lines tr.ln-note > td.mv { display: none; }
  table.lines tr.ln-note { background: #fff; border-style: dashed; }
  /* Descrição do produto: 3 linhas; ao tocar para editar, abre inteira */
  table.lines textarea.desc { line-height: 1.4; max-height: calc(4.2em + 10px); overflow: hidden; }
  table.lines textarea.desc:focus { max-height: none; overflow: auto; }
  table.lines .desc-cell > div:not(.m2o) { font-size: 13px; }
  table.lines tr.add-line { display: flex; flex-wrap: wrap; gap: 6px; background: none; border: 0; box-shadow: none; padding: 4px 0; }
  table.lines tr.add-line td { display: contents; }
  table.lines tr.add-line td::before { content: none !important; }
  table.lines tr.add-line .btn-link { padding: 9px 12px; border-radius: 10px; background: #eaf5fb; text-decoration: none; font-weight: 600; font-size: 14px; }
  /* Totais */
  .totals, #totals { margin-left: 0 !important; width: 100% !important; }

  /* ---------- Janelas (modais) viram folhas de baixo para cima ---------- */
  .modal-bg { align-items: end !important; justify-items: stretch !important; padding: 0 !important; }
  .modal, .modal.wide, .pk-modal .modal.wide, .mk-modal .modal.wide { width: 100% !important; max-width: none !important; max-height: 94dvh; margin: 0 !important; border-radius: 20px 20px 0 0 !important; display: flex; flex-direction: column; }
  .modal-b { overflow-y: auto; overscroll-behavior: contain; flex: 1; }
  .modal-f { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important; }
  .theme-solar .modal { animation: mSheet .3s cubic-bezier(.2,.8,.2,1); }
  @keyframes mSheet { from { transform: translateY(40px); opacity: .4; } }
  .m2o-dd { max-height: 50dvh; }

  /* ---------- Janela de produtos: busca primeiro, filtros recolhidos ---------- */
  .pk { display: flex !important; flex-direction: column; min-height: 0; gap: 8px; }
  .pk-main { order: 1; }
  .pk-side { order: 2; display: none; max-height: none !important; border: 0 !important; padding: 0 !important; }
  .pk.show-filters .pk-side { display: block; order: 0; border-bottom: 1px solid var(--border) !important; padding-bottom: 8px !important; }
  .pk-top { flex-wrap: wrap; }
  .pk-top #pk-q { flex-basis: 100%; }
  .pk-top .pk-ftoggle, .pk-top #pk-sort { flex: 1 1 0; width: auto; }
  .pk-list { max-height: none; }
  .pk-facet > button { min-height: 40px; align-items: center; }

  /* ---------- Tela inicial ---------- */
  .hero { height: 150px; padding-bottom: 20px; }
  .hero-sun { width: 80px; height: 80px; right: 8%; top: calc(18px + env(safe-area-inset-top, 0px)); }
  .hero-moon svg { width: 80px; height: 80px; }
  .hero-text h1 { font-size: 24px; }
  .solar-body { gap: 16px; padding: 4px 12px calc(28px + env(safe-area-inset-bottom, 0px)); }
  .solar-side { order: 1 !important; }
  .solar-apps { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .s-tile { padding: 14px 4px 11px; border-radius: 18px; font-size: 12.5px; gap: 8px; }
  .s-ico { width: 52px; height: 52px; border-radius: 16px; }
  .s-ico svg { width: 26px; height: 26px; }
  .drag-hint { display: none; }
  .sp-time b { font-size: 38px; }

  /* Listas em tabela: rolagem lateral suave dentro do quadro */
  .list-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
}

/* ---------- Link da proposta (cliente no celular): itens em cartões ---------- */
@media (max-width: 640px) {
  .pt-table-wrap { overflow: visible; }
  .pt-table, .pt-table tbody { display: block; width: 100%; }
  .pt-table thead { display: none; }
  .pt-table tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .pt-table td { display: block; padding: 0; border: 0; white-space: normal !important; text-align: left !important; }
  .pt-table tr.r-prod > td:first-child { grid-column: 1 / -1; }
  .pt-table td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
  .pt-table td.val { font-weight: 700; }
  .pt-table tr.r-sec { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; background: #e9ecef; border-radius: 10px; margin: 10px 0 2px; border: 0; }
  .pt-table tr.r-sec td { background: none !important; }
  .pt-table tr.r-note { display: block; }
  .pt-table .ln-flex { gap: 10px; }
}

/* ---------- App instalado na tela de início (modo tela cheia) ---------- */
@media (display-mode: standalone) {
  html, body { overscroll-behavior-y: none; }
  body { min-height: 100dvh; }
}
