/*
 * Formulário de projeto (projects/new e projects/edit).
 * Também serve aos formulários de coordenador, unidade e departamento (.pf-simple).
 * Tudo vive dentro de .pf: o resto do site usa Skeleton + Bootstrap, então os controles
 * são redefinidos aqui (altura, margens, bordas) para não herdar os estilos globais.
 * Layout: índice fixo à esquerda + cartões de seção à direita; no celular o índice vira uma faixa no topo.
 */

.pf {
  --pf-bg: var(--ui-bg);
  --pf-surface: var(--ui-surface);
  --pf-fg: var(--ui-fg);
  --pf-muted: var(--ui-muted);
  --pf-line: var(--ui-line);
  --pf-accent: var(--ui-accent);
  --pf-accent-fg: var(--ui-accent-fg);
  --pf-accent-soft: var(--ui-accent-soft);
  --pf-ok: var(--ui-ok);
  --pf-err: var(--ui-err);
  --pf-err-soft: var(--ui-err-soft);
  --pf-radius: var(--ui-radius);

  max-width: 1120px;
  margin: 40px auto 0;
  padding: 0 16px 24px;
  color: var(--pf-fg);
  font-size: 15px;
  line-height: 1.5;
  text-align: left;
}
.pf *, .pf *::before, .pf *::after { box-sizing: border-box; }

/* Cabeçalho */
.pf-header { padding: 8px 0 22px; }
.pf-crumbs { color: var(--pf-muted); font-size: 13px; }
.pf-crumbs a { color: inherit; }
.pf .pf-title { color: var(--pf-fg); margin: 6px 0 4px; font-size: 30px; line-height: 1.2; font-weight: 600; letter-spacing: 0; text-transform: none; }
.pf-header p { margin: 0; color: var(--pf-muted); max-width: 62ch; }

.pf-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 32px; align-items: start; }

/* Índice */
.pf-steps { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 2px; }
.pf-steps a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--pf-muted);
  text-decoration: none; font-weight: 500; font-size: 14px; }
.pf-steps a:hover, .pf-steps a[aria-current="true"] { background: var(--pf-accent-soft); color: var(--pf-fg); }
.pf-dot { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--pf-line); display: grid; place-items: center;
  font-size: 11px; font-weight: 600; color: var(--pf-muted); background: var(--pf-surface); }
