/* ============================================================================
   DESIGN SYSTEM — base comum a todas as aplicações
   Copiar para public/assets/css/theme.css. NÃO editar por aplicação:
   personalização vai em brand.css, carregado DEPOIS deste arquivo.
   ============================================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ─── Tokens ───────────────────────────────────────────────────────────────── */
:root {
  /* Marca */
  --primary:    #2563eb;
  --primary-lt: #3b82f6;
  --primary-dk: #1d4ed8;
  --accent:     #f59e0b;   /* destaque sobre fundo escuro */
  --accent-dk:  #b45309;   /* mesma família, para TEXTO sobre fundo claro */

  /* Semânticas — significado fixo, não usar por estética */
  --success:    #10b981;   /* concluído, total, dentro da meta */
  --warning:    #f59e0b;   /* parcial, atenção, prazo próximo */
  --danger:     #ef4444;   /* erro, vencido, cancelado */
  --info:       #3b82f6;   /* em andamento, informativo */
  --neutral:    #94a3b8;   /* sem dado, não iniciado */

  /* Apoio para séries de gráfico */
  --purple:     #8b5cf6;
  --teal:       #0d9488;

  /* Superfícies */
  --bg:         #eef2f7;
  --card:       #ffffff;
  --panel:      #f8fafc;
  --border:     #e2e8f0;
  --text:       #1a2535;
  --text-muted: #64748b;

  /* ── Barra lateral — CLARA por padrão ──────────────────────────────────────
     Paleta escolhida COM O USUÁRIO no início do projeto (ver a skill: sempre
     oferecer opções claras). Trocar apenas estes tokens em brand.css.        */
  --side-bg1:        #ffffff;   /* topo do gradiente */
  --side-bg2:        #f1f5f9;   /* base do gradiente */
  --side-text:       #334155;   /* item de menu */
  --side-text-strong:#0f172a;   /* nome do usuário, título */
  --side-border:     #e2e8f0;
  --side-hover:      rgba(15,23,42,.06);
  --side-active-bg:  rgba(37,99,235,.12);
  --side-active-text:#1d4ed8;
  --side-section:    #64748b;   /* rótulo de seção do menu */
  --side-logo-bg:    #ffffff;   /* área do logo */
  --side-footer-bg:  rgba(15,23,42,.04);
  --sidebar-w:       256px;

  /* Tela de login */
  --login-bg1:  #eef2f7;
  --login-bg2:  #dbe6f5;

  /* Forma */
  --radius:     16px;
  --radius-sm:  10px;
  --shadow:     0 1px 4px rgba(15,23,42,.05), 0 6px 20px rgba(15,23,42,.07);
  --shadow-md:  0 8px 32px rgba(15,23,42,.13);
  --shadow-lg:  0 20px 56px rgba(15,23,42,.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ─── Login ────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--login-bg1) 0%, var(--login-bg2) 100%);
  position: relative; overflow: hidden;
}
.login-page::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 60% 60% at 70% 40%, rgba(255,255,255,.6) 0%, transparent 70%);
}
.login-box {
  background: var(--card); border-radius: 20px; padding: 52px 44px;
  width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); position: relative;
  border: 1px solid var(--border);
}
.login-logo { text-align: center; margin-bottom: 36px; }
.login-logo h1 { font-size: 2.2rem; font-weight: 800; color: var(--primary); letter-spacing: -1.5px; }
.login-logo-img { display: block; width: 72%; max-width: 240px; height: auto; margin: 0 auto 4px; }
.login-logo p { color: var(--text-muted); font-size: .9rem; margin-top: 6px; }

