/* Embala Tudo Fábrica */
:root {
  --bg: #f2f0eb;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --ink: #1b211e;
  --ink-2: #4c5450;
  --muted: #7d8580;
  --line: #e2dfd8;
  --brand: #C8140A;
  --brand-ink: #ffffff;
  --brand-soft: #fbe3e1;
  --bar: #4a5563;
  --run-ink: #ffffff;
  --run: #1f7a4d;   --run-soft: #e2f1e8;
  --stop: #c2361f;  --stop-soft: #fbe6e2;
  --idle: #7d8580;  --idle-soft: #eeede9;
  --warn: #a8660a;  --warn-soft: #fbf0dc;
  --header: #1b211e;
  --shadow: 0 1px 2px rgba(20,30,25,.06), 0 4px 14px rgba(20,30,25,.06);
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131715; --surface: #1c211f; --surface-2: #232927; --ink: #eef1ef; --ink-2: #c3cac6; --muted: #8e9792;
    --line: #2f3633; --brand: #E0281C; --brand-ink: #ffffff; --brand-soft: #3a1a17; --bar: #9aa4b2; --run-ink: #0d1411;
    --run: #4bb983; --run-soft: #1d3328; --stop: #ef6a52; --stop-soft: #3a1f1a; --idle: #8e9792; --idle-soft: #262c29;
    --warn: #e3a447; --warn-soft: #3a2d17; --header: #0d1110; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131715; --surface: #1c211f; --surface-2: #232927; --ink: #eef1ef; --ink-2: #c3cac6; --muted: #8e9792;
  --line: #2f3633; --brand: #E0281C; --brand-ink: #ffffff; --brand-soft: #3a1a17; --bar: #9aa4b2; --run-ink: #0d1411;
  --run: #4bb983; --run-soft: #1d3328; --stop: #ef6a52; --stop-soft: #3a1f1a; --idle: #8e9792; --idle-soft: #262c29;
  --warn: #e3a447; --warn-soft: #3a2d17; --header: #0d1110; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.n, .kpi .v { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- topo */
.topo {
  position: sticky; top: 0; z-index: 20;
  background: var(--header); color: #fff;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 60px;
}
.marca { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; }
.marca .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; }
.marca small { display: block; font-weight: 500; opacity: .65; font-size: 12px; letter-spacing: 0; }
.topo .esp { flex: 1; }
.topo .quem { text-align: right; font-size: 14px; line-height: 1.2; }
.topo .quem small { opacity: .65; }
.btn-topo { background: rgba(255,255,255,.1); border: 0; color: #fff; padding: 10px 14px; border-radius: 10px; cursor: pointer; }
.btn-topo:hover { background: rgba(255,255,255,.18); }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,.1); white-space: nowrap; cursor: pointer; border: 0; color: #fff; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: #5fd69a; }
.sync.pend i { background: #f1b44c; }
.sync.off i { background: #ef6a52; }

.abas { display: flex; gap: 4px; padding: 0 16px; background: var(--header); overflow-x: auto; }
.abas button { background: none; border: 0; color: rgba(255,255,255,.65); padding: 12px 14px; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; font-weight: 600; }
.abas button.on { color: #fff; background: var(--brand); border-bottom-color: var(--brand); border-radius: 10px 10px 0 0; }

main { padding: 20px 16px 60px; max-width: 1280px; margin: 0 auto; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 24px 0 12px; font-weight: 700; }
h2:first-child { margin-top: 0; }

/* ---------- botões e formulários */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 12px 18px; border-radius: 12px; font-weight: 600; cursor: pointer; min-height: 48px; }
.btn:hover { border-color: var(--muted); }
.btn.pri { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ok { background: var(--run); color: var(--run-ink); border-color: var(--run); }
.btn.perigo { background: var(--stop); color: #fff; border-color: var(--stop); }
.btn.grande { min-height: 64px; font-size: 18px; padding: 14px 22px; border-radius: 14px; width: 100%; }
.btn.peq { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 9px; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 8px 4px; min-height: 0; }
.btn:disabled { opacity: .5; cursor: default; }

label.campo { display: block; }
label.campo > span, div.campo > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.inp, select.inp, textarea.inp {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); min-height: 50px; font-size: 17px;
}
.inp:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.grade-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.grade-form .full { grid-column: 1 / -1; }
.erro { background: var(--stop-soft); color: var(--stop); padding: 10px 14px; border-radius: 10px; font-weight: 600; }
.dica { color: var(--muted); font-size: 14px; }

/* ---------- logo */
.logo-chip { background: #fff; border-radius: 8px; padding: 5px 8px; display: flex; align-items: center; }
.logo-chip img { height: 30px; display: block; }
.marca-login { flex-direction: column; align-items: flex-start; gap: 10px; }
.logo-login { width: 100%; max-width: 320px; height: auto; display: block; background: #fff; border-radius: 10px; padding: 8px; box-sizing: border-box; }
@media (max-width: 600px) { .logo-chip img { height: 24px; } .topo .marca > div { display: none; } }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { background: var(--surface); border-radius: 18px; padding: 32px 28px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.login .marca { color: var(--ink); margin-bottom: 26px; font-size: 20px; }
.login .marca small { color: var(--muted); opacity: 1; font-size: 13px; }
.login .marca .logo { width: 44px; height: 44px; border-radius: 12px; }
.login form { display: grid; gap: 16px; }

/* ---------- grade de máquinas (operador) */
.maquinas { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.maq {
  text-align: left; background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--idle);
  border-radius: var(--r); padding: 16px 16px 14px; cursor: pointer; box-shadow: var(--shadow); min-height: 150px;
  display: flex; flex-direction: column; gap: 6px; transition: transform .08s;
}
.maq:active { transform: scale(.98); }
.maq.run { border-left-color: var(--run); }
.maq.stop { border-left-color: var(--stop); background: linear-gradient(0deg, var(--surface), var(--surface)) padding-box; }
.maq .n { font-size: 13px; color: var(--muted); font-weight: 700; letter-spacing: .5px; }
.maq .nome { font-size: 22px; font-weight: 750; line-height: 1.15; }
.maq .info { font-size: 14px; color: var(--ink-2); flex: 1; }
.maq .rod { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.maq .kg { font-size: 14px; color: var(--muted); }
.maq .kg b { color: var(--ink); font-size: 17px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.status.run { background: var(--run-soft); color: var(--run); }
.status.stop { background: var(--stop-soft); color: var(--stop); }
.status.idle { background: var(--idle-soft); color: var(--idle); }
.status svg { width: 14px; height: 14px; }

/* ---------- tela da máquina */
.voltar { margin-bottom: 14px; }
.cab-maq { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.cab-maq h1 { margin: 0; font-size: 28px; }
.cab-maq .tipo { color: var(--muted); font-weight: 600; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 820px) { .cols { grid-template-columns: 1fr; } }
.cartao { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.cartao h3 { margin: 0 0 12px; font-size: 18px; }
.cartao .acoes { display: grid; gap: 10px; }
.painel-parada { background: var(--stop-soft); border: 2px solid var(--stop); border-radius: var(--r); padding: 20px; margin-bottom: 16px; }
.painel-parada .t { color: var(--stop); font-weight: 800; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.painel-parada .tempo { font-size: 44px; font-weight: 800; color: var(--stop); margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.painel-parada .d { color: var(--ink-2); margin-bottom: 14px; }
.em-andamento { background: var(--run-soft); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.em-andamento b { color: var(--run); }
.motivos { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.motivos .btn { min-height: 76px; font-size: 18px; white-space: normal; }

.lista-dia { display: grid; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface-2); border-radius: 12px; }
.item .q { flex: 1; min-width: 0; }
.item .q b { display: block; }
.item .q small { color: var(--muted); }
.item .v { font-weight: 700; text-align: right; white-space: nowrap; }
.item.parada { background: var(--stop-soft); }
.pend { color: var(--warn); font-size: 12px; font-weight: 700; }

/* ---------- modal */
.modal-fundo { position: fixed; inset: 0; background: rgba(10,15,12,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; padding: 0; }
@media (min-width: 700px) { .modal-fundo { align-items: center; padding: 24px; } }
.modal { background: var(--bg); width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 22px 20px 20px; }
@media (min-width: 700px) { .modal { border-radius: 18px; } }
.modal h3 { margin: 0 0 16px; font-size: 21px; }
.modal .rodape { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.modal .rodape .btn { min-width: 140px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 12px; z-index: 60; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: calc(100% - 32px); }

/* ---------- filtros do resumo por máquina */
.filtro-res { display: flex; gap: 8px; flex-wrap: wrap; }
.filtro-res .inp { width: auto; min-height: 40px; padding-top: 6px; padding-bottom: 6px; }

/* ---------- ficha da OP (corte) */
.ficha-cab { display: flex; flex-wrap: wrap; gap: 8px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; font-weight: 700; }
.ficha-cab small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
i.auto { font-style: normal; font-weight: 500; font-size: 11px; color: var(--muted); margin-left: 4px; cursor: pointer; }
i.auto.editado { color: var(--brand); }

/* ---------- botões + e ✕ das linhas (mesmo tamanho; ✕ em vermelho) */
.ins-linha [data-mais], .ins-linha [data-del], .bob-linha [data-del], .ins-linha #cli-edit {
  flex: 0 0 44px; width: 44px; height: 44px; min-height: 44px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 800; line-height: 1; }
.ins-linha [data-del], .bob-linha [data-del] { color: var(--brand); border-color: var(--brand); }

/* ---------- botão no canto superior direito (tela de máquinas) */
.canto-acoes { display: flex; justify-content: flex-end; margin-bottom: -8px; }
.canto-acoes .btn { min-height: 40px; padding: 8px 16px; font-size: 14px; }

/* ---------- insumos */
.ins-linha { display: flex; gap: 8px; align-items: center; }
.ins-linha select { flex: 1; min-width: 0; }
.ins-linha input { max-width: 120px; }
.txt-alerta { color: var(--brand); }

/* ---------- bobinas */
.bob-sec { display: grid; gap: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.bob-tit { font-weight: 800; font-size: 14px; }
.bob-tit small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.bob-lista { display: grid; gap: 8px; }
.bob-linha { display: flex; align-items: center; gap: 8px; }
.bob-linha .inp { max-width: 140px; min-height: 44px; }
.bob-num { font-weight: 800; min-width: 92px; font-variant-numeric: tabular-nums; }
.bob-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.bob-chip { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; text-align: left; cursor: pointer; min-height: 48px; }
.bob-chip small { display: block; color: var(--muted); font-size: 12px; }
.bob-chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.bob-chip.on small { color: var(--brand-ink); opacity: .85; }

/* ---------- medidores de rendimento */
.gauges { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; margin-bottom: 16px; }
.gauge { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 12px 14px; text-align: center; }
.g-nome { font-weight: 800; font-size: 15px; }
.g-svg { width: 100%; max-width: 150px; display: block; margin: 2px auto 0; }
.g-fundo { fill: none; stroke: var(--idle-soft); stroke-width: 11; stroke-linecap: round; }
.g-valor { fill: none; stroke-width: 11; stroke-linecap: round; stroke: var(--idle); }
.gauge.run .g-valor { stroke: var(--run); } .gauge.warn .g-valor { stroke: var(--warn); } .gauge.stop .g-valor { stroke: var(--stop); }
.g-num { font-size: 20px; font-weight: 800; text-anchor: middle; dominant-baseline: middle; fill: var(--ink); font-variant-numeric: tabular-nums; }
.g-rot { font-weight: 800; font-size: 14px; margin-top: -6px; }
.gauge.run .g-rot { color: var(--run); } .gauge.warn .g-rot { color: var(--warn); } .gauge.stop .g-rot { color: var(--stop); } .gauge.sem .g-rot, .gauge.idle .g-rot { color: var(--muted); }
.g-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- painel admin */
.filtros { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; margin-bottom: 14px; }
.filtros label.campo { min-width: 0; width: 138px; }
.filtros label.campo:has(input[type=time]) { width: 112px; }
.filtros label.campo:has(select) { width: 180px; }
.filtros label.campo > span { font-size: 12px; margin-bottom: 3px; }
.filtros .inp { min-height: 34px; font-size: 14px; padding: 4px 8px; }
.filtros .atalhos .btn.peq { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.filtros .atalhos { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: none; padding: 9px 16px; border-radius: 9px; font-weight: 700; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--brand); color: var(--brand-ink); box-shadow: var(--shadow); }
.barra-visao { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.barra-visao .dica { font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.kpi .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 28px; font-weight: 800; line-height: 1.15; margin-top: 4px; }
.kpi .v small { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.alerta .v { color: var(--stop); }
.kpi.clicavel { cursor: pointer; transition: background .15s, border-color .15s, transform .1s; }
.kpi.clicavel:hover { border-color: var(--brand); }
.kpi.clicavel:active { transform: scale(.98); }
.kpi.sel { background: var(--brand); border-color: var(--brand); }
.kpi.sel .l, .kpi.sel .v, .kpi.sel .v small, .kpi.sel .s { color: #fff; }
@keyframes pisca { 0%, 60% { background: var(--brand-soft); box-shadow: 0 0 0 3px var(--brand); } 100% { background: transparent; box-shadow: 0 0 0 0 transparent; } }
.destaque { animation: pisca 3.5s ease-out; border-radius: 8px; }
@keyframes piscaL { 0%, 60% { background: var(--brand-soft); color: var(--brand); } 100% { background: transparent; } }
tr.destaque > td { animation: piscaL 3.5s ease-out; }
tr.destaque { animation: none; }

.duas { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .duas { grid-template-columns: 1fr; } }

.barras { display: grid; gap: 8px; }
.barras .grupo { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-top: 6px; }
.barras .linha { display: grid; grid-template-columns: 150px 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.barras .linha .rot { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.barras .trilho { height: 18px; position: relative; }
.barras .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.barras .fill.parado { background: var(--stop); }
.barras .val { font-weight: 700; min-width: 70px; text-align: right; font-variant-numeric: tabular-nums; }
.barras .linha:hover .fill { filter: brightness(1.1); }
.vazio { color: var(--muted); padding: 18px 0; text-align: center; }

.tabela-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; }
tfoot td { font-weight: 800; background: var(--surface-2); }
tr.inativo td { color: var(--muted); }
.cab-tabela { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 24px 0 10px; flex-wrap: wrap; }
.cab-tabela h2 { margin: 0; }

.subabas { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chk { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 50px; }
.chk input { width: 22px; height: 22px; }

@media (max-width: 600px) {
  .topo .quem { display: none; }
  .maq .nome { font-size: 19px; }
  .barras .linha { grid-template-columns: 84px 1fr auto; }
}

/* ---- v23: alertas, romaneio, rastreio, OP, histórico, inventário, resumo ---- */
.txt-ok { color: var(--run); }
.faixa-alerta { background: var(--stop); color: #fff; padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 14px; }
.faixa-alerta span { background: rgba(255,255,255,.18); border-radius: 8px; padding: 2px 8px; }
.lista-avisos { padding-left: 18px; margin: 10px 0; display: grid; gap: 8px; }
.romaneios { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: -4px 0 10px; }
.barra-op { position: relative; height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-top: 6px; }
.barra-op i { position: absolute; left: 0; top: 0; bottom: 0; }
.barra-op i.pr { background: var(--run-soft); border-right: 2px solid var(--run); }
.barra-op i.ex { background: var(--run); height: 4px; top: auto; }
.op-item .q small b { font-weight: 700; }
.rast-bloco { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.rast-bloco h4 { margin: 0 0 8px; font-size: 15px; }
.rast-passo { display: grid; gap: 2px; padding: 8px 0 8px 12px; border-left: 3px solid var(--brand); margin-left: 4px; }
.rast-passo + .rast-passo { margin-top: 4px; }
.rast-passo small { color: var(--muted); }
.acao { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 12px; font-weight: 700; background: var(--idle-soft); }
.acao.ok { background: var(--run-soft); color: var(--run); }
.acao.warn { background: var(--warn-soft); color: var(--warn); }
.acao.stop { background: var(--stop-soft); color: var(--stop); }
.hist-det .dif { display: inline-block; margin-right: 12px; font-size: 13px; }
.inv-inp { max-width: 110px; min-height: 36px; padding: 4px 8px; text-align: right; margin-left: auto; display: block; }
.inv-barra { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.resumo-bloco { margin-bottom: 14px; }
.resumo-bloco h3 { margin-top: 0; }
@media (max-width: 600px) {
  .resumo-kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .resumo-kpis .kpi { padding: 10px 12px; }
  .resumo-kpis .kpi .v { font-size: 22px; }
  .abas { padding: 0 8px; }
  .abas button { padding: 10px 10px; font-size: 14px; }
}

/* ---- v24: celular sem rolagem lateral — tabelas viram cartões, menus quebram linha ---- */
@media (max-width: 640px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  main#tela { padding-left: 12px; padding-right: 12px; }
  .seg { display: flex; flex-wrap: wrap; width: 100%; }
  .seg button { flex: 1 1 auto; padding: 8px 10px; font-size: 14px; }
  .barra-visao { flex-wrap: wrap; }
  .abas { flex-wrap: wrap; overflow-x: visible; padding: 4px 8px 0; gap: 2px; }
  .abas button { padding: 8px 10px; font-size: 13px; border-radius: 10px 10px 0 0; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; min-width: 0; }
  .kpi .v { font-size: 22px; }
  .cab-tabela { flex-wrap: wrap; gap: 8px; }
  .cab-tabela .filtro-res { width: 100%; flex-wrap: wrap; }
  .cab-tabela .filtro-res .inp { max-width: none !important; flex: 1 1 100%; }
  .cab-tabela .filtro-res .btn { flex: 1 1 auto; }
  .cab-maq h1 { font-size: 22px; }
  /* tabela → um cartão por linha, cada célula com o nome da coluna */
  .tabela-wrap { overflow: visible; background: none; border: 0; }
  .tabela-wrap table, .tabela-wrap tbody, .tabela-wrap tfoot, .tabela-wrap tr, .tabela-wrap td { display: block; width: 100%; }
  .tabela-wrap thead { display: none; }
  .tabela-wrap tr { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px 12px; }
  .tabela-wrap tr.hidden { display: none; }
  .tabela-wrap tfoot tr { background: var(--surface-2); font-weight: 700; }
  .tabela-wrap td { border: 0; padding: 5px 0; white-space: normal; text-align: right; display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 0; word-break: break-word; }
  .tabela-wrap td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; text-align: left; flex: 0 0 auto; max-width: 45%; }
  .tabela-wrap td[data-label=""]::before, .tabela-wrap td:not([data-label])::before { display: none; }
  .tabela-wrap td:empty { display: none; }
  .tabela-wrap td:first-child { font-size: 15px; }
  .tabela-wrap td.vazio { justify-content: center; }
  .tabela-wrap td .inv-inp { max-width: 140px; margin-left: 0; }
  .barra-op { width: 100%; }
  /* formulários */
  .modal { padding: 18px 14px 16px; max-height: 94vh; }
  .grade-form { grid-template-columns: 1fr !important; }
  .ins-linha input { max-width: 76px; }
  .ins-linha select { font-size: 15px; }
  .rodape { flex-wrap: wrap; }
  .rodape .btn { flex: 1 1 auto; }
  .filtros label.campo, .filtros label.campo:has(select), .filtros label.campo:has(input[type=time]) { width: calc(50% - 4px); }
  .romaneios .btn { flex: 1 1 auto; }
  .inv-barra .btn { flex: 1 1 auto; }
  .faixa-alerta { font-size: 13px; padding: 8px 12px; }
}

/* ---- v25: datas no iPhone, abas do e-commerce alinhadas, recebimento mais compacto ---- */
input.inp[type=date], input.inp[type=time], input.inp[type=datetime-local] { -webkit-appearance: none; appearance: none; min-width: 0; max-width: 100%; width: 100%; display: block; text-align: left; }
input.inp::-webkit-date-and-time-value { text-align: left; margin: 0; }
.ec-receber { margin-bottom: 16px; }
.ec-receber .btn.grande { min-height: 56px; }
.data-peq { display: inline-flex; align-items: center; gap: 8px; }
.data-peq .inp { width: 170px; min-height: 40px; padding: 6px 10px; font-size: 15px; }
.seg-ec { display: grid; grid-template-columns: repeat(5, auto); }
@media (max-width: 640px) {
  .seg-ec { grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 4px; }
  .seg-ec button { grid-column: span 2; padding: 9px 4px; font-size: 14px; text-align: center; }
  .seg-ec button:nth-child(n+4) { grid-column: span 3; }
  .ec-receber { padding: 12px; }
  .ec-receber .btn.grande { min-height: 50px; font-size: 17px; }
  .ec-dia-cab .filtro-res { justify-content: space-between; align-items: center; }
  .ec-dia-cab .filtro-res .data-peq { flex: 0 0 auto; }
  .ec-dia-cab .filtro-res .data-peq .inp { width: 150px; flex: none; font-size: 15px; }
  .cartao { padding: 14px; }
  .cartao h3 { font-size: 17px; }
}
.telas-chk { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 12px; }
.telas-chk .chk { min-height: 40px; font-weight: 500; }
.bob-aberta + .bob-aberta { margin-top: 10px; }
.bob-aberta .acoes { grid-template-columns: 2fr 1fr; }

/* v30: corte sem bobina informada */
.bob-tit small.aviso-bob { color: var(--danger, #b42318); font-weight: 600; }

/* ---- v31: vendas (clientes e pedidos) ---- */
.sec-tit { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; padding-top: 12px; border-top: 1px solid var(--line); }
form > .sec-tit:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.seg-mini { display: inline-flex; }
.seg-mini button { padding: 7px 12px; font-size: 14px; }
.sit-ped { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 700; white-space: nowrap; background: var(--idle-soft); color: var(--ink-2); }
.sit-ped.aberto { background: var(--warn-soft); color: var(--warn); }
.sit-ped.parcial { background: var(--brand-soft); color: var(--brand); }
.sit-ped.entregue { background: var(--run-soft); color: var(--run); }
.sit-ped.cancelado { text-decoration: line-through; }
.ped-item { display: grid; grid-template-columns: minmax(0, 1fr) 96px 120px 120px 44px; gap: 8px; align-items: end; padding: 10px; background: var(--surface-2); border-radius: 12px; margin-bottom: 8px; }
.ped-item label span, .ped-item-tot span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.ped-item-tot b { display: block; min-height: 44px; line-height: 44px; text-align: right; white-space: nowrap; }
.ped-item [data-del] { color: var(--brand); border-color: var(--brand); min-height: 44px; }
.ped-item .full-linha { grid-column: 1 / -1; }
.ped-totais { margin: 14px 0 0 auto; max-width: 300px; display: grid; gap: 4px; }
.ped-totais div { display: flex; justify-content: space-between; gap: 12px; }
.ped-totais .tot { font-size: 19px; border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; }
.ped-cab { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -4px 0 12px; }
.ped-cab .pend { flex-basis: 100%; }
.ped-info { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-top: 14px; }
.ped-info > div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.ped-info .full { grid-column: 1 / -1; }
.ped-info span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.ped-info small { display: block; color: var(--muted); }
.op-tag { display: inline-block; padding: 2px 8px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; font-weight: 600; white-space: nowrap; }
.ped-acoes { flex-wrap: wrap; }
.seg-ec { display: flex; flex-wrap: wrap; }
@media (max-width: 640px) {
  .seg-ec { display: grid; grid-template-columns: repeat(12, 1fr); }
  .seg-ec button, .seg-ec button:nth-child(n+4) { grid-column: span 3; }
  .seg-ec button:nth-child(n+5) { grid-column: span 4; }
  .seg-mini { display: flex; width: 100%; }
  .seg-mini button { flex: 1 1 auto; padding: 8px 6px; font-size: 13px; }
  .ped-item { grid-template-columns: 1fr 1fr 44px; }
  .ped-item > select { grid-column: 1 / -1; }
  .ped-item-tot { grid-column: 1 / 3; }
  .ped-item-tot b { min-height: 0; line-height: 1.4; text-align: left; }
  .ped-item [data-del] { grid-row: 3; grid-column: 3; }
  .ped-totais { max-width: none; }
  .ped-acoes .btn { flex: 1 1 40%; }
}
.kpi .v.din { font-size: 22px; padding-top: 6px; }

/* ---- v33: nota fiscal de entrada (foto, chave, XML) ---- */
.nf-bloco { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); display: grid; gap: 8px; }
.nf-tit { font-weight: 800; }
.nf-tit small { display: block; font-weight: 500; color: var(--muted); font-size: 13px; }
.nf-acoes { display: flex; flex-wrap: wrap; gap: 8px; }
.nf-acoes label.btn { cursor: pointer; }
.nf-chave .inp { max-width: none; flex: 1; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.nf-info { font-size: 14px; line-height: 1.5; }
.nf-info:empty, .nf-anexos:empty { display: none; }
.nf-item { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.nf-item small { font-weight: 500; color: var(--muted); }
.nf-link { min-height: 30px; padding: 2px 8px; font-size: 13px; }
.nf-chave-txt { font-family: ui-monospace, Menlo, monospace; font-size: 14px; word-break: break-all; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }
.nf-zoom { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.88); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 12px; }
.nf-zoom img { max-width: 100%; max-height: calc(100% - 70px); object-fit: contain; border-radius: 6px; background: #fff; }
@media (max-width: 640px) {
  .nf-acoes label.btn { flex: 1 1 45%; text-align: center; }
}
/* v34: valor da entrada de insumo */
.ei-linha { align-items: flex-end; }
.ei-campo { display: flex; flex-direction: column; gap: 2px; }
.ei-campo small { font-size: 11px; font-weight: 600; color: var(--muted); padding-left: 2px; }
.ei-linha .ei-campo input { max-width: 120px; }
.ei-linha .ei-campo input.ei-valor { max-width: 130px; }
@media (max-width: 640px) {
  .ei-linha { flex-wrap: wrap; }
  .ei-linha select { flex: 1 1 100%; }
  .ei-linha .ei-campo { flex: 1 1 0; min-width: 0; }
  .ei-linha .ei-campo input, .ei-linha .ei-campo input.ei-valor { max-width: none; width: 100%; }
}

/* v35: barra de ações do estoque + filtro de histórico */
.acoes-estoque { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
.acoes-estoque .btn { flex: 1 1 200px; }
.sel-hist { width: auto; min-width: 110px; padding: 4px 8px; }
.hist-rodape { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin: 4px 0 12px; }
.hist-rodape:empty { display: none; }
.op-tag[data-op-ver] { cursor: pointer; }
.op-previa { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 10px 12px; font: inherit; font-size: 14px; margin: 8px 0 0; }
.tag-kit { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 1px 6px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); vertical-align: middle; }
.inv-val { margin: 4px 0 10px; font-size: 14px; }
.tabela-wrap th.inv-pr, .tabela-wrap td.inv-pr { background: var(--surface-2); }
.inv-pr .inv-inp { max-width: 100px; }
.ins-linha .sel-emb { flex: 0 0 auto; width: auto; min-width: 120px; }
@media (max-width: 640px) {
  .ec-linha .ins-linha { flex-wrap: wrap; }
  .ec-linha .ins-linha select[name=merc] { flex: 1 1 100%; }
  .ec-linha .ins-linha .sel-emb { flex: 1 1 auto; }
}

/* v38: financeiro */
.fin-acoes { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.fin-acoes .btn.grande { flex: 1 1 260px; }
.fin-v { font-size: 22px !important; }
.fin-sit { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.fin-sit.ok { background: var(--run-soft); color: var(--run); }
.fin-sit.alerta { background: var(--stop-soft); color: var(--stop); }
.fin-sit.aviso { background: var(--warn-soft); color: var(--warn); }
.fin-grade { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-bottom: 8px; }
.fin-mini { width: 100%; border-collapse: collapse; font-size: 14px; }
.fin-mini th, .fin-mini td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.fin-mini .n { text-align: right; }
.fin-linha { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.fin-linha:last-child { border-bottom: 0; }
.fin-barra { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; align-items: center; gap: 8px; font-size: 14px; margin: 6px 0; }
.fin-barra i { display: block; height: 10px; border-radius: 6px; background: var(--brand); opacity: .75; }
.fin-foto { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.fin-foto .btn { flex: 1 1 160px; justify-content: center; }
.fin-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.fin-chips button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 7px 12px; font-weight: 600; cursor: pointer; font-size: 14px; }
.fin-chips button.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.inp-grande { font-size: 24px; font-weight: 800; }
.fin-pago { background: var(--run-soft); color: var(--run); border-radius: 10px; padding: 10px 12px; }
.fin-contas { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-bottom: 8px; }
.fin-conta { text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; font: inherit; color: var(--ink); }
.fin-conta span { font-size: 20px; font-weight: 800; }
.fin-conta.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.fin-foto .btn.grande { font-size: 17px; padding: 12px; }
.ec-linha .ins-linha { align-items: flex-end; }
.ins-linha input.ec-valor { max-width: 130px; }
@media (max-width: 640px) { .ec-linha .ins-linha .ei-campo { flex: 1 1 0; min-width: 0; } .ec-linha .ins-linha .ei-campo input { max-width: none; width: 100%; } }
.forn-novo { display: grid; grid-template-columns: 200px 1fr 170px; gap: 8px; margin-top: 6px; }
@media (max-width: 640px) { .forn-novo { grid-template-columns: 1fr; } }

/* v41: tabelas mais compactas — cabem na tela sem rolar para o lado */
@media (min-width: 641px) {
  main { max-width: 1440px; }
  table { font-size: 13px; }
  th { font-size: 11px; letter-spacing: .3px; padding: 8px 8px; white-space: normal; line-height: 1.2; vertical-align: bottom; }
  td { padding: 7px 8px; white-space: normal; line-height: 1.3; }
  td.n, th.n, td .fin-sit, td .sit-ped, td .status { white-space: nowrap; }
  td small { font-size: 11px; }
  td .btn.peq { padding: 5px 9px; font-size: 13px; }
  .tabela-wrap td .inv-inp { max-width: 86px; min-height: 32px; padding: 3px 6px; }
  .inv-pr .inv-inp { max-width: 86px; }
  .tag-kit { font-size: 10px; padding: 1px 4px; }
}
@media (min-width: 641px) and (max-width: 1100px) {
  table { font-size: 12px; }
  th { font-size: 10px; padding: 6px 5px; letter-spacing: .2px; }
  td { padding: 6px 5px; }
  td .btn.peq { padding: 4px 7px; font-size: 12px; }
  .tabela-wrap td .inv-inp, .inv-pr .inv-inp { max-width: 70px; font-size: 13px; }
}
@media (min-width: 641px) and (max-width: 900px) {
  td .status { white-space: normal; font-size: 11px; padding: 3px 6px; }
  td.n, th.n { white-space: normal; }
}
/* ambiente de teste */
.amb-teste body { padding-top: 22px; }
.amb-teste body::before { content: 'AMBIENTE DE TESTE — os lançamentos aqui não valem para a fábrica'; position: fixed; top: 0; left: 0; right: 0; z-index: 9999; height: 22px; line-height: 22px;
  text-align: center; font-size: 12px; font-weight: 800; letter-spacing: .4px; color: #1b211e; background: repeating-linear-gradient(45deg, #ffd23f 0 14px, #ffc400 14px 28px); }
.amb-teste .topo { top: 22px; }
