/* ── Variáveis ─────────────────────────────────────────────── */
:root {
  --primary:       #16a34a;
  --primary-dark:  #15803d;
  --primary-light: #dcfce7;
  --text:          #111827;
  --muted:         #6b7280;
  --border:        #e5e7eb;
  --bg:            #f9fafb;
  --white:         #ffffff;
  --shadow-sm:     0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:     0 4px 16px rgba(0,0,0,0.10);
  --radius:        12px;
  --h-header:      56px;
  --h-filter:      120px; /* mobile: filtros quebram em ~2-3 linhas */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --h-header-total: calc(var(--h-header) + var(--safe-top));

  /* Paleta de gráficos */
  --c1: #16a34a;
  --c2: #0284c7;
  --c3: #d97706;
  --c4: #dc2626;
  --c5: #7c3aed;
  --c6: #0891b2;
  --c7: #be185d;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-top: calc(var(--h-header-total) + var(--h-filter));
  padding-bottom: 40px;
  overscroll-behavior: none;
}

/* ── Header ─────────────────────────────────────────────────── */
.dash-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--h-header-total);
  padding-top: var(--safe-top);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.dash-header-left { display: flex; align-items: center; gap: 14px; }
.dash-header-right { display: flex; align-items: center; gap: 10px; }

.btn-back {
  background: rgba(255,255,255,0.18);
  border: none;
  border-radius: 10px;
  padding: 6px 14px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-back:hover { background: rgba(255,255,255,0.28); }

.dash-header h1 { font-size: 18px; font-weight: 700; }

.last-update { font-size: 12px; color: rgba(255,255,255,0.75); }

.btn-refresh {
  background: rgba(255,255,255,0.18);
  border: none;
  border-radius: 10px;
  width: 44px; height: 44px;
  color: white;
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.btn-refresh:hover { background: rgba(255,255,255,0.28); }
.btn-refresh.spinning { animation: spin 0.8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Filtros ────────────────────────────────────────────────── */
.filter-bar {
  position: fixed;
  top: var(--h-header-total);
  left: 0; right: 0;
  height: auto;
  min-height: var(--h-filter);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  z-index: 90;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.filter-group label { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }

.filter-group select,
.filter-group input[type="date"] {
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}
.filter-group select:focus,
.filter-group input[type="date"]:focus { border-color: var(--primary); }

.btn-export-dash {
  margin-left: auto;
  height: 36px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-export-dash:hover { background: var(--border); }

/* ── Métricas ───────────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 16px;
  /* top padding handled by body padding-top */
}

@media (min-width: 640px)  { .metrics-grid { grid-template-columns: repeat(4, 1fr); } }

.metric-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.metric-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 6px;
}

.metric-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}
.metric-value.primary { color: var(--primary); }

.metric-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  min-height: 16px;
}

/* ── Gráficos ───────────────────────────────────────────────── */
.chart-section {
  margin: 0 16px 16px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.chart-tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  padding: 0 4px;
}
.chart-tabs::-webkit-scrollbar { display: none; }

.chart-tab {
  border: none;
  background: none;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  flex-shrink: 0;
}
.chart-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

.chart-wrapper {
  padding: 20px;
  position: relative;
  height: 300px;
}

@media (min-width: 768px) { .chart-wrapper { height: 380px; } }

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 10px;
  font-size: 16px;
}
.chart-empty span { font-size: 48px; }

#chart-canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Tabela ─────────────────────────────────────────────────── */
.table-section {
  margin: 0 16px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.table-header h2 { font-size: 15px; font-weight: 700; }

.table-count {
  font-size: 13px;
  color: var(--muted);
  background: var(--bg);
  padding: 3px 10px;
  border-radius: 20px;
}

.table-scroll { overflow-x: auto; }

.sales-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.sales-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.sales-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}

.sales-table tr:last-child td { border-bottom: none; }

.sales-table tbody tr:hover { background: var(--bg); }

.table-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px !important;
  font-size: 15px;
}

.td-valor  { font-weight: 700; color: var(--primary); }
.td-pay    {
  display: inline-block;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
}
.td-itens  { color: var(--muted); font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.td-seller { font-weight: 600; color: var(--primary-dark); }

/* ── Responsivo ─────────────────────────────────────────────── */
@media (min-width: 640px) {
  :root { --h-filter: 60px; }
  body { padding-top: calc(var(--h-header-total) + var(--h-filter)); }
  .filter-bar { flex-wrap: nowrap; height: var(--h-filter); }
}

@media (min-width: 1024px) {
  .metrics-grid { padding: 20px 24px 0; }
  .chart-section, .table-section { margin: 0 24px 20px; }
  .chart-wrapper { height: 420px; }
}
