:root {
  --ink: #16232E;
  --ink-soft: #3A4756;
  --paper: #EDEFEA;
  --paper-raised: #FFFFFF;
  --line: #D8DBD3;
  --teal: #1F7A6C;
  --teal-bg: #E4F0EC;
  --amber: #A6721F;
  --amber-bg: #F5ECDC;
  --slate: #3557A6;
  --slate-bg: #E7ECF6;
  --danger: #A6341F;
  --danger-bg: #F5DDD6;

  --font-display: "Source Serif 4", Georgia, serif;
  --font-body: "Inter", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", monospace;

  --radius: 3px;
  --shadow-card: 0 1px 2px rgba(22, 35, 46, 0.06), 0 1px 1px rgba(22, 35, 46, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; }

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

button {
  font-family: var(--font-body);
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--slate);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- */
/* Topbar                                                            */
/* ---------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  background: var(--ink);
  color: var(--paper);
  border-bottom: 3px solid var(--teal);
  flex-wrap: wrap;
}

.topbar__brand { display: flex; align-items: center; gap: 12px; }

.topbar__mark {
  font-family: var(--font-display);
  font-size: 28px;
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--teal);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--teal);
  flex-shrink: 0;
}

.topbar__title { font-size: 19px; color: #fff; letter-spacing: 0.2px; }
.topbar__subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: #B9C3C0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topbar__nav { display: flex; gap: 4px; flex-wrap: wrap; }

.navlink {
  color: #D7DDDA;
  text-decoration: none;
  font-size: 13.5px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 500;
}

.navlink:hover { background: rgba(255,255,255,0.06); }

.navlink.active {
  color: #fff;
  background: rgba(31, 122, 108, 0.35);
  border-color: var(--teal);
}

/* ---------------------------------------------------------------- */
/* Layout                                                             */
/* ---------------------------------------------------------------- */

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-head h2 { font-size: 24px; }
.page-head__eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 24px;
  margin-bottom: 20px;
}

.card h3 {
  font-size: 15px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.notice {
  background: var(--slate-bg);
  border: 1px solid #C5D1EA;
  border-left: 3px solid var(--slate);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--ink);
  margin-bottom: 20px;
}

.notice--danger {
  background: var(--danger-bg);
  border-color: #E4C3B9;
  border-left-color: var(--danger);
}

/* ---------------------------------------------------------------- */
/* Forms                                                              */
/* ---------------------------------------------------------------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-grid--3 { grid-template-columns: repeat(3, 1fr); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field--full { grid-column: 1 / -1; }

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field .hint { font-size: 11.5px; color: var(--ink-soft); font-weight: 400; text-transform: none; }

input, select, textarea {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

input[data-numeric], input.mono { font-family: var(--font-mono); text-align: right; }

input:invalid, .field.error input, .field.error select {
  border-color: var(--danger);
}

.field-error { color: var(--danger); font-size: 12px; margin-top: 2px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.btn {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
}

.btn:hover { background: #223141; }

.btn--ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn--ghost:hover { background: #F2F1EA; }

.btn--danger { background: var(--danger); border-color: var(--danger); }
.btn--sm { padding: 5px 10px; font-size: 12px; }

/* ---------------------------------------------------------------- */
/* Tables (estilo livro-razão: números monoespaçados à direita)      */
/* ---------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  border-bottom: 1.5px solid var(--ink);
  padding: 8px 10px;
}

thead th.num, td.num {
  text-align: right;
  font-family: var(--font-mono);
}

tbody td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  vertical-align: middle;
}

tbody tr:hover { background: #F6F5F0; }

.table-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13.5px;
}

/* ---------------------------------------------------------------- */
/* Badges & stamp (elemento de assinatura visual)                    */
/* ---------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge--ativo { background: var(--teal-bg); color: var(--teal); }
.badge--inativo { background: #E7E5DC; color: #6B6A60; }

.stamp {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--teal);
  border: 1.5px solid var(--teal);
  border-radius: 50%;
  width: 62px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transform: rotate(-8deg);
  line-height: 1.15;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------- */
/* Home                                                               */
/* ---------------------------------------------------------------- */

.home-hero {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 36px 32px;
  margin-bottom: 24px;
}

.home-hero h2 { font-size: 30px; margin-bottom: 8px; }
.home-hero p { color: var(--ink-soft); max-width: 46ch; }

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

.home-tile {
  display: block;
  text-decoration: none;
  color: var(--ink);
}

.home-tile .card { margin-bottom: 0; height: 100%; }
.home-tile h4 { font-size: 15px; margin-bottom: 6px; }
.home-tile p { font-size: 13px; color: var(--ink-soft); margin: 0; }

