/* ============================================================
   Sistema de Ordem de Serviço — CopyTec
   Estilo mobile-first (celular primeiro, depois telas maiores)
   ============================================================ */
:root {
  --azul: #1d4ed8;
  --azul-escuro: #163a9e;
  --azul-claro: #e8efff;
  --verde: #15803d;
  --verde-claro: #e7f6ec;
  --ambar: #b45309;
  --ambar-claro: #fdf3e3;
  --roxo: #6d28d9;
  --roxo-claro: #f1eafd;
  --vermelho: #b91c1c;
  --vermelho-claro: #fdecec;
  --cinza: #5b6472;
  --cinza-claro: #eef1f6;
  --borda: #dde3ec;
  --fundo: #f2f5fa;
  --card: #ffffff;
  --texto: #171c26;
  --raio: 12px;
  --sombra: 0 1px 3px rgba(23, 28, 38, 0.08), 0 4px 14px rgba(23, 28, 38, 0.06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--fundo);
  color: var(--texto);
  font-size: 15px;
  line-height: 1.45;
}
.hidden { display: none !important; }
img { max-width: 100%; }
button { font: inherit; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
p { margin: 6px 0; }

/* ------------------------- botões e campos ------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--azul); color: #fff; font-weight: 600; cursor: pointer;
  text-decoration: none; text-align: center; transition: filter .15s, transform .05s;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { transform: scale(.98); }
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.sec { background: #fff; color: var(--azul); border-color: var(--azul); }
.btn.cinza { background: #e5e9f1; color: var(--texto); }
.btn.perigo { background: var(--vermelho); }
.btn.sucesso { background: var(--verde); }
.btn.ambar { background: var(--ambar); }
.btn.pequeno { min-height: 34px; padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.bloco { width: 100%; }
.btn.quadrado { width: 44px; padding: 0; }

.campo { margin-bottom: 12px; }
.campo label { display: block; font-size: 12.5px; font-weight: 600; color: var(--cinza); margin-bottom: 4px; }
.campo .dica { font-weight: 400; color: #8a93a3; }
input[type="text"], input[type="password"], input[type="search"], input[type="date"],
input[type="time"], input[type="email"], input[type="number"], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 11px; border: 1.5px solid var(--borda);
  border-radius: 10px; background: #fff; font: inherit; color: var(--texto);
  -webkit-appearance: none; appearance: none;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--azul); box-shadow: 0 0 0 3px rgba(29, 78, 216, .15);
}
.radio-linha { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-linha label {
  flex: 1 1 auto; min-width: 110px; display: inline-flex; align-items: center; gap: 8px;
  border: 1.5px solid var(--borda); border-radius: 10px; padding: 8px 10px;
  background: #fff; cursor: pointer; font-size: 14px; min-height: 42px;
}
.radio-linha input { width: 18px; height: 18px; accent-color: var(--azul); flex: none; }
.radio-linha label.sel { border-color: var(--azul); background: var(--azul-claro); font-weight: 600; }
.linha2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.linha3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }
.linha4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 8px; }
@media (max-width: 460px) { .linha4 { grid-template-columns: 1fr 1fr; } .linha3 { grid-template-columns: 1fr 1fr; } }

/* ------------------------------- telas ------------------------------ */
.tela { min-height: 100vh; }
#tela-login {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 18px; background: linear-gradient(160deg, #123a94 0%, #1d4ed8 60%, #2f6bff 100%);
}
.cartao-login {
  width: 100%; max-width: 380px; background: var(--card); border-radius: 18px;
  padding: 26px 22px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.cartao-login .logo {
  display: block; margin: 0 auto 10px; max-height: 74px; max-width: 220px;
}
.cartao-login h1 { font-size: 19px; text-align: center; color: var(--azul-escuro); margin-bottom: 2px; }
.cartao-login .sub { text-align: center; color: var(--cinza); font-size: 13px; margin-bottom: 18px; }
.aviso-erro {
  background: var(--vermelho-claro); color: var(--vermelho);
  border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; display: none;
}
.aviso-erro.visivel { display: block; }
.rodape-login { color: rgba(255, 255, 255, .75); font-size: 12px; margin-top: 16px; text-align: center; }

/* ------------------------------- topo ------------------------------ */
.topo {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 10px;
  background: var(--card); border-bottom: 1px solid var(--borda); padding: 8px 14px;
  padding-top: calc(8px + env(safe-area-inset-top));
}
.topo .logo { height: 38px; width: auto; }
.topo .titulo { font-weight: 700; font-size: 15.5px; line-height: 1.15; }
.topo .titulo small { display: block; font-weight: 500; color: var(--cinza); font-size: 11.5px; }
.topo .espaco { flex: 1; }
.topo .usuario { font-size: 13px; color: var(--cinza); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 420px) { .topo .usuario { display: none; } }

/* ------------------------------- abas ------------------------------ */
.abas {
  position: sticky; top: 55px; z-index: 30; display: flex; gap: 6px; overflow-x: auto;
  background: var(--fundo); padding: 8px 12px; scrollbar-width: none;
}
.abas::-webkit-scrollbar { display: none; }
.abas .aba {
  flex: none; border: 1.5px solid var(--borda); background: #fff; color: var(--cinza);
  border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: 13.5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; -webkit-tap-highlight-color: transparent;
}
.abas .aba.ativa { background: var(--azul); border-color: var(--azul); color: #fff; }
.abas .aba .cont { font-size: 11px; background: var(--cinza-claro); color: var(--cinza); border-radius: 999px; padding: 1px 7px; }
.abas .aba.ativa .cont { background: rgba(255,255,255,.25); color: #fff; }

/* ------------------------------ conteúdo ---------------------------- */
main { max-width: 1100px; margin: 0 auto; padding: 12px 12px calc(96px + env(safe-area-inset-bottom)); }
.cabecalho-pag { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; flex-wrap: wrap; }
.cabecalho-pag h1 { font-size: 19px; margin: 0; flex: 1; min-width: 150px; }
.pag-desc { color: var(--cinza); font-size: 13px; }

/* cards genéricos */
.cartao { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); box-shadow: var(--sombra); }
.cartao.pad { padding: 14px; }
.cartao + .cartao, .cartao { margin-bottom: 12px; }

/* ----------------------------- dashboard --------------------------- */
.grade-nums { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .grade-nums { grid-template-columns: repeat(4, 1fr); } }
.num-card { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); padding: 12px; box-shadow: var(--sombra); }
.num-card .rot { font-size: 11.5px; color: var(--cinza); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.num-card .val { font-size: 23px; font-weight: 800; margin-top: 2px; }
.num-card .val.moeda { font-size: 17px; }
.azul-t { color: var(--azul); } .verde-t { color: var(--verde); } .ambar-t { color: var(--ambar); } .roxo-t { color: var(--roxo); }
.acoes-rapidas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.acoes-rapidas .btn { min-height: 52px; font-size: 15px; }

/* ------------------------------ status ----------------------------- */
.etiqueta {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px;
  padding: 3px 10px; font-size: 12px; font-weight: 700; white-space: nowrap;
}
.et-aberta { background: var(--azul-claro); color: var(--azul); }
.et-em_atendimento { background: var(--ambar-claro); color: var(--ambar); }
.et-aguardando_peca { background: var(--roxo-claro); color: var(--roxo); }
.et-concluida { background: var(--verde-claro); color: var(--verde); }
.et-fechada { background: var(--verde-claro); color: var(--verde); }
.et-cancelada { background: var(--vermelho-claro); color: var(--vermelho); }

/* ------------------------------ listas ------------------------------ */
.lista-item {
  display: block; text-decoration: none; color: inherit; background: var(--card);
  border: 1px solid var(--borda); border-radius: var(--raio); padding: 12px;
  box-shadow: var(--sombra); cursor: pointer; margin-bottom: 10px;
  -webkit-tap-highlight-color: transparent;
}
.lista-item:active { transform: scale(.995); }
.li-topo { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.li-titulo { font-weight: 700; font-size: 15px; flex: 1; min-width: 140px; }
.li-numero { font-weight: 800; color: var(--azul); font-size: 14px; }
.li-info { color: var(--cinza); font-size: 13.5px; margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.li-rodape { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; font-size: 13px; gap: 8px; flex-wrap: wrap; }
.li-valor { font-weight: 700; }
.li-data { color: var(--cinza); font-size: 12.5px; }
.li-acao { color: var(--azul); font-weight: 700; font-size: 13.5px; margin-top: 8px; }

.filtros { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.filtros .busca { flex: 1; min-width: 180px; position: relative; }
.vazio { text-align: center; color: var(--cinza); padding: 34px 12px; }
.vazio .ico { font-size: 38px; margin-bottom: 6px; }
.barra-filtro-status { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.barra-filtro-status::-webkit-scrollbar { display: none; }
.filtro-chip {
  flex: none; border: 1.5px solid var(--borda); background: #fff; color: var(--cinza);
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.filtro-chip.ativa { background: var(--texto); border-color: var(--texto); color: #fff; }

/* --------------------------- FAB (nova OS) --------------------------- */
.fab {
  position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 50;
  width: 58px; height: 58px; border-radius: 50%; border: none; background: var(--azul); color: #fff;
  font-size: 30px; line-height: 1; box-shadow: 0 8px 22px rgba(29, 78, 216, .45); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(.94); }
.fab span { position: absolute; right: 64px; background: var(--texto); color: #fff; font-size: 12.5px;
  font-weight: 600; padding: 6px 10px; border-radius: 8px; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity .15s; }
.fab:hover span { opacity: 1; }

/* ------------------------------ detalhe OS --------------------------- */
.bloco-secao { margin-bottom: 12px; }
.bloco-secao > h3 {
  font-size: 12px; letter-spacing: .6px; text-transform: uppercase; color: var(--cinza);
  margin: 14px 2px 6px; display: flex; align-items: center; gap: 8px;
}
.bloco-secao > h3::after { content: ""; flex: 1; height: 1px; background: var(--borda); }
.grade-dados { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
@media (max-width: 460px) { .grade-dados { grid-template-columns: 1fr 1fr; } }
.grade-dados .cel { min-width: 0; }
.grade-dados .cel.toda { grid-column: 1 / -1; }
.grade-dados .rot { font-size: 11.5px; color: var(--cinza); font-weight: 600; text-transform: uppercase; letter-spacing: .2px; }
.grade-dados .v { font-size: 14px; word-break: break-word; margin-top: 1px; }

.tabela { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tabela th { text-align: left; font-size: 11px; text-transform: uppercase; color: var(--cinza); padding: 6px 8px; border-bottom: 1.5px solid var(--borda); }
.tabela td { padding: 7px 8px; border-bottom: 1px solid var(--borda); vertical-align: top; }
.tabela td.numerico, .tabela th.numerico { text-align: right; }
.tabela .totais td { border-bottom: none; }
.tabela-total { border-top: 2px solid var(--texto); }
.linha-total { font-weight: 800; }

/* --------------------------- editor de OS ---------------------------- */
.grupo-form { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); padding: 14px; margin-bottom: 12px; box-shadow: var(--sombra); }
.grupo-form h2 { font-size: 15px; color: var(--azul-escuro); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.grupo-form h2 .num { width: 26px; height: 26px; border-radius: 8px; background: var(--azul); color: #fff; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; }
.caixa-total {
  position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--texto); color: #fff; border-radius: 14px; padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.caixa-total .rot { font-size: 12px; opacity: .8; }
.caixa-total .val { font-size: 19px; font-weight: 800; }
.linha-peca { display: grid; grid-template-columns: 72px 1fr 64px 92px 30px; gap: 6px; margin-bottom: 6px; align-items: center; }
.linha-peca .x { border: none; background: var(--vermelho-claro); color: var(--vermelho); width: 30px; height: 30px; border-radius: 8px; font-weight: 800; cursor: pointer; }
@media (max-width: 480px) { .linha-peca { grid-template-columns: 60px 1fr 56px 84px 30px; } }
.linha-peca input { min-height: 38px; font-size: 13.5px; }
/* locação: sem valor unitário nas peças */
.modo-locacao .linha-peca { grid-template-columns: 72px 1fr 64px 30px; }
.modo-locacao .p-unit { display: none; }

/* ------------------------------ timeline ----------------------------- */
.timeline { padding-left: 4px; }
.tl-item { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--borda); margin-left: 6px; }
.tl-item:last-child { border-left-color: transparent; }
.tl-item::before {
  content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--azul); border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--azul);
}
.tl-item .tl-tit { font-weight: 700; font-size: 13.5px; }
.tl-item .tl-data { font-size: 12px; color: var(--cinza); }
.tl-item .tl-nota { font-size: 13.5px; color: var(--texto); margin-top: 3px; white-space: pre-wrap; }

/* ------------------------------ modal ------------------------------- */
.fundo-modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.janela-modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 480px; max-height: 88vh;
  overflow-y: auto; padding: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.janela-modal h3 { margin: 0 0 12px; font-size: 17px; }
.modal-acoes { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.fechar-x { float: right; border: none; background: var(--cinza-claro); width: 34px; height: 34px; border-radius: 50%; font-size: 16px; cursor: pointer; color: var(--cinza); }

/* ------------------------------ toast ------------------------------- */
#toasts { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 0; right: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast {
  background: var(--texto); color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px;
  max-width: 480px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: aparecer .2s ease;
}
.toast.erro { background: var(--vermelho); }
.toast.ok { background: var(--verde); }
.toast.chamado-alerta {
  background: var(--azul); color: #fff; font-weight: 600; pointer-events: auto; cursor: pointer;
  border: 2px solid #fff; animation: aparecer .2s ease;
}
@keyframes aparecer { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* --------------------------- usuários/config ------------------------- */
.linha-usuario { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--borda); }
.linha-usuario:last-child { border-bottom: none; }
.linha-usuario .nome { font-weight: 600; font-size: 14.5px; flex: 1; min-width: 0; }
.linha-usuario .det { font-size: 12px; color: var(--cinza); }
.badge-funcao { font-size: 11px; font-weight: 700; border-radius: 6px; padding: 2px 8px; background: var(--cinza-claro); color: var(--cinza); }
.badge-funcao.admin { background: var(--azul-claro); color: var(--azul); }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .trilho { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; transition: .15s; cursor: pointer; }
.switch .trilho::before { content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .trilho { background: var(--verde); }
.switch input:checked + .trilho::before { transform: translateX(18px); }

.info-caixa { background: var(--azul-claro); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--azul-escuro); margin-bottom: 12px; }
.info-caixa.aviso { background: var(--ambar-claro); color: var(--ambar); }
.info-caixa.perigo { background: var(--vermelho-claro); color: var(--vermelho); }

.topo-acao { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (min-width: 640px) { main { padding-top: 16px; } }

/* campo de busca de cliente (lista grande) */
.combo-res {
  max-height: 250px; overflow: auto; background: #fff;
  border: 1.5px solid var(--borda); border-radius: 10px; margin-top: 6px;
}
.combo-res .combo-item {
  display: block; width: 100%; text-align: left; background: #fff; border: none;
  border-bottom: 1px solid var(--cinza-claro); padding: 11px 12px; font: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.combo-res .combo-item:hover { background: var(--azul-claro); }
.combo-escolhido {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--verde-claro); border: 1.5px solid var(--verde); border-radius: 10px;
  padding: 8px 10px; margin-top: 6px; font-weight: 600;
}
.combo-escolhido.hidden { display: none; }
