:root {
  --brand-red: #ed1c24;
  --brand-yellow: #f5d40c;
  --action: #ba1420;
  --action-hover: #99101b;
  --ink: #242629;
  --muted: #62676c;
  --border: #dedfe2;
  --surface: #ffffff;
  --canvas: #f5f5f3;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 24px; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--action); text-decoration: underline; text-underline-offset: 3px; }
a:hover { color: var(--action-hover); }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 3px solid #8b3900; outline-offset: 3px; }

/* Cabeçalho padrão Klaus Essen */
.top {
  min-height: 92px;
  padding: 16px 4%;
  background: #191b1e;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 3px solid var(--brand-red);
}
.brand {
  display: flex;
  align-items: center;
  gap: 20px;
  color: #ffffff;
  text-decoration: none;
  min-width: 0;
}
.brand:hover { color: #ffffff; }
.brand-logo { display: block; width: 140px; height: auto; flex-shrink: 0; }
.brand-caption {
  border-left: 1px solid #ffffff35;
  padding-left: 20px;
  font-size: 15px;
  font-weight: 600;
  max-width: 280px;
}
.brand-caption small {
  display: block;
  color: #c6c8cc;
  font-size: 12px;
  font-weight: 400;
  margin-top: 2px;
}

.top nav { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.top .nav-btn {
  background: none;
  border: 0;
  border-radius: 0;
  min-height: auto;
  color: #f1f1f2;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.top .nav-btn:hover { background: none; color: var(--brand-yellow); }
.top .nav-btn.active { color: var(--brand-yellow); border-color: var(--brand-yellow); font-weight: 600; }
.identity { font-size: 13px; color: #c6c8cc; }

.quiet {
  background: none;
  color: #e2e4e7;
  padding: 8px 10px;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.quiet:hover { background: #ffffff14; color: var(--brand-yellow); }

/* Container principal */
main {
  width: 100%;
  max-width: 1450px;
  margin: 28px auto;
  padding: 0 4%;
  flex: 1;
}

h1 { font-size: 28px; line-height: 1.2; letter-spacing: -0.5px; margin: 6px 0 10px; overflow-wrap: anywhere; }
h2 { font-size: 19px; line-height: 1.4; margin: 0 0 10px; }
h3 { font-size: 16px; margin: 0 0 8px; }
p { margin: 8px 0; }

.eyebrow {
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 1.4px;
  color: var(--action);
  margin: 0;
  text-transform: uppercase;
}
.muted, .help { color: var(--muted); }
.help { font-size: 13px; margin: 6px 0 14px; }

/* Cartões */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 22px;
  min-width: 0;
}

/* Barra de etapas */
.step-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  background: var(--surface);
  padding: 14px 22px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.step-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 4px 8px;
  min-height: auto;
  font: inherit;
}
.step-item.active { color: var(--ink); font-weight: 600; }
.step-item.clickable { cursor: pointer; }
.step-item.clickable:hover { background: #f5f5f3; color: var(--action); border-radius: 6px; }
.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f0f1f3;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.step-item.active .step-num {
  background: var(--action);
  border-color: var(--action);
  color: #ffffff;
}
.step-divider { flex: 1; height: 1px; background: var(--border); margin: 0 18px; }

/* Avisos */
.notice, .error, .success { padding: 13px 16px; margin: 14px 0; border-radius: 6px; font-size: 14px; line-height: 1.45; }
.notice { background: #fff9de; border-left: 3px solid #cfad00; color: #5d532d; }
.error { background: #fff0f1; border-left: 3px solid #b72b39; color: #952530; }
.success { background: #e9f5ec; border-left: 3px solid #458456; color: #295a39; }

/* Formulários (unificados — evita qualquer campo sem estilo) */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 14px; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-group { display: flex; flex-direction: column; min-width: 0; }
.form-group.span-2 { grid-column: span 2; }

label { display: block; font-size: 13px; font-weight: 600; color: #484d53; margin-bottom: 6px; }

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select,
textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid #bfc3c8;
  border-radius: 6px;
  background: #ffffff;
  padding: 9px 12px;
  font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--action);
  outline-offset: 1px;
}

input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--action); cursor: pointer; }

.model-select-row { display: flex; gap: 8px; align-items: stretch; }
.model-select-row select { flex: 1; min-width: 0; }
.model-select-row button { flex-shrink: 0; min-height: 42px; }
#inp-openai-model-custom { margin-top: 8px; }

/* Botões */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--action);
  color: #ffffff;
  padding: 9px 16px;
  cursor: pointer;
  font: 600 14px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  text-decoration: none;
}
button:hover:not(:disabled), .button:hover { background: var(--action-hover); color: #ffffff; text-decoration: none; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary { background: #f3f3f4; color: #30343a; border-color: #d5d8dc; }
.secondary:hover:not(:disabled) { background: #e7e9ec; color: var(--ink); }

.btn-good { background: #2d6841; color: #ffffff; }
.btn-good:hover:not(:disabled) { background: #235233; }

.btn-danger-outline { background: #fff0f1; color: #952530; border-color: #f0c2c6; }
.btn-danger-outline:hover:not(:disabled) { background: #fde2e4; color: #7f1d27; }

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.full { width: 100%; margin-top: 8px; }

.action-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 18px; }
.align-right { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.space-top { margin-top: 22px; }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* Dropzone */
.dropzone {
  border: 2px dashed #c6c9ce;
  border-radius: 8px;
  padding: 36px 20px;
  text-align: center;
  background: #fafaf8;
  cursor: pointer;
  margin-top: 10px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--action);
  background: #fff5f5;
}
.dropzone-icon { color: var(--action); margin-bottom: 10px; }
.dropzone h3 { font-size: 16px; margin-bottom: 4px; }
.dropzone p { color: var(--muted); font-size: 14px; margin: 4px 0 8px; }
.btn-text {
  background: none;
  border: 0;
  padding: 0;
  min-height: auto;
  color: var(--action);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}
.btn-text:hover { background: none; color: var(--action-hover); }
.file-hint { display: block; font-size: 12px; color: var(--muted); }

.file-list { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fafaf8;
  padding: 9px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 14px;
  gap: 12px;
}
.file-name { font-weight: 600; overflow-wrap: anywhere; }
.file-size { color: var(--muted); font-size: 12px; margin-left: 8px; white-space: nowrap; }
.file-remove {
  background: none; border: 0; min-height: auto; padding: 4px 8px; flex-shrink: 0;
  color: #952530; cursor: pointer; font-size: 13px; font-weight: 600;
}
.file-remove:hover { background: #fff0f1; color: #7f1d27; }

/* Cabeçalho do resultado & Stats */
.heading { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 16px; margin-bottom: 18px; }
.resumo-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.code-badge {
  display: inline-block;
  font-size: 12px;
  background: #eeeef0;
  color: #474b50;
  padding: 3px 9px;
  border-radius: 5px;
  font-weight: 700;
  margin-left: 8px;
  vertical-align: middle;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0 18px;
}
.stat-card {
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  min-width: 0;
}
.stat-card span { display: block; font-size: 13px; color: var(--muted); }
.stat-card strong { display: block; font-size: 26px; line-height: 1.15; font-weight: 650; margin-top: 4px; color: var(--ink); }
.stat-card small { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; min-height: 16px; }
.stat-card.good strong { color: #2d6841; }
.stat-card.warn strong { color: #76500f; }
.stat-card.danger strong { color: #a12531; }

/* Toolbar e filtros */
.cae-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filter-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-pill {
  background: #f3f3f4;
  border: 1px solid #d5d8dc;
  color: #30343a;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.filter-pill:hover { background: #e7e9ec; color: var(--ink); }
.filter-pill.active { background: var(--ink); border-color: var(--ink); color: #ffffff; }
.cae-search-wrap { min-width: 260px; flex: 1; max-width: 340px; }

/* Tabela principal de análise */
.table-wrap {
  overflow: auto;
  max-height: 74vh;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.cae-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 1120px;
}
.cae-table col.cg-it { width: 56px; }
.cae-table col.cg-perg { width: 220px; }
.cae-table col.cg-ia { width: 76px; }
.cae-table col.cg-pag { width: 86px; }
.cae-table col.cg-ke { width: 84px; }
.cae-table col.cg-sim { width: 36px; }
.cae-table col.cg-com { width: auto; }

.cae-table thead tr:first-child th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 36px;
}
.cae-table thead tr:nth-child(2) th {
  position: sticky;
  top: 36px;
  z-index: 2;
}
.cae-table th {
  padding: 6px 4px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid var(--border);
  text-align: center;
  background: #f6f6f5;
  color: #30343a;
}
.cae-table th.grp-ia { background: #eef3fa; color: #1e3a5f; }
.cae-table th.grp-ke { background: #e9f5ec; color: #295a39; }
.cae-table th.grp-sim { background: #f3effa; color: #4a3b69; }
.cae-table th.sub-ia, .cae-table th.sub-ke, .cae-table th.sub-sim {
  font-size: 10.5px;
  line-height: 1.2;
  padding: 5px 3px;
  background: #f9f9f8;
  color: var(--muted);
}
.cae-table th.col-perg, .cae-table th.col-com { text-align: left; padding-left: 8px; }

.cae-table td {
  padding: 10px 6px;
  border: 1px solid #ececef;
  vertical-align: top;
  overflow-wrap: break-word;
}
.cae-table tbody tr:hover { background: #fcfbf6; }
.cae-table tbody tr.row-divergente { background: #fff0f1; }

.cell-center { text-align: center; }
.it-num { font-weight: 700; color: var(--ink); font-size: 14px; }
.tipo-chip {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.tipo-chip.resp { background: #eef3fa; color: #1e3a5f; }
.tipo-chip.qual { background: #f3effa; color: #4a3b69; }

.mark-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 3px 8px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 12px;
}
.mark-x { background: #e4f3e9; color: #2d643f; border: 1px solid #b5dec2; }
.mark-na { background: #fff0d5; color: #76500f; border: 1px solid #ebd09b; }
.mark-empty { color: #8c9197; font-size: 13px; }

.ke-toggle-group {
  display: inline-flex;
  flex-shrink: 0;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid #cfd3d8;
  background: #ffffff;
}
.ke-btn {
  background: transparent;
  border: 0;
  border-radius: 0;
  min-height: 26px;
  color: var(--muted);
  padding: 3px 5px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.ke-btn:hover { background: #f3f3f4; color: var(--ink); }
.ke-btn.active-empty { background: #e9eaed; color: var(--ink); }
.ke-btn.active-x { background: #e4f3e9; color: #2d643f; }
.ke-btn.active-na { background: #fff0d5; color: #76500f; }

.sim-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 11.5px;
}
.sim-1 { background: #e4f3e9; color: #2d643f; }
.sim-0 { background: #fce8eb; color: #9b2734; }
.sim-muted { background: #f1f2f4; color: #8c9197; }

.pag-badge {
  display: inline-block;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 5px;
  background: #eef3fa;
  color: #1e3a5f;
  font-size: 12px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.comentario-wrap { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.comentario-texto { font-size: 13.5px; line-height: 1.45; color: var(--ink); white-space: pre-wrap; overflow-wrap: break-word; }
.comentario-na { color: #76500f; font-style: italic; }
.evidencia-box {
  border-left: 3px solid #cfd3d8;
  background: #f8f8f7;
  padding: 7px 10px;
  border-radius: 0 5px 5px 0;
  font-size: 12.5px;
  color: #484d53;
  font-style: italic;
  line-height: 1.4;
  overflow-wrap: break-word;
}
.evid-status-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge { border-radius: 5px; background: #eeeef0; color: #474b50; padding: 3px 8px; font-size: 11px; font-weight: 600; }
.badge.good { background: #e4f3e9; color: #2d643f; }
.badge.warn { background: #fff0d5; color: #76500f; }
.badge.danger { background: #fce8eb; color: #9b2734; }

.btn-link-sm {
  background: none; border: 0; min-height: auto; padding: 0;
  color: var(--action); font-size: 12px; font-weight: 600;
  cursor: pointer; text-decoration: underline;
}
.btn-link-sm:hover { background: none; color: var(--action-hover); }
.comentario-editor { min-height: 68px; font-size: 13px; resize: vertical; }

/* Barra pegajosa de salvamento */
.save-bar {
  position: sticky;
  bottom: 12px;
  z-index: 10;
  background: #fff9de;
  border: 1px solid #e6d37d;
  padding: 12px 18px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  box-shadow: 0 4px 16px rgba(36, 38, 41, 0.12);
}
.save-bar span { font-size: 13.5px; font-weight: 600; color: #5d532d; }

details { margin: 16px 0; }
summary { cursor: pointer; color: var(--action); font-weight: 600; padding: 4px 0; }
summary:hover { text-decoration: underline; }
.tech-details {
  background: #fafaf8;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
}
.tech-details-body { margin-top: 10px; font-size: 13.5px; color: var(--muted); line-height: 1.5; }

/* Histórico */
.search-row { display: flex; align-items: stretch; gap: 10px; margin-bottom: 16px; }
.search-row input { flex: 1; min-width: 0; }
.search-row button { flex-shrink: 0; min-height: 42px; }
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  background: #fafaf8;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.history-item .title { font-weight: 650; font-size: 15px; margin-bottom: 4px; }
.history-item .meta { font-size: 13px; color: var(--muted); line-height: 1.45; }
.history-item .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Editor de perguntas (Configurações) */
.editable-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 960px;
}
.editable-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: left;
  color: #555b62;
  background: #f6f6f5;
  font-weight: 650;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
}
.editable-table td { padding: 8px 6px; border-bottom: 1px solid #ececef; vertical-align: top; }
.editable-table .col-ed-it { width: 84px; text-align: center; }
.editable-table .col-ed-perg { width: 34%; }
.editable-table .col-ed-tipo { width: 215px; }
.editable-table .col-ed-dicas { width: auto; }
.editable-table .col-ed-ativo { width: 68px; text-align: center; }
.editable-table .col-ed-rem { width: 48px; text-align: center; }

input.num-input {
  text-align: center;
  padding: 7px 6px;
  font-weight: 700;
  min-height: 38px;
  appearance: textfield;
  -moz-appearance: textfield;
}
input.num-input::-webkit-inner-spin-button,
input.num-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

textarea.table-textarea {
  min-height: 58px;
  line-height: 1.4;
  resize: vertical;
  padding: 8px 10px;
  font-size: 13.5px;
}

.row-remove-btn {
  background: none; border: 0; min-height: 36px; padding: 4px 8px;
  color: #952530; cursor: pointer; font-size: 18px; line-height: 1;
}
.row-remove-btn:hover { background: #fff0f1; color: #7f1d27; }

/* Login (layout igual ao klaus-financeiro) */
.login-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 64px;
  align-items: center;
  max-width: 1100px;
  margin: 52px auto;
}
.login-layout h1 { font-size: 38px; max-width: 540px; }
.intro { font-size: 18px; color: var(--muted); }
.login-card { border-top: 3px solid var(--brand-red); }
.login-card h2 { margin-bottom: 14px; }
.login-card hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.login-field { margin-top: 14px; }
.login-card button[type="submit"] { margin-top: 18px; }

/* Rodapé & Toast */
footer {
  max-width: 1450px;
  width: 100%;
  margin: 24px auto;
  padding: 0 4%;
  font-size: 12px;
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 8px;
  z-index: 999;
  background: #191b1e;
  color: #ffffff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
  border-left: 4px solid var(--brand-yellow);
}
.toast-ok { border-left-color: #458456; }
.toast-error { border-left-color: var(--brand-red); }

@media (max-width: 960px) {
  .form-grid, .form-grid-3, .form-grid-4, .login-layout { grid-template-columns: 1fr; gap: 16px; }
  .form-group.span-2 { grid-column: span 1; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top { flex-wrap: wrap; gap: 14px; }
  .login-layout { margin: 28px auto; }
  .login-layout h1 { font-size: 30px; }
}
@media (max-width: 640px) {
  .brand-logo { width: 112px; }
  .brand-caption { padding-left: 14px; font-size: 13px; }
  .identity { display: none; }
  .card { padding: 16px; }
  .stats strong { font-size: 22px; }
  .save-bar { flex-direction: column; align-items: stretch; }
}
