/* =====================================================
   Nomos New — Design System (Light Theme · SERTA)
   ===================================================== */

/* ── Variáveis ───────────────────────────────────────── */
:root {
  --bg:             #F4F6F8;
  --bg-sidebar:     #1C1C2E;
  --bg-card:        #FFFFFF;
  --bg-input:       #FFFFFF;
  --border:         #E2E8F0;
  --border-soft:    #F1F5F9;
  --border-focus:   #D32F2F;
  --text:           #334155;
  --text-muted:     #64748B;
  --text-head:      #0F172A;
  --primary:        #D32F2F;
  --primary-d:      #B71C1C;
  --primary-light:  #FEF2F2;
  --primary-glow:   rgba(211,47,47,.15);
  --bg-input-fill:  #EEF2F8;
  --success:        #10B981;
  --success-light:  #ECFDF5;
  --warning:        #F59E0B;
  --warning-light:  #FFFBEB;
  --danger:         #EF4444;
  --danger-light:   #FEF2F2;
  --info:           #3B5BDB;
  --info-light:     #EEF2FF;
  --purple:         #8B5CF6;
  --sidebar-w:      220px;
  --topbar-h:       60px;
  --radius:         10px;
  --radius-sm:      6px;
  --shadow-sm:      0 1px 2px rgba(0,0,0,.05);
  --shadow:         0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:      0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg:      0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.05);
}

/* ── Reset ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

/* =====================================================
   Layout principal
   ===================================================== */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 200;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}

.sidebar-logo img {
  height: 208px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
}

.nav-list { list-style: none; margin: 0; padding: 8px; flex: 1; }

.nav-section-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .8px;
  color: rgba(255,255,255,.3);
  text-transform: uppercase;
  padding: 14px 8px 5px;
}

/* ── Acordeão de navegação ── */
.nav-group { list-style: none; }

.nav-group-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  cursor: pointer;
  padding: 14px 8px 5px;
  color: rgba(255,255,255,.3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  font-family: inherit;
  transition: color .15s;
}
.nav-group-btn:hover { color: rgba(255,255,255,.55); }

.nav-chevron { flex-shrink: 0; transition: transform .22s ease; }
.nav-group.open .nav-chevron { transform: rotate(180deg); }

.nav-group-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height .28s ease;
}
.nav-group.open .nav-group-list { max-height: 800px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
  margin-bottom: 1px;
  border-left: 3px solid transparent;
}

.nav-link svg { flex-shrink: 0; opacity: .75; }

.nav-link:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
}
.nav-link:hover svg { opacity: 1; }

.nav-link.active {
  background: rgba(211,47,47,.18);
  color: #FF6B6B;
  border-left-color: var(--primary);
}
.nav-link.active svg { opacity: 1; color: #FF6B6B; }

.nav-link-disabled {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 400;
  border-left: 3px solid transparent;
  color: rgba(255,255,255,.25);
  cursor: not-allowed;
  pointer-events: none;
  user-select: none;
}
.nav-link-disabled svg { flex-shrink: 0; opacity: .25; }

/* Sidebar empresa info */
.sidebar-empresa {
  padding: 6px 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-empresa-back {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: rgba(255,255,255,.4);
  text-decoration: none;
  padding: 5px 4px;
  border-radius: 4px;
  transition: color .15s;
}
.sidebar-empresa-back:hover { color: rgba(255,255,255,.7); }
.sidebar-empresa-nome {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,.85);
  padding: 4px 4px 0;
}

/* Sidebar modulos link */
.sidebar-modulos-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,.35);
  text-decoration: none;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  margin-bottom: 4px;
  transition: color .15s;
}
.sidebar-modulos-link:hover { color: rgba(255,255,255,.65); }

/* ── Área principal ──────────────────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* ── Topbar ──────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  gap: 16px;
  flex-shrink: 0;
}

.topbar-search {
  position: relative;
  max-width: 320px;
  width: 100%;
}
.topbar-search svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.topbar-search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-input-fill);
  color: var(--text);
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.topbar-search input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: #fff;
}
.topbar-search input::placeholder { color: var(--text-muted); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--bg);
  transition: box-shadow .15s;
}
.topbar-user:hover { box-shadow: var(--shadow); }

.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

.topbar-user-data {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.topbar-user-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-head);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.topbar-logout {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-decoration: none;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.topbar-logout:hover { background: var(--primary-light); color: var(--primary); }

/* ── Main content ────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 24px;
  background: var(--bg);
  min-width: 0;
}

/* =====================================================
   Ambiente de Trabalho — Checkbox chips (Step 4)
   ===================================================== */

