/* design.json tokens */
:root {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-muted: #FAFAFB;
  --border: #E6E8EE;
  --border-strong: #D9DDE7;
  --text: #101828;
  --text-muted: #667085;
  --text-subtle: #98A2B3;
  --primary: #111827;
  --primary-text-on: #FFFFFF;
  --success: #12B76A;
  --warning: #F79009;
  --danger: #F04438;
  --sidebar-bg: #FFFFFF;
  --sidebar-item: #344054;
  --sidebar-item-hover-bg: #F2F4F7;
  --sidebar-item-active-bg: #111827;
  --sidebar-item-active-text: #FFFFFF;
  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-card: 0 1px 2px rgba(16,24,40,0.06), 0 1px 3px rgba(16,24,40,0.10);
  --font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  --sidebar-width: 268px;
  --topbar-height: 56px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.4;
}

/* Layout logado: AppShell + Sidebar + Main */
.app-shell {
  min-height: 100vh;
  display: flex;
  background: var(--bg);
}
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 16px;
  flex-shrink: 0;
}
.sidebar-brand { margin-bottom: 24px; }
.sidebar-brand .title {
  font-size: 0;
  width: 100%;
  max-width: 180px;
  height: 52px;
  background: url('/images/logo_final.png') no-repeat left center;
  background-size: contain;
}
.sidebar-brand .subtitle { display: none; }
.sidebar-nav { list-style: none; padding: 0; margin: 0; }
.sidebar-nav li { margin-bottom: 4px; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--sidebar-item);
  text-decoration: none;
  border-radius: var(--radius-md);
}
.sidebar-nav a:hover { background: var(--sidebar-item-hover-bg); }
.sidebar-nav a.active { background: var(--sidebar-item-active-bg); color: var(--sidebar-item-active-text); }

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}
.topbar .icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text);
}
.topbar .icon-btn:hover { background: var(--surface-muted); }
.content {
  padding: 24px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}
.content > h1 {
  margin: 0 0 16px 0;
  font-size: 32px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* Cards e formulários */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 24px;
  max-width: 420px;
  margin: 0 auto;
}
.card h1 { margin-top: 0; font-size: 22px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; color: var(--text); font-weight: 500; }
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--primary); }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 560px) {
  .form-row { grid-template-columns: 1fr; }
}
.form-fieldset-ncm,
.form-fieldset-anexos,
.form-fieldset-descricoes,
.form-fieldset-campos-personalizados {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px 4px;
  margin: 0 0 16px 0;
}
.form-fieldset-ncm legend,
.form-fieldset-anexos legend,
.form-fieldset-descricoes legend,
.form-fieldset-campos-personalizados legend {
  padding: 0 6px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.form-row-3 {
  grid-template-columns: 1fr 1fr 1fr;
}
@media (max-width: 720px) {
  .form-row-3 { grid-template-columns: 1fr; }
}
.form-label-strong {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 8px 0;
  display: block;
}
.label-file {
  display: block;
  font-size: 14px;
  font-weight: 500;
}
.label-file input[type="file"] {
  display: block;
  margin-top: 6px;
  font-size: 13px;
}
.produto-anexos-existentes {
  margin-bottom: 16px;
}
.produto-anexos-existentes-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.produto-anexos-existentes-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.produto-anexo-nome { flex: 1; min-width: 120px; word-break: break-word; }
.produto-anexo-tipos { color: var(--text-muted); font-size: 13px; }
.produto-anexo-tipos span { margin-right: 8px; }
.link-inline { font-size: 14px; }
.checkbox-wrap-inline { margin: 0; }
.produto-anexos-novos { margin-bottom: 12px; }
.produto-anexo-linha {
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 12px;
  background: var(--surface-alt, #fafbfc);
}
.produto-anexo-linha-tipos {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}
.form-hint-inline { font-size: 13px; color: var(--text-muted); margin-right: 4px; }
.btn.btn-sm {
  height: 32px;
  padding: 6px 12px;
  font-size: 13px;
}
.form-hint-block { display: block; margin-top: 8px; }
.card.card-produto-form { max-width: min(720px, 100%); }
.form-actions { display: flex; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
.form-group .required { color: var(--danger); }
.form-group .error { color: var(--danger); font-size: 13px; margin-top: 4px; }
.form-group .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-group .form-static { font-size: 14px; color: var(--text); margin: 0; padding: 10px 0; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 44px; }
.password-wrap .toggle-visibility {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-muted);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  height: 36px;
  border-radius: var(--radius-xl);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: var(--primary-text-on); }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-muted); }
