:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #18202b;
  --muted: #5d6877;
  --line: #dfe3e8;
  --brand: #1f4fd1;
  --brand-ink: #ffffff;
  --brand-soft: #e8eefc;
  --ok: #157347;
  --ok-soft: #e3f4ea;
  --warn: #9a6200;
  --warn-soft: #fdf2dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* Topo */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top .in { max-width: 1400px; margin: 0 auto; padding: 0 20px; height: 56px; display: flex; align-items: center; gap: 24px; }
.brand { font-weight: 700; font-size: 15px; color: var(--ink); display: flex; gap: 8px; align-items: center; }
.brand b { background: var(--brand); color: #fff; border-radius: 6px; padding: 2px 7px; font-size: 13px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); padding: 8px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
.nav a.on { background: var(--brand-soft); color: var(--brand); }
.user { color: var(--muted); font-size: 13px; display: flex; gap: 12px; align-items: center; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

/* Botões e campos */
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[readonly], input:disabled, select:disabled, textarea:disabled { background: var(--bg); color: var(--muted); }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; min-width: 0; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.row.c2 { grid-template-columns: 1fr 1fr; }
.row.c3 { grid-template-columns: repeat(3, 1fr); }
.inline { display: flex; gap: 8px; align-items: flex-end; }
.inline > .grow { flex: 1; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; font-weight: 500; color: var(--ink); margin: 0; cursor: pointer; }
.check input { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 14px; font: inherit; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--brand); color: #fff; }
.radios { display: grid; gap: 6px; }
.radios label { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; color: var(--ink); font-size: 14px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; margin: 0; }
.radios label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.radios input { width: auto; margin-top: 3px; }
.radios small { display: block; color: var(--muted); font-weight: 400; }

/* Cartões */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card h2 { display: flex; align-items: center; gap: 8px; }
.card h2 .n { background: var(--brand-soft); color: var(--brand); width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; }
.sub { border: 1px dashed var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow); }
.kpi:hover { border-color: var(--brand); }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 2px; }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

/* Tabelas */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { max-width: 280px; }
.filters select { width: auto; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.rascunho { background: #eef0f3; color: #4a5565; }
.badge.enviado { background: var(--warn-soft); color: var(--warn); }
.badge.assinado { background: var(--ok-soft); color: var(--ok); }
.badge.vencendo { background: var(--warn-soft); color: var(--warn); }
.badge.vencido, .badge.recusado, .badge.cancelado { background: var(--bad-soft); color: var(--bad); }
.badge.encerrado { background: #eef0f3; color: #4a5565; }

.alert { border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 13px; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--brand-soft); color: #173b9c; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* Editor */
.editor { display: grid; grid-template-columns: minmax(380px, 520px) 1fr; gap: 20px; align-items: start; }
.preview-col { position: sticky; top: 76px; }
.preview-tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }
.paper { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: calc(100vh - 160px); overflow: auto; }
.cron { width: 100%; border-collapse: collapse; font-size: 13px; }
.cron td, .cron th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.cron .num { text-align: right; }
.cron tfoot td { font-weight: 700; border-bottom: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip { background: var(--brand-soft); color: var(--brand); border: 0; border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); margin-top: 16px; z-index: 5; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.sig-list { list-style: none; padding: 0; margin: 0; }
.sig-list li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 90vw; }
.toast.bad { background: var(--bad); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }

@media (max-width: 1000px) {
  .editor { grid-template-columns: 1fr; }
  .preview-col { position: static; }
  .paper { max-height: none; }
}
@media (max-width: 640px) {
  .top .in { gap: 10px; padding: 0 12px; overflow-x: auto; }
  .user span { display: none; }
  .wrap { padding: 16px 12px 60px; }
  .row.c2, .row.c3 { grid-template-columns: 1fr; }
}
table.list th.num, table.list td.num { text-align: right; }
