:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #16233a;
  --nav: #13233b;
  --muted: #64748b;
  --border: #e4e8ee;
  --accent: #0f766e;      /* teal */
  --accent-soft: #ccfbf1;
  --pago: #059669;        /* verde */
  --pago-soft: #d1fae5;
  --pend: #b45309;        /* âmbar */
  --pend-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(16,35,58,.06), 0 4px 12px rgba(16,35,58,.05);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; color: var(--ink); }

/* ---------- Navbar ---------- */
.nav {
  background: var(--nav);
  color: #fff;
  display: flex; align-items: center; gap: 28px;
  padding: 0 24px; height: 56px;
  position: sticky; top: 0; z-index: 20;
}
.nav .brand { font-weight: 700; font-size: 16px; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.nav .brand .dot { width: 9px; height: 9px; border-radius: 50%; background: #2dd4bf; display: inline-block; }
.nav .links { display: flex; gap: 4px; }
.nav .links a {
  color: #b8c4d6; padding: 8px 14px; border-radius: 8px; font-weight: 500;
}
.nav .links a:hover { color: #fff; background: rgba(255,255,255,.08); text-decoration: none; }
.nav .links a.active { color: #fff; background: rgba(45,212,191,.16); }
.nav .right { margin-left: auto; display: flex; align-items: center; gap: 14px; color: #b8c4d6; font-size: 13px; }
.nav .right form { margin: 0; }
.nav .right button {
  background: transparent; border: 1px solid rgba(255,255,255,.18); color: #cdd7e5;
  padding: 5px 12px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
.nav .right button:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ---------- Layout ---------- */
.wrap { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.sub { color: var(--muted); margin: 0; }

/* ---------- Cards / tiles ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 18px 20px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 16px 18px; }
.tile .label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.tile .value.money { color: var(--ink); }
.tile .foot { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.tile.accent { border-top: 3px solid var(--accent); }
.tile.pend { border-top: 3px solid var(--pend); }
.tile.pago { border-top: 3px solid var(--pago); }

.grid2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
@media (max-width: 820px) { .grid2 { grid-template-columns: 1fr; } }

/* container de altura FIXA para os gráficos — impede o Chart.js de crescer em loop */
.chart-box { position: relative; height: 260px; }
.chart-box.wide { height: 200px; }

/* fluxograma (embed do Miro) */
.fluxo-box { position: relative; height: 78vh; min-height: 480px; }
.fluxo-box iframe { width: 100%; height: 100%; border: 0; border-radius: 8px; display: block; }

/* ---------- Setores ---------- */
.setores-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.setor-card {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 0 18px 16px; border-top: 4px solid var(--cor);
  color: var(--ink); transition: transform .12s, box-shadow .12s;
}
.setor-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 20px rgba(16,35,58,.1); }
.setor-top { display: flex; align-items: baseline; justify-content: space-between; padding-top: 16px; }
.setor-nome { font-weight: 700; font-size: 15px; }
.setor-n { font-size: 30px; font-weight: 700; color: var(--cor); letter-spacing: -1px; }
.setor-desc { color: var(--muted); font-size: 12.5px; margin: 6px 0 12px; min-height: 34px; }
.setor-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; }
.setor-pend { background: var(--pend-soft); color: #92400e; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }

.setor-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.setor-tab { padding: 6px 13px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface); border: 1px solid var(--border); color: var(--muted); }
.setor-tab:hover { text-decoration: none; color: var(--ink); }
.setor-tab.active { background: var(--cor); border-color: var(--cor); color: #fff; }

.status-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: #eef1f5; color: #475569; border-radius: 8px; padding: 5px 11px; font-size: 12.5px; }
.chip b { color: var(--ink); margin-left: 3px; }

/* ---------- Mensagens ---------- */
.msg { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 10px; background: #eef1f5; color: #334155; }
.msg.success { background: var(--pago-soft); color: #065f46; }
.msg.error { background: var(--danger-soft); color: #991b1b; }

/* ---------- Formulários ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 16px; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field.wide { grid-column: 1 / -1; }
.form-field label, .form label:not(.chk) { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.form input, .form select, .form textarea,
.form-grid input, .form-grid select, .form-grid textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; font-size: 13px;
  background: var(--surface); color: var(--ink); font-family: inherit; width: 100%;
}
.form input:focus, .form select:focus, .form textarea:focus,
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
.form .form-field + .form-field { margin-top: 0; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; }
.req { color: var(--danger); }
.field-erro { color: var(--danger); font-size: 12px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); font-weight: 500; margin: 8px 0; }
.chk input { width: auto; }

/* ---------- Grade de permissões ---------- */
table.perms td, table.perms th { padding: 8px 12px; }
.setor-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; margin-right: 6px; }

/* ---------- Itens / separação ---------- */
.item-desistido td { text-decoration: line-through; color: var(--muted); }
.item-desistido td input[type=text] { text-decoration: none; }
.sep-progresso { font-size: 12.5px; font-weight: 700; color: var(--pend); background: var(--pend-soft); padding: 3px 10px; border-radius: 999px; }
.sep-progresso.ok { color: #065f46; background: var(--pago-soft); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 14px; border-left: 2px solid var(--border); position: relative; font-size: 13px; display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.tl-quando { color: var(--muted); font-size: 12px; min-width: 108px; }
.tl-status { background: #eef1f5; color: #475569; border-radius: 6px; padding: 1px 8px; font-size: 11.5px; }

/* ---------- Tabela ---------- */
.tbl-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 10px 12px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
table.data tr:hover td { background: #f8fafc; }
table.data td.money, table.data th.money { text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.entregue { background: var(--pago-soft); color: #065f46; }
.badge.parcial { background: var(--pend-soft); color: #92400e; }
.badge.andamento { background: #e0f2fe; color: #075985; }
.badge.cancel { background: var(--danger-soft); color: #991b1b; }
.badge.neutro { background: #eef1f5; color: #475569; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; background: #eef1f5; color: #475569; }
.tag.esc { background: #ede9fe; color: #5b21b6; }
.dot-ok { color: var(--pago); font-weight: 700; }
.dot-no { color: #cbd5e1; }

/* ---------- Filtros ---------- */
.filtros { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.filtros input, .filtros select {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px; font-size: 13px;
  background: var(--surface); color: var(--ink); font-family: inherit;
}
.filtros input:focus, .filtros select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.filtros input[type=search] { min-width: 240px; }
.resumo-linha { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.resumo-linha b { color: var(--ink); }

/* ---------- Paginação / botões ---------- */
.btn { display: inline-block; border: 1px solid var(--border); background: var(--surface); color: var(--ink); padding: 7px 14px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #0d635c; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; color: var(--muted); }

/* ---------- Detalhe ---------- */
.dl { display: grid; grid-template-columns: 180px 1fr; gap: 0; }
.dl dt { color: var(--muted); padding: 9px 0; border-bottom: 1px solid #eef1f5; font-size: 13px; }
.dl dd { margin: 0; padding: 9px 0; border-bottom: 1px solid #eef1f5; font-size: 13px; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator { opacity: 1; }

/* ---------- Login ---------- */
.login-bg { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #13233b, #0f766e); }
.login-card { background: #fff; border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.25); padding: 34px 32px; width: 340px; }
.login-card .brand { font-weight: 700; font-size: 20px; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.login-card .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: #0f766e; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 5px; font-weight: 600; }
.login-card input { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.login-card button { width: 100%; margin-top: 20px; }
.login-erro { background: var(--danger-soft); color: #991b1b; padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-top: 14px; }

/* ---------- Filtros clicáveis no cabeçalho da tabela ---------- */
th .th-sort { cursor: pointer; user-select: none; }
th .th-sort:hover { color: var(--ink); }
th .th-filtro { position: relative; display: inline-block; }
th .th-filtro summary { cursor: pointer; user-select: none; list-style: none; }
th .th-filtro summary::-webkit-details-marker { display: none; }
th .th-filtro summary::after { content: " ▾"; opacity: .55; }
th .th-filtro .menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow), 0 10px 28px rgba(16,35,58,.14); min-width: 180px;
  max-height: 300px; overflow: auto; padding: 4px; }
th .th-filtro .menu a { display: block; padding: 6px 10px; border-radius: 6px; cursor: pointer;
  color: var(--ink); font-weight: 400; font-size: 12.5px; text-transform: none; letter-spacing: 0; }
th .th-filtro .menu a:hover { background: var(--bg); }
th .th-filtro .menu a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
th .th-on { color: var(--accent); text-transform: none; }
th .th-x { display: inline-block; padding: 0 4px; border-radius: 50%; cursor: pointer;
  color: var(--accent); font-weight: 700; }
th .th-x:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Responsivo (tablet / smartphone) ---------- */
@media (max-width: 900px) {
  /* navbar em duas linhas: marca + usuário em cima, links roláveis embaixo */
  .nav { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 10px; row-gap: 2px; }
  .nav .links { order: 3; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
    gap: 2px; padding-bottom: 4px; scrollbar-width: none; }
  .nav .links::-webkit-scrollbar { display: none; }
  .nav .links a { padding: 7px 11px; white-space: nowrap; }
  .wrap { padding: 16px 14px; }
  .tiles { gap: 10px; }
  .card { padding: 14px; }
}

@media (max-width: 700px) {
  h1 { font-size: 19px; }
  .tile .value { font-size: 21px; }
  /* busca ocupa a linha; selects dividem o espaço aos pares */
  .filtros input[type=search] { min-width: 0; width: 100%; flex: 1 1 100%; }
  .filtros select { flex: 1 1 45%; min-width: 0; }
  /* inputs com 16px no toque: evita o zoom automático do iOS ao focar */
  .form input, .form select, .form textarea,
  .form-grid input, .form-grid select, .form-grid textarea,
  .filtros input, .filtros select, .login-card input { font-size: 16px; }
  table.data th, table.data td { padding: 8px 9px; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1 1 auto; text-align: center; }
  .fluxo-box { height: 65vh; min-height: 360px; }
}

@media (max-width: 560px) {
  .wrap { padding: 12px 10px; }
  .dl { grid-template-columns: 125px 1fr; }
  .nav .right > span { display: none; }  /* esconde o nome de usuário; sino e Sair ficam */
  .page-head .btn { padding: 8px 12px; }
  .login-card { width: min(340px, 92vw); padding: 26px 20px; }
  .timeline .tl-quando { min-width: 0; }
  .setor-desc { min-height: 0; }
}

/* tabela de itens do empenho: colunas de controle com largura fixa e padding curto
   (cabeçalhos inteiros), descrição com o texto COMPLETO quebrando em linhas ->
   sem reticências e sem rolagem horizontal */
table.itens { table-layout: fixed; width: 100%; }
table.itens th, table.itens td { padding: 8px 7px; white-space: nowrap; overflow: hidden; }
table.itens td:first-child { white-space: normal; overflow: visible; }
table.itens input[type=text], table.itens input[type=number] { width: 100%; }

/* fila dos setores: colunas centralizadas (inclusive valores e controles) */
table.data.centro th, table.data.centro td { text-align: center; }
table.data.centro th.money, table.data.centro td.money { text-align: center; }
table.data.centro td > div { justify-content: center; }

