*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --roxo: #4E2096;
  --gelo: #F3EEE8;
  --ink: #1A1918;
  --cinza: #6B6B6B;
  --borda: #E0D8EF;
  --verde: #1A8044;
  --laranja: #C05A00;
  --erro: #C0392B;
  --radius: 8px;
}
body { font-family: 'Segoe UI', Arial, sans-serif; background: var(--gelo); color: var(--ink); min-height: 100vh; }
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--roxo); color: #fff; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 16px; border-bottom: 1px solid rgba(255,255,255,.15); }
.brand h1 { font-size: 17px; font-weight: 700; }
.brand p { font-size: 11px; color: #d4b8f0; margin-top: 4px; }
.nav { padding: 12px; flex: 1; }
.nav button {
  width: 100%; text-align: left; padding: 10px 12px; margin-bottom: 4px;
  border: none; border-radius: 6px; background: transparent; color: rgba(255,255,255,.8);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.nav button:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav button.active { background: rgba(255,255,255,.2); color: #fff; }
.sidebar-foot { padding: 12px 16px; font-size: 11px; color: #c9b3e8; border-top: 1px solid rgba(255,255,255,.12); }
.main { flex: 1; min-width: 0; padding: 24px 28px; }
.page { display: none; }
.page.active { display: block; }
h2 { font-size: 20px; margin-bottom: 16px; color: var(--roxo); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.field label { display: block; font-size: 11px; font-weight: 600; color: var(--cinza); margin-bottom: 4px; }
.field select, .field input {
  padding: 8px 10px; border: 1.5px solid var(--borda); border-radius: 6px;
  font-size: 13px; min-width: 140px; background: #fff;
}
.field input.busca { min-width: 220px; }
.btn {
  padding: 8px 14px; border-radius: 6px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--roxo); color: #fff; }
.btn-outline { background: #fff; color: var(--roxo); border: 1.5px solid var(--borda); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border-radius: var(--radius); padding: 14px; border: 1px solid var(--borda); }
.kpi strong { display: block; font-size: 22px; color: var(--roxo); }
.kpi span { font-size: 11px; color: var(--cinza); }
.meta { font-size: 12px; color: var(--cinza); margin-bottom: 12px; }
.table-wrap {
  background: #fff; border-radius: var(--radius); border: 1px solid var(--borda);
  overflow: auto; max-height: calc(100vh - 320px);
}
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #f0ebf5; white-space: nowrap; }
th {
  background: #faf8fc; position: sticky; top: 0; z-index: 2;
  font-weight: 700; color: var(--roxo); cursor: pointer; user-select: none;
}
th:hover { background: #f1ebfa; }
tr:hover td { background: #faf8fc; }
.score-pill {
  display: inline-block; min-width: 28px; text-align: center; padding: 2px 8px;
  border-radius: 12px; font-weight: 700; font-size: 11px;
}
.score-alto { background: #e8f5ee; color: var(--verde); }
.score-medio { background: #fff6e9; color: var(--laranja); }
.score-baixo { background: #fdecea; color: var(--erro); }
.paginacao { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.loading-overlay {
  position: fixed; inset: 0; background: rgba(243,238,232,.85);
  display: none; align-items: center; justify-content: center; z-index: 200;
}
.loading-overlay.show { display: flex; }
.loading-box { background: #fff; padding: 24px 32px; border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.1); text-align: center; }
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--borda); border-top-color: var(--roxo);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.alert { padding: 12px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; display: none; }
.alert.show { display: block; }
.alert-erro { background: #fdecea; color: var(--erro); border: 1px solid #f5c6c2; }
.alert-ok { background: #e8f5ee; color: var(--verde); border: 1px solid #b8dfc8; }
.cards-grid { display: grid; gap: 10px; }
.card-item {
  background: #fff; border: 1px solid var(--borda); border-radius: var(--radius);
  padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.card-item h4 { font-size: 14px; margin-bottom: 4px; }
.card-item p { font-size: 12px; color: var(--cinza); }
.card-item-click { cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.card-item-click:hover { border-color: var(--roxo-l); box-shadow: 0 2px 10px rgba(78,32,150,.1); }
.card-item-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.meta-id { font-weight: 600; color: var(--roxo); }
.badge { font-size: 10px; padding: 2px 8px; border-radius: 10px; background: var(--gelo); font-weight: 600; }
.editor-layout { display: grid; grid-template-columns: 280px 1fr; gap: 20px; }
@media (max-width: 960px) { .editor-layout { grid-template-columns: 1fr; } }
.editor-card-list { max-height: 420px; overflow: auto; }
.editor-card-item {
  padding: 10px 12px; border: 1px solid var(--borda); border-radius: 6px;
  margin-bottom: 8px; cursor: pointer; background: #fff;
}
.editor-card-item:hover { border-color: var(--roxo); }
.editor-card-item.active { border-color: var(--roxo); background: #f8f4fc; }
.editor-card-item h4 { font-size: 13px; margin-bottom: 4px; }
.editor-card-item p { font-size: 11px; color: var(--cinza); }
.table-editor-wrap { overflow: auto; max-height: 65vh; border: 1px solid var(--borda); border-radius: 8px; background: #fff; }
.table-editor { border-collapse: separate; border-spacing: 0; min-width: max-content; }
.table-editor th { position: sticky; top: 0; z-index: 2; background: var(--gelo); font-size: 11px; padding: 8px 6px; white-space: nowrap; }
.table-editor .th-grp { background: #e8ddf5; color: var(--roxo); font-weight: 700; text-align: center; top: 0; z-index: 3; }
.table-editor .col-edit-h { background: #faf7ff; }
.table-editor .col-edit { background: #fff; vertical-align: top; }
.table-editor .editor-field {
  width: 100%; min-width: 88px; max-width: 220px; padding: 5px 6px; font-size: 11px;
  border: 1px solid var(--borda); border-radius: 4px; box-sizing: border-box;
}
.table-editor .editor-ta { min-height: 44px; resize: vertical; max-width: 280px; }
.table-editor .kpi-cell { background: #f3f0f8; color: var(--ink); font-size: 11px; white-space: nowrap; }
.table-editor .kpi-missing { color: #999; font-style: italic; }
.obs-box { width: 100%; min-height: 56px; padding: 8px; border-radius: 6px; border: 1.5px solid var(--borda); }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; }
  .main { padding: 16px; }
}
