/* ============================================================
   DESIGN TOKENS — BI360 | Avenida
   Paleta: vinho da marca Avenida + dourado de destaque
   Tipografia: Fraunces (display, números-chave) + Inter (dados/UI)
   ============================================================ */

:root {
  --wine-900: #4A0E13;
  --wine-700: #7A1119;
  --wine-600: #931821;
  --wine-500: #A5232D;
  --gold-500: #D7A42A;
  --gold-100: #F4E7CA;

  --paper: #F5F3EF;
  --surface: #FFFFFF;
  --surface-sunken: #FAF8F5;
  --border: #E8E1D9;
  --border-strong: #D9CFC2;

  --ink-900: #22252A;
  --ink-700: #4A4F55;
  --ink-500: #767D83;
  --ink-300: #A2A8AC;

  --positive: #1E8E5A;
  --negative: #B8262F;
  --neutral: #767D83;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius-lg: 18px;
  --radius-md: 13px;
  --radius-sm: 9px;

  --shadow-card: 0 2px 10px rgba(34, 20, 15, 0.05);
  --shadow-header: 0 6px 18px rgba(74, 14, 19, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink-900);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 440px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------------- HEADER ---------------- */

.app-header {
  position: relative;
  padding: 20px 18px 16px;
  overflow: hidden;
  background:
    radial-gradient(circle at 8% 0%, rgba(255,255,255,0.12), transparent 40%),
    linear-gradient(130deg, var(--wine-600) 0%, var(--wine-700) 55%, var(--wine-900) 100%);
  color: #FFFFFF;
  flex-shrink: 0;
}

.app-header::after {
  content: "";
  position: absolute;
  width: 240px;
  height: 200px;
  top: -90px;
  right: -90px;
  transform: rotate(-24deg);
  border: 1px solid rgba(255,255,255,0.10);
  pointer-events: none;
}

.app-header-top {
  display: flex;
  align-items: center;
  gap: 13px;
  position: relative;
  z-index: 1;
}

.app-logo {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-logo img { width: 44px; height: 44px; object-fit: contain; }

.app-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.2px;
  line-height: 1.15;
}

.app-subtitle {
  margin-top: 3px;
  color: var(--gold-500);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.app-update {
  margin-top: 13px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.14);
  color: rgba(255,255,255,0.85);
  font-size: 10.5px;
  position: relative;
  z-index: 1;
}

.app-update strong { color: #FFFFFF; font-weight: 700; }

.pulse-dot {
  display: inline-block;
  margin-left: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #37D673;
  box-shadow: 0 0 0 rgba(55, 214, 115, 0.6);
  animation: pulse 2.2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(55, 214, 115, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(55, 214, 115, 0); }
  100% { box-shadow: 0 0 0 0 rgba(55, 214, 115, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .pulse-dot { animation: none; }
}

/* ---------------- CONTENT ---------------- */

.app-content {
  flex: 1;
  padding: 14px 12px 90px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-900);
  margin: 18px 3px 4px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.section-title .tag-live {
  font-family: var(--font-body);
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--gold-100);
  color: #8A6412;
  padding: 2px 7px;
  border-radius: 10px;
}

.section-caption {
  font-size: 10.5px;
  color: var(--ink-500);
  line-height: 1.4;
  margin: 0 3px 10px;
}

/* Seletor de competência */

.period-select-wrap { margin: 6px 3px 4px; }

.period-select-label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ink-500);
  margin-bottom: 5px;
}

select.period-select {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23767D83'/%3E%3C/svg%3E") no-repeat right 14px center;
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-900);
  appearance: none;
  box-shadow: var(--shadow-card);
}

/* KPI grid */

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.kpi-card {
  min-height: 92px;
  padding: 12px 11px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.kpi-card.featured {
  grid-column: span 2;
  background: linear-gradient(135deg, #FFFFFF, #FBF1EC);
  border-color: var(--border-strong);
}

.kpi-label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--ink-500);
  margin-bottom: 8px;
}

.kpi-value {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--ink-900);
  line-height: 1.1;
}

.kpi-card.featured .kpi-value { font-size: 26px; }

.kpi-note {
  font-size: 9.5px;
  color: var(--ink-700);
  line-height: 1.35;
  margin-top: 7px;
}

.kpi-note.ok { color: var(--positive); font-weight: 700; }

.kpi-trend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
}

.kpi-trend svg { width: 46px; height: 18px; }

.kpi-trend-tag {
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
}