/* ---------------------------------------------------------------- */
/* Modal (gate de PIN admin)                                         */
/* ---------------------------------------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(22, 35, 46, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 26px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.modal h3 { margin-bottom: 6px; }
.modal p { font-size: 13px; color: var(--ink-soft); margin: 0 0 16px; }

/* ---------------------------------------------------------------- */
/* Toast                                                              */
/* ---------------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  z-index: 60;
  max-width: 340px;
}

.toast--erro { background: var(--danger); }

/* ---------------------------------------------------------------- */
/* Footer                                                             */
/* ---------------------------------------------------------------- */

.footer {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 24px 40px;
  color: var(--ink-soft);
  font-size: 12px;
}

/* ---------------------------------------------------------------- */
/* Wizard de simulação                                                */
/* ---------------------------------------------------------------- */

.wizard-steps {
  display: flex;
  align-items: flex-start;
  margin-bottom: 24px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.wizard-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--ink-soft);
  flex: 1;
  min-width: 84px;
  position: relative;
}

.wizard-step::before {
  content: "";
  position: absolute;
  top: 15px;
  left: -50%;
  width: 100%;
  height: 1.5px;
  background: var(--line);
  z-index: 0;
}

.wizard-step:first-child::before { display: none; }

.wizard-step__circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--paper-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  z-index: 1;
}

.wizard-step__label {
  font-size: 11px;
  text-align: center;
  line-height: 1.25;
  max-width: 90px;
}

.wizard-step--active .wizard-step__circle { background: var(--ink); border-color: var(--ink); color: #fff; }
.wizard-step--active .wizard-step__label { color: var(--ink); font-weight: 600; }

.wizard-step--done .wizard-step__circle { background: var(--teal-bg); border-color: var(--teal); color: var(--teal); }
.wizard-step--done::before { background: var(--teal); }

.wizard-step--disabled { cursor: not-allowed; opacity: 0.5; }
.wizard-step--disabled .wizard-step__circle { background: #F1F0EA; }

.wizard-nav-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.autosave-indicator {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--teal);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.autosave-indicator.show { opacity: 1; }

/* ---------------------------------------------------------------- */
/* Composição de vendas / categorias de compras                      */
/* ---------------------------------------------------------------- */

.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.mode-toggle button {
  border: none;
  background: #fff;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
}

.mode-toggle button.active { background: var(--ink); color: #fff; }

.composicao-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.7fr;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.composicao-row:last-of-type { border-bottom: none; }
.composicao-row__label { font-size: 13.5px; }
.composicao-row__pct { font-family: var(--font-mono); font-size: 13px; text-align: right; color: var(--ink-soft); }

.composicao-total {
  display: flex;
  justify-content: space-between;
  padding: 12px 0 0;
  margin-top: 8px;
  border-top: 1.5px solid var(--ink);
  font-weight: 600;
}

.composicao-total .num { font-family: var(--font-mono); }

.compra-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.compra-card h4 {
  font-size: 13.5px;
  margin-bottom: 10px;
  font-family: var(--font-body);
  font-weight: 600;
}

.compra-card .form-grid { grid-template-columns: 1fr 1fr 1.4fr; gap: 10px; }

.progress-warning {
  font-size: 12.5px;
  color: var(--danger);
  margin-top: 8px;
}

.progress-ok {
  font-size: 12.5px;
  color: var(--teal);
  margin-top: 8px;
}

/* ---------------------------------------------------------------- */
/* Responsive                                                         */
/* ---------------------------------------------------------------- */

@media (max-width: 720px) {
  .form-grid, .form-grid--3 { grid-template-columns: 1fr; }
  .home-hero { flex-direction: column; align-items: flex-start; }
  .topbar { padding: 12px 16px; }
  .app { padding: 20px 14px 48px; }
}

/* ---------------------------------------------------------------- */
/* Impressão do relatório                                            */
/* ---------------------------------------------------------------- */

@media print {
  .topbar, .footer, .wizard-nav-actions, .no-print { display: none !important; }
  body, .app { background: #fff; }
  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  a[href]::after { content: ""; }
  .app { max-width: 100%; padding: 0; }
}

.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Ícone de ajuda "?" ao lado dos campos (ex.: % sujeito a crédito nas Compras) */
.ajuda-credito {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px; height: 15px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--slate, #4a5b6b);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  cursor: help;
  vertical-align: middle;
  text-transform: none;
  letter-spacing: 0;
  user-select: none;
}
.ajuda-credito:hover, .ajuda-credito:focus { background: var(--ink, #1a2530); outline: none; }

.dica-box {
  position: absolute;
  z-index: 1000;
  max-width: 280px;
  background: var(--ink, #1a2530);
  color: #fff;
  font-size: 12.5px;
  line-height: 1.45;
  padding: 9px 11px;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
}
