:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-soft: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --slate-bg: #f1f5f9;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .18);
  --radius: 12px;
}

* { box-sizing: border-box; }
/* Garante que o atributo [hidden] sempre esconda (mesmo em .form-field display:flex). */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 264px;
  background: var(--bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 18px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 10px;
  background: #fff; overflow: hidden;
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 16px;
}
.brand-logo img { width: 100%; height: 100%; object-fit: cover; display: block; background: #fff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: 15px; }
.brand-text span { font-size: 12px; color: #94a3b8; }

.empresa-switch { padding: 8px 6px 16px; }
.empresa-switch label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #94a3b8; margin-bottom: 6px; }
.empresa-switch select {
  width: 100%; padding: 9px 30px 9px 10px; border-radius: 9px; border: 1px solid #334155;
  background: var(--bg-2); color: #e2e8f0; font-size: 13px; cursor: pointer;
  text-overflow: ellipsis;
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-group {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: #64748b; font-weight: 700; padding: 12px 12px 4px;
}
.nav-group:first-child { padding-top: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 9px;
  color: #cbd5e1; text-decoration: none; font-weight: 500; font-size: 13.5px;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg-2); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-ico { font-size: 16px; width: 20px; text-align: center; }
.badge {
  margin-left: auto; background: #334155; color: #fff;
  font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
}
.nav-item.active .badge { background: rgba(255,255,255,.25); }
.badge-warn { background: var(--amber); }

.sidebar-foot { padding: 12px 8px 0; border-top: 1px solid #1e293b; }
.sidebar-foot a { color: #94a3b8; font-size: 12px; text-decoration: none; }
.sidebar-foot a:hover { color: #fff; }
.user-box { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.user-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-info strong { color: #e2e8f0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info span { font-size: 11px; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .btn { background: #334155; color: #e2e8f0; border: none; }
.user-box .btn:hover { background: #475569; }

/* ---------- Tela de login ---------- */
#login-root {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #0f172a, #1e3a8a);
}
.login-card {
  background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 380px; padding: 32px 28px;
}
.login-card .brand-logo { width: 52px; height: 52px; border-radius: 12px; font-size: 20px; margin: 0 auto 14px; }
.login-logo { display: block; width: auto; max-width: 230px; max-height: 110px; margin: 0 auto 18px; }
.login-card h1 { text-align: center; font-size: 20px; margin: 0 0 4px; }
.login-card .sub { text-align: center; color: var(--text-soft); font-size: 13px; margin-bottom: 22px; }
.login-card .form-field { margin-bottom: 14px; }
.login-card label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }
.login-erro { background: var(--red-bg); color: var(--red); font-size: 13px; padding: 9px 12px; border-radius: 8px; margin-bottom: 14px; }

/* ---------- Permissões (empresas do usuário) ---------- */
.emp-checks { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.emp-checks label { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 13.5px; cursor: pointer; }
.emp-checks input { width: auto; }

/* ---------- Tarifas do equipamento ---------- */
.tarifas-box { display: flex; flex-direction: column; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.tarifa-row { display: flex; align-items: center; gap: 10px; }
.tarifa-row input[type="number"] { flex: 1; }

/* ---------- Jornada por dia da semana (funcionário) ---------- */
.jornada-grid { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.jd {
  display: grid; grid-template-columns: 56px 1fr auto 1fr; gap: 8px; align-items: center;
  font-weight: 400; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px;
}
.jd .jd-dia { font-size: 12px; color: var(--text-soft); font-weight: 600; }
.jd .jd-sep { font-size: 12px; color: var(--text-soft); text-align: center; }
.jd input { width: 100%; text-align: center; padding: 8px 4px; }
.jornada-total { margin-top: 8px; font-size: 12.5px; }

/* ---------- Períodos do apontamento de horas ---------- */
#ap-periodos { display: flex; flex-direction: column; gap: 8px; }
.periodo-row {
  display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: center;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px;
}
.periodo-row .pr-sep { color: var(--text-soft); font-weight: 600; text-align: center; }
.periodo-row input { width: 100%; }

/* ---------- Combo com busca (estilizado) ---------- */
.combo { position: relative; }
.combo-input { width: 100%; padding-right: 28px; }
.combo-caret {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-soft); font-size: 11px; cursor: pointer; user-select: none;
}
.combo-pop {
  position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 100%; width: max-content; max-width: 360px;
  z-index: 60; background: #fff;
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg);
  max-height: 240px; overflow-y: auto; padding: 4px;
}
.combo-opt { padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-opt:hover, .combo-opt.sel { background: var(--surface-2); }
.combo-vazio { padding: 8px 10px; color: var(--text-soft); font-size: 13px; }

/* ---------- Montador de itens do serviço ---------- */
#sv-itens { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: grid; grid-template-columns: 1.5fr 1.05fr 0.95fr 0.8fr 1fr auto;
  gap: 8px; align-items: end;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px;
}
.item-row .mini-lbl { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-soft); font-weight: 600; margin-bottom: 3px; }
.item-row select, .item-row input { width: 100%; }
.item-row select { padding-left: 8px; padding-right: 22px; font-size: 13px; }
.item-row .combo-input { padding-left: 8px; }
.item-row .it-subtotal { display: inline-block; font-weight: 700; padding: 8px 0; font-variant-numeric: tabular-nums; }
.item-row .it-remove { height: 36px; }
.servico-total { text-align: right; font-size: 16px; padding: 6px 2px; }
.servico-total strong { color: var(--green); font-size: 19px; }
@media (max-width: 720px) {
  .item-row { grid-template-columns: 1fr 1fr; }
}

/* ---------- Content ---------- */
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 600; }
.view { padding: 24px 28px; }

/* Botão de menu (☰) — só aparece no celular (ver media query no fim do arquivo) */
.topbar-menu {
  display: none; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--text);
  padding: 4px 8px; margin-right: 6px; border-radius: 8px;
}
.topbar-menu:hover { background: var(--slate-bg); }
/* Fundo escuro atrás do menu aberto no celular */
.sidebar-overlay { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .5); }

/* ---------- Barra de ações (topo da página) ---------- */
.page-actions { display: flex; gap: 10px; justify-content: flex-end; margin-bottom: 16px; flex-wrap: wrap; }

/* ---------- Navegação por mês ---------- */
.month-nav {
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; box-shadow: var(--shadow); flex-wrap: wrap;
}
.month-arrow { padding: 6px 12px; font-size: 14px; line-height: 1; }
.month-label {
  font-weight: 600; font-size: 15px; text-transform: capitalize;
  min-width: 150px; text-align: center;
}
.month-nav .btn-sm { margin-left: 2px; }
.month-nav #mes-todos { margin-left: auto; }

.filtro-aviso {
  background: var(--amber-bg); color: var(--amber); font-size: 13px; font-weight: 500;
  padding: 8px 14px; border-radius: 8px; margin-bottom: 14px;
}

/* ---------- Toolbar / filtros ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
  margin-bottom: 18px;
}
.toolbar .field { display: flex; flex-direction: column; gap: 4px; }
.toolbar .field label { font-size: 11px; color: var(--text-soft); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.toolbar .spacer { flex: 1; }

input, select, textarea {
  font-family: inherit; font-size: 13.5px; color: var(--text);
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; outline: none;
}
/* Espaço à direita para a seta não cobrir o texto selecionado. */
select { padding-right: 30px; text-overflow: ellipsis; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
textarea { resize: vertical; min-height: 80px; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 600; font-size: 13px; cursor: pointer; background: var(--slate-bg); color: var(--text);
  transition: background .12s, box-shadow .12s, opacity .12s;
  text-decoration: none;  /* botões em <a> não devem mostrar sublinhado */
}
.btn:hover { background: #e2e8f0; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--slate-bg); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards / tabela ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-soft); font-weight: 600; padding: 12px 16px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-soft); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }

/* ---------- Pills de status ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-pago { background: var(--green-bg); color: var(--green); }
.pill-pendente { background: var(--amber-bg); color: var(--amber); }
.pill-vencido { background: var(--red-bg); color: var(--red); }
.pill-neutral { background: var(--slate-bg); color: var(--text-soft); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; background: var(--slate-bg); color: var(--text-soft); }

/* ---------- Checklist mensal ---------- */
.ck-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 6px; border-bottom: 1px solid var(--border); }
.ck-item:last-child { border-bottom: none; }
.ck-check { display: flex; align-items: center; gap: 11px; cursor: pointer; flex: 1; min-width: 0; }
.ck-check input { width: 19px; height: 19px; flex: none; cursor: pointer; accent-color: var(--green); }
.ck-titulo { font-size: 15px; word-break: break-word; }
.ck-item.feito .ck-titulo { text-decoration: line-through; color: var(--text-soft); }
.ck-actions { display: flex; gap: 6px; flex: none; }

/* ---------- Banner (faixa de status da Alocação) ---------- */
.banner { padding: 11px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; border: 1px solid transparent; }
.banner.ok { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.banner.warn { background: var(--amber-bg); color: var(--amber); border-color: var(--amber); }

/* ---------- Estado vazio / loading ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--text-soft); }
.empty .ico { font-size: 40px; margin-bottom: 10px; }
.skeleton { padding: 40px; text-align: center; color: var(--text-soft); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2.5px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--text-soft); font-weight: 600; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.danger .value { color: var(--red); }
.kpi.warn .value { color: var(--amber); }
.kpi.ok .value { color: var(--green); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: flex; justify-content: center; align-items: flex-start;
  padding: 5vh 20px; z-index: 50; overflow-y: auto;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 520px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  margin: auto; animation: pop .15s ease;
  max-height: 90vh;  /* cabeçalho/rodapé fixos; o corpo rola */
}
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.modal.wide { max-width: 680px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-soft); line-height: 1; }
.modal-body { padding: 22px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex: none; }

.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.form-field .hint { font-size: 11.5px; color: var(--text-soft); }
.form-field.full { grid-column: 1 / -1; }

.dow { display: flex; gap: 6px; flex-wrap: wrap; }
.dow label {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 34px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px; font-weight: 600; cursor: pointer; user-select: none; color: var(--text-soft);
}
.dow input { display: none; }
.dow input:checked + span { color: #fff; }
.dow label:has(input:checked) { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Checkbox customizado (padrão do sistema) — esconde o input nativo */
.check-inline { display: inline-flex; align-items: center; cursor: pointer; user-select: none;
  font-size: 13.5px; font-weight: 500; color: var(--text); }
.check-inline input { display: none; }
.check-inline > span { position: relative; padding-left: 28px; line-height: 20px; }
.check-inline > span::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; border: 1.5px solid var(--border); border-radius: 6px;
  background: var(--surface); transition: background .15s, border-color .15s;
}
.check-inline > span::after {
  content: ""; position: absolute; left: 7px; top: 50%;
  transform: translateY(-60%) rotate(45deg);
  width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0;
  opacity: 0; transition: opacity .15s;
}
.check-inline:has(input:checked) > span::before { background: var(--primary); border-color: var(--primary); }
.check-inline:has(input:checked) > span::after { opacity: 1; }

.termino-opcoes { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.radio-inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; cursor: pointer; font-size: 13.5px; }
.radio-inline input { width: auto; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--text-soft); font-weight: 600; }
.kv dd { margin: 0; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
  background: var(--bg); color: #fff; padding: 12px 16px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 360px;
  display: flex; align-items: center; gap: 10px; animation: slidein .2s ease;
}
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }
.toast.ok { border-left: 4px solid var(--green); }
.toast.err { border-left: 4px solid var(--red); }
.toast.info { border-left: 4px solid var(--primary); }

.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.obs-inline {
  margin-top: 4px; font-size: 12px; color: var(--amber);
  background: var(--amber-bg); border-radius: 6px; padding: 2px 8px;
  display: inline-block; max-width: 320px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.foto-link {
  display: inline-block; margin-top: 4px; font-size: 12px; font-weight: 600;
  color: var(--primary); text-decoration: none;
}
.foto-link:hover { text-decoration: underline; }

/* ---------- Conexão do WhatsApp ---------- */
.wa-status { margin-bottom: 14px; padding: 14px 16px; }
.wa-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.wa-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.wa-connect { text-align: center; }
.wa-connect p { margin: 8px 0; }
.wa-qr { width: 260px; max-width: 80vw; height: auto; border: 1px solid var(--border); border-radius: 10px; margin: 6px auto; display: block; background: #fff; }
.wa-ok { text-align: center; font-size: 16px; font-weight: 600; color: var(--green, #16a34a); padding: 18px 0; }
.wa-err { color: var(--red, #dc2626); background: var(--red-bg, #fee2e2); border-radius: 8px; padding: 12px 14px; }
@media (max-width: 720px) {
  /* A barra lateral vira um menu que desliza da esquerda. */
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 50;
    height: 100vh; width: 264px; max-width: 84vw;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar-menu { display: inline-flex; }
  .form-grid.two { grid-template-columns: 1fr; }
}