.kpi-trend-tag.positiva { color: var(--positive); background: #E4F5EC; }
.kpi-trend-tag.negativa { color: var(--negative); background: #FBEAEA; }
.kpi-trend-tag.neutra { color: var(--neutral); background: #F0EEEA; }

/* Painéis genéricos */

.panel {
  padding: 13px 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  margin-bottom: 10px;
}

.panel-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-900);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-subtitle {
  font-size: 10px;
  color: var(--ink-500);
  margin-bottom: 8px;
  line-height: 1.35;
}

.tag-current {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--gold-100);
  color: #8A6412;
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
}

.chart-box { position: relative; width: 100%; }
.chart-box.h-140 { height: 140px; }
.chart-box.h-170 { height: 170px; }
.chart-box.h-190 { height: 190px; }

/* Tributos */

.tax-grid { display: grid; grid-template-columns: 1fr; gap: 9px; }

.tax-card {
  padding: 13px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.tax-header { display: flex; justify-content: space-between; align-items: start; gap: 8px; margin-bottom: 9px; }

.tax-name {
  font-size: 13.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--ink-700);
}

.tax-origin { font-size: 8.5px; color: var(--ink-500); text-align: right; line-height: 1.25; font-weight: 600; }

.tax-main {
  padding: 10px;
  border-radius: 10px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  margin-bottom: 9px;
}

.tax-result-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-500);
}

.tax-value { font-family: var(--font-display); font-size: 21px; font-weight: 600; margin-top: 4px; }
.tax-value.pagar { color: var(--negative); }
.tax-value.credito { color: var(--positive); }
.tax-value.zerado { color: var(--neutral); }

.tax-detail-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding-top: 6px; margin-top: 6px; border-top: 1px solid var(--border);
  font-size: 10px;
}
.tax-detail-row:first-child { border-top: none; margin-top: 0; padding-top: 0; }
.tax-detail-label { color: var(--ink-700); font-weight: 600; }
.tax-detail-value { font-weight: 700; }
.tax-detail-value.pagar { color: var(--negative); }
.tax-detail-value.credito { color: var(--positive); }
.tax-detail-value.zerado { color: var(--neutral); }

.tax-status {
  margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--border);
  font-size: 8.7px; font-weight: 600; color: #A66A16; line-height: 1.3;
}
.tax-status.validado { color: var(--positive); }

/* Dias / linha do dia */

