:root {
  --navy: #0f2a43;
  --navy-2: #163a5c;
  --gold: #c9a227;
  --page: #f4f5f2;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --line-2: #c3c2b7;
  --ok: #006300;
  --ok-bg: #e5f4e5;
  --bad: #b42323;
  --bad-bg: #fbe9e9;
  --warn-bg: #fff4d6;
  --info: #1c5cab;
  --info-bg: #e3eefb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 0 0 1px rgba(11, 11, 11, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); font-size: 14px; line-height: 1.5; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.ico { width: 18px; height: 18px; flex: none; }

/* ---------- Estrutura ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex: none; background: var(--navy); color: #cfd8e3;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; font-weight: 600; color: #fff; font-size: 15px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--gold); color: var(--navy);
  display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: .5px;
}
.brand-dark { color: var(--navy); padding: 0 0 18px; }
.sidebar nav { flex: 1; padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #cfd8e3; }
.sidebar a:hover { background: var(--navy-2); color: #fff; text-decoration: none; }
.sidebar a.active { background: var(--navy-2); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.sidebar-foot { padding: 10px; border-top: 1px solid rgba(255, 255, 255, .08); }
.sidebar-foot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 18px 28px 6px;
}
.topbar h1 { font-size: 22px; margin: 0; }
.menu-btn { display: none; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--ink); }
.content { padding: 14px 28px 40px; max-width: 1400px; width: 100%; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.sub { color: var(--ink-2); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 18px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi .label { color: var(--ink-2); font-size: 12.5px; }
.kpi .value { font-size: clamp(15px, 1.3vw, 21px); font-weight: 650; margin-top: 2px; white-space: nowrap; line-height: 1.3; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.accent { background: var(--navy); color: #fff; }
.kpi.accent .label, .kpi.accent .hint { color: #b8c6d6; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f1f1ee; text-decoration: none; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-danger { color: var(--bad); border-color: #e7b4b4; }
.btn-danger:hover { background: var(--bad-bg); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-link { background: none; border: 0; color: var(--info); padding: 0; cursor: pointer; font: inherit; }
.btn-link.danger { color: var(--bad); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions select { width: auto; max-width: 100%; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert-success { background: var(--ok-bg); color: #0b4d0b; }
.alert-error { background: var(--bad-bg); color: #8a1c1c; }
.alert-info { background: var(--info-bg); color: #123e74; }
.alert-warn { background: var(--warn-bg); color: #6b4e00; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 550; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: #0b4d0b; }
.badge-info { background: var(--info-bg); color: #123e74; }
.badge-dark { background: #e6e8eb; color: #2c3640; }
.badge-muted { background: #efefec; color: var(--muted); }
.badge-warn { background: var(--warn-bg); color: #6b4e00; }
.tipo-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.tipo-tag i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* Tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .3px; background: #f7f7f4; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: #fafaf7; }
tfoot td { font-weight: 650; border-top: 2px solid var(--line-2); border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 26px; }

/* Formulários */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
label { font-weight: 550; font-size: 13px; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=color], select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; color: var(--ink); width: 100%;
}
input[type=color] { padding: 2px; height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9ec5f4; outline-offset: 0; border-color: var(--info); }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
.help { font-size: 12px; color: var(--muted); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { min-width: 140px; }
form.inline { display: inline; }

/* Gráficos */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }
.chart-box.short { height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Barra de progresso */
.progress { height: 8px; background: #ecebe6; border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--ok); border-radius: 99px; }

/* Linha do tempo de fases */
.stepper { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.step { padding: 5px 11px; border-radius: 99px; font-size: 12.5px; background: #efefec; color: var(--muted); }
.step.done { background: var(--info-bg); color: #123e74; }
.step.current { background: var(--navy); color: #fff; font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--info); }
.timeline .when { font-size: 12px; color: var(--muted); }

/* Documentos */
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.doc-list li:last-child { border-bottom: 0; }
.doc-status { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.doc-status.ok { background: var(--ok-bg); color: var(--ok); }
.doc-status.pend { background: var(--warn-bg); color: #8a6500; }
.doc-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.doc-name .small { display: block; }
.file-input { font-size: 12.5px; max-width: 230px; }

.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.dl dt { color: var(--ink-2); }
.dl dd { margin: 0; font-weight: 550; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { min-width: 160px; }

.lamina-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.print-only { display: none; }

/* ---------- Login ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--navy), #0a1d2f); padding: 16px; }
.auth-box { width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; padding: 30px 28px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.auth-box h1 { font-size: 19px; margin-bottom: 18px; }
.auth-box .field { margin-bottom: 14px; }
.auth-box .btn { width: 100%; justify-content: center; padding: 10px; }
.auth-links { margin-top: 16px; text-align: center; font-size: 13px; }

/* ---------- Responsivo ---------- */
@media (max-width: 1080px) {
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 14px 16px 4px; }
  .topbar h1 { font-size: 19px; }
  .content { padding: 12px 16px 30px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: clamp(14px, 4.2vw, 18px); }
}

/* ---------- Impressão da lâmina ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 11px; }
  .sidebar, .topbar, .no-print, .alert { display: none !important; }
  .print-only { display: block; }
  .content { padding: 0; max-width: none; }
  .card, .kpi { box-shadow: none; border: 1px solid var(--line); break-inside: avoid; }
  .kpi.accent { background: #fff; color: var(--ink); }
  .kpi.accent .label, .kpi.accent .hint { color: var(--ink-2); }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .g2, .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-box { height: 220px; }
  a { color: var(--ink); }
}
