:root {
  --green-900: #14532d;
  --green-700: #15803d;
  --green-50: #f0fdf4;
  --amber-100: #fef3c7;
  --amber-800: #92400e;
  --red-600: #dc2626;
  --red-50: #fef2f2;
  --bg: #f4f5f2;
  --card: #fff;
  --ink: #1c1f1d;
  --muted: #5f6762;
  --line: #dfe2dc;
  --radius: 10px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  font-size: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.25; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- barra superior ---------- */
.topbar { background: var(--green-900); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-in { max-width: 1100px; margin: 0 auto; padding: .5rem 1rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.05rem; margin-right: auto; }
.nav { display: flex; gap: .25rem; overflow-x: auto; }
.nav a { color: #d7eadd; text-decoration: none; padding: .5rem .75rem; border-radius: 8px; white-space: nowrap; }
.nav a:hover { background: rgba(255,255,255,.12); }
.nav a.active { background: #fff; color: var(--green-900); font-weight: 600; }
.main { max-width: 1100px; margin: 0 auto; padding: 1rem; }

/* ---------- componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card.editing { border-color: var(--green-700); box-shadow: 0 0 0 2px #bbf7d0; }
.grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field .label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field .hint { font-size: .8rem; color: var(--muted); }
input, select, textarea {
  font: inherit; padding: .6rem .65rem; border: 1px solid #bfc5bb; border-radius: 8px; background: #fff; width: 100%; min-height: 44px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible { outline: 3px solid #86efac; outline-offset: 1px; border-color: var(--green-700); }
.btn {
  font: inherit; font-weight: 600; padding: .6rem 1rem; border-radius: 8px; border: 1px solid #bfc5bb; background: #fff; color: var(--ink);
  cursor: pointer; min-height: 44px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
.btn:hover { background: #f1f3ef; }
.btn.primary { background: var(--green-700); border-color: var(--green-700); color: #fff; }
.btn.primary:hover { background: var(--green-900); }
.btn.danger { background: var(--red-600); border-color: var(--red-600); color: #fff; }
.btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.seg { display: inline-flex; border: 1px solid #bfc5bb; border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; border: 0; background: #fff; padding: .6rem 1.2rem; cursor: pointer; min-height: 44px; font-weight: 600; }
.seg button + button { border-left: 1px solid #bfc5bb; }
.seg button.on { background: var(--green-700); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { font: inherit; border: 1px solid #bfc5bb; background: #fff; border-radius: 999px; padding: .4rem .8rem; cursor: pointer; min-height: 40px; }
.chip.on { background: var(--green-50); border-color: var(--green-700); color: var(--green-900); font-weight: 600; }
.preview { background: var(--green-50); border: 1px solid #bbf7d0; border-radius: 8px; padding: .6rem .8rem; margin-top: .75rem; }
.preview.warn { background: var(--amber-100); border-color: #fcd34d; color: var(--amber-800); }
.banner { background: var(--amber-100); color: var(--amber-800); border: 1px solid #fcd34d; border-radius: 8px; padding: .6rem .8rem; margin-bottom: .75rem; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e5e7e3; color: #374039; }
.badge.closed { background: #dcfce7; color: var(--green-900); }
.badge.open { background: var(--amber-100); color: var(--amber-800); }
.badge.prod { background: #e0e7ff; color: #3730a3; }
.stats { display: flex; gap: 1.5rem; flex-wrap: wrap; margin: .25rem 0 .75rem; }
.stat b { display: block; font-size: 1.25rem; }
.stat span { font-size: .8rem; color: var(--muted); }

/* ---------- tabelas ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem 0; }
@media (max-width: 720px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td, table.stack tfoot { display: block; }
  table.stack tr { border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; margin-bottom: .6rem; background: #fff; }
  table.stack td { border: 0; padding: .2rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  table.stack td::before { content: attr(data-label); font-size: .8rem; color: var(--muted); text-align: left; flex: none; }
  table.stack td.actions { justify-content: flex-end; }
  table.stack td.actions::before { content: none; }
  table.stack tfoot tr { background: var(--green-50); }
}

/* ---------- fechamento ---------- */
.period-cell { min-width: 230px; }
.period-cell .total { font-weight: 700; font-size: 1.05rem; }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 12vh auto; padding: 0 1rem; }
.login .card { padding: 1.5rem; }
.error-text { color: var(--red-600); margin: .5rem 0 0; }

/* ---------- diálogos e avisos ---------- */
dialog.modal { border: 0; border-radius: var(--radius); padding: 1.25rem; width: min(480px, calc(100vw - 2rem)); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog.modal::backdrop { background: rgba(0,0,0,.45); }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.modal dl { display: grid; grid-template-columns: auto 1fr; gap: .25rem 1rem; margin: .75rem 0; }
.modal dt { color: var(--muted); } .modal dd { margin: 0; font-weight: 600; text-align: right; }
#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 100; width: min(460px, calc(100vw - 2rem)); }
.toast { background: var(--green-900); color: #fff; padding: .75rem 1rem; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast.error { background: var(--red-600); }

/* ---------- relatório / impressão ---------- */
.report { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.report h1 { font-size: 1.3rem; margin-bottom: .1rem; }
.report .meta { display: flex; gap: 2rem; flex-wrap: wrap; margin: .75rem 0 1rem; }
.report .meta div span { display: block; font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.report h3.company { margin: 1.2rem 0 .3rem; padding-bottom: .2rem; border-bottom: 2px solid var(--green-700); }
.report .grand { margin-top: 1.2rem; border: 2px solid var(--ink); border-radius: 8px; padding: .6rem 1rem; display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; font-weight: 700; }
.report .foot { margin-top: 1rem; font-size: .8rem; color: var(--muted); }
@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  .topbar, .no-print, #toasts { display: none !important; }
  .main { max-width: none; padding: 0; }
  .report { border: 0; padding: 0; }
  table.stack { display: table !important; }
  table.stack thead { display: table-header-group !important; }
  table.stack tbody { display: table-row-group !important; }
  table.stack tfoot { display: table-footer-group !important; }
  table.stack tr { display: table-row !important; border: 0 !important; padding: 0 !important; margin: 0 !important; }
  table.stack td { display: table-cell !important; text-align: left; padding: .3rem .4rem !important; border-bottom: 1px solid #ccc !important; font-size: 10pt; }
  table.stack td.num { text-align: right; }
  table.stack td::before { content: none !important; }
  tr { break-inside: avoid; }
}
