/* ============================================================
   MARGEM.CSS — alinhado com style.css
   Depende de: style.css (tokens :root, .hdr, .kpi, .panel, etc.)
   ============================================================ */

/* ============================================================
   TABELA
   ============================================================ */

.margem-page #margem-tbody tr {
  cursor: default;
}

.margem-page #margem-tbody tr:hover td {
  background: rgba(255,255,255,.012);
}

.margem-page #margem-tbody td:last-child {
  text-align: center;
}

/* linha clicável */
.margem-page #margem-tbody tr.margem-row-clickable {
  cursor: pointer;
  transition: background .15s;
}

.margem-page #margem-tbody tr.margem-row-clickable:hover td {
  background: var(--bg-hover);
}

.margem-page #margem-tbody td.col-txt {
  font-size: 11.5px;
  font-family: var(--font);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.margem-page #margem-tbody td.col-txt:last-child {
  font-weight: 400;
  text-align: center;
  white-space: normal;
}

/* ============================================================
   NOTA EXPLICATIVA
   ============================================================ */

.margem-note {
  margin-bottom: 24px;
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card2);
  line-height: 1.6;
  font-size: 12.5px;
  color: var(--text-dim);
  position: relative;
  overflow: hidden;
}

.margem-note::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0; width: 2.5px;
  background: linear-gradient(180deg, var(--blue), var(--blue2));
  border-radius: 2px 0 0 2px;
}

.margem-note strong {
  color: var(--text);
  font-weight: 600;
}

/* ============================================================
   KPIs — herda .kpi do style.css, apenas ajustes da página
   ============================================================ */

.margem-kpi-grid {
  margin-bottom: 24px;
}

/* cor extra pro KPI amarelo (ausente no style.css) */
.kpi.yellow {
  border-color: rgba(245,158,11,.20);
}

.kpi.yellow:hover {
  border-color: rgba(245,158,11,.40);
}

.kpi.yellow::before {
  background: linear-gradient(90deg, var(--amber), #fbbf24);
}

/* ============================================================
   LISTAS — Mix de Custos e Top Itens
   ============================================================ */

.mix-list,
.item-list {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.mix-row,
.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.013);
  transition: background .12s;
}

.mix-row:hover,
.item-row:hover {
  background: var(--bg-hover);
}

.mix-label,
.item-label {
  display: grid;
  gap: 4px;
}

.mix-title,
.item-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.mix-sub,
.item-sub {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.mix-value,
.item-value {
  text-align: right;
}

.mix-amount,
.item-amount {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
}

.mix-percent,
.item-percent {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
}

/* barra de progresso */
.mix-bar {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: var(--radius-pill);
  background: rgba(255,255,255,.06);
  overflow: hidden;
}

.mix-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--blue2));
  border-radius: var(--radius-pill);
}

/* ============================================================
   MODAL DA MARGEM
   ============================================================ */

body.margem-modal-open {
  overflow: hidden;
}

.margem-modal-faux {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 16px;
  background: rgba(2,5,10,.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.margem-modal-faux.open {
  display: flex;
}

.margem-modal-box {
  width: min(940px, 100%);
  max-height: calc(100vh - 64px);
  overflow: hidden;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border3);
  box-shadow: 0 24px 64px rgba(0,0,0,.55);
}

/* cabeçalho do modal */
.margem-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border);
}

.margem-modal-head h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.margem-modal-head p {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 4px;
}

/* botão fechar */
.margem-modal-close {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border3);
  background: rgba(255,255,255,.04);
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}

.margem-modal-close:hover {
  background: rgba(244,63,94,.12);
  border-color: rgba(244,63,94,.28);
  color: var(--red);
}

/* corpo do modal */
.margem-modal-body {
  padding: 18px 22px;
  overflow-y: auto;
  max-height: calc(100vh - 160px);
}

/* tabela interna do modal */
.margem-modal-table-wrap {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.margem-modal-table-scroll {
  max-height: calc(100vh - 240px);
  overflow: auto;
}

.margem-modal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.margem-modal-table thead th {
  position: sticky;
  top: 0;
  background: rgba(255,255,255,.02);
  z-index: 1;
}

.margem-modal-table tbody tr:hover td {
  background: var(--bg-hover);
}

/* níveis de indentação */
.margem-modal-level-1 {
  padding-left: 30px;
  position: relative;
}

.margem-modal-level-1::before {
  content: '';
  position: absolute;
  left: 16px;
  top: 50%;
  width: 8px;
  height: 1px;
  background: var(--border3);
}

/* linhas destacadas */
.margem-modal-row-principal td {
  background: var(--blue-dim);
  font-weight: 700;
}

.margem-modal-row-total td {
  background: var(--red-dim);
  font-weight: 700;
}

.margem-modal-row-resultado td {
  background: var(--green-dim);
  font-weight: 700;
}

/* ============================================================
   RESPONSIVO
   ============================================================ */

@media (max-width: 960px) {
  .margem-bottom-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .shell { padding: 0 12px 36px; }
  .hdr { margin-inline: -12px; }
  .hdr-info h1 { font-size: .95rem; }
  .hdr-time { display: none; }
  .nav-link-btn { padding: 8px 12px; font-size: 10px; }
}