/* Portal de Metas — tokens do SPEC_DESIGN_PORTAL_CMAIS.md */
:root {
  --navy-950: #04162f;
  --navy-900: #062653;
  --navy-800: #0a3470;
  --lime-500: #94c11f;
  --lime-400: #a8d52b;
  --blue-500: #338af3;
  --mint-500: #43c985;
  --magenta-600: #c9004f;
  --canvas: #f3f5f8;
  --surface: #fff;
  --text: #172033;
  --muted: #667085;
  --border: #d9e0e8;

  --ok-bg: #e9f8f0; --ok-fg: #147a4b;
  --warn-bg: #fff7df; --warn-fg: #8a5a00;
  --err-bg: #fdecef; --err-fg: #b4233c;
  --info-bg: #eaf3ff; --info-fg: #175cd3;
  --neutral-bg: #eef1f5; --neutral-fg: #475467;

  --radius-control: 8px;
  --radius-card: 14px;
  --shadow-card: 0 6px 20px rgba(4, 22, 47, .08);

  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); font-size: 15px; line-height: 1.5; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Botões ------------------------------------------------------------------ */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border: 1px solid transparent; border-radius: var(--radius-control);
  font-weight: 600; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s;
}
.button-primary { background: var(--lime-500); color: var(--navy-950); }
.button-primary:hover { background: var(--lime-400); }
.button-secondary { background: var(--surface); border-color: var(--navy-900); color: var(--navy-900); }
.button-secondary:hover { background: var(--neutral-bg); }
.button-ghost { background: transparent; color: var(--navy-900); }
.button-ghost:hover { background: var(--neutral-bg); }
.button-small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.button-block { width: 100%; min-height: 48px; }
.button[disabled] { cursor: not-allowed; opacity: .6; }
.button.is-loading::before {
  content: ""; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Mensagens ---------------------------------------------------------------- */
.alert { margin: 0 0 16px; padding: 10px 14px; border-radius: var(--radius-control); font-size: 14px; }
.alert-error { background: var(--err-bg); color: var(--err-fg); }
.alert-info { background: var(--info-bg); color: var(--info-fg); }
.alert-warn { background: var(--warn-bg); color: var(--warn-fg); }

/* Login minimalista ------------------------------------------------------- */
.login-page { display: grid; min-height: 100vh; padding: 32px 16px; place-items: center; }
.login-card {
  width: 100%; max-width: 400px; padding: 36px 32px 28px;
  border: 1px solid #e4e7ec; border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--shadow-card);
}
.login-logo { display: block; height: 44px; width: auto; margin-bottom: 28px; }
.login-card h1 { margin: 0 0 6px; color: var(--navy-900); font-size: 26px; line-height: 1.2; }
.login-card .lead { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
.field + .field { margin-top: 18px; }
.field label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 600; }
.field input {
  display: block; width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(51, 138, 243, .18); }
.password-control { position: relative; display: block; }
.password-control input { padding-right: 52px; }
.password-toggle {
  position: absolute; top: 2px; right: 2px; display: grid; place-items: center; width: 44px; height: 44px;
  border: 0; border-radius: var(--radius-control); background: transparent; color: var(--muted); cursor: pointer;
}
.password-toggle:hover { color: var(--navy-900); }
.password-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.password-toggle[aria-pressed="false"] .slash { display: none; }
.login-card .button-block { margin-top: 24px; }
.login-footer { margin-top: 20px; color: var(--muted); font-size: 13px; text-align: center; }
.login-footer small { display: block; margin-top: 4px; font-size: 12px; }

/* Shell ------------------------------------------------------------------- */
.app-shell { display: grid; grid-template-columns: 88px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; display: flex; flex-direction: column; align-items: center; gap: 24px;
  height: 100vh; padding: 20px 10px; background: var(--navy-900); color: #fff;
}
.sidebar-brand img { display: block; width: 44px; height: 44px; }
.sidebar nav { display: grid; gap: 6px; width: 100%; }
.nav-item {
  position: relative; display: grid; justify-items: center; gap: 4px; padding: 10px 4px;
  border-radius: var(--radius-control); color: #c9d6e8; font-size: 12px; font-weight: 600; text-decoration: none;
}
.nav-item svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: var(--navy-800); color: #fff; }
.nav-item.is-active { background: var(--navy-800); color: #fff; }
.nav-item.is-active::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--lime-500); }

.app-main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 64px; padding: 0 28px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.breadcrumb { margin: 0; color: var(--muted); font-size: 14px; }
.breadcrumb strong { color: var(--text); }
.topbar-user { display: flex; align-items: center; gap: 14px; min-width: 0; }
.user-info { display: grid; text-align: right; line-height: 1.3; min-width: 0; }
.user-info strong { font-size: 14px; }
.user-info span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.env-badge { padding: 3px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn-fg); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.content { width: min(100%, 1600px); margin: 0 auto; padding: 28px 32px 40px; }