.links { margin-top: 16px; text-align: center; font-size: 13px; }
.links a { color: var(--primary); text-decoration: none; }
.links a:hover { text-decoration: underline; }
.alert { padding: 12px; border-radius: var(--radius-md); margin-bottom: 16px; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-error { background: #fee2e2; color: #991b1b; }
.checkbox-wrap { display: flex; align-items: center; gap: 8px; }
.checkbox-wrap input[type="checkbox"] { width: auto; }

/* Manutenção: menu superior da seção */
.manutencao-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.manutencao-tabs a {
  padding: 10px 16px;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
}
.manutencao-tabs a:hover { color: var(--text); }
.manutencao-tabs a.active { color: var(--primary); font-weight: 500; border-bottom-color: var(--primary); }

/* Tabela de dados */
.card-table { max-width: none; }
.card-table h2 { margin-top: 0; font-size: 18px; }
.card-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.card-table-header .btn { flex-shrink: 0; }
.table-info { font-size: 13px; color: var(--text-muted); margin: 0 0 12px 0; }
.table-wrap { overflow-x: auto; }
.cliente-nome {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 12px 0;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th { background: var(--surface-muted); font-weight: 600; color: var(--text); }
.data-table tbody tr:hover { background: var(--surface-muted); }
.data-table td { color: var(--text); }
.pagination {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.pagination a {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}
.pagination a:hover:not(.disabled) { background: var(--surface-muted); }
.pagination a.disabled { opacity: 0.5; pointer-events: none; }
.pagination-info { font-size: 13px; color: var(--text-muted); }

/* Células de texto longas: truncamento visual (complementa truncamento em 100 chars no servidor) */
.data-table td.cell-text {
  max-width: 35ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.data-table tbody tr.clickable { cursor: default; }
.data-table tbody tr.clickable:hover { background: var(--surface-muted); }
.data-table td a.external-link { color: var(--primary); text-decoration: none; }
.data-table td a.external-link:hover { text-decoration: underline; }

/* Ações na tabela (editar / excluir) */
.data-table td.cell-actions {
  white-space: nowrap;
  vertical-align: middle;
}
.data-table .row-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  margin-right: 6px;
}
.data-table .row-action:last-child { margin-right: 0; }
.data-table .row-action:hover { background: var(--surface-muted); }
.data-table .row-action.icon-btn-danger { color: var(--danger); border-color: var(--danger); }
.data-table .row-action.icon-btn-danger:hover { background: rgba(240, 68, 56, 0.08); }
.data-table .row-action.is-disabled {
  opacity: 0.45;
  pointer-events: none;
  cursor: default;
}
.data-table .row-action-form { display: inline; margin-right: 6px; }
.data-table .row-action-form .row-action-delete { margin-left: 14px; margin-right: 0; }
.data-table .row-action-form button.row-action { padding: 0; font: inherit; cursor: pointer; }

/* Modal de detalhes */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.is-open { display: flex; }
.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: 560px;
  min-height: 320px;
  width: 85vw;
  max-width: 960px;
  height: 80vh;
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 4px 24px rgba(16, 24, 40, 0.15);
}
/* Sobrescreve .modal-content (max-width: 960px) para modais de formulário largos */
.modal-content.modal-content--form {
  width: min(98vw, 1440px);
  max-width: 1440px;
  min-width: 0;
  min-height: 0;
  height: auto;
  max-height: min(94vh, 960px);
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* Coluna esquerda = painéis coloridos; coluna direita = formulário (não empilha o form abaixo dos boxes) */
.modal-reporte-intro {
  margin-bottom: 0.75rem;
}
.modal-reporte-layout {
  display: grid;
  grid-template-columns: minmax(260px, 520px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}
.modal-reporte-detalhes-col.modal-erro-detalhes {
  margin-bottom: 0;
}
.modal-reporte-detalhes-col {
  min-width: 0;
  max-height: min(82vh, 880px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 1100px) {
  .modal-reporte-layout {
    grid-template-columns: 1fr;
  }
  .modal-reporte-detalhes-col {
    max-height: none;
    overflow: visible;
  }
}

/* Bloco inferior: descrição + CST / cClassTrib (abaixo da linha colorida + sugestão) */
.modal-reporte-form-bottom {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.modal-reporte-cst-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.modal-reporte-form-sugestao {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-muted);
  min-width: 0;
}
.modal-reporte-sugestao-lead {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
}
.modal-reporte-sugestao-hint {
  margin-top: 0;
  margin-bottom: 0.75rem;
  font-size: 12px;
}
.modal-reporte-use-cb {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 0.35rem;
  cursor: pointer;
}
.modal-reporte-use-cb input {
  margin-top: 0.15rem;
  flex-shrink: 0;
}
.modal-reporte-sugestao-block select:disabled {
  opacity: 0.65;
}
.modal-reporte-multi {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.modal-reporte-multi--ufs {
  max-height: 9rem;
}
.modal-reporte-zfm {
  width: 100%;
  max-width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
}
.modal-reporte-form-actions {
  margin-top: 1rem;
}
@media (max-width: 768px) {
  .modal-reporte-cst-grid {
    grid-template-columns: 1fr;
  }
}
.modal-content h3 { margin-top: 0; font-size: 18px; }
.modal-content .detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.modal-content .detail-table th {
  text-align: left;
  padding: 8px 12px 8px 0;
  vertical-align: top;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  width: 1%;
}
.modal-content .detail-table td {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}
.modal-content .detail-table td a.external-link {
  color: var(--primary);
  text-decoration: none;
}
.modal-content .detail-table td a.external-link:hover { text-decoration: underline; }
.modal-content .detail-table tr.bug-detail-section-row th {
  padding: 14px 0 8px;
  border-bottom: 1px solid var(--border-strong);
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: none;
}
.modal-close {
  margin-top: 16px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
}
.modal-close:hover { background: var(--surface-muted); }

/* Modal reportar erro: blocos empilhados; rolagem só no modal e no corpo de cada seção (sem scroll duplo no invólucro) */
.modal-erro-detalhes {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  background: var(--surface-muted);
}

.modal-erro-detalhes--painel {
  overflow: visible;
  max-height: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-reportar-erro {
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text, inherit);
}
.btn-reportar-erro:hover { background: var(--surface-muted); }
.btn-reportar-erro .btn-reportar-erro__icon {
  width: 1.5em;
  height: 1.5em;
  vertical-align: middle;
  flex-shrink: 0;
  display: block;
}

.modal-erro-secao {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.modal-erro-secao--cliente {
  border-left: 4px solid #1565c0;
  background: linear-gradient(to right, rgba(21, 101, 192, 0.06), var(--surface));
}

.modal-erro-secao--oficial {
  border-left: 4px solid #37474f;
  background: linear-gradient(to right, rgba(55, 71, 79, 0.06), var(--surface));
}

.modal-erro-secao__titulo {
  flex: 0 0 auto;
  margin: 0;
  padding: 8px 10px;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.modal-erro-secao__body {
  flex: 0 1 auto;
  min-height: 5.5rem;
  max-height: min(28vh, 280px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 10px 10px;
  -webkit-overflow-scrolling: touch;
}

/* Primeiro bloco reúne planilha + contexto (mais linhas): mais altura útil, mesma rolagem interna */
.modal-erro-secao__body--reporte-linha {
  max-height: min(44vh, 400px);
}

.modal-erro-secao__body .detail-table {
  margin: 0;
}

/* Grid de serviços do cliente (menu em cards) */
.servicos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin: 16px 0;
}
.servico-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  aspect-ratio: 1 / 1;
}
.servico-card--inactive {
  background: var(--surface-muted);
  border-color: var(--border-strong);
  box-shadow: none;
  color: var(--text-subtle);
}
.servico-card--inactive .servico-card-title {
  color: var(--text-subtle);
}
.servico-card--inactive .servico-card-desc {
  color: var(--text-muted);
}
.servico-card-link {
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.servico-card-link:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.12);
  color: var(--primary);
}
.servico-card-title {
  font-size: 17px;
  font-weight: 700;
  color: inherit;
}
.servico-card-desc {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted, #64748b);
  line-height: 1.35;
}

/* Link de download do template de planilha */
.template-download {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
}
.template-download:hover {
  text-decoration: underline;
}
.template-download-icon-svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* Filtros listagem */
.filtros-form { margin-bottom: 16px; }
.filtro-rapido {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.filtro-rapido .input-search {
  min-width: 260px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.filtros-avancados {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  background: var(--surface-muted);
  border-radius: var(--radius-md);
}
.filtros-avancados.is-open { display: flex; }
.filtros-avancados select { padding: 6px 10px; border-radius: var(--radius-xs); border: 1px solid var(--border); }
.th-sort { text-decoration: none; color: inherit; }
.th-sort:hover { text-decoration: underline; }
.btn-inline { margin-left: 8px; }
/* Limpar filtros: esmaecido quando não há filtro aplicado, em destaque quando há */
.btn-clear-filters--inactive { opacity: 0.6; cursor: default; }
.btn-clear-filters--inactive:hover { background: var(--surface); }
.btn-clear-filters--active { font-weight: 500; }
.pagination .pagination-size { margin-left: 8px; }
.pagination .pagination-size select { padding: 6px 10px; border-radius: var(--radius-xs); border: 1px solid var(--border); font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.checkbox-group { display: flex; flex-wrap: wrap; gap: 12px 24px; }
.checkbox-inline { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; cursor: pointer; }
.radio-group { display: flex; flex-wrap: wrap; gap: 12px 24px; }
.radio-inline { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; cursor: pointer; }
.form-hint { font-size: 13px; color: var(--text-muted); margin: 0 0 8px 0; }

/* Breadcrumb (footprint) */
.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.breadcrumb a {
  color: var(--primary);
  text-decoration: none;
}
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb-sep { margin: 0 6px; }
.breadcrumb-current { color: var(--text); font-weight: 500; }
