/* ═══════════════════════════════════════════════════════════════════════
   Menu principal do cabeçalho (expande para baixo) + Dashboard + Economia
   Carregado depois de ui.css/ui-modern.css para vencer a cascata.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── 1. Menu na mesma linha do cabeçalho ─────────────────────────────── */
.header { position: relative; }

.main-menu {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.main-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.main-menu-toggle:hover,
.main-menu-toggle.active {
  background: var(--primary-soft, rgba(74, 158, 255, 0.16));
  border-color: var(--primary);
  color: var(--primary);
}
.main-menu-icon { font-size: 0.95rem; line-height: 1; }
.main-menu-caret { font-size: 0.7rem; opacity: 0.8; }

/* Dropdown: abre para baixo, ancorado no cabeçalho */
.main-menu-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 1200;
  display: grid;
  grid-template-columns: repeat(3, minmax(190px, 1fr));
  gap: 4px 18px;
  padding: 14px 16px;
  min-width: 620px;
  max-width: min(94vw, 860px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  animation: mainMenuIn 0.14s ease-out;
}
@keyframes mainMenuIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.main-menu-col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.main-menu-col h3 {
  margin: 0 0 6px;
  padding: 0 8px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.main-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.83rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.main-menu-item:hover { background: var(--surface-2); color: var(--primary); }
.main-menu-item .roles-badge { margin-left: auto; }
.main-menu-hint {
  padding: 6px 10px;
  font-size: 0.72rem;
  color: var(--warning);
}

/* ── 2. Contador de economia de tokens ───────────────────────────────── */
.savings-box {
  margin-bottom: 14px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.savings-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.8rem;
  font-weight: 600;
}
.savings-box-head small { color: var(--text-muted); font-weight: 400; }
.savings-periods { display: flex; gap: 4px; }

.savings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}
.savings-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  min-width: 0;
}
.savings-cell.success {
  border-color: rgba(34, 197, 94, 0.45);
  background: rgba(34, 197, 94, 0.08);
}
.savings-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.savings-cell strong {
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}
.savings-cell.success strong { color: var(--success); }
.savings-cell small {
  font-size: 0.68rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.savings-bar {
  margin-top: 10px;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.savings-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), #10b981);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.savings-foot {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.savings-foot strong { color: var(--success); }

/* ── 3. Dashboard ────────────────────────────────────────────────────── */
.dashboard-modal .dashboard-body {
  padding: 12px 14px 18px;
  max-height: 74vh;
  overflow-y: auto;
}

.dash-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.dash-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.dash-card-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.dash-card strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.dash-card small { font-size: 0.7rem; color: var(--text-muted); }

.dash-section { margin-top: 16px; }
.dash-section h3 {
  margin: 0 0 8px;
  font-size: 0.88rem;
  font-weight: 600;
}
.dash-section h3 small { color: var(--text-muted); font-weight: 400; }

.dash-empty {
  margin: 0 0 8px;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.dash-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 0.62rem;
  color: var(--text-muted);
}
.dash-legend {
  display: flex;
  gap: 14px;
  margin-top: 4px;
  font-size: 0.66rem;
  color: var(--text-muted);
}
.dash-legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-radius: 2px;
}

.dash-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
}
.dash-table thead tr {
  text-align: left;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.dash-table th { padding: 4px 6px; font-weight: 500; }
.dash-table td { padding: 4px 6px; border-bottom: 1px solid var(--surface-2); }
.dash-mono {
  font-family: var(--mono);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dash-num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dash-ok { color: var(--success); }
.dash-warn { color: var(--warning); }
.dash-bad { color: var(--error); }

.dash-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 0.72rem;
}
.dash-bar-name {
  width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
}
.dash-bar-track {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.dash-bar-fill { height: 100%; border-radius: 4px; }
.dash-bar-fill.ok { background: var(--success); }
.dash-bar-fill.warn { background: var(--warning); }
.dash-bar-val {
  width: 62px;
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* ── 3b. Jobs (background) ───────────────────────────────────────────── */
.jobs-body {
  padding: 4px 2px 8px;
  max-height: 72vh;
  overflow-y: auto;
}

.jobs-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}
.jobs-filter {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.jobs-filter select,
.jobs-filter input {
  font-size: 0.76rem;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  min-width: 140px;
}
.jobs-filter-id input { min-width: 200px; font-family: var(--mono); }

.jobs-detail {
  margin: 8px 0 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
}
.jobs-detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}
.jobs-detail-meta {
  margin: 6px 0 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ── 4. Responsivo ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .main-menu-dropdown {
    grid-template-columns: 1fr;
    min-width: 240px;
    max-width: 88vw;
    max-height: 70vh;
    overflow-y: auto;
  }
}
@media (max-width: 700px) {
  .main-menu-label { display: none; }
  .main-menu-toggle { padding: 6px 10px; }
  .dash-cards { grid-template-columns: repeat(2, 1fr); }
}