.day-row {
  min-height: 44px; padding: 6px 9px; margin-bottom: 5px;
  display: grid; grid-template-columns: 84px 1fr 52px; align-items: center; gap: 6px;
  border-radius: 8px; background: var(--surface-sunken); border: 1px solid transparent;
}
.day-row.today { background: #FFF4EE; border-color: var(--gold-500); }
.day-name { font-size: 11px; font-weight: 700; color: var(--ink-700); }
.day-date { font-size: 9px; color: var(--ink-500); margin-top: 1px; }
.day-value { font-family: var(--font-display); font-weight: 600; font-size: 13px; text-align: right; }
.day-status { font-size: 8.5px; font-weight: 700; text-align: right; color: var(--ink-500); text-transform: uppercase; }
.day-status.today { color: #A66A16; }

/* Comparativo semanal */

.weekly-compare {
  padding: 11px; border-radius: var(--radius-md);
  background: linear-gradient(135deg, #FBF1EC, #FFFFFF); border: 1px solid var(--border-strong);
  margin-bottom: 10px;
}
.weekly-compare-title { font-size: 10.5px; font-weight: 700; color: var(--ink-700); margin-bottom: 8px; }
.weekly-values { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.weekly-value-label { font-size: 9px; color: var(--ink-500); font-weight: 600; }
.weekly-value-number { font-family: var(--font-display); font-size: 15px; font-weight: 600; margin-top: 2px; }
.weekly-variation { font-size: 11px; font-weight: 700; }
.weekly-variation.positiva { color: var(--positive); }
.weekly-variation.negativa { color: var(--negative); }
.weekly-variation.neutra { color: var(--neutral); }

.warning-box {
  padding: 11px 12px; border-radius: var(--radius-md);
  background: var(--gold-100); color: #6B4A0C; font-size: 10px; line-height: 1.4;
  margin: 4px 0 12px;
}

.empty-state {
  padding: 22px 14px; text-align: center; color: var(--ink-500); font-size: 12px;
}

.app-footer {
  text-align: center; font-size: 9.5px; color: var(--ink-300);
  line-height: 1.5; padding: 14px 0 4px;
}

/* Produtos */

.filters-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 3px 12px; }

.prod-kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.prod-kpi {
  display: flex; align-items: center; gap: 9px;
  padding: 11px; border-radius: var(--radius-md); border: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow-card);
}
.prod-kpi-icon {
  width: 30px; height: 30px; border-radius: 9px; background: var(--gold-100); color: #8A6412;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.prod-kpi-icon svg { width: 16px; height: 16px; }
.prod-kpi-label { font-size: 8.8px; font-weight: 700; text-transform: uppercase; color: var(--ink-500); }
.prod-kpi-value { font-family: var(--font-display); font-size: 14.5px; font-weight: 600; margin-top: 2px; }

.bar-row { margin-bottom: 11px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-head { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; margin-bottom: 5px; }
.bar-label { font-weight: 600; color: var(--ink-900); }
.bar-value { color: var(--ink-500); font-weight: 600; white-space: nowrap; }
.bar-track { height: 8px; border-radius: 5px; background: var(--surface-sunken); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; background: var(--wine-500); }
.bar-fill.secondary { background: var(--gold-500); }

table.data-table {
  width: 100%; border-collapse: collapse; font-size: 11px;
}
table.data-table th {
  text-align: left; font-size: 9px; text-transform: uppercase; color: var(--ink-500);
  font-weight: 700; padding: 0 4px 6px; border-bottom: 1px solid var(--border);
}
table.data-table th.num, table.data-table td.num { text-align: right; }
table.data-table td {
  padding: 7px 4px; border-bottom: 1px solid var(--border); color: var(--ink-900);
}
table.data-table td.produto { font-weight: 600; }
table.data-table tr:last-child td { border-bottom: none; }

/* Financeiro / donut */

.fin-summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.fin-summary-box {
  padding: 10px; border-radius: var(--radius-sm); background: var(--surface-sunken); border: 1px solid var(--border);
}
.fin-summary-label { font-size: 9px; color: var(--ink-500); font-weight: 700; text-transform: uppercase; }
.fin-summary-value { font-family: var(--font-display); font-size: 15px; font-weight: 600; margin-top: 3px; }

.fin-legend-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-top: 1px solid var(--border); font-size: 11px; }
.fin-legend-row:first-child { border-top: none; }
.fin-legend-left { display: flex; align-items: center; gap: 7px; }
.fin-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.fin-legend-name { font-weight: 600; }
.fin-legend-right { display: flex; align-items: center; gap: 8px; }
.fin-legend-percent { color: var(--ink-500); font-size: 10px; min-width: 40px; text-align: right; }

/* Placeholder (Fiscal) */

.placeholder-card {
  padding: 20px 16px; border-radius: var(--radius-lg); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-card); text-align: center;
}
.placeholder-title { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.placeholder-subtitle { font-size: 11.5px; color: var(--ink-700); line-height: 1.5; margin-bottom: 14px; }
.placeholder-list { display: grid; gap: 7px; text-align: left; margin-bottom: 14px; }
.placeholder-item {
  font-size: 11px; padding: 9px 11px; border-radius: 9px; background: var(--surface-sunken);
  border: 1px solid var(--border); color: var(--ink-700);
}

/* Loading / erro */

.loading-state, .error-state { padding: 40px 16px; text-align: center; color: var(--ink-500); font-size: 12px; }
.error-state { color: var(--negative); }

.spinner {
  width: 22px; height: 22px; margin: 0 auto 10px;
  border: 2.5px solid var(--border-strong); border-top-color: var(--wine-500);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.6s; } }

/* ---------------- BOTTOM NAV ---------------- */

.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 440px;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 14px rgba(34, 20, 15, 0.06);
  z-index: 20;
}

.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 9px 0 10px; background: none; border: none; cursor: pointer;
  color: var(--ink-500); font-family: var(--font-body); font-size: 9.5px; font-weight: 600;
}

.nav-item svg { width: 21px; height: 21px; }

.nav-item.active { color: var(--wine-600); }
.nav-item.active svg { color: var(--wine-600); }

.nav-indicator {
  width: 4px; height: 4px; border-radius: 50%; background: transparent; margin-top: 1px;
}
.nav-item.active .nav-indicator { background: var(--wine-600); }

@media (max-width: 380px) {
  .kpi-value { font-size: 17px; }
  .kpi-card.featured .kpi-value { font-size: 22px; }
}