/* ─── Layout ───────────────────────────────────────────────────────────────── */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; overflow-y: auto;
  background: linear-gradient(180deg, var(--side-bg1) 0%, var(--side-bg2) 100%);
  color: var(--side-text); display: flex; flex-direction: column;
  border-right: 1px solid var(--side-border);
  box-shadow: 2px 0 20px rgba(15,23,42,.06);
}
.sidebar-logo {
  padding: 18px 20px; background: var(--side-logo-bg);
  border-bottom: 1px solid var(--side-border);
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
.sidebar-logo img { max-width: 100%; height: auto; }
.sidebar-logo h2 { font-size: 1.2rem; font-weight: 800; color: var(--side-text-strong); letter-spacing: -.4px; }
.sidebar-logo p  { font-size: .7rem; color: var(--text-muted); letter-spacing: .4px; text-transform: uppercase; font-weight: 600; }
.sidebar-nav { flex: 1; padding: 10px 0; }
.nav-section {
  font-size: .62rem; color: var(--side-section); padding: 16px 22px 6px;
  letter-spacing: 1.6px; text-transform: uppercase; font-weight: 700;
  border-top: 1px solid var(--side-border); margin-top: 4px;
}
.nav-section:first-child { border-top: none; margin-top: 0; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 22px;
  cursor: pointer; font-size: .85rem; font-weight: 500; color: var(--side-text);
  text-decoration: none; transition: all .18s; margin: 1px 8px; border-radius: 10px;
}
.nav-item:hover  { background: var(--side-hover); color: var(--side-text-strong); }
.nav-item.active {
  background: var(--side-active-bg); color: var(--side-active-text); font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--side-active-bg);
}
.nav-item .icon { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-footer {
  padding: 16px 20px; background: var(--side-footer-bg);
  border-top: 1px solid var(--side-border);
}
.sidebar-footer strong { display: block; font-size: .84rem; font-weight: 700; color: var(--side-text-strong); margin-bottom: 2px; }
.sidebar-footer small  { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.btn-logout {
  margin-top: 12px; width: 100%; padding: 8px; cursor: pointer;
  background: var(--side-active-bg); color: var(--side-active-text);
  border: 1px solid var(--side-border); border-radius: var(--radius-sm);
  font-size: .8rem; font-weight: 600; font-family: inherit; transition: filter .18s;
}
.btn-logout:hover { filter: brightness(.94); }

.main-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; padding: 0 30px; flex-shrink: 0; position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,.92); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border); box-shadow: 0 4px 20px rgba(15,23,42,.05);
}
.topbar h1 { font-size: 1rem; font-weight: 700; letter-spacing: -.3px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.badge-role { font-size: .68rem; padding: 3px 11px; border-radius: 20px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; }
.badge-role.admin   { background: linear-gradient(135deg,#dbeafe,#bfdbfe); color: var(--primary-dk); }
.badge-role.usuario { background: linear-gradient(135deg,#d1fae5,#a7f3d0); color: #065f46; }

.page { flex: 1; padding: 26px 30px; animation: fadeInUp .28s ease; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ─── Filtros ──────────────────────────────────────────────────────────────── */
.filtros {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 20px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 24px; box-shadow: var(--shadow);

  /* CONGELADO: só os registros rolam. O filtro é o que o usuário mais volta a
     mexer numa tela de consulta; obrigá-lo a rolar até o topo para trocar um
     período é atrito puro.

     top: 60px porque a .topbar já ocupa essa faixa, também grudada. */
  position: sticky; top: 60px; z-index: 5;
}

/* Faixa de fundo que cobre o vão entre a topbar e o filtro quando ele está
   GRUDADO — sem ela, o conteúdo aparece deslizando por esse vão. Os 30px batem
   com o padding lateral da .page.

   Só vale com a classe .grudado, que o front liga quando o filtro de fato
   chega ao topo. Aplicada sempre, a faixa se estendia 60px para cima e
   encobria a base do que viesse antes do filtro na página (cards de KPI,
   por exemplo) mesmo sem rolagem nenhuma. */
.filtros.grudado,
.area-fixa.grudado { box-shadow: var(--shadow), 0 -30px 0 30px var(--bg); }

/* Bloco congelado composto: use quando MAIS DE UM elemento precisa ficar fixo
   (ex.: filtros + KPIs + abas numa tela de relatórios). Gruda-se o CONTÊINER;
   grudar cada filho faria um empilhar sobre o outro conforme a rolagem.

     <div class="area-fixa">
       <div class="filtros">…</div>
       <div class="kpi-grid">…</div>
       <div class="filtros">abas</div>
     </div>                                                                   */
.area-fixa {
  position: sticky; top: 60px; z-index: 5;
  background: var(--bg);
}
.area-fixa .filtros { position: static; box-shadow: var(--shadow); }
.area-fixa > :last-child { margin-bottom: 18px; }

/* Faixa de KPIs recolhível. Bloco congelado alto come a tela útil: ofereça um
   botão que alterna esta classe e guarde a escolha no localStorage. */
.kpi-grid.oculto { display: none; }

.filtros label { font-size: .76rem; color: var(--text-muted); font-weight: 600; }
.filtros input, .filtros select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px 11px; font-size: .84rem; color: var(--text); background: #fff; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.filtros input:focus, .filtros select:focus {
  outline: none; border-color: var(--primary-lt); box-shadow: 0 0 0 3px rgba(59,130,246,.14);
}
.filtro-sep { width: 1px; height: 24px; background: var(--border); }

/* ─── KPI ──────────────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 18px; margin-bottom: 24px; }
.kpi-card {
  min-width: 0;   /* item de grid: sem isto, o conteúdo define a largura mínima */
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); transition: transform .18s, box-shadow .18s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-card-icon {
  width: 38px; height: 38px; border-radius: 12px; margin-bottom: 14px;
  display: flex; align-items: center; justify-content: center;
}
.kpi-card-icon svg { width: 20px; height: 20px; }
.kpi-card-icon.blue   { background: linear-gradient(135deg,#dbeafe,#bfdbfe); color: var(--primary); }
.kpi-card-icon.green  { background: linear-gradient(135deg,#d1fae5,#a7f3d0); color: #059669; }
.kpi-card-icon.amber  { background: linear-gradient(135deg,#fef3c7,#fde68a); color: #d97706; }
.kpi-card-icon.red    { background: linear-gradient(135deg,#fee2e2,#fecaca); color: #dc2626; }
.kpi-card-icon.purple { background: linear-gradient(135deg,#ede9fe,#ddd6fe); color: #7c3aed; }
.kpi-card-icon.teal   { background: linear-gradient(135deg,#ccfbf1,#99f6e4); color: #0d9488; }
.kpi-label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .8px; font-weight: 700; }
/* O valor encolhe com a tela e, em último caso, quebra — nunca empurra o
   cartão para fora da grade. Sem isso, "R$ 1.450.000,00" num celular ficava
   mais largo que a coluna e o cartão aparecia cortado. */
.kpi-value {
  font-size: clamp(1.15rem, 4.2vw, 1.75rem); font-weight: 800; margin-top: 5px; line-height: 1.1;
  letter-spacing: -1px; overflow-wrap: anywhere;
}
.kpi-sub   { font-size: .75rem; color: var(--text-muted); margin-top: 7px; display: flex; align-items: center; gap: 5px; }
.kpi-trend { font-size: .71rem; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.kpi-trend.up   { background: #d1fae5; color: #059669; }
.kpi-trend.down { background: #fee2e2; color: #dc2626; }
.kpi-trend.flat { background: #f1f5f9; color: var(--text-muted); }

/* ─── Gráficos ─────────────────────────────────────────────────────────────── */
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; margin-bottom: 24px; }
.chart-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); transition: box-shadow .18s;
}
.chart-card:hover { box-shadow: var(--shadow-md); }
.chart-header { margin-bottom: 16px; }
.chart-header h3 { font-size: .9rem; font-weight: 700; }
.chart-header p  { font-size: .75rem; color: var(--text-muted); margin-top: 3px; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.tall  { height: 320px; }
.chart-wrap.short { height: 200px; }

/* ─── Tabelas ──────────────────────────────────────────────────────────────── */
.table-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); margin-bottom: 24px; overflow-x: auto;
}
.table-card h3 { font-size: .9rem; font-weight: 700; margin-bottom: 4px; }
.table-card p.sub { font-size: .75rem; color: var(--text-muted); margin-bottom: 18px; }
.data-table { width: 100%; border-collapse: collapse; font-size: .83rem; }
.data-table th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-muted); font-weight: 700; padding: 10px 12px; border-bottom: 2px solid var(--border);
}
.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); }
.data-table tbody tr { transition: background .12s; }
.data-table tbody tr:hover { background: #f0f7ff; }
.data-table tbody tr:last-child td { border-bottom: none; }
/* Vale para td E th: o título de uma coluna numérica leva a mesma classe .num
   e fica alinhado com os valores abaixo dele. */
.data-table .num  { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.data-table .bold { font-weight: 600; }
.data-table tr.row-click { cursor: pointer; }

/* ─── Badges de estado (cores semânticas) ──────────────────────────────────── */
.stbadge { padding: 3px 10px; border-radius: 20px; font-size: .69rem; font-weight: 700; white-space: nowrap; }
.stbadge.success { background: #d1fae5; color: #065f46; }
.stbadge.warn    { background: #fef3c7; color: #92400e; }
.stbadge.danger  { background: #fee2e2; color: #991b1b; }
.stbadge.info    { background: #dbeafe; color: #1e40af; }
.stbadge.neutral { background: #f1f5f9; color: #475569; }

/* ─── Progresso ────────────────────────────────────────────────────────────── */
.pct-bar-wrap { display: flex; align-items: center; gap: 10px; }
.pct-bar-bg   { flex: 1; height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
.pct-bar-fill { height: 100%; border-radius: 4px; transition: width .7s cubic-bezier(.4,0,.2,1); }
.pct-label    { font-size: .75rem; font-weight: 700; min-width: 44px; text-align: right; }

/* ─── Formulários ──────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: .77rem; font-weight: 600; margin-bottom: 5px; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 13px; font-size: .87rem; color: var(--text); background: #fff; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary-lt); box-shadow: 0 0 0 3px rgba(59,130,246,.14);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; margin-bottom: 22px; }
.panel h4 { font-size: .86rem; font-weight: 700; margin-bottom: 16px; }

/* ─── Botões ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 18px;
  border-radius: var(--radius-sm); border: none; font-size: .84rem; font-weight: 600;
  cursor: pointer; transition: all .18s; text-decoration: none; font-family: inherit;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary-lt) 0%, var(--primary) 100%);
  color: #fff; box-shadow: 0 2px 8px rgba(37,99,235,.28);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dk) 100%); transform: translateY(-1px); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; transform: translateY(-1px); }
.btn-danger { background: linear-gradient(135deg,#ef4444,#dc2626); color: #fff; }
.btn-danger:hover { background: linear-gradient(135deg,#dc2626,#b91c1c); transform: translateY(-1px); }
.btn-sm { padding: 5px 11px; font-size: .75rem; }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }

/* ─── Alertas ──────────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: .84rem; margin-bottom: 14px; font-weight: 500; }
.alert-error, .alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ─── Carregando / vazio ───────────────────────────────────────────────────── */
.loading { text-align: center; padding: 52px; color: var(--text-muted); }
.spinner {
  width: 32px; height: 32px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary-lt); animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 44px; color: var(--text-muted); font-size: .86rem; }

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto; padding: 26px;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-size: 1rem; font-weight: 800; letter-spacing: -.3px; }
.modal-head .sub { font-size: .78rem; color: var(--text-muted); }

/* ─── Barra de rolagem ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ─── Responsivo ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
  .kpi-grid    { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-row    { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .sidebar { width: 56px; }
  .sidebar-logo p, .nav-item span, .nav-section,
  .sidebar-footer strong, .sidebar-footer small { display: none; }
  .nav-item { justify-content: center; padding: 14px; margin: 1px 4px; }
  .page { padding: 16px; }
}