.amb-options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
}

.amb-option {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: border-color .15s, background .15s;
  user-select: none;
}

.amb-option input[type="checkbox"] {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--primary);
}

.amb-option:hover {
  border-color: #FECACA;
  background: #FFF9F9;
}

.amb-option:has(input:checked) {
  background: #FEF2F2;
  border-color: var(--primary);
}

.amb-option:has(input:checked) span {
  color: var(--primary);
  font-weight: 700;
}

/* =====================================================
   Fatores de Risco — Chip Layout (Step 5)
   ===================================================== */

.fatores-tabs-bar {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow-x: auto;
}

.fatores-tab-btn {
  padding: 12px 22px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  font-family: inherit;
  transition: color .15s, border-color .15s, background .15s;
  flex-shrink: 0;
}

.fatores-tab-btn:hover {
  color: var(--text-head);
  background: var(--bg);
}

.fatores-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

.fatores-cat-panel {
  padding: 0 4px;
}

.fatores-cat-heading {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-head);
  margin: 0 0 20px;
}

.fatores-chips-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 8px;
}

/* Chip — estado normal */
.fator-chip {
  position: relative;
  display: flex;
  align-items: center;
  padding: 16px 44px 16px 18px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
  min-height: 64px;
  user-select: none;
}

.fator-chip input[type="checkbox"] {
  display: none;
  width: 0;
  height: 0;
  position: absolute;
}

.chip-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}

.fator-chip:hover {
  border-color: #FECACA;
  background: #FFF9F9;
  box-shadow: 0 2px 8px rgba(211,47,47,.08);
}

/* Chip — selecionado (via :has) */
.fator-chip:has(input:checked) {
  background: #FEF2F2;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(211,47,47,.12);
}

.fator-chip:has(input:checked) .chip-text {
  color: var(--primary);
  font-weight: 700;
}

/* Chip — desabilitado (ex.: fator Psicossocial sem matriz P/C configurada) */
.fator-chip:has(input:disabled) {
  opacity: .5;
  cursor: not-allowed;
  background: var(--bg-card);
}

/* Checkmark no canto superior direito quando selecionado */
.fator-chip:has(input:checked)::after {
  content: '✓';
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 24px;
  text-align: center;
}

/* Barra inferior fixa */
.fatores-bottom-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 24px;
  box-shadow: 0 -4px 12px rgba(0,0,0,.06);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* Responsivo */
@media (max-width: 900px) {
  .fatores-chips-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .fatores-chips-grid { grid-template-columns: 1fr; }
}

/* =====================================================
   Login
   ===================================================== */
.login-body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 30%, rgba(211,47,47,.07) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(59,91,219,.06) 0%, transparent 60%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-container { width: 100%; max-width: 420px; padding: 16px; }

.login-card {
  background: var(--bg-card);
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.login-header {
  background: var(--bg-sidebar);
  padding: 32px 28px 24px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.login-title {
  margin: 0;
  font-size: 24px;
  color: #fff;
  font-weight: 700;
  letter-spacing: -.3px;
}

.login-subtitle { margin: 6px 0 0; color: rgba(255,255,255,.5); font-size: 13px; }

.login-form { padding: 28px; }

/* =====================================================
   Formulários
   ===================================================== */
.form-group { margin-bottom: 16px; }

.form-group label,
.form-label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: .2px;
}

.form-control {
  width: 100%;
  padding: 9px 13px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--bg-input-fill);
  color: var(--text-head);
  transition: border-color .15s, background .15s, box-shadow .15s;
  font-family: inherit;
}

