:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e2e5ea;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #0f8f57;
  --accent-soft: #e7f0ec;
  --ok: #12a05f;
  --warn: #e08a00;
  --danger: #d92d20;
  --c1: #12a05f;
  --c2: #7cc06a;
  --c3: #f0b429;
  --c4: #e2703a;
  --c5: #3b82f6;
  --c6: #a855f7;
  --c7: #06b6d4;
  --c8: #ef4444;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --surface-2: #22272c;
    --border: #2e353c;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --accent: #34d399;
    --accent-soft: #223029;
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --c1: #10b981;
    --c2: #a3e635;
    --c3: #fbbf24;
    --c4: #fb923c;
    --c5: #60a5fa;
    --c6: #c084fc;
    --c7: #22d3ee;
    --c8: #f87171;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 360px;
}

.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

/* ---------- layout ---------- */

header.topo {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

header.topo h1 { font-size: 17px; margin: 0; font-weight: 650; }
header.topo .sub { color: var(--muted); font-size: 13px; }
header.topo .espaco { flex: 1; }

nav.abas {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky;
  top: 57px;
  z-index: 19;
}

nav.abas button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

nav.abas button.ativa { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 20px; max-width: none; }

.aba { display: none; }
.aba.ativa { display: block; }

/* ---------- componentes ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.card h2 { font-size: 14px; margin: 0 0 14px; font-weight: 600; letter-spacing: .01em; }
.card h2 .dica { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }

@media (max-width: 1180px) { .kpis { grid-template-columns: repeat(3, 1fr); } }

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.kpi .rotulo { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .valor { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .nota { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.destaque .valor { color: var(--ok); }
.kpi.alerta .valor { color: var(--danger); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 650; border-top: 2px solid var(--border); border-bottom: none; }

.rolar { overflow-x: auto; }
.rolar table { min-width: 1080px; }
.rolar td:first-child { min-width: 260px; }

/* linha compacta + detalhe expansível */
#aba-itens td { padding: 6px 10px; }
/* a tabela de itens acompanha a largura da tela: encolhe as colunas em vez de rolar */
#aba-itens .rolar table { min-width: 0; }
#aba-itens .rolar td:first-child { min-width: 0; }
#aba-itens tbody td:not(.num) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
#aba-itens tbody td:first-child { max-width: none; }

/* no desktop as colunas dividem a largura da tela em porcentagem, então nunca rola */
@media (min-width: 701px) {
  #aba-itens table { table-layout: fixed; width: 100%; }
  #aba-itens thead th:nth-child(1) { width: 20%; }
  #aba-itens thead th:nth-child(2) { width: 10%; }
  #aba-itens thead th:nth-child(3) { width: 10%; }
  #aba-itens thead th:nth-child(4) { width: 11%; }
  #aba-itens thead th:nth-child(5) { width: 6%; }
  #aba-itens thead th:nth-child(6) { width: 8%; }
  #aba-itens thead th:nth-child(7) { width: 8%; }
  #aba-itens thead th:nth-child(8) { width: 9%; }
  #aba-itens thead th:nth-child(9) { width: 8%; }
  #aba-itens thead th:nth-child(10) { width: 8%; }
  #aba-itens thead th:nth-child(11) { width: 6%; }
}
#aba-itens tbody tr.detalhe td { white-space: normal; max-width: none; overflow: visible; }

button.seta {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  width: 18px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  margin-right: 4px;
}
button.seta:hover { color: var(--accent); filter: none; }
span.seta.vazia { display: inline-block; width: 18px; margin-right: 4px; }

tr.detalhe td {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
  padding: 10px 14px 12px 32px;
  border-bottom: 1px solid var(--border);
}
tr.detalhe td strong { color: var(--text); font-weight: 600; }
tr.detalhe:hover td { background: var(--surface-2); }

table.matriz th:first-child { white-space: nowrap; }
table.matriz td:first-child { white-space: normal; min-width: 320px; max-width: 430px; }

.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip.ok { background: #cdf2df; color: #0b7a4b; border-color: #7ad4a9; }
.chip.fora { background: #ffdcd8; color: #c0261c; border-color: #ffb3ab; }
.chip.neutro { background: var(--surface-2); color: var(--text); border-color: var(--border); }

@media (prefers-color-scheme: dark) {
  .chip.ok { background: #10402c; color: #56e39f; border-color: #1c6644; }
  .chip.fora { background: #4d1f1a; color: #ff8f83; border-color: #6e2d26; }
}
h3.titulo-opcoes {
  font-size: 13px;
  margin: 18px 0 8px;
  font-weight: 650;
  color: #eab308;
}
@media (prefers-color-scheme: dark) { h3.titulo-opcoes { color: #fbbf24; } }

table.matriz thead th.num { text-align: right; }
table.matriz tfoot tr:first-child td { border-top: 2px solid var(--border); }
table.matriz tfoot tr:last-child td { border-bottom: none; padding-top: 0; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}
.badge.b-orcado { background: #dde5ff; color: #2841b8; border-color: #b9c8ff; }
.badge.b-aguardando { background: #fff2c2; color: #946800; border-color: #ffdf7a; }
.badge.b-em-execucao { background: #ffe0c2; color: #c2410c; border-color: #ffbe86; }
.badge.b-comprado { background: #d5f2e3; color: #0f7a4d; border-color: #9fdcbe; }
.badge.b-entregue { background: #cdf2df; color: #0b7a4b; border-color: #8ddcb8; }
.badge.b-instalado { background: #bdedd3; color: #096b41; border-color: #7ad4a9; }
.badge.b-descartado { background: #ffdcd8; color: #c0261c; border-color: #ffb3ab; text-decoration: line-through; }
.badge.b-atraso { background: #ffdcd8; color: #c0261c; border-color: #ffb3ab; }

@media (prefers-color-scheme: dark) {
  .badge.b-orcado { background: #1f2b57; color: #b9c8ff; border-color: #33417a; }
  .badge.b-aguardando { background: #40320d; color: #fbd45c; border-color: #5c4813; }
  .badge.b-em-execucao { background: #4a2a10; color: #ffb066; border-color: #6b3d17; }
  .badge.b-comprado, .badge.b-entregue, .badge.b-instalado { background: #1e2f28; color: #8fd0b4; border-color: #2b4438; }
  .badge.b-atraso, .badge.b-descartado { background: #3a2220; color: #f0a49b; border-color: #4d2c29; }
}

button, .btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  font-family: inherit;
}
button:hover { filter: brightness(1.08); }
button.sec { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button.mini { padding: 4px 9px; font-size: 12.5px; }
button.perigo { background: var(--danger); }

input, select, textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}
textarea { min-height: 60px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 550; }
.campo { margin-bottom: 12px; }

.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filtros .campo { margin-bottom: 0; min-width: 150px; }
.filtros .campo.busca { flex: 1; min-width: 200px; }

/* ---------- modal ---------- */

.modal-fundo {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 18, .5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 22px;
  width: 100%;
  max-width: 720px;
  margin: auto;
}
.modal h2 { margin: 0 0 16px; font-size: 17px; }
.modal .linha { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal .linha3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.modal .acoes { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal .acoes .esq { margin-right: auto; }

/* ---------- gráficos ---------- */

.legenda { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.legenda span { display: flex; align-items: center; gap: 6px; }
.legenda i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.rosca-wrap { display: flex; gap: 18px; align-items: center; }
.rosca-legenda { flex-direction: column; gap: 6px; margin-top: 0; flex: 1; min-width: 0; }
.rosca-legenda span { line-height: 1.35; }

svg text { fill: var(--muted); font-size: 11px; }
svg .rotulo-valor { fill: var(--text); font-size: 11px; font-weight: 600; }

.alerta-caixa {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 13.5px;
}
.alerta-caixa strong { display: block; margin-bottom: 2px; }

.vazio { color: var(--muted); font-size: 14px; padding: 20px 0; text-align: center; }

.so-mobile { display: none; }

@media (max-width: 700px) {
  main { padding: 8px; }
  .modal .linha, .modal .linha3 { grid-template-columns: 1fr; }

  /* cabeçalho rola junto, as abas é que ficam fixas no topo */
  header.topo { position: static; padding: 10px 12px; gap: 8px; }
  header.topo h1 { font-size: 15px; }
  header.topo .sub { font-size: 11.5px; }
  header.topo .espaco { flex: 1 0 100%; height: 0; }
  header.topo button.mini { font-size: 11px; padding: 4px 8px; border-radius: 6px; }
  nav.abas { top: 0; padding: 0 6px; }
  nav.abas button { font-size: 12.5px; padding: 9px 9px; }

  /* tabelas: fonte menor, menos respiro e sem largura mínima gigante */
  .card { padding: 10px; border-radius: 8px; }
  .card h2 { font-size: 13px; margin-bottom: 10px; }
  table { font-size: 11.5px; }
  th, td { padding: 5px 4px; }
  th { font-size: 10px; letter-spacing: 0; }
  .rolar table { min-width: 0; }
  .rolar td:first-child { min-width: 0; }
  table.matriz { min-width: 460px; }
  table.matriz td:first-child { min-width: 130px; max-width: 190px; }

  /* colunas secundárias somem; o conteúdo delas vai para o detalhe */
  .so-desktop { display: none !important; }
  .so-mobile { display: block; }
  #aba-itens table { width: 100%; }
  #aba-itens thead th:first-child, #aba-itens tbody td:first-child { min-width: 196px; }
  #aba-itens tfoot { display: none; }
  .resumo-lista {
    font-size: 12.5px;
    color: var(--muted);
    padding: 4px 0 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
  }
  .resumo-lista strong { color: var(--text); }

  /* rosca menor com a legenda ao lado */
  .rosca-wrap { gap: 10px; }
  .rosca-wrap svg { width: 116px !important; height: 116px !important; }
  .rosca-legenda { font-size: 10.5px; gap: 4px; }
  .rosca-legenda i { width: 8px; height: 8px; border-radius: 2px; }
  #aba-itens tbody td:first-child { max-width: none; white-space: normal; }
  #aba-itens tbody td:last-child { text-align: right; padding-right: 0; }
  #aba-itens td { padding: 6px 4px; }
  #aba-itens tbody td:first-child { padding-left: 2px; }
  button.seta, span.seta.vazia { width: 14px; margin-right: 2px; }
  tr.detalhe td { padding: 8px 10px 10px 26px; }

  .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi { padding: 8px 9px; }
  .kpi .valor { font-size: 18px; }
  .kpi .rotulo { font-size: 10.5px; }
  .kpi .nota { font-size: 11px; }

  .filtros { gap: 8px; }
  .filtros .campo { min-width: 0; flex: 1 1 calc(50% - 4px); }
  .filtros .campo.busca { flex: 1 1 100%; }
  .filtros button { flex: 1 1 100%; }
  .filtros label { font-size: 11px; margin-bottom: 2px; }
  .filtros input, .filtros select { padding: 6px 8px; font-size: 13px; }
  .docs { grid-template-columns: 1fr; }
  .badge { font-size: 10.5px; padding: 2px 6px; }
  .chip { font-size: 11px; padding: 2px 8px; }

  /* botão de editar vira só o lápis */
  #aba-itens tbody td:last-child button { font-size: 0; padding: 4px 7px; }
  #aba-itens tbody td:last-child button::after { content: '\270E'; font-size: 14px; }
  .status-inline { display: inline; margin-left: 4px; white-space: nowrap; }
  .status-inline .badge { margin-right: 2px; }
}

.graf-wrap .tip {
  display: none;
  position: absolute;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
  padding: 8px 12px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text);
  pointer-events: none;
  max-width: 260px;
}
.barra-entrega:hover { filter: brightness(1.15); }

.card.estado-ok { border-left: 4px solid var(--ok); }
.card.estado-andamento { border-left: 4px solid #f97316; }

.selo {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  text-transform: none;
  letter-spacing: 0;
  vertical-align: 1px;
}
.selo.ok { background: #cdf2df; color: #0b7a4b; }
.selo.andamento { background: #ffe0c2; color: #c2410c; }

@media (prefers-color-scheme: dark) {
  .selo.ok { background: #10402c; color: #56e39f; }
  .selo.andamento { background: #4a2a10; color: #ffb066; }
}

/* faixa de status na tabela do cronograma */
tr.faixa td:first-child { border-left: 4px solid transparent; }
tr.faixa-entregue td:first-child, tr.faixa-instalado td:first-child { border-left-color: var(--ok); }
tr.faixa-em-execucao td:first-child { border-left-color: #f97316; }
tr.faixa-aguardando td:first-child { border-left-color: #eab308; }

/* aba Ver o projeto */
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }

a.doc {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  text-decoration: none;
  color: var(--text);
  transition: border-color .12s, transform .12s;
}
a.doc:hover { border-color: var(--accent); transform: translateY(-1px); }

.doc-ico {
  flex: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  color: #fff;
  background: #d92d20;
  border-radius: 5px;
  padding: 4px 6px;
  margin-top: 2px;
}
.doc-txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.doc-txt strong { font-size: 14px; }
.doc-txt span { color: var(--muted); font-size: 12.5px; line-height: 1.45; }

/* ---------- animações de entrada dos gráficos ---------- */

@keyframes sobe { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes cresce { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes aparece { from { opacity: 0; } to { opacity: 1; } }
@keyframes desenha { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes gira { from { opacity: 0; transform: rotate(-90deg) scale(.85); } to { opacity: 1; transform: none; } }

.anim-sobe {
  transform-box: fill-box;
  transform-origin: bottom;
  animation: sobe .65s cubic-bezier(.22, .9, .3, 1) both;
}

.anim-cresce {
  transform-origin: left center;
  animation: cresce .6s cubic-bezier(.22, .9, .3, 1) both;
}

.anim-aparece { animation: aparece .35s ease-out both; }

.anim-linha {
  stroke-dasharray: 1;
  animation: desenha 1s ease-out .25s both;
}

.anim-rosca {
  transform-origin: center;
  animation: gira .6s cubic-bezier(.22, .9, .3, 1) both;
}

/* nasce pausada; solta quando o card entra na tela */
.pausado { animation-play-state: paused !important; }

@media (prefers-reduced-motion: reduce) {
  .anim-sobe, .anim-cresce, .anim-aparece, .anim-linha, .anim-rosca, .pausado {
    animation: none !important;
    stroke-dasharray: none;
  }
}
