:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --neutral-bg: #f3f4f6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: #111827;
  color: #e5e7eb;
  padding: 1.25rem 1rem;
  flex-shrink: 0;
}
.sidebar .marca { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 1.5rem; }
.sidebar .marca-logo { width: 100%; max-width: 160px; height: auto; margin-bottom: 0.6rem; }
.sidebar h1 { font-size: 1.1rem; margin: 0; color: #fff; }
.sidebar nav a {
  display: block;
  color: #d1d5db;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  margin-bottom: 2px;
  font-size: 0.92rem;
}
.sidebar nav a:hover, .sidebar nav a.ativo { background: #1f2937; color: #fff; text-decoration: none; }
.sidebar .usuario { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #374151; font-size: 0.85rem; color: #9ca3af; }
.sidebar .usuario form { margin-top: 0.5rem; }
.sidebar .usuario button { background: none; border: none; color: #d1d5db; cursor: pointer; padding: 0; font-size: 0.85rem; }

.main { flex: 1; padding: 1.5rem 2rem; max-width: 1400px; }

.btn-menu-mobile { display: none; }
.overlay-menu { display: none; }

@media (max-width: 768px) {
  .layout { display: block; }
  .btn-menu-mobile {
    display: block; position: fixed; top: 0.75rem; left: 0.75rem; z-index: 60;
    width: 2.5rem; height: 2.5rem; border: none; border-radius: 6px;
    background: #111827; color: #fff; font-size: 1.3rem; line-height: 1; cursor: pointer;
  }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 260px; max-width: 80vw;
    overflow-y: auto; z-index: 55; transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.aberto { transform: translateX(0); }
  .overlay-menu.aberto {
    display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 50;
  }
  .main { padding: 4rem 1rem 1.5rem; max-width: 100%; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

.main { overflow-x: hidden; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.kpi { text-align: center; }
.kpi .valor { font-size: 2rem; font-weight: 700; }
.kpi .rotulo { color: var(--text-muted); font-size: 0.85rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }

.filtros { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin-bottom: 1.25rem; }
.filtros label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.filtros input, .filtros select {
  padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem;
}
.filtros select[multiple] { min-width: 180px; }

.caixa-checkbox {
  display: flex; flex-direction: column; gap: 0.2rem; max-height: 130px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 6px; padding: 0.4rem 0.6rem; min-width: 180px;
}
.caixa-checkbox label {
  display: flex !important; align-items: center; gap: 0.4rem; font-size: 0.85rem; font-weight: normal;
  color: var(--text); margin: 0 !important;
}
.caixa-checkbox input { width: auto !important; }

.legenda-cor { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 2px; flex-shrink: 0; }

.radio-inline { display: flex; gap: 0.9rem; font-size: 0.85rem; }
.radio-inline label { display: flex !important; align-items: center; gap: 0.3rem; font-weight: normal; margin: 0 !important; }
.radio-inline input { width: auto !important; }

.btn-expandir {
  width: 1.6rem; height: 1.6rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--neutral-bg); color: var(--text); cursor: pointer; font-size: 0.9rem; line-height: 1;
}
.btn-expandir:hover { background: var(--border); }
.linha-historico td { color: var(--text-muted); background: var(--neutral-bg); font-size: 0.85rem; }

.btn {
  display: inline-block; background: var(--primary); color: #fff; border: none;
  padding: 0.5rem 1rem; border-radius: 6px; cursor: pointer; font-size: 0.9rem;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secundario { background: var(--neutral-bg); color: var(--text); }
.btn-secundario:hover { background: var(--border); }

.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-atrasado { background: var(--danger-bg); color: var(--danger); }
.badge-proximo { background: var(--warning-bg); color: var(--warning); }
.badge-futuro { background: var(--neutral-bg); color: var(--text-muted); }
.badge-ok { background: var(--success-bg); color: var(--success); }
.badge-revisar { background: #ede9fe; color: #6d28d9; margin-left: 0.4rem; }

/* Status de execução (Controle por imagem / Aguarda procedimento indicado) */
.badge-status-previsto { background: var(--neutral-bg); color: var(--text-muted); }
.badge-status-solicitado { background: #dbeafe; color: #2563eb; }
.badge-status-autorizado { background: var(--warning-bg); color: var(--warning); }
.badge-status-agendado { background: var(--success-bg); color: var(--success); }
.badge-status-com_pendencia { background: #ede9fe; color: #6d28d9; }
.badge-status-negado { background: var(--danger-bg); color: var(--danger); }

.dropdown-conduta { position: relative; display: inline-block; }
.menu-dropdown {
  position: absolute; right: 0; top: 100%; z-index: 20; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  min-width: 230px; padding: 0.25rem; margin-top: 0.25rem;
}
.menu-dropdown .item-dropdown {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 0.4rem 0.6rem; font-size: 0.85rem; color: var(--text); cursor: pointer; border-radius: 6px;
  white-space: nowrap;
}
.menu-dropdown .item-dropdown:hover { background: var(--neutral-bg); }

.sugestao-vinculo { margin-top: 0.35rem; }
.sugestao-item {
  background: var(--warning-bg); color: var(--warning); border-radius: 6px;
  padding: 0.3rem 0.5rem; font-size: 0.8rem; margin-top: 0.25rem;
}
.sugestao-item button {
  border: none; border-radius: 4px; padding: 0.1rem 0.4rem; margin-left: 0.4rem;
  cursor: pointer; font-size: 0.75rem;
}
.sugestao-item .btn-vincular { background: var(--warning); color: #fff; }
.sugestao-item .btn-recusar { background: var(--surface); color: var(--text-muted); }

.combobox-opcoes {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  max-height: 220px; overflow-y: auto; margin-top: 0.2rem;
}
.combobox-opcoes .combobox-item {
  padding: 0.4rem 0.6rem; font-size: 0.85rem; color: var(--text); cursor: pointer;
}
.combobox-opcoes .combobox-item:hover { background: var(--neutral-bg); }

.mensagens { margin-bottom: 1rem; }
.mensagem { padding: 0.6rem 0.9rem; border-radius: 6px; margin-bottom: 0.5rem; font-size: 0.9rem; }
.mensagem.success { background: var(--success-bg); color: var(--success); }
.mensagem.error { background: var(--danger-bg); color: var(--danger); }

.form-linha { margin-bottom: 0.9rem; }
.form-linha label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.form-linha input, .form-linha select, .form-linha textarea {
  width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem;
}
.errorlist { color: var(--danger); font-size: 0.8rem; list-style: none; padding: 0; margin: 0.2rem 0 0; }

h2 { font-size: 1.15rem; margin-top: 0; }
.secao-titulo { font-size: 0.95rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; margin: 0 0 0.75rem; }

.campo-condicional { display: none; }
.campo-condicional.ativo { display: block; }

.calculo-prazo {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem;
  font-size: 0.85rem; color: var(--text-muted);
}
.calculo-prazo input, .calculo-prazo select { width: auto; padding: 0.3rem 0.5rem; }
.calculo-prazo .btn-secundario { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
