/* =====================================================================
   Sistema de Escalas — estilo base (tema corporativo, limpo, responsivo)
   ===================================================================== */

:root {
    --cor-primaria: #1f4e79;
    --cor-primaria-escura: #163a5c;
    --cor-texto: #1f2933;
    --cor-texto-suave: #64748b;
    --cor-borda: #e2e8f0;
    --cor-fundo: #e9edf2;
    --cor-branco: #ffffff;
    --cor-ok: #1b7f4b;
    --cor-ok-fundo: #e6f4ec;
    --cor-erro: #b42318;
    --cor-erro-fundo: #fdeceb;
    --cor-info: #1f4e79;
    --cor-info-fundo: #e8eff7;
    --cor-perigo: #b42318;
    /* grid */
    --g-line: #c7d0db;
    --g-line2: #aab6c4;
    --g-head: #eef3f8;
    --g-head2: #e3ebf3;
    --g-zebra: #f6f8fb;
    --g-weekend: #eaf0f6;
    --g-sel: #f6c544;
    --g-sel-row: #fff8e6;
    --raio: 8px;
    --sombra: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
    --fonte: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body { margin: 0; font-family: var(--fonte); color: var(--cor-texto); background: var(--cor-fundo); line-height: 1.45; }
a { color: var(--cor-primaria); }
.container { max-width: 1500px; margin: 0 auto; padding: 24px 16px; }
.muted { color: var(--cor-texto-suave); font-size: .85rem; }

/* ---------- Barra superior ---------- */
.topbar { background: var(--cor-primaria); color: #fff; }
.topbar-inner { max-width: 1500px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; min-height: 56px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.05rem; }
.menu { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.menu a { color: #e6eef7; text-decoration: none; padding: 6px 12px; border-radius: 6px; font-size: .95rem; }
.menu a:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-nome { font-size: .9rem; color: #e6eef7; }
.rodape { text-align: center; color: var(--cor-texto-suave); padding: 24px 16px; }

/* ---------- Cabeçalho de página ---------- */
.page-head { margin-bottom: 20px; }
.page-head h1 { margin: 0 0 4px; font-size: 1.5rem; color: var(--cor-primaria); }
.page-head--acoes { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.link-voltar { display: inline-block; margin-top: 4px; text-decoration: none; font-size: .9rem; }

/* ---------- Botões ---------- */
.btn { display: inline-block; padding: 9px 16px; border: 1px solid var(--g-line2); border-radius: 8px; background: var(--cor-branco); color: var(--cor-texto); font-size: .9rem; font-weight: 500; cursor: pointer; text-decoration: none; line-height: 1.2; font-family: inherit; }
.btn:hover { background: #f0f3f7; }
.btn:focus-visible { outline: 2px solid var(--cor-primaria); outline-offset: 2px; }
.btn-sm { padding: 6px 11px; font-size: .83rem; }
.btn-bloco { width: 100%; }
.btn-primary { background: var(--cor-primaria); border-color: var(--cor-primaria); color: #fff; }
.btn-primary:hover { background: var(--cor-primaria-escura); }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.4); color: #fff; }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-perigo { border-color: var(--cor-perigo); color: var(--cor-perigo); background: #fff; }
.btn-perigo:hover { background: var(--cor-erro-fundo); }

/* ---------- Alertas ---------- */
.alert { margin: 0 0 16px; padding: 12px 14px; border-radius: var(--raio); font-size: .95rem; }
.alert-ok   { background: var(--cor-ok-fundo);   color: var(--cor-ok);   }
.alert-erro { background: var(--cor-erro-fundo); color: var(--cor-erro); }
.alert-info { background: var(--cor-info-fundo);  color: var(--cor-info); }
.lista-erros { margin: 8px 0 0; padding-left: 18px; }

/* ---------- Login ---------- */
.tela-login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--cor-branco); border: 1px solid var(--cor-borda); border-radius: var(--raio); box-shadow: var(--sombra); padding: 32px; width: 100%; max-width: 380px; }
.login-titulo { margin: 0 0 4px; font-size: 1.4rem; color: var(--cor-primaria); }

/* ---------- Formulários ---------- */
.campo { display: block; margin: 14px 0; }
.campo > span { display: block; margin-bottom: 6px; font-size: .9rem; font-weight: 500; }
.campo input, .campo select { width: 100%; padding: 10px 12px; border: 1px solid var(--g-line2); border-radius: 8px; font-size: .95rem; font-family: inherit; }
.campo input:focus { outline: none; border-color: var(--cor-primaria); box-shadow: 0 0 0 3px rgba(31, 78, 121, .12); }
.form-card { background: var(--cor-branco); border: 1px solid var(--cor-borda); border-radius: var(--raio); box-shadow: var(--sombra); padding: 24px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-flags { display: flex; gap: 24px; margin: 8px 0 16px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; }
.form-acoes { display: flex; gap: 10px; margin-top: 20px; }
.permissoes { border: 1px solid var(--cor-borda); border-radius: var(--raio); padding: 16px; margin-top: 8px; }
.permissoes legend { font-weight: 600; padding: 0 6px; color: var(--cor-primaria); }

/* ---------- Tabelas genéricas ---------- */
.tabela-wrap { overflow-x: auto; background: var(--cor-branco); border: 1px solid var(--cor-borda); border-radius: var(--raio); }
.tabela { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tabela th, .tabela td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--cor-borda); }
.tabela thead th { background: #f7f9fb; font-weight: 600; color: var(--cor-texto-suave); white-space: nowrap; }
.tabela tbody tr:hover { background: #f9fafb; }
.col-acoes { white-space: nowrap; text-align: right; }
.col-check { text-align: center; width: 90px; }
.inline-form { display: inline; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef1f4; color: var(--cor-texto-suave); }
.badge-admin { background: #e8eff7; color: var(--cor-primaria); }
.badge-ok    { background: var(--cor-ok-fundo); color: var(--cor-ok); }
.badge-off   { background: #f0f1f3; color: var(--cor-texto-suave); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.modulo-card { display: block; text-decoration: none; color: inherit; background: var(--cor-branco); border: 1px solid var(--cor-borda); border-radius: var(--raio); box-shadow: var(--sombra); padding: 20px; transition: transform .08s ease, box-shadow .08s ease; }
.modulo-card:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,.1); }
.modulo-card h3 { margin: 0 0 6px; color: var(--cor-primaria); }

/* ===================================================================
   MÓDULO DE ESCALAS — planilha estilo Excel
   =================================================================== */
.escala-toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.escala-toolbar h1 { margin: 0; font-size: 1.4rem; color: var(--cor-primaria); letter-spacing: -.01em; }
.form-periodo { display: flex; align-items: center; gap: 6px; }
.form-periodo select, .form-periodo input { padding: 6px 8px; border: 1px solid var(--g-line2); border-radius: 8px; font-family: inherit; font-size: .85rem; }

.cab { background: var(--cor-branco); border: 1px solid var(--cor-borda); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; font-size: .82rem; }
.cab .t { font-weight: 700; color: var(--cor-primaria); text-align: center; margin-bottom: 4px; }
.cab .l { display: flex; gap: 16px; flex-wrap: wrap; }

/* Barras de ferramenta */
.bar { background: var(--cor-branco); border: 1px solid var(--cor-borda); border-radius: 10px; padding: 9px 12px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; box-shadow: var(--sombra); }
.bar .rot { font-weight: 600; font-size: .78rem; color: var(--cor-texto-suave); text-transform: uppercase; letter-spacing: .05em; }
.bar select { padding: 6px 8px; border: 1px solid var(--g-line2); border-radius: 8px; font-family: inherit; font-size: .85rem; }
.bar .sep { width: 1px; height: 24px; background: var(--g-line); margin: 0 2px; }
.bar .spacer { flex: 1; }
.pincel { min-width: 42px; padding: 6px 10px; border: 1px solid var(--g-line2); border-radius: 8px; font-weight: 700; font-size: .82rem; cursor: pointer; color: #243244; font-variant-numeric: tabular-nums; }
.pincel:hover { filter: brightness(.97); }
.pincel.ativo { outline: 3px solid var(--cor-primaria); outline-offset: 1px; border-color: var(--cor-primaria); }
.status { font-size: .82rem; }
.status.ok { color: var(--cor-ok); } .status.aviso { color: #9a6700; } .status.erro { color: var(--cor-erro); }

/* Planilha: cabeçalho e 2 primeiras colunas congeladas */
.sheet { border: 1px solid var(--g-line2); border-radius: 10px; overflow: auto; max-height: 70vh; background: var(--cor-branco); box-shadow: var(--sombra); }
.grid-escala { border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
.grid-escala th, .grid-escala td { border-right: 1px solid var(--g-line); border-bottom: 1px solid var(--g-line); padding: 0; height: 30px; text-align: center; white-space: nowrap; font-size: .8rem; background: var(--cor-branco); }
.grid-escala thead th { position: sticky; top: 0; z-index: 5; background: var(--g-head); color: #33455a; font-weight: 600; border-bottom: 1px solid var(--g-line2); }
.grid-escala thead tr.r2 th { top: 30px; background: var(--g-head2); }
.grid-escala th.wend, .grid-escala td.wend { background: var(--g-weekend); }
.grid-escala thead th.wend { background: #e1e9f2; }

.cNum { width: 38px; min-width: 38px; position: sticky; left: 0; z-index: 4; cursor: pointer; user-select: none; font-weight: 600; color: var(--cor-texto-suave); }
.cNome { width: 190px; min-width: 190px; max-width: 190px; position: sticky; left: 38px; z-index: 4; text-align: left; padding: 0 8px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.grid-escala thead .cNum, .grid-escala thead .cNome { z-index: 7; }
.cCargo { width: 52px; min-width: 52px; }
.cCoren { width: 82px; min-width: 82px; }
.cHora  { width: 58px; min-width: 58px; }
.cDia   { width: 40px; min-width: 40px; }
.cTot   { width: 50px; min-width: 50px; position: sticky; right: 0; z-index: 4; background: var(--g-head2); font-weight: 700; }
.grid-escala thead .cTot { z-index: 7; }
.cDel   { width: 34px; min-width: 34px; }

.grid-escala tbody td { color: #243244; }
.grid-escala tbody tr.linha:nth-child(odd) td { background: var(--g-zebra); }
.grid-escala tbody tr.linha:nth-child(odd) td.wend { background: #eef3f9; }
.grid-escala tbody tr.linha:hover td { background: #eaf3ff; }
.grid-escala tbody tr.linha.sel td { background: var(--g-sel-row); }
.grid-escala tbody tr.linha.sel .cNum { background: var(--g-sel); color: #3a2d00; font-weight: 800; }

.cel { font-weight: 700; cursor: text; }
.cNome[contenteditable], .fld { cursor: text; }
.paint .cel { cursor: cell; }
.paint { user-select: none; }
.grid-escala td.cel:focus, .grid-escala td.fld:focus, .cNome:focus { outline: none; box-shadow: inset 0 0 0 2px var(--cor-primaria); background: #fffdf2 !important; }
.dirty { box-shadow: inset 0 0 0 2px var(--g-sel); }
.grp td { background: var(--cor-primaria) !important; color: #fff; text-align: left; font-weight: 700; font-size: .72rem; letter-spacing: .06em; padding: 4px 10px; position: sticky; left: 0; z-index: 4; }
.add td { background: #f3f9f4 !important; }
.add .hint { text-align: left; color: var(--cor-texto-suave); font-style: italic; padding: 0 10px; }
[contenteditable]:empty:before { content: attr(data-ph); color: #9aa6b2; font-weight: 400; font-style: italic; }
.delx { border: none; background: transparent; color: var(--cor-perigo); cursor: pointer; font-size: .9rem; line-height: 1; }
.delx:hover { color: #7a1610; }

.legenda { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; background: var(--cor-branco); border: 1px solid var(--cor-borda); border-radius: 10px; padding: 10px 14px; margin-top: 12px; font-size: .82rem; }
.leg-item { display: inline-flex; align-items: center; gap: 6px; }
.leg-cod { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 21px; border-radius: 5px; font-weight: 700; font-size: .74rem; padding: 0 5px; border: 1px solid rgba(0,0,0,.06); }

/* Modal */
.modal-ov { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: #fff; border-radius: var(--raio); box-shadow: 0 10px 40px rgba(0,0,0,.25); padding: 22px; width: 100%; max-width: 440px; }
.modal-box h3 { margin: 0 0 12px; color: var(--cor-primaria); }
.modal-acoes { display: flex; gap: 10px; margin-top: 16px; }
.btn-ghost-escuro { background: #fff; border: 1px solid var(--g-line2); color: var(--cor-texto); }
.modal-box .form-grid { gap: 0 14px; }
.modal-box select { width: 100%; padding: 10px 12px; border: 1px solid var(--g-line2); border-radius: 8px; font-family: inherit; }

/* ---------- Responsivo ---------- */
@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .topbar-inner { min-height: auto; padding: 8px 16px; }
    .escala-toolbar { align-items: stretch; }
    .cNome { width: 140px; min-width: 140px; max-width: 140px; }
}
