/* ==========================================================================
   BI Flash / Prime — Design System
   Tema claro moderno, marca Flash (vermelho) como acento
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;700;800&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500&display=swap');

:root{
  /* Marca — acento, nunca dominante */
  --flash-red: #d90000;
  --flash-red-dark: #b30000;
  --flash-red-soft: #fdeaea;
  --flash-amber: #f5a623;
  --flash-amber-soft: #fef6e7;

  /* Base */
  --bg-page: #f3f4f7;
  --bg-card: #ffffff;
  --bg-muted: #f8f9fb;
  --bg-sidebar: #14151b;
  --border-soft: #e7e9ee;
  --border-strong: #dcdfe6;

  --text-primary: #15161d;
  --text-secondary: #5c6270;
  --text-muted: #8b90a0;
  --text-on-dark: #f4f5f8;
  --text-on-dark-muted: #9498a6;

  --status-ok: #17864f;
  --status-ok-bg: #e8f7ef;
  --status-warn: #b4680a;
  --status-warn-bg: #fdf1de;
  --status-bad: #b3261e;
  --status-bad-bg: #fbeceb;
  --status-muted: #9aa0ac;
  --status-muted-bg: #f1f2f5;

  --shadow-sm: 0 1px 2px rgba(15,17,23,.05), 0 1px 3px rgba(15,17,23,.06);
  --shadow-md: 0 6px 16px rgba(15,17,23,.06), 0 2px 6px rgba(15,17,23,.05);
  --shadow-lg: 0 16px 32px rgba(15,17,23,.09), 0 4px 10px rgba(15,17,23,.05);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --font-display: 'Manrope', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --sidebar-w: 76px;
}