/* Páginas ----------------------------------------------------------------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 16px 24px; margin-bottom: 24px; }
.page-header h1 { margin: 0; font-size: 30px; line-height: 1.2; color: var(--navy-950); }
.page-header p { margin: 4px 0 0; }
.page-actions { display: flex; align-items: flex-end; gap: 12px; }
.select-field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
.select-field select {
  min-height: 44px; min-width: 120px; padding: 0 12px; border: 1px solid var(--border);
  border-radius: var(--radius-control); background: var(--surface);
}
.panel { border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--shadow-card); }
.panel-body { padding: 24px; }
.empty-state { padding: 48px 24px; text-align: center; }
.empty-state h1, .empty-state h2 { margin: 0 0 6px; font-size: 20px; color: var(--navy-950); }

/* Indicadores ------------------------------------------------------------- */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric { padding: 18px 20px; border-left: 4px solid var(--border); }
.metric-label { margin: 0; color: var(--muted); font-size: 13px; font-weight: 600; }
.metric-value { margin: 6px 0 0; font-size: clamp(18px, 1.9vw, 24px); white-space: nowrap; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--navy-950); }
.metric-hint { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.metric-version { border-left-color: var(--navy-900); }
.metric-ref { border-left-color: var(--blue-500); }
.metric-goal { border-left-color: var(--lime-500); }
.metric-var.is-positive { border-left-color: var(--mint-500); }
.metric-var.is-positive .metric-value { color: var(--ok-fg); }
.metric-var.is-negative { border-left-color: var(--magenta-600); }
.metric-var.is-negative .metric-value { color: var(--magenta-600); }

/* Badges de status -------------------------------------------------------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-RASCUNHO { background: var(--info-bg); color: var(--navy-800); }
.status-FINALIZADA { background: var(--warn-bg); color: var(--warn-fg); }
.status-PROCESSANDO { background: var(--info-bg); color: var(--info-fg); }
.status-CARREGADA { background: var(--ok-bg); color: var(--ok-fg); }
.status-ERRO { background: var(--err-bg); color: var(--err-fg); }
.status-ARQUIVADA { background: var(--neutral-bg); color: var(--neutral-fg); }

/* Tabela ------------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: #f6f8fb;
  color: var(--muted); font-size: 12px; font-weight: 700; text-align: left; text-transform: uppercase; letter-spacing: .03em;
}
.data-table th.num { text-align: right; }
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fafbfd; }
.row-actions { display: flex; justify-content: flex-end; gap: 8px; }
.skeleton { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, #eef1f5 25%, #f6f8fb 50%, #eef1f5 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Responsivo -------------------------------------------------------------- */
@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; flex-direction: row; height: auto; padding: 8px 16px; gap: 16px; }
  .sidebar-brand img { width: 36px; height: 36px; }
  .sidebar nav { display: flex; width: auto; }
  .nav-item { grid-auto-flow: column; padding: 8px 12px; }
  .nav-item.is-active::before { display: none; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .user-info span { max-width: 180px; }
  .content { padding: 20px 16px 32px; }
  .page-header h1 { font-size: 24px; }
  .metrics { grid-template-columns: 1fr; }
  /* Tabela vira cards */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .data-table td { padding: 4px 0; border: 0; text-align: left; }
  .data-table td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12px; font-weight: 600; }
  .row-actions { justify-content: flex-start; margin-top: 8px; }
  .login-card { padding: 28px 20px 22px; }
}
/* Formulários ------------------------------------------------------------- */
.form-narrow { max-width: 560px; }
.field-help { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.field textarea {
  display: block; width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-control); font: inherit; resize: vertical;
}
.field textarea:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(51, 138, 243, .18); }
.field input[aria-invalid="true"] { border-color: var(--err-fg); }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
.form-actions.center { justify-content: center; }
.button-dark { background: var(--navy-900); color: #fff; }
.button-dark:hover { background: var(--navy-800); }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--navy-900); text-decoration: underline; }
.section-title { margin: 0 0 4px; font-size: 18px; color: var(--navy-950); }
.panel-title { padding: 18px 20px 10px; margin: 0; }
.check-field { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; font-weight: 600; }
.check-field input { width: 18px; height: 18px; accent-color: var(--navy-900); }