.pf-steps a[aria-current="true"] .pf-dot { border-color: var(--pf-accent); color: var(--pf-accent); }
.pf-dot svg { display: none; width: 12px; height: 12px; }
.pf-steps a.done .pf-dot { background: var(--pf-ok); border-color: var(--pf-ok); color: #fff; }
.pf-steps a.done .pf-dot span { display: none; }
.pf-steps a.done .pf-dot svg { display: block; }
.pf-progress { margin-top: 14px; padding: 12px 10px 0; border-top: 1px solid var(--pf-line); color: var(--pf-muted); font-size: 13px; }
.pf-bar { height: 6px; border-radius: 99px; background: var(--pf-line); margin-top: 8px; overflow: hidden; }
.pf-bar i { display: block; height: 100%; width: 0; background: var(--pf-accent); transition: width .3s; }

/* Formulário e cartões */
.pf-form { display: flex; flex-direction: column; gap: 20px; min-width: 0; margin: 0; }
.pf-card { background: var(--pf-surface); border: 1px solid var(--pf-line); border-radius: var(--pf-radius);
  box-shadow: var(--ui-shadow); padding: 24px; scroll-margin-top: 16px; }
.pf-card > header { margin-bottom: 18px; }
.pf .pf-card h3 { color: var(--pf-fg); margin: 0 0 2px; font-size: 20px; line-height: 1.3; font-weight: 600; letter-spacing: 0; text-transform: none; }
.pf-card > header p { margin: 0; color: var(--pf-muted); font-size: 14px; }
.pf-grid { display: grid; gap: 18px 20px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.pf-span-6 { grid-column: span 6; }
.pf-span-4 { grid-column: span 4; }
.pf-span-3 { grid-column: span 3; }
.pf-span-2 { grid-column: span 2; }

/* Campos */
.pf-field { min-width: 0; }
.pf .pf-field label, .pf .pf-label { display: block; margin: 0 0 6px; font-size: 14px; font-weight: 500; color: var(--pf-fg); }
.pf-opt { color: var(--pf-muted); font-weight: 400; }
.pf-hint { display: block; margin-top: 5px; color: var(--pf-muted); font-size: 12.5px; }
.pf-error { display: block; margin-top: 5px; color: var(--pf-err); font-size: 13px; font-weight: 500; }
.pf-field.invalid .pf-hint { display: none; }

.pf input[type=text], .pf textarea, .pf select {
  display: block; width: 100%; height: auto; min-height: 42px; margin: 0; padding: 10px 12px;
  font: inherit; color: var(--pf-fg); background-color: var(--pf-surface);
  border: 1px solid var(--pf-line); border-radius: 8px; box-shadow: none;
}
.pf textarea { min-height: 0; resize: vertical; }
.pf select { appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238a98a8' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
.pf input::placeholder, .pf textarea::placeholder { color: var(--pf-muted); opacity: .75; }
.pf input[type=text]:focus, .pf textarea:focus, .pf select:focus,
.pf .pf-btn:focus-visible, .pf .pf-seg input:focus-visible + span {
  outline: 2px solid var(--pf-accent); outline-offset: 1px; border-color: var(--pf-accent); }
.pf-field.invalid input[type=text], .pf-field.invalid textarea, .pf-field.invalid select,
.pf-field.invalid .select2-container .select2-selection, .pf-field.invalid .mce-tinymce {
  border-color: var(--pf-err); background-color: var(--pf-err-soft); }
.pf-field.invalid .pf-seg { border-color: var(--pf-err); }
/* Controle individual dentro de um grupo (palavras-chave, anos de desembolso) */
.pf-field input[type=text].bad { border-color: var(--pf-err); background-color: var(--pf-err-soft); }

/* select2 com a mesma aparência dos demais campos */
.pf .select2-container { width: 100% !important; }
.pf .select2-container .select2-selection--single { height: 42px; border: 1px solid var(--pf-line); border-radius: 8px; background: var(--pf-surface); }
.pf .select2-container--default .select2-selection--single .select2-selection__rendered { line-height: 40px; padding-left: 12px; padding-right: 32px; color: var(--pf-fg); }
.pf .select2-container--default .select2-selection--single .select2-selection__arrow { height: 40px; right: 6px; }
.pf .select2-container--default.select2-container--focus .select2-selection--single,
.pf .select2-container--default.select2-container--open .select2-selection--single { border-color: var(--pf-accent); }

/* TinyMCE */
.pf .mce-tinymce { width: 100% !important; border-radius: 8px; border-color: var(--pf-line); box-shadow: none; overflow: hidden; }

/* Controle segmentado (Sim/Não etc.) */
.pf-seg { display: inline-flex; flex-wrap: wrap; gap: 3px; max-width: 100%; padding: 3px; background: var(--pf-bg);
  border: 1px solid var(--pf-line); border-radius: 10px; }
.pf .pf-seg label { position: relative; display: block; margin: 0; }
.pf .pf-seg input[type=radio] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.pf-seg span { display: block; padding: 8px 16px; border-radius: 7px; font-size: 14px; font-weight: 500; color: var(--pf-muted); }
.pf-seg input:checked + span { background: var(--pf-surface); color: var(--pf-accent); box-shadow: 0 1px 3px rgba(20, 32, 46, .18); }

/* Revelação progressiva */
.pf-reveal { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows .3s ease, opacity .3s; }
.pf-reveal.open { grid-template-rows: 1fr; opacity: 1; }
.pf-reveal > div { min-height: 0; overflow: hidden; }
.pf-reveal.open > div { overflow: visible; }
.pf-reveal .pf-grid { padding-top: 18px; }

/* Vigência e desembolsos */
.pf-pill { display: inline-flex; align-items: center; padding: 5px 12px; border-radius: 99px; background: var(--pf-accent-soft);
  color: var(--pf-accent); font-size: 13px; font-weight: 600; }
.pf-pill.off { background: var(--pf-bg); color: var(--pf-muted); font-weight: 500; }
.pf .pf-years { width: 100%; margin: 4px 0 0; border-collapse: collapse; }
.pf .pf-years th { padding: 0 0 6px; border: 0; text-align: left; font-size: 13px; font-weight: 500; color: var(--pf-muted); }
.pf .pf-years td { padding: 4px 0; border: 0; text-align: left; }
.pf .pf-years td:first-child { width: 42%; padding-right: 12px; font-size: 14px; color: var(--pf-muted); font-variant-numeric: tabular-nums; }
.pf .pf-years tfoot td { padding-top: 10px; border-top: 1px solid var(--pf-line); font-weight: 600; color: var(--pf-fg); }
.pf .pf-years .pf-total { text-align: right; font-variant-numeric: tabular-nums; }
.pf .pf-years input[type=text], .pf #money_approved { font-variant-numeric: tabular-nums; }
.pf-empty { padding: 14px; border: 1px dashed var(--pf-line); border-radius: 8px; color: var(--pf-muted); font-size: 14px; }

/* Erros do servidor */
.pf-alert { padding: 14px 16px; border: 1px solid var(--pf-err); border-radius: var(--pf-radius); background: var(--pf-err-soft); color: var(--pf-err); }
.pf-alert p { margin: 0 0 6px; font-weight: 600; }
.pf-alert ul { margin: 0; padding-left: 20px; list-style: disc; }

/* Barra de ações fixa */
.pf-actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--pf-surface); border-top: 1px solid var(--pf-line); padding: 12px 16px; }
.pf-actions-in { max-width: 1120px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pf-actions-msg { min-width: 0; color: var(--pf-muted); font-size: 13.5px; }
.pf-actions-msg.err { color: var(--pf-err); font-weight: 600; }
.pf-btns { display: flex; gap: 10px; }
.pf .pf-btn, .pf input[type=submit].pf-btn { display: inline-flex; align-items: center; justify-content: center; width: auto; height: auto; margin: 0;
  padding: 10px 20px; font: inherit; font-weight: 600; line-height: 1.4; letter-spacing: 0; text-transform: none; text-decoration: none;
  color: var(--pf-fg); background: var(--pf-surface); border: 1px solid var(--pf-line); border-radius: 8px; cursor: pointer; }
.pf .pf-btn:hover { background: var(--pf-bg); color: var(--pf-fg); text-decoration: none; }
.pf .pf-btn-primary, .pf input[type=submit].pf-btn-primary { color: var(--pf-accent-fg); background: var(--pf-accent); border-color: var(--pf-accent); }
.pf .pf-btn-primary:hover { background: var(--pf-accent); color: var(--pf-accent-fg); filter: brightness(1.08); }

@media (max-width: 900px) {
  .pf-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .pf-steps { top: 0; z-index: 5; flex-direction: row; overflow-x: auto; margin: 0 -16px; padding: 8px 16px; background: var(--pf-bg); }
  .pf-steps a { white-space: nowrap; }
  .pf-progress { display: none; }
}
@media (max-width: 640px) {
  .pf-span-4, .pf-span-3, .pf-span-2 { grid-column: span 6; }
  .pf-card { padding: 18px 16px; }
  .pf-actions-msg { display: none; }
  .pf-actions-in, .pf-btns { width: 100%; }
  .pf-btns .pf-btn { flex: 1; }
  .pf .pf-years td:first-child { width: 36%; }
}
@media (prefers-reduced-motion: reduce) {
  .pf *, .pf *::before, .pf *::after { transition: none !important; }
}

/* Formulários simples (coordenador, unidade, departamento) */
.pf.pf-simple { max-width: 760px; }
.pf-card-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--pf-line); }
.pf input[type=text][readonly] { background-color: var(--pf-bg); color: var(--pf-muted); cursor: not-allowed; }
@media (max-width: 640px) {
  .pf-card-actions .pf-btn { flex: 1; }
}

/* Palavras-chave: quatro campos lado a lado; duas por linha no tablet e uma por linha no celular */
.pf-kw { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .pf-kw { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .pf-kw { grid-template-columns: minmax(0, 1fr); } }
