:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #18152d;
  background: #f5f6fb;
  font-synthesis: none;
  --purple: #1d1934;
  --purple-2: #2a2448;
  --yellow: #ffc629;
  --border: #dde2ee;
  --muted: #6b7280;
  --danger: #dc2626;
  --success: #15803d;
  --surface: #ffffff;
  --shadow: 0 12px 32px rgba(29, 25, 52, 0.08);
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.app-loading, .setup-error { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #e5e7eb; border-top-color: var(--yellow); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; background: var(--purple); }
.login-hero { padding: 72px; color: white; display: flex; flex-direction: column; justify-content: center; background: radial-gradient(circle at 20% 20%, #403765, var(--purple) 55%); }
.brand-mark { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; background: var(--yellow); color: var(--purple); font-size: 28px; box-shadow: 0 16px 30px rgba(255,198,41,.2); }
.login-hero h1 { font-size: clamp(38px, 6vw, 72px); margin: 24px 0 12px; letter-spacing: -.04em; }
.login-hero p { color: #d7d2ea; max-width: 560px; font-size: 18px; line-height: 1.6; }
.login-panel { background: #f8f9fd; display: grid; place-items: center; padding: 32px; }
.login-card { width: min(430px, 100%); background: white; border-radius: 24px; padding: 36px; box-shadow: var(--shadow); }
.login-card h2 { margin: 0 0 8px; font-size: 28px; }
.login-card p { margin: 0 0 28px; color: var(--muted); }
.field { display: grid; gap: 7px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 700; color: #34304b; }
.input, .select, .textarea { width: 100%; border: 1px solid var(--border); border-radius: 11px; padding: 12px 13px; background: white; color: #18152d; outline: none; transition: .2s; }
.input:focus, .select:focus, .textarea:focus { border-color: #9f8eed; box-shadow: 0 0 0 4px rgba(117,91,220,.1); }
.input.invalid { border-color: #ef4444; }
.error-text { color: var(--danger); font-size: 12px; }
.btn { border: 0; border-radius: 11px; min-height: 42px; padding: 0 16px; font-weight: 750; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-primary { background: var(--yellow); color: #17132a; box-shadow: 0 8px 20px rgba(255,198,41,.25); }
.btn-primary:hover { filter: brightness(.98); transform: translateY(-1px); }
.btn-secondary { background: white; color: var(--purple); border: 1px solid var(--border); }
.btn-danger { background: #fee2e2; color: #991b1b; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.text-button { border: 0; background: transparent; color: #6552c5; padding: 6px; font-weight: 700; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar { background: var(--purple); color: white; padding: 18px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 10px 8px 26px; }
.sidebar-brand .brand-mark { width: 42px; height: 42px; border-radius: 12px; font-size: 20px; }
.sidebar-brand strong { display: block; }
.sidebar-brand small { color: #aaa3c1; }
.nav-title { color: #8e87a7; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; padding: 12px 10px 8px; }
.nav-item { border: 0; color: #d5d1e1; background: transparent; width: 100%; display: flex; align-items: center; gap: 11px; padding: 12px; border-radius: 10px; text-align: left; margin: 2px 0; }
.nav-item.active { background: rgba(255,198,41,.14); color: white; box-shadow: inset 3px 0 var(--yellow); }
.sidebar-footer { margin-top: auto; border-radius: 12px; background: #2a2544; padding: 12px; color: #c8c3d8; font-size: 12px; }
.main { min-width: 0; }
.topbar { height: 72px; background: white; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 10; }
.topbar-title h1 { margin: 0; font-size: 24px; }
.topbar-title p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.user-menu { display: flex; align-items: center; gap: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: #fff4c2; color: var(--purple); display: grid; place-items: center; font-weight: 800; }
.content { padding: 24px; }
.page-actions { display: flex; gap: 10px; justify-content: flex-end; margin-bottom: 16px; flex-wrap: wrap; }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-bottom: 14px; }
.filters { background: white; border: 1px solid var(--border); border-radius: 16px; padding: 16px; display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; box-shadow: var(--shadow); }
.table-card { background: white; border: 1px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.table-meta { padding: 15px 16px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1250px; }
th { background: #f8f9fc; text-align: left; color: #3e3854; font-size: 11px; text-transform: uppercase; letter-spacing: .035em; padding: 12px 14px; border-bottom: 1px solid var(--border); }
td { padding: 13px 14px; border-bottom: 1px solid #eef1f6; font-size: 13px; vertical-align: middle; }
tr:hover td { background: #fcfcfe; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.badge.saved, .badge.generated { background: #e0f2fe; color: #075985; }
.badge.awaiting_review, .badge.awaiting_signature { background: #fff7d6; color: #854d0e; }
.badge.signed { background: #dcfce7; color: #166534; }
.badge.error, .badge.refused { background: #fee2e2; color: #991b1b; }
.badge.draft, .badge.pending_data { background: #f1f5f9; color: #475569; }
.actions { display: flex; gap: 7px; }
.icon-btn { border: 1px solid var(--border); background: white; min-width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; }
.pagination { padding: 14px 16px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.empty { padding: 70px 20px; text-align: center; color: var(--muted); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 12, 28, .55); z-index: 100; display: grid; place-items: center; padding: 18px; }
.modal { width: min(1050px, 100%); max-height: 94vh; overflow: auto; background: white; border-radius: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: white; z-index: 2; display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { margin: 0; }
.modal-body { padding: 24px; }
.form-section { border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 18px; }
.form-section h3 { margin: 0 0 15px; font-size: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; }
.lookup-note { min-height: 28px; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.review-card { background: #fafafe; border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.review-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.review-item small { color: var(--muted); display: block; margin-bottom: 4px; }
.modal-footer { padding: 18px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; background: white; }
.toast-container { position: fixed; top: 86px; right: 20px; z-index: 200; display: grid; gap: 10px; }
.toast { min-width: 300px; max-width: 430px; padding: 13px 15px; border-radius: 12px; background: #1d1934; color: white; box-shadow: var(--shadow); }
.toast.error { background: #991b1b; }
.toast.success { background: #166534; }
.setup-card { max-width: 700px; background: white; border-radius: 20px; padding: 28px; box-shadow: var(--shadow); }
.setup-card code { background: #f1f5f9; padding: 2px 6px; border-radius: 5px; }
@media (max-width: 980px) {
  .login-page { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .app-shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar-brand div, .nav-item span, .nav-title, .sidebar-footer { display: none; }
  .sidebar { align-items: center; }
  .nav-item { justify-content: center; }
  .filters { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .col-3, .col-4 { grid-column: span 2; }
}
@media (max-width: 640px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .topbar { padding: 0 14px; }
  .content { padding: 14px; }
  .filters, .form-grid, .review-grid { grid-template-columns: 1fr; }
  .col-2, .col-3, .col-4 { grid-column: span 1; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { border-radius: 18px 18px 0 0; max-height: 96vh; }
  .user-menu .user-details { display: none; }
}

/* Etapa 2 — revisão e versionamento documental */
.btn-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.btn-success:hover { background: #bbf7d0; }
.muted-note { color: var(--muted); margin: 16px 0 0; line-height: 1.55; }
.warning-box, .success-box { border-radius: 12px; padding: 13px 15px; margin-bottom: 16px; line-height: 1.5; }
.warning-box { background: #fff7d6; border: 1px solid #fde68a; color: #854d0e; }
.success-box { background: #dcfce7; border: 1px solid #bbf7d0; color: #166534; }
.badge.review_approved, .badge.ready_to_send { background: #dcfce7; color: #166534; }
.badge.review_rejected { background: #fee2e2; color: #991b1b; }
.badge.superseded, .badge.outdated { background: #f1f5f9; color: #475569; }
.badge.generating { background: #ede9fe; color: #5b21b6; }
.spinner.small { width: 18px; height: 18px; border-width: 2px; }
.details-modal { width: min(1180px, 100%); }
.details-body { display: grid; gap: 18px; background: #f8f9fd; }
.details-hero { background: white; border: 1px solid var(--border); border-radius: 16px; padding: 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.details-hero h3 { margin: 12px 0 4px; }
.details-hero p { margin: 0; color: var(--muted); }
.details-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.detail-section { background: white; border: 1px solid var(--border); border-radius: 16px; padding: 18px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 16px; }
.section-heading h3 { margin: 0; font-size: 17px; }
.section-heading span { color: var(--muted); font-size: 12px; }
.empty-section { text-align: center; color: var(--muted); padding: 28px; }
.empty-section h3 { color: var(--purple); }
.review-panel { border-color: #facc15; box-shadow: 0 0 0 3px rgba(250,204,21,.09); }
.review-status.approved { border-color: #86efac; }
.review-status.rejected { border-color: #fca5a5; }
.review-observation { background: #f8fafc; border-left: 3px solid var(--purple); padding: 10px 12px; border-radius: 6px; }
.hash-line { color: var(--muted); font-size: 12px; }
.hash-line code, .version-meta code { background: #f1f5f9; padding: 2px 6px; border-radius: 5px; }
.review-controls { display: grid; gap: 15px; }
.declaration { display: flex; align-items: flex-start; gap: 10px; background: #fffdf0; border: 1px solid #fde68a; border-radius: 12px; padding: 14px; font-weight: 650; line-height: 1.45; }
.declaration input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--purple); }
.review-buttons { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.version-list { display: grid; gap: 10px; }
.version-item { display: grid; grid-template-columns: 58px minmax(0,1fr) auto; align-items: center; gap: 14px; border: 1px solid var(--border); border-radius: 13px; padding: 13px; background: #fcfcfe; }
.version-item.current { border-color: #d8b400; background: #fffdf3; }
.version-number { width: 48px; height: 48px; border-radius: 12px; background: var(--purple); color: white; display: grid; place-items: center; font-weight: 850; }
.version-title { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.version-meta { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin-top: 7px; }
.version-review { margin-top: 8px; font-size: 12px; color: #166534; }
.version-review.invalidated { color: #991b1b; }
.version-actions { display: flex; gap: 8px; }
.timeline { position: relative; display: grid; gap: 0; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 8px; bottom: 8px; width: 2px; background: #e5e7eb; }
.timeline-item { position: relative; display: grid; grid-template-columns: 20px 1fr; gap: 10px; padding: 8px 0; }
.timeline-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--yellow); border: 4px solid #fff7d6; z-index: 1; margin-top: 2px; }
.timeline-item strong { font-size: 13px; }
.timeline-item p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

@media (max-width: 760px) {
  .details-hero, .section-heading { align-items: flex-start; flex-direction: column; }
  .details-actions, .review-buttons { width: 100%; }
  .details-actions .btn, .review-buttons .btn { flex: 1; }
  .version-item { grid-template-columns: 48px minmax(0,1fr); }
  .version-actions { grid-column: 1 / -1; }
  .version-actions .btn { width: 100%; }
}