.form-control::placeholder { color: #94A3B8; }

.form-control:focus {
  outline: none;
  background: #FFFFFF;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

input[type="date"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .6; }

/* =====================================================
   Botões
   ===================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all .15s;
  line-height: 1.4;
  letter-spacing: .1px;
  font-family: inherit;
}

.btn:active { transform: scale(.98); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 4px rgba(211,47,47,.3);
}
.btn-primary:hover { background: var(--primary-d); border-color: var(--primary-d); box-shadow: 0 4px 12px rgba(211,47,47,.35); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); color: var(--text-head); border-color: #CBD5E1; }

.btn-danger {
  background: var(--danger-light);
  color: #991B1B;
  border-color: #FECACA;
}
.btn-danger:hover { background: #FEE2E2; color: #7F1D1D; }

.btn-success {
  background: var(--success-light);
  color: #065F46;
  border-color: #A7F3D0;
}
.btn-success:hover { background: #D1FAE5; }

.btn-sm { padding: 5px 11px; font-size: 11px; }
.btn-block { display: flex; width: 100%; text-align: center; justify-content: center; }

/* =====================================================
   Badges / perfis
   ===================================================== */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.badge-admin        { background: #EEF2FF; color: #3730A3; border: 1px solid #C7D2FE; }
.badge-operador     { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.badge-cliente      { background: #F0F9FF; color: #075985; border: 1px solid #BAE6FD; }
.badge-auditor      { background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }
.badge-suporte      { background: #F5F3FF; color: #5B21B6; border: 1px solid #DDD6FE; }
.badge-visualizador { background: #F8FAFC; color: #475569; border: 1px solid #E2E8F0; }

/* =====================================================
   Flash messages
   ===================================================== */
.flash {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 13px;
  font-weight: 500;
}

.flash-success { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.flash-error   { background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }

/* =====================================================
   Cards
   ===================================================== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 8px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  transition: box-shadow .2s;
}

/* Cards que contêm tabelas não devem ter padding (a tabela vai até as bordas) */
.card:has(> .table-wrapper),
.card:has(> table) {
  padding: 0;
  overflow: hidden;
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.card-body { padding: 16px; }

.card-stat {
  font-size: 34px;
  font-weight: 700;
  color: var(--text-head);
  margin: 0 0 4px;
  letter-spacing: -1px;
}

.card-label { font-size: 12px; color: var(--text-muted); margin: 0; }

/* KPI card com borda superior colorida */
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  border-top: 3px solid var(--primary);
}
.kpi-card .kpi-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 6px;
}
.kpi-card .kpi-label { font-size: 13px; color: var(--text-muted); }
.kpi-card.kpi-blue   { border-top-color: var(--info); }
.kpi-card.kpi-blue   .kpi-value { color: var(--info); }
.kpi-card.kpi-green  { border-top-color: var(--success); }
.kpi-card.kpi-green  .kpi-value { color: var(--success); }
.kpi-card.kpi-orange { border-top-color: var(--warning); }
.kpi-card.kpi-orange .kpi-value { color: var(--warning); }

/* =====================================================
   Tabelas
   ===================================================== */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow);
}

table, .table { width: 100%; border-collapse: collapse; }

thead th {
  background: #F8FAFC;
  color: var(--text-muted);
  padding: 11px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border-soft); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #FAFBFC; }

td {
  padding: 11px 14px;
  font-size: 13px;
  color: var(--text);
  vertical-align: middle;
}

td strong { color: var(--text-head); }

td code {
  font-size: 12px;
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 4px;
  color: var(--info);
  font-family: 'Consolas', monospace;
  border: 1px solid var(--border);
}

/* =====================================================
   Page header
   ===================================================== */
.btn-voltar {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 10px;
  transition: color .15s;
}
.btn-voltar:hover { color: var(--primary); }

.page-header { margin-bottom: 24px; }

.page-title,
.page-header h1,
.page-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-head);
  letter-spacing: -.3px;
}

.text-muted { color: var(--text-muted); font-size: 13px; margin: 0; }

/* =====================================================
   Form cards
   ===================================================== */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 560px;
  box-shadow: var(--shadow);
}

.form-card h3 { color: var(--text-head); }

.form-actions { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }

.filter-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

td.actions { white-space: nowrap; display: flex; gap: 5px; align-items: center; }

/* =====================================================
   Error page
   ===================================================== */
.error-page { text-align: center; padding: 80px 24px; }
.error-page h2 { font-size: 28px; color: var(--text-head); margin-bottom: 12px; font-weight: 700; }
.error-page p { color: var(--text-muted); margin-bottom: 28px; }

/* =====================================================
   Modal
   ===================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,18,36,.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  color: var(--text-head);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { margin: 0; font-size: 15px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}

.modal-close:hover { color: var(--text-head); background: var(--bg); }

.modal-box form { padding: 24px; }

/* =====================================================
   Árvore organizacional
   ===================================================== */
.org-tree-list { list-style: none; margin: 0; padding: 0 0 0 28px; }
.org-tree-list:first-child { padding-left: 0; }

.org-tree-item { margin: 6px 0; }

.org-node {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s;
}

.org-node:hover { box-shadow: var(--shadow); }

.org-node-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.org-node-type { font-size: 12px; color: var(--primary); min-width: 60px; font-weight: 600; }
.org-node-name { font-size: 13px; color: var(--text-head); font-weight: 500; }

.org-node-code {
  font-size: 11px;
  background: var(--bg);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 4px;
  font-family: monospace;
  border: 1px solid var(--border);
}

.org-depth-badge {
  font-size: 10px;
  color: #fff;
  padding: 2px 7px;
  border-radius: 99px;
  font-weight: 700;
}

.org-node-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.empty-state { color: var(--text-muted); font-size: 14px; padding: 32px 0; text-align: center; }

/* =====================================================
   Overrides de inline styles dark → light
   ===================================================== */

/* Inputs e selects */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="color"],
textarea,
select {
  color: var(--text-head);
  background-color: var(--bg-input-fill);
}

select { cursor: pointer; }
select option { background: #fff; color: var(--text-head); }

label { color: var(--text-muted); }

/* Backgrounds dark → white */
[style*="background:#0f1923"],  [style*="background: #0f1923"],
[style*="background:#0f172a"],  [style*="background: #0f172a"],
[style*="background:#0d1117"],  [style*="background: #0d1117"],
[style*="background:#161b27"],  [style*="background: #161b27"],
[style*="background:#1c2333"],  [style*="background: #1c2333"],
[style*="background:#1a2036"],  [style*="background: #1a2036"] {
  background: var(--bg-card) !important;
}

[style*="background:#1e2d3d"],  [style*="background: #1e2d3d"] {
  background: var(--bg) !important;
}

/* Textos claros (feitos para fundo escuro) → textos escuros */
[style*="color:#e2e8f0"],  [style*="color: #e2e8f0"],
[style*="color:#f1f5f9"],  [style*="color: #f1f5f9"],
[style*="color:#cbd5e1"],  [style*="color: #cbd5e1"] {
  color: var(--text-head) !important;
}

[style*="color:#94a3b8"],  [style*="color: #94a3b8"],
[style*="color:#64748b"],  [style*="color: #64748b"] {
  color: var(--text-muted) !important;
}

/* Borders dark → light */
[style*="border:1px solid #334155"],   [style*="border: 1px solid #334155"],
[style*="border:1px solid #1e2d3d"],   [style*="border: 1px solid #1e2d3d"],
[style*="border:1px solid #1e3a5f"],   [style*="border: 1px solid #1e3a5f"] {
  border-color: var(--border) !important;
}

[style*="border-bottom:1px solid #1e2d3d"],
[style*="border-bottom: 1px solid #1e2d3d"] {
  border-bottom-color: var(--border) !important;
}

/* Input backgrounds dark */
[style*="background:#1e2d3d"] input,
[style*="background:#0f1923"] input {
  background: var(--bg-input) !important;
  border-color: var(--border) !important;
  color: var(--text-head) !important;
}

/* Inline backgrounds brancos / claros (mantém conforme já estava) */
[style*="background:#fff"],        [style*="background: #fff"],
[style*="background:#fafafa"],     [style*="background: #fafafa"],
[style*="background-color:#fff"],  [style*="background-color: #fff"] {
  background: var(--bg-card) !important;
}

[style*="background:#f4f6f9"],  [style*="background: #f4f6f9"],
[style*="background:#F4F6F8"],  [style*="background: #F4F6F8"] {
  background: var(--bg) !important;
}

/* Headings com cor SERTA/azul escuro */
[style*="color:#1F3864"]  { color: var(--text-head) !important; }
[style*="color:#333"],    [style*="color: #333"]    { color: var(--text) !important; }
[style*="color:#555"],    [style*="color: #555"],
[style*="color:#666"],    [style*="color: #666"],
[style*="color:#888"],    [style*="color: #888"]    { color: var(--text-muted) !important; }

/* Table headers com fundo azul escuro → vermelho SERTA */
th[style*="background:#1F3864"],
th[style*="background: #1F3864"],
th[style*="background:#1e3a5f"],
th[style*="background: #1e3a5f"] {
  background: var(--bg-sidebar) !important;
  color: #fff !important;
}

/* Badge status inline */
.badge[style*="background:#14532d"] { background: #DCFCE7 !important; color: #166534 !important; border: 1px solid #BBF7D0 !important; }
.badge[style*="background:#1c1917"] { background: #F1F5F9 !important; color: #475569 !important; border: 1px solid #E2E8F0 !important; }

/* Textos de alerta vermelho (mantém) */
[style*="color:#ef4444"],  [style*="color: #ef4444"]  { color: #DC2626 !important; }
[style*="color:#f87171"],  [style*="color: #f87171"]  { color: #DC2626 !important; }
[style*="color:#fca5a5"],  [style*="color: #fca5a5"]  { color: #991B1B !important; }

small { color: var(--text-muted); }

/* =====================================================
   Animações / helpers
   ===================================================== */
.fade-in { animation: fadeIn .2s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* =====================================================
   Responsivo — Mobile
   ===================================================== */

/* Botão hambúrguer (visível só no mobile) */
.topbar-menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, color .15s;
  padding: 0;
}
.topbar-menu-btn:hover { background: var(--bg); color: var(--text-head); }

/* Overlay escuro atrás da sidebar (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,18,36,.5);
  z-index: 199;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

@media (max-width: 768px) {
  /* Sidebar vira drawer deslizante */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .28s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }

  /* Topbar mobile */
  .topbar-menu-btn { display: flex; }
  .topbar-search { display: none; }
  .topbar { padding: 0 16px; }

  .main-content { padding: 16px; }
  .cards-grid { grid-template-columns: 1fr 1fr; }
  .page-header { margin-bottom: 16px; }
  .page-title, .page-header h1, .page-header h2 { font-size: 18px; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .btn { width: 100%; justify-content: center; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }
  .table-wrapper { font-size: 12px; }
  .modal-box { margin: 16px; }
}

@media (max-width: 480px) {
  .cards-grid { grid-template-columns: 1fr; }
  .topbar-user-name { max-width: 80px; }
  .fatores-chips-grid { grid-template-columns: 1fr; }
}

/* ── Matriz de Riscos — Step 6 (mobile) ──────────────────────────── */
@media (max-width: 768px) {
  /* Card de cabeçalho: título + botão Salvar empilham */
  #step-pane-6 > .card > div:first-child {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }
  #step-pane-6 > .card > div:first-child > button {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Bloco individual */
  .analise-bloco, .analise-psico-bloco { padding: 12px !important; }

  /* Situação Analisada + Taxa de Ocupação → coluna */
  .analise-row-situacao {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .analise-row-situacao > div[style*="width:130px"] {
    width: 100% !important;
  }

  /* Variáveis: remove largura fixa, ocupa 100% */
  .var-item {
    width: 100% !important;
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }
  .var-group-row { flex-wrap: wrap !important; }

  /* NRE box: full width, layout horizontal */
  .nre-box {
    width: 100% !important;
    margin-left: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 8px 0 0 !important;
    border-top: 1px solid var(--border-soft);
  }
  .nre-box label { margin-bottom: 0 !important; }
  .nre-box .nre-valor { font-size: 26px !important; }

  /* Steps nav: ajusta tamanho dos botões */
  #step-nav .step-btn {
    font-size: 11px !important;
    padding: 5px 8px !important;
  }
}

/* ── Plano de Ação — Step 9 (mobile) ─────────────────────────────── */
@media (max-width: 768px) {
  /* Cabeçalho: título + Prompt IA → coluna */
  .plano-header { flex-direction: column !important; gap: 12px !important; }
  .plano-prompt-wrap { width: 100% !important; }
  .plano-prompt-wrap select { min-width: 0 !important; width: 100% !important; flex: 1 !important; }

  /* Item do plano */
  .pa-item { margin-bottom: 12px; }

  /* Ação Proposta + botão IA → coluna */
  .pa-acao-row { flex-direction: column !important; }
  .pa-ai-wrap { padding-top: 0 !important; width: 100% !important; }
  .pa-ai-wrap .pa-ai-btn { width: 100% !important; justify-content: center; font-size: 13px !important; }

  /* Campos (Responsável / Prazo / Prioridade / Tipo Investimento) */
  #plano-acao-container div[style*="min-width:140px"],
  #plano-acao-container div[style*="min-width:100px"],
  #plano-acao-container div[style*="min-width:120px"] {
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }
}
