:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #667085;
  --border: #dfe5ef;
  --primary: #0f766e;
  --primary-hover: #0d625c;
  --danger: #dc2626;
  --warning: #f59e0b;
  --success: #16a34a;
  --shadow: 0 12px 35px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.header img { height: 42px; }
.header-actions { display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 14px; }

.container { max-width: 1180px; margin: 28px auto; padding: 0 18px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.card + .card { margin-top: 18px; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card { max-width: 420px; width: 100%; }
.login-logo { display:block; margin: 0 auto 18px; height: 54px; }

h1, h2, h3 { margin: 0 0 14px; }
p { color: var(--muted); line-height: 1.55; }

.form-row { display: grid; gap: 8px; margin-bottom: 14px; }
label { font-weight: 650; font-size: 14px; }
input[type="text"], input[type="email"], input[type="password"], input[type="file"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  font-size: 15px;
}
input:focus { outline: 3px solid rgba(15, 118, 110, 0.15); border-color: var(--primary); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn.secondary { background: #e8eef7; color: #1f2937; }
.btn.secondary:hover { background: #dce5f2; }
.btn.danger { background: var(--danger); }
.btn.warning { background: var(--warning); color: #111827; }
.btn.small { padding: 8px 10px; border-radius: 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.alert { padding: 13px 15px; border-radius: 12px; margin-bottom: 14px; }
.alert.error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert.info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert.warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert.success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.stats { display: flex; flex-wrap: wrap; gap: 10px; }
.stat {
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
}
.stat strong { color: var(--text); }

.table { width: 100%; border-collapse: collapse; overflow: hidden; }
.table th, .table td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { color: #475467; font-size: 13px; background: #f8fafc; }
.table td { font-size: 14px; }
.table .actions { display:flex; gap:8px; flex-wrap:wrap; }

.badge { display:inline-flex; padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.done { background:#dcfce7; color:#166534; }
.badge.processing { background:#fef3c7; color:#92400e; }
.badge.error { background:#fee2e2; color:#991b1b; }
.badge.pending { background:#e0f2fe; color:#075985; }

.upload-zone {
  border: 2px dashed #b8c3d6;
  border-radius: 18px;
  background: #fbfdff;
  padding: 20px;
}

.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.page-card {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.page-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(15,23,42,.08); }
.page-card.aso { border-color: var(--success); background: #f0fdf4; }
.page-card.removed { border-color: var(--danger); background: #fff1f2; opacity: .62; }
.page-card canvas { width: 100%; display:block; background: #f1f5f9; }
.page-meta {
  padding: 9px 10px;
  display:flex;
  justify-content: space-between;
  align-items:center;
  gap: 8px;
  font-size: 13px;
}
.page-status { font-weight: 800; }
.page-card.aso .page-status { color: var(--success); }
.page-card.removed .page-status { color: var(--danger); }
.page-num {
  position:absolute; top:8px; left:8px;
  background: rgba(15,23,42,.80); color:#fff;
  padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
}

.progress-wrap { display:none; margin-top: 16px; }
.progress-bar { height: 12px; background:#e5e7eb; border-radius: 999px; overflow:hidden; }
.progress-bar div { height:100%; background: var(--primary); width:0%; transition: width .2s ease; }
.progress-text { margin-top:8px; color: var(--muted); font-size: 14px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal.open { display:flex; }
.modal-content {
  max-width: 92vw;
  max-height: 92vh;
  background:#fff;
  border-radius: 18px;
  padding: 16px;
  overflow:auto;
}
.modal-head { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:12px; }
.preview-canvas { max-width: 100%; height:auto; border:1px solid var(--border); border-radius: 12px; }

.footer-note { color: var(--muted); font-size: 13px; margin-top: 16px; }
.empty { text-align:center; padding: 42px 20px; color: var(--muted); }

@media (max-width: 700px) {
  .header { padding: 12px 16px; }
  .table { display:block; overflow-x:auto; }
  .toolbar { align-items:flex-start; }
}

.wide-container { max-width: 1500px; }
.table-scroll { width: 100%; overflow-x: auto; }
.meta-table { min-width: 1380px; }
.table-input, select.table-input {
  width: 100%;
  min-width: 90px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 9px;
  background: #fff;
  font-size: 13px;
}
.name-input { min-width: 170px; }
.cpf-input { min-width: 116px; }
.cnpj-input { min-width: 142px; }
.type-input { min-width: 140px; }
.small-input { min-width: 74px; text-align: center; }
.tiny-input { min-width: 58px; text-align: center; }
.meta-table code { white-space: nowrap; }


.form-grid.two-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 14px;
}
.checkline {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.checkline input { margin-top: 2px; }
.ocr-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
@media (max-width: 720px) {
  .form-grid.two-cols { grid-template-columns: 1fr; }
}

/* Revisão dos exames - layout amplo para dados do ASO */
.review-table { min-width: 1180px; }
.review-table th,
.review-table td { vertical-align: middle; }
.review-table .exam-col { width: 84px; }
.review-table .type-col { width: 160px; }
.review-table .period-col { width: 112px; }
.review-table .pages-col { width: 78px; text-align: center; }
.review-table .actions-col { width: 118px; }
.review-table .download-col { width: 210px; }

.aso-data-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.15fr) minmax(220px, 1fr);
  gap: 10px 14px;
  min-width: 480px;
}
.aso-data-grid label {
  display: grid;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.aso-data-grid .table-input {
  min-width: 0;
  width: 100%;
  padding: 10px 11px;
  font-size: 14px;
  border-radius: 12px;
  color: var(--text);
  text-transform: uppercase;
}
.review-table .type-input {
  min-width: 150px;
  padding: 10px 11px;
  font-size: 14px;
  border-radius: 12px;
}
.period-input {
  width: 92px !important;
  min-width: 92px !important;
  text-align: center;
  font-weight: 700;
  padding: 10px 8px;
  font-size: 14px;
  border-radius: 12px;
}
.period-col small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}
.review-table .actions {
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
}
.review-table .actions .btn { width: 100%; }
.review-table code {
  display: inline-block;
  max-width: 210px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
}

@media (max-width: 900px) {
  .aso-data-grid { grid-template-columns: 1fr; min-width: 280px; }
  .review-table { min-width: 980px; }
}
.input-error{border-color:#ef4444!important;background:#fff1f2!important}


/* v36: revisão somente CPF/CNPJ */
.docs-grid { display:grid; grid-template-columns:minmax(220px, 280px) minmax(240px, 320px); gap:12px 16px; align-items:end; }
.docs-grid label { display:flex; flex-direction:column; gap:6px; }
.docs-grid label span { font-size:12px; text-transform:uppercase; color:#5a6b85; font-weight:700; letter-spacing:.02em; }
.compact-review-table .docs-col { min-width: 340px; }
@media (max-width: 900px){ .docs-grid{grid-template-columns:1fr;} }


/* v37: CPF e CNPJ lado a lado para poupar espaço */
.compact-review-table { min-width: 1260px; }
.compact-review-table .docs-col { width: 520px !important; min-width: 520px !important; }
.docs-grid { display:flex !important; flex-direction:row !important; flex-wrap:nowrap !important; gap:14px !important; align-items:flex-end !important; min-width:500px; }
.docs-grid label { flex:1 1 0; min-width:0; display:flex; flex-direction:column; gap:6px; }
.docs-grid .cpf-input, .docs-grid .cnpj-input { width:100%; min-width:0; }
@media (max-width: 900px){ .docs-grid{flex-wrap:wrap !important; min-width:0;} .docs-grid label{flex:1 1 220px;} }


/* v38: CPF e CNPJ lado a lado, sem depender de cache antigo */
.compact-review-table{min-width:1180px !important;}
.compact-review-table .docs-col{width:560px !important; min-width:560px !important;}
.compact-review-table .docs-grid{display:flex !important; flex-direction:row !important; flex-wrap:nowrap !important; gap:14px !important; align-items:flex-end !important; min-width:520px !important;}
.compact-review-table .docs-grid label{display:flex !important; flex-direction:column !important; gap:6px !important; flex:1 1 0 !important; min-width:0 !important;}
.compact-review-table .docs-grid .table-input{width:100% !important; min-width:0 !important;}
.compact-review-table .docs-grid span{font-size:12px; text-transform:uppercase; color:#5a6b85; font-weight:700; letter-spacing:.02em;}
@media (max-width:900px){.compact-review-table .docs-grid{flex-wrap:wrap !important; min-width:0 !important}.compact-review-table .docs-grid label{min-width:220px !important}}
