:root {
  --accent:        #16a34a;
  --accent-dark:   #15803d;
  --accent-soft:   #dcfce7;
  --blue:          #2563eb;
  --orange:        #f97316;
  --red:           #ef4444;
  --yellow:        #eab308;

  --bg-page:       #f6f7f9;
  --bg-card:       #ffffff;
  --border:        #e7e9ee;
  --text-primary:  #14161a;
  --text-secondary:#5b616e;
  --text-muted:    #9aa0ac;

  --sidebar-bg:    #14161f;
  --sidebar-text:  #b7bcc9;
  --sidebar-text-active: #ffffff;
  --sidebar-hover: #1e2130;

  --shadow-card: 0 1px 2px rgba(16,18,27,0.04), 0 4px 16px rgba(16,18,27,0.06);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

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

/* Sidebar ------------------------------------------------------------------ */

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  transition: width 0.18s ease, flex-basis 0.18s ease;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 4px 22px 10px;
}
.sidebar-brand-mark {
  color: var(--accent);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}
.sidebar-brand-name { color: #fff; font-weight: 600; font-size: 1.05rem; white-space: nowrap; }

.btn-collapse {
  margin-left: auto;
  border: none;
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease;
}
.btn-collapse:hover { background: var(--accent); color: #fff; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; overflow-x: hidden; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.88rem;
  font-family: inherit;
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-item .nav-item-nome { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-item-overview { margin-bottom: 10px; padding-bottom: 11px; border-bottom: 1px solid rgba(255,255,255,0.08); }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; }
.dot-ok       { background: var(--accent); }
.dot-erro     { background: var(--red); }
.dot-pendente { background: #565c6b; }

.nav-item-avatar {
  display: none;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  background: #2a2d3d;
  color: #cfd2db;
  font-size: 0.68rem;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.02em;
}
.nav-item.status-ok .nav-item-avatar       { background: var(--accent); color: #fff; }
.nav-item.status-erro .nav-item-avatar     { background: var(--red); color: #fff; }
.nav-item.active .nav-item-avatar          { background: #fff; color: var(--accent); }

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  font-size: 0.72rem;
  color: #6c7280;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin-top: 10px;
  white-space: nowrap;
  overflow: hidden;
}

.btn-logout {
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 5px;
  flex: 0 0 auto;
}
.btn-logout:hover { background: var(--sidebar-hover); color: #fff; }

/* Collapsed state ----------------------------------------------------------*/

.sidebar.collapsed { width: 72px; flex-basis: 72px; }
.sidebar.collapsed .sidebar-brand { padding-left: 0; justify-content: center; }
.sidebar.collapsed .sidebar-brand-name { display: none; }
.sidebar.collapsed .btn-collapse { margin-left: 0; transform: rotate(180deg); }
.sidebar.collapsed .nav-item { justify-content: center; padding: 8px; }
.sidebar.collapsed .nav-item-nome,
.sidebar.collapsed .nav-item .dot,
.sidebar.collapsed .sidebar-foot { display: none; }
.sidebar.collapsed .nav-item-avatar { display: flex; }

/* Main ----------------------------------------------------------------------*/

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 32px;
  flex-wrap: wrap;
}
.main-header-title h1 { margin: 0; font-size: 1.4rem; font-weight: 700; letter-spacing: -0.01em; }
.main-header-subtitle { font-size: 0.85rem; color: var(--text-secondary); }

.header-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }

.filtro-data {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 5px 8px;
  box-shadow: var(--shadow-card);
}
.filtro-data input[type="date"] {
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.82rem;
  font-family: inherit;
  padding: 3px 2px;
}
.filtro-data-sep { color: var(--text-muted); font-size: 0.78rem; }

.filtro-presets { display: flex; gap: 4px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 4px; box-shadow: var(--shadow-card); }
.preset-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
}
.preset-btn:hover { background: var(--bg-page); }
.preset-btn.active { background: var(--accent); color: #fff; }

.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-size: 0.86rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-card); }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }

.btn-icon {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 3px 5px;
  border-radius: 4px;
}
.btn-icon:hover { background: var(--bg-page); color: var(--text-secondary); }

.main-content { padding: 4px 32px 48px; display: flex; flex-direction: column; gap: 20px; }

/* Cards ---------------------------------------------------------------------*/

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px 22px;
}
.card h2 { margin: 0 0 16px; font-size: 0.95rem; font-weight: 700; }
.card h3 { margin: 0 0 14px; font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }

/* KPI tiles -------------------------------------------------------------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(205px, 1fr));
  gap: 14px;
}
.kpi-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.kpi-tile::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--kpi-accent, var(--accent));
}
.kpi-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 600; }
.kpi-value { font-size: 1.3rem; font-weight: 700; color: var(--text-primary); margin-top: 6px; }

/* Charts ----------------------------------------------------------------- */

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.chart-card.chart-wide { grid-column: 1 / -1; }

@media (max-width: 820px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.chart-canvas-wrap { position: relative; width: 100%; }

/* Cards por App ------------------------------------------------------------*/

.app-cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.app-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}
.app-card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.app-card-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; }
.app-card-nome { font-weight: 700; font-size: 0.92rem; color: var(--text-primary); }
.app-card-pct { margin-left: auto; font-size: 0.78rem; font-weight: 700; color: var(--text-secondary); }

.app-card-metrics { display: flex; flex-direction: column; gap: 9px; }
.app-card-metric { display: flex; align-items: baseline; justify-content: space-between; }
.app-card-metric .k { font-size: 0.76rem; color: var(--text-secondary); }
.app-card-metric .v { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* Pedidos — Origem -> Pedidos (accordion) --------------------------------- */

.grupos-origem-wrap { display: flex; flex-direction: column; gap: 10px; }

details.grupo-origem {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
details.grupo-origem > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-page);
  cursor: pointer;
  list-style: none;
  font-size: 0.86rem;
  font-weight: 600;
}
details.grupo-origem > summary::-webkit-details-marker { display: none; }
details.grupo-origem > summary::before { content: '▸'; color: var(--text-muted); font-weight: 400; }
details.grupo-origem[open] > summary::before { content: '▾'; }

.grupo-qtd { color: var(--text-secondary); font-size: 0.82rem; font-weight: 400; }
.grupo-valor { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
thead th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
tbody td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr.linha-pedido { cursor: pointer; }
tbody tr.linha-pedido:hover { background: var(--bg-page); }

.origem-tag { padding: 2px 9px; border-radius: 20px; font-size: 0.7rem; font-weight: 700; color: #fff; }
.origem-N { background: var(--blue); }
.origem-X { background: var(--orange); }

.expand-toggle { color: var(--text-muted); font-size: 0.7rem; width: 18px; text-align: center; }

.detalhe-row td { background: var(--bg-page); padding: 12px 16px; white-space: normal; }
.detalhe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px 18px;
  font-size: 0.78rem;
}
.detalhe-grid div span.k { color: var(--text-muted); display: block; font-size: 0.65rem; text-transform: uppercase; }

.sem-dados { text-align: center; color: var(--text-muted); padding: 40px 0; font-size: 0.88rem; }

@media (max-width: 760px) {
  .main-header { padding: 18px 18px; }
  .main-content { padding: 4px 18px 40px; }
}

/* Login ---------------------------------------------------------------------*/

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 32px 30px;
}

.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.logo-mark {
  width: 44px; height: 44px; flex: 0 0 44px;
  background: var(--sidebar-bg);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
}
.logo-mark img { width: 28px; height: 28px; object-fit: contain; }
.logo-text .name { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.logo-text .sub  { font-size: 0.7rem; font-weight: 700; color: var(--text-muted); letter-spacing: 0.12em; text-transform: uppercase; }

.login-error {
  display: none;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 0.82rem;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}
.login-error.show { display: block; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text-primary);
}
.field input:focus { outline: none; border-color: var(--accent); }

.btn-full { width: 100%; margin-top: 6px; }