*{ box-sizing: border-box; }
html, body{ height: 100%; }
body{
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg-page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4{
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--text-primary);
  margin: 0;
}
p{ margin: 0; }
a{ color: inherit; text-decoration: none; }
button{ font-family: inherit; cursor: pointer; }
::-webkit-scrollbar{ width: 8px; height: 8px; }
::-webkit-scrollbar-thumb{ background: #d3d6dd; border-radius: 8px; }
::-webkit-scrollbar-track{ background: transparent; }

/* ===== LAYOUT SHELL ===== */
.app-shell{
  display: flex;
  min-height: 100vh;
}

.sidebar{
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  color: var(--text-on-dark);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 22px 18px 22px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .mark{
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--flash-red), var(--flash-red-dark));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-brand .name{ font-family: var(--font-display); font-weight: 800; font-size: 15px; letter-spacing: .01em; }
.sidebar-brand .sub{ font-size: 11px; color: var(--text-on-dark-muted); margin-top: 1px; }

.nav-group{ padding: 16px 12px 4px 12px; }
.nav-group-label{
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: #6c7080;
  padding: 8px 10px 6px 10px;
}
.nav-item{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-on-dark-muted);
  margin-bottom: 2px;
  transition: background .12s ease, color .12s ease;
}
.nav-item svg{ width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.nav-item:hover{ background: rgba(255,255,255,.06); color: var(--text-on-dark); }
.nav-item.active{ background: rgba(217,0,0,.16); color: #fff; }
.nav-item.active svg{ opacity: 1; }

.sidebar-footer{
  margin-top: auto;
  padding: 14px 20px 20px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
  color: var(--text-on-dark-muted);
}
.sidebar-footer button{
  background: transparent;
  border: 1px solid rgba(255,255,255,.14);
  color: var(--text-on-dark-muted);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  width: 100%;
  margin-top: 10px;
  transition: all .12s ease;
}
.sidebar-footer button:hover{ border-color: rgba(255,255,255,.3); color: #fff; }

.main{
  flex: 1;
  min-width: 0;
  padding: 26px 32px 40px 32px;
}

.topbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.topbar .crumbs{ font-size: 12.5px; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; }
.topbar h1{ font-size: 1.5rem; }
.topbar-right{ display: flex; align-items: center; gap: 14px; }
.pill-date{
  display: flex; align-items: center; gap: 7px;
  background: var(--bg-card); border: 1px solid var(--border-soft);
  border-radius: 999px; padding: 8px 14px;
  font-size: 12.5px; font-weight: 600; color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
}
.user-chip{
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-card); border: 1px solid var(--border-soft);
  border-radius: 999px; padding: 6px 14px 6px 6px;
  box-shadow: var(--shadow-sm);
}
.user-chip .avatar{
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--flash-red-soft); color: var(--flash-red-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 12px; font-family: var(--font-display);
}
.user-chip .info{ font-size: 12px; line-height: 1.3; }
.user-chip .info b{ font-size: 12.5px; color: var(--text-primary); display: block; }

/* ===== CARDS ===== */
.card{
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.card-pad{ padding: 20px 22px; }

.kpi-grid{ display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.kpi-card{
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--flash-red);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease;
}
.kpi-card:hover{ box-shadow: var(--shadow-md); }
.kpi-label{
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin-bottom: 8px;
}
.kpi-value{
  font-family: var(--font-mono); font-size: 1.55rem; font-weight: 600;
  color: var(--text-primary); line-height: 1.1;
}
.kpi-delta{
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 700; margin-top: 9px; padding: 3px 8px; border-radius: 999px;
}
.kpi-delta.up{ color: var(--status-ok); background: var(--status-ok-bg); }
.kpi-delta.down{ color: var(--status-bad); background: var(--status-bad-bg); }
.kpi-delta.flat{ color: var(--status-muted); background: var(--status-muted-bg); }

.section-title{
  font-size: 1.02rem; font-weight: 800; font-family: var(--font-display);
  margin: 26px 0 12px 0;
}
.section-sub{ font-size: 12.5px; color: var(--text-muted); margin-top: -8px; margin-bottom: 14px; font-weight: 500; }

.grid-2{ display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid-3{ display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

.chart-title{ font-size: .95rem; font-weight: 800; font-family: var(--font-display); }
.chart-sub{ font-size: 11.5px; color: var(--text-muted); font-weight: 500; margin-top: 2px; margin-bottom: 14px; }

/* Container obrigatório para qualquer canvas do Chart.js.
   Sem uma altura explícita aqui, o canvas "responsive" pode colapsar
   para altura zero dentro de containers flex/grid e o gráfico some,
   mesmo com os dados corretos. Sempre usar com maintainAspectRatio:false. */
.chart-canvas-wrap{ position: relative; width: 100%; height: 260px; }
.chart-canvas-wrap.short{ height: 220px; }

/* ===== BUTTONS ===== */
.btn{
  display: inline-flex; align-items: center; gap: 7px;
  border-radius: 10px; border: 1px solid var(--flash-red);
  background: var(--flash-red); color: #fff;
  font-size: 13px; font-weight: 700; padding: 9px 16px;
  box-shadow: var(--shadow-sm); transition: all .13s ease;
}
.btn:hover{ background: var(--flash-red-dark); border-color: var(--flash-red-dark); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn.secondary{ background: var(--bg-card); color: var(--text-secondary); border-color: var(--border-strong); }
.btn.secondary:hover{ color: var(--text-primary); background: var(--bg-muted); transform: none; }
.btn svg{ width: 15px; height: 15px; }

.select, .input{
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: 9px; padding: 8px 12px; font-size: 13px; color: var(--text-primary);
  font-family: inherit;
}
.select:focus, .input:focus{ outline: none; border-color: var(--flash-red); box-shadow: 0 0 0 3px rgba(217,0,0,.10); }

.field label{ font-size: 11.5px; font-weight: 700; color: var(--text-secondary); display: block; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .03em; }

/* ===== TABLE ===== */
.table-wrap{ background: var(--bg-card); border: 1px solid var(--border-soft); border-radius: var(--radius-md); overflow: hidden; box-shadow: var(--shadow-sm); }
table.dtable{ width: 100%; border-collapse: collapse; font-size: 13px; }
table.dtable thead th{
  background: var(--bg-muted); text-align: left; color: var(--text-secondary);
  font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .02em;
  padding: 11px 16px; border-bottom: 1px solid var(--border-soft);
}
table.dtable tbody td{ padding: 11px 16px; border-bottom: 1px solid var(--border-soft); color: var(--text-primary); }
table.dtable tbody tr:last-child td{ border-bottom: none; }
table.dtable tbody tr:hover{ background: var(--flash-red-soft); }

/* ===== STATUS PILLS ===== */
.pill{ display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.pill.ok{ color: var(--status-ok); background: var(--status-ok-bg); }
.pill.warn{ color: var(--status-warn); background: var(--status-warn-bg); }
.pill.bad{ color: var(--status-bad); background: var(--status-bad-bg); }
.pill.muted{ color: var(--status-muted); background: var(--status-muted-bg); }

/* ===== LOGIN ===== */
.login-page{
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1000px 500px at 15% -10%, rgba(217,0,0,.06), transparent),
    var(--bg-page);
}
.login-card{
  width: 380px; background: var(--bg-card); border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 40px 36px 32px 36px;
}
.login-mark{
  width: 46px; height: 46px; border-radius: 12px; margin: 0 auto 18px auto;
  background: linear-gradient(135deg, var(--flash-red), var(--flash-red-dark));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; color: #fff; font-size: 18px;
}
.login-eyebrow{ text-align: center; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--flash-red); margin-bottom: 6px; }
.login-title{ text-align: center; font-size: 1.3rem; margin-bottom: 6px; }
.login-sub{ text-align: center; font-size: 12.5px; color: var(--text-muted); margin-bottom: 22px; line-height: 1.5; }
.login-field{ margin-bottom: 14px; }
.login-field label{ font-size: 12px; font-weight: 700; color: var(--text-secondary); display: block; margin-bottom: 6px; }
.login-field input{ width: 100%; }
.login-error{ font-size: 12px; color: var(--status-bad); margin-top: 10px; text-align: center; font-weight: 600; display: none; }
.login-hint{ margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border-soft); font-size: 11px; color: var(--text-muted); line-height: 1.6; }
.login-hint b{ color: var(--text-secondary); }

/* ===== MISC ===== */
.badge-fake{ font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; background: var(--flash-amber-soft); color: #8a5a06; padding: 2px 8px; border-radius: 999px; }
.empty-state{ text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 13px; }

/* ===== CLASSIFICAÇÃO CONTÁBIL (Contábil / Relatórios) ===== */
.kpi-hint{ font-size: 11px; color: var(--text-muted); margin-top: 6px; font-weight: 500; }

.linha-verde{ background: rgba(46, 204, 113, 0.12); }
.linha-amarela{ background: rgba(241, 196, 15, 0.16); }
.linha-vermelha{ background: rgba(231, 76, 60, 0.12); }
table.dtable tbody tr.linha-verde:hover,
table.dtable tbody tr.linha-amarela:hover,
table.dtable tbody tr.linha-vermelha:hover{ filter: brightness(0.97); }

.select-classificacao{
  width: 100%; min-width: 190px; max-width: 240px;
  padding: 6px 9px; font-size: 12.5px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--bg-card); color: var(--text-primary);
}
.select-classificacao:focus{ outline: none; border-color: var(--flash-red); box-shadow: 0 0 0 3px rgba(217,0,0,.10); }

.classificacao-cell{ display: flex; align-items: center; gap: 6px; }
.btn-editar-classificacao{
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 7px;
  border: 1px solid var(--border-strong); background: var(--bg-card); color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center; font-size: 12px;
}
.btn-editar-classificacao:hover:not(:disabled){ background: var(--bg-muted); color: var(--text-primary); }
.btn-editar-classificacao:disabled{ opacity: .35; cursor: not-allowed; }

/* Modal de cadastro/edição de classificação */
.flash-modal-overlay{
  position: fixed; inset: 0; background: rgba(15,17,23,.45);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.flash-modal{
  width: 440px; max-width: 92vw; background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 24px 26px; max-height: 90vh; overflow-y: auto;
}
.flash-modal h3{ font-size: 1.05rem; margin-bottom: 4px; }
.flash-modal .modal-sub{ font-size: 12px; color: var(--text-muted); margin-bottom: 18px; }
.flash-modal .field{ margin-bottom: 14px; }
.flash-modal .field input, .flash-modal .field select, .flash-modal .field textarea{ width: 100%; }
.flash-modal textarea{
  border: 1px solid var(--border-strong); border-radius: 9px; padding: 8px 12px; font-size: 13px;
  font-family: inherit; resize: vertical; min-height: 60px; color: var(--text-primary);
}
.flash-modal-actions{ display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ===== PPR — barra de progresso de pesos, modal largo, cards de resultado ===== */
.flash-modal.wide{ width: 640px; }

.flash-progress-track{
  width: 100%; height: 8px; border-radius: 999px; background: var(--bg-muted);
  overflow: hidden; margin-top: 8px;
}
.flash-progress-fill{ height: 100%; border-radius: 999px; transition: width .2s ease; }
.flash-progress-fill.ok{ background: var(--status-ok); }
.flash-progress-fill.warn{ background: var(--status-warn); }
.flash-progress-fill.bad{ background: var(--status-bad); }
.flash-progress-label{ font-size: 11.5px; font-weight: 700; margin-top: 6px; }
.flash-progress-label.ok{ color: var(--status-ok); }
.flash-progress-label.warn{ color: var(--status-warn); }
.flash-progress-label.bad{ color: var(--status-bad); }

.flash-avatar-inline{
  width: 34px; height: 34px; border-radius: 50%; background: var(--flash-red-soft); color: var(--flash-red-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px;
  font-family: var(--font-display); flex-shrink: 0;
}

.flash-obs-box{
  background: var(--bg-muted); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 12.5px; color: var(--text-secondary); line-height: 1.6;
}

.flash-toolbar-row{ display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ===== ESTADOS DE DADOS (preparado para quando os dados vierem do Supabase) =====
   Convenção: todo container que recebe dado dinâmico deve alternar entre estas
   classes conforme o estado da consulta:
   - .state-loading  -> enquanto a query está em andamento
   - .state-error    -> quando a consulta falha
   - .state-empty    -> quando a consulta retorna sem linhas (usa .empty-state acima)
   - ausência de classe -> dado carregado normalmente
*/
.state-loading{
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px; color: var(--text-muted); font-size: 12.5px; font-weight: 600;
}
.state-loading .spinner{
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--flash-red);
  animation: flash-spin .7s linear infinite;
}
@keyframes flash-spin{ to{ transform: rotate(360deg); } }

.state-error{
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--status-bad-bg); color: var(--status-bad);
  font-size: 12.5px; font-weight: 650;
}

@media (max-width: 980px){
  .kpi-grid, .grid-3{ grid-template-columns: repeat(2, 1fr); }
  .grid-2{ grid-template-columns: 1fr; }
}


/* ===== MENU COMPACTO COM ÍCONES E SUBMENUS FLUTUANTES ===== */
.sidebar{
  overflow: visible;
  z-index: 50;
}
.sidebar-brand.compact{
  justify-content: center;
  padding: 16px 10px 14px 10px;
}
.sidebar-logo-compact{
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 12px;
  background: #050505;
  padding: 5px;
  box-shadow: 0 10px 22px rgba(0,0,0,.18);
}
.sidebar-nav-compact{
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 10px;
}
.nav-group-compact{
  position: relative;
  padding: 0;
}
.nav-group-trigger{
  width: 54px;
  height: 54px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
  color: var(--text-on-dark-muted);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .14s ease, color .14s ease, border-color .14s ease, transform .14s ease;
}
.nav-group-trigger svg{
  width: 22px;
  height: 22px;
}
.nav-group-compact:hover .nav-group-trigger,
.nav-group-compact.active .nav-group-trigger{
  background: rgba(217,0,0,.18);
  border-color: rgba(217,0,0,.45);
  color: #fff;
}
.nav-group-compact:hover .nav-group-trigger{
  transform: translateX(2px);
}
.nav-flyout{
  position: absolute;
  left: 66px;
  top: 0;
  min-width: 260px;
  background: #181a22;
  color: var(--text-on-dark);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 100;
}
.nav-group-compact:hover .nav-flyout,
.nav-group-compact:focus-within .nav-flyout{
  display: block;
}
.nav-flyout-title{
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #9ca3af;
  padding: 5px 8px 10px 8px;
}
.nav-flyout-item{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 11px;
  color: var(--text-on-dark-muted);
  font-size: 13px;
  font-weight: 750;
  transition: background .12s ease, color .12s ease;
}
.nav-flyout-item svg{
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}
.nav-flyout-item:hover,
.nav-flyout-item.active{
  background: rgba(217,0,0,.16);
  color: #fff;
}
.sidebar-footer.compact{
  padding: 12px 10px 16px 10px;
  display: flex;
  justify-content: center;
}
.sidebar-footer.compact button{
  width: 54px;
  height: 44px;
  margin-top: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
}
.sidebar-footer.compact button svg{
  width: 19px;
  height: 19px;
}
@media(max-width: 760px){
  :root{ --sidebar-w: 64px; }
  .main{ padding: 18px 16px 32px 16px; }
  .nav-group-trigger{ width: 44px; height: 48px; }
  .nav-flyout{ left: 54px; min-width: 238px; }
  .sidebar-logo-compact{ width: 36px; height: 36px; }
}
