:root {
  --fundo: #f4f5f7;
  --cartao: #fff;
  --texto: #1f2328;
  --suave: #667085;
  --borda: #d0d5dd;
  --primaria: #1d5fa8;
  --primaria-escura: #164a84;
  --perigo: #b42318;
  --ok: #067647;
  --folga: #9aa4b2;
  --folga-texto: #101828;
  --extra: #f5c26b;
  --ferias: #c7d7fe;
  --fechado: #eef0f3;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--fundo); color: var(--texto); }
.topo { background: #12263f; color: #fff; padding: 10px 20px; display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.topo h1 { font-size: 18px; margin: 0; }
#abas { display: flex; gap: 4px; flex-wrap: wrap; }
#abas button { background: transparent; color: #c9d3e0; border: 0; padding: 8px 12px; border-radius: 6px; cursor: pointer; font: inherit; }
#abas button:hover { background: rgba(255,255,255,.08); color: #fff; }
#abas button.ativa { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.usuario-topo { margin-left: auto; display: flex; align-items: center; gap: 10px; color: #c9d3e0; font-size: 13px; }
.usuario-topo button { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); padding: 4px 10px; }
.usuario-topo button:hover { background: rgba(255,255,255,.12); }
main { padding: 16px 20px 40px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 18px 0 6px; }
.cartao { background: var(--cartao); border: 1px solid var(--borda); border-radius: 10px; padding: 16px; }
.cartao.estreito { max-width: 560px; }
.colunas { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; align-items: start; }
.dica { color: var(--suave); font-size: 13px; margin: 4px 0 10px; }
.vazio { color: var(--suave); font-style: italic; }

button { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--borda); background: #fff; cursor: pointer; }
button:hover { background: #f2f4f7; }
button:disabled { opacity: .6; cursor: wait; }
button.primario { background: var(--primaria); border-color: var(--primaria); color: #fff; }
button.primario:hover { background: var(--primaria-escura); }
button.perigo { color: var(--perigo); border-color: transparent; background: transparent; }
button.perigo:hover { background: #fef3f2; }
input, select { font: inherit; padding: 6px 8px; border: 1px solid var(--borda); border-radius: 6px; background: #fff; }
input.num { width: 80px; }
.linha-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.linha-form input:not(.num) { flex: 1; min-width: 160px; }
.grade-form { display: grid; gap: 10px; margin-bottom: 12px; }
/* calendário de folgas extras */
.cal-extra { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; max-width: 420px; }
.cal-extra .cab { text-align: center; font-size: 12px; font-weight: 600; color: var(--suave); padding: 2px 0; }
.cal-extra button { padding: 8px 0; text-align: center; font-weight: 600; position: relative; }
.cal-extra button.dom { color: #b42318; }
.cal-extra button.feriado { background: #eff8ff; border-color: #84caff; }
.cal-extra button.ausente { background: #f2f4f7; color: #98a2b3; cursor: not-allowed; }
.cal-extra button.marcado { background: #fdb022; border-color: #dc6803; color: #000; }
.cal-extra button.tirada { background: #d1fadf; border-color: #32d583; color: #05603a; cursor: not-allowed; }
.cal-extra button.mudou::after { content: ''; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--primaria); }
.grade-form label { display: grid; gap: 4px; font-weight: 500; }
.grade-form label[hidden] { display: none; }
.grade-form button { justify-self: start; }
fieldset { border: 1px solid var(--borda); border-radius: 8px; }
.dias { display: flex; gap: 12px; flex-wrap: wrap; }
.dia { display: flex !important; align-items: center; gap: 4px; font-weight: 400 !important; }

.tabela { width: 100%; border-collapse: collapse; }
.tabela th, .tabela td { text-align: left; padding: 6px; border-bottom: 1px solid #eaecf0; }
.tabela th { font-size: 12px; color: var(--suave); text-transform: uppercase; letter-spacing: .03em; }
.tabela td input:not([type=checkbox]), .tabela td select { width: 100%; }
.tabela td input.num { width: 72px; }
#aba-funcionarios .colunas { grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); }
#tab-func td:first-child { width: 40%; }
#tab-func td:nth-child(2) { width: 30%; }
#tab-func .num { width: 64px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; background: #fef0c7; color: #93370d; font-size: 12px; }
.tag.ok { background: #dcfae6; color: var(--ok); }
.saldo { margin: 0; padding-left: 18px; }

#toast { position: fixed; right: 20px; bottom: 20px; background: #12263f; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 10; max-width: 420px; }
#toast.erro { background: var(--perigo); }

/* escala */
.barra { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.status { color: var(--suave); font-size: 13px; }
.status.pendente { color: #b54708; font-weight: 600; }
.alerta-box { background: #fffaeb; border: 1px solid #fedf89; border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
.alerta-box ul { margin: 6px 0 0; padding-left: 18px; max-height: 180px; overflow: auto; }
.ok-box { background: #ecfdf3; border: 1px solid #abefc6; color: var(--ok); border-radius: 8px; padding: 8px 14px; margin-bottom: 12px; }

.folha-grupo + .folha-grupo { margin-top: 28px; padding-top: 18px; border-top: 2px dashed #c7ccd6; }
#area-impressao.por-folha > .cab-impressao,
#area-impressao.por-folha > .feriados-mes,
#area-impressao.por-folha > .assinatura { display: none; }
#area-impressao { background: #fff; border: 1px solid var(--borda); border-radius: 10px; padding: 16px; }
.cab-impressao { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.imp-empresa { font-size: 18px; font-weight: 700; }
.imp-titulo { font-size: 15px; font-weight: 600; color: #344054; }
.legenda { display: flex; gap: 14px; font-size: 12px; flex-wrap: wrap; }
.legenda i { font-style: normal; display: inline-block; min-width: 24px; text-align: center; padding: 1px 4px; border: 1px solid #98a2b3; font-weight: 700; margin-right: 3px; }
.assinatura { display: flex; justify-content: space-between; gap: 20px; margin-top: 28px; font-size: 13px; flex-wrap: wrap; }

#grade-wrap { overflow-x: auto; }
.grade { border-collapse: collapse; width: 100%; font-size: 12px; }
.grade th, .grade td { border: 1px solid #98a2b3; text-align: center; padding: 3px 2px; min-width: 24px; }
.grade th.nome { text-align: left; padding: 3px 8px; white-space: nowrap; min-width: 150px; font-weight: 600; background: #fff; position: sticky; left: 0; z-index: 1; }
.grade thead th { background: #f2f4f7; font-weight: 600; }
.grade thead th.ini { font-weight: 400; font-size: 11px; }
.grade .seg { border-left: 2px solid #475467; }
.grade .fechado { background: var(--fechado); }
.grade thead th.domingo { background: #e4e7ec; }
.grade tr.grupo th { background: #344054; color: #fff; text-align: left; padding: 4px 8px; letter-spacing: .04em; text-transform: uppercase; font-size: 12px; }
.grade td.cel { cursor: pointer; font-weight: 600; user-select: none; }
.grade td.cel:hover { outline: 2px solid var(--primaria); outline-offset: -2px; }
.c-T { color: #c0c6cf; font-weight: 400 !important; }
.c-F { background: var(--folga) !important; color: var(--folga-texto); }
.c-FX { background: var(--extra) !important; color: #000; }
.c-FE { background: var(--ferias) !important; color: #1d2939; }
.grade td.problema { box-shadow: inset 0 0 0 2px var(--perigo); }
.grade tr.totais td, .grade tr.totais th { font-size: 11px; color: var(--suave); font-weight: 400; font-style: italic; }
.grade td.alerta { color: var(--perigo) !important; font-weight: 700 !important; background: #fef3f2; }
.grade td.tot, .grade th.tot { white-space: nowrap; padding: 3px 6px; font-size: 11px; }

/* matriz */
#matriz-wrap { overflow: auto; margin-top: 10px; }
.matriz { border-collapse: collapse; font-size: 12px; }
.matriz th.vert { height: 130px; vertical-align: bottom; padding: 4px 0; }
.matriz th.vert span { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; }
.matriz th.lin { text-align: left; white-space: nowrap; padding: 4px 8px; }
.matriz th.lin small { color: var(--suave); font-weight: 400; }
.matriz td { border: 1px solid var(--borda); width: 38px; height: 28px; text-align: center; }
.matriz td.par { cursor: pointer; }
.matriz td.sim { color: var(--ok); }
.matriz td.nao { background: #fee4e2; color: var(--perigo); font-weight: 700; }
.matriz td.diag { background: #eaecf0; }

@media (max-width: 640px) {
  main { padding: 12px; }
  .colunas, #aba-funcionarios .colunas { grid-template-columns: 1fr; }
}

/* feriados e folgas fixas */
.suave { color: var(--suave); font-weight: 400; }
.c-FR { background: #d1e9ff !important; color: #1849a9; }
.grade thead th.feriado { background: #b2ddff; color: #1849a9; }
.grade td.feriado:not(.cel) { background: #eff8ff; }
.feriados-mes { font-size: 12px; margin: -4px 0 8px; color: #344054; }
.chips { display: flex; gap: 3px; flex-wrap: nowrap; }
.chip { padding: 2px 0; font-size: 12px; border-radius: 6px; width: 26px; font-weight: 600; }
.chip.on { background: var(--primaria); border-color: var(--primaria); color: #fff; }
.check { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-weight: 400; }

/* histórico */
.rolagem { overflow-x: auto; }
.tabela td.n, .tabela th.n { text-align: center; }
.tabela td.acima { background: #fef3f2; color: var(--perigo); font-weight: 600; }
.tabela td.abaixo { background: #ecfdf3; color: var(--ok); font-weight: 600; }
.tabela tr.inativo td { color: var(--suave); }
.por-dia { display: inline-flex; gap: 4px; white-space: nowrap; }
.por-dia span { display: inline-flex; flex-direction: column; align-items: center; min-width: 26px; border: 1px solid var(--borda); border-radius: 4px; font-size: 12px; padding: 1px 2px; }
.por-dia i { font-style: normal; font-size: 10px; color: var(--suave); }

/* admissão / desligamento e refazer */
.cel.c-NC { color: #98a2b3; background: repeating-linear-gradient(45deg, #fff, #fff 3px, #f2f4f7 3px, #f2f4f7 6px); cursor: default; }
.refazer { display: inline-flex; align-items: center; gap: 6px; padding-left: 8px; border-left: 1px solid var(--borda); }
#tab-func input[type=date] { width: 122px; }
#tab-func .f-nome { min-width: 130px; }
#tab-func .f-grupo { min-width: 110px; }
#aba-funcionarios .cartao:first-child { overflow-x: auto; }

/* turnos e plantões */
.grade td.c-turno { color: #101828; font-size: 11px; }
.chip.larga { width: auto; min-width: 30px; padding: 2px 5px; }
.lista-regimes { margin: 0; padding-left: 18px; }
.lista-regimes li { margin-bottom: 4px; }
.aviso-turnos { margin-bottom: 16px; }
#aba-turnos .colunas { margin-bottom: 16px; }
#aba-turnos > .cartao + .cartao { margin-top: 16px; }
#tab-turnos input[type=time] { width: 110px; }
#tab-turnos input[type=color], #form-turno input[type=color] { width: 44px; padding: 2px; height: 32px; flex: none; min-width: 0; }
#form-turno input[type=time] { flex: none; min-width: 0; width: 120px; }
#legenda-turnos { margin-top: 4px; }
#legenda-turnos:empty { display: none; }
.grade th.nome small { font-weight: 400; margin-left: 4px; }
#aba-turnos .colunas { grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); }
#tab-turnos input.t-sigla { width: 60px; }
#tab-turnos input.t-nome { min-width: 150px; }
#aba-turnos .cartao:has(#tab-turnos) { overflow-x: auto; }
#form-turno input[name=sigla] { width: 70px; flex: none; min-width: 0; }
@media (max-width: 900px) { #aba-turnos .colunas { grid-template-columns: 1fr; } }
#tab-usuarios td.acoes { white-space: nowrap; }
#tab-usuarios td.acoes button { margin-left: 4px; }