/* Editor ------------------------------------------------------------------ */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.filters .select-field input {
  min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-control); font-weight: 400;
}
.filters .grow { flex: 1 1 220px; }
.filters .grow input { width: 100%; }
.metrics-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.conflict-banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.grid-panel { margin-bottom: 96px; }
.goal-grid thead th { position: sticky; top: 0; z-index: 2; }
.goal-grid td:first-child, .goal-grid th:first-child { position: sticky; left: 0; background: inherit; z-index: 1; }
.goal-grid th:first-child { background: #f6f8fb; z-index: 3; }
.goal-grid tr.month-row td { background: #f6f8fb; font-weight: 700; }
.goal-grid tr.dept-row td { background: var(--surface); }
.goal-grid tr.dept-row td:first-child { padding-left: 44px; font-weight: 400; }
.goal-grid tr.month-tools td { background: var(--surface); padding-top: 6px; padding-bottom: 16px; }
.month-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 6px 0 0;
  border: 0; background: none; font-weight: 700; cursor: pointer; color: var(--navy-950);
}
.month-toggle::before { content: "▸"; display: inline-block; width: 14px; transition: transform .15s; color: var(--muted); }
.month-toggle[aria-expanded="true"]::before { transform: rotate(90deg); }
.money-input {
  width: 150px; min-height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-control);
  background: var(--surface); text-align: right; font-variant-numeric: tabular-nums;
}
.money-input:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(51, 138, 243, .18); }
.money-input[aria-invalid="true"] { border-color: var(--err-fg); background: var(--err-bg); }
.money-input.is-dirty { border-color: var(--lime-500); }
.money-input:read-only { background: var(--neutral-bg); border-color: transparent; }
.input-error { display: block; margin-top: 4px; color: var(--err-fg); font-size: 12px; font-weight: 400; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip-ok { background: var(--ok-bg); color: var(--ok-fg); }
.chip-ok::before { content: "✓"; }
.chip-pending { background: var(--warn-bg); color: var(--warn-fg); }
.chip-pending::before { content: "!"; font-weight: 800; }
.chip-error { background: var(--err-bg); color: var(--err-fg); }
.chip-error::before { content: "✕"; }
.var-positive { color: var(--ok-fg); }
.var-negative { color: var(--magenta-600); }
.month-tools-inner { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 16px; }
.month-tools-inner .obs { flex: 1 1 320px; }
.month-tools-inner .obs textarea { min-height: 38px; }
.dept-sum { font-size: 13px; color: var(--muted); font-weight: 400; }
.dept-sum strong { color: var(--text); }
.cell-focus { animation: flash 1.6s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--lime-500); } to { box-shadow: 0 0 0 3px transparent; } }

.action-bar {
  position: fixed; left: 88px; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 32px; border-top: 1px solid var(--border); background: rgba(255, 255, 255, .97);
  box-shadow: 0 -6px 20px rgba(4, 22, 47, .06);
}
.save-state { margin: 0; color: var(--muted); font-size: 14px; }
.save-state.is-dirty { color: var(--warn-fg); font-weight: 600; }
.save-state.is-error { color: var(--err-fg); font-weight: 600; }
.save-state.is-saved { color: var(--ok-fg); }
.action-buttons { display: flex; gap: 12px; }

/* Revisão ----------------------------------------------------------------- */
.validation { margin-bottom: 24px; }
.validation.is-valid { border-left: 4px solid var(--mint-500); }
.validation.is-invalid { border-left: 4px solid var(--err-fg); }
.error-group { margin-top: 16px; }
.error-group h3 { margin: 0 0 8px; font-size: 15px; }
.error-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.error-list a {
  display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-radius: var(--radius-control);
  background: var(--err-bg); color: var(--err-fg); text-decoration: none; font-size: 14px;
}
.error-list a:hover { text-decoration: underline; }
.review-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.success-panel .badge { font-size: 14px; }

/* Diálogos ---------------------------------------------------------------- */
.dialog {
  width: min(92vw, 480px); padding: 28px; border: 0; border-radius: var(--radius-card);
  box-shadow: 0 20px 60px rgba(4, 22, 47, .25);
}
.dialog::backdrop { background: rgba(4, 22, 47, .45); }
.dialog h2 { margin: 0 0 8px; font-size: 20px; color: var(--navy-950); }

@media (max-width: 1100px) {
  .review-grid { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  .metrics-3 { grid-template-columns: 1fr; }
  .action-bar { left: 0; padding: 10px 16px; flex-direction: column; align-items: stretch; }
  .action-buttons .button { flex: 1; }
  .goal-grid tr.dept-row td:first-child { padding-left: 0; }
  .goal-grid td:first-child, .goal-grid th:first-child { position: static; }
  .money-input { width: 100%; }
}

/* Django (renderização no servidor) --------------------------------------- */
.alert-ok { background: var(--ok-bg); color: var(--ok-fg); }
.messages { margin-bottom: 8px; }
.inline-form { display: flex; align-items: flex-end; gap: 8px; }
.goal-grid tbody.month + tbody.month tr.month-row th,
.goal-grid tbody.month + tbody.month tr.month-row td { border-top: 2px solid var(--border); }
.data-table th[scope="row"] {
  text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); padding: 14px 16px;
}
.goal-grid tr.month-row th { font-weight: 700; text-align: left; background: #f6f8fb; }
.goal-grid tr.month-tools td { padding: 0 16px 12px; background: var(--surface); }
.goal-grid details > summary {
  cursor: pointer; padding: 8px 0; color: var(--navy-800); font-size: 14px; font-weight: 600; list-style-position: inside;
}
.goal-grid details[open] > summary { margin-bottom: 8px; }
.dept-table { margin: 0 0 12px; border: 1px solid var(--border); border-radius: var(--radius-control); }
.dept-table th[scope="row"] { font-weight: 500; text-align: left; background: var(--surface); }
.reopen { margin-bottom: 20px; }
.reopen > summary { cursor: pointer; font-weight: 600; color: var(--navy-800); }
.finalize { margin-bottom: 24px; }
.finalize .check-field input { width: 18px; height: 18px; }
.field select, .field input[type="number"] { font: inherit; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
