/* ===== RESET E BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #6366f1;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;
  --sidebar-width: 240px;

  --cor-primaria: #6366f1;
  --cor-primaria-hover: #4f46e5;
  --cor-sucesso: #10b981;
  --cor-erro: #ef4444;
  --cor-aviso: #f59e0b;
  --cor-info: #3b82f6;

  --fundo: #f8fafc;
  --fundo-card: #ffffff;
  --borda: #e2e8f0;
  --texto: #1e293b;
  --texto-suave: #64748b;

  --sombra: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --sombra-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --raio: 8px;
  --raio-lg: 12px;
  --fonte: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  font-family: var(--fonte);
  background: var(--fundo);
  color: var(--texto);
  font-size: 14px;
  line-height: 1.5;
}

/* ===== LAYOUT PRINCIPAL ===== */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid #1e293b;
}

.logo-icone {
  width: 32px; height: 32px;
  background: var(--cor-primaria);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: white; font-weight: 700;
}

.logo-texto {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.3px;
}

.logo-texto span {
  color: var(--cor-primaria);
}

/* Navegação */
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-secao {
  font-size: 10px;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 12px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #cbd5e1;
}

.nav-item.ativo {
  background: var(--cor-primaria);
  color: var(--sidebar-text-active);
}

.nav-item .bi {
  font-size: 16px;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.nav-badge {
  margin-left: auto;
  background: #1e293b;
  color: #94a3b8;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 600;
}

.nav-item.ativo .nav-badge {
  background: rgba(255,255,255,.2);
  color: white;
}

/* Rodapé da sidebar */
.sidebar-rodape {
  padding: 12px;
  border-top: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--cor-primaria);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.usuario-nome {
  font-size: 13px;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.usuario-perfil {
  font-size: 11px;
  color: #64748b;
  text-transform: capitalize;
}

.btn-sair {
  margin-left: auto;
  color: #64748b;
  font-size: 18px;
  text-decoration: none;
  padding: 4px;
  border-radius: 4px;
  transition: color .15s;
  flex-shrink: 0;
}

.btn-sair:hover { color: #ef4444; }

/* ===== CONTEÚDO PRINCIPAL ===== */
.conteudo-principal {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topo {
  background: var(--fundo-card);
  border-bottom: 1px solid var(--borda);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topo-titulo {
  font-size: 16px;
  font-weight: 600;
  color: var(--texto);
}

.topo-acoes {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pagina {
  padding: 28px;
  flex: 1;
}

/* ===== ALERTAS ===== */
.alerta {
  padding: 12px 16px;
  border-radius: var(--raio);
  margin-bottom: 16px;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alerta-sucesso { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alerta-erro    { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alerta-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alerta-aviso   { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ===== CARDS ===== */
.card {
  background: var(--fundo-card);
  border: 1px solid var(--borda);
  border-radius: var(--raio-lg);
  box-shadow: var(--sombra);
  padding: 20px;
}

.card-titulo {
  font-size: 15px;
  font-weight: 600;
  color: var(--texto);
  margin-bottom: 16px;
}

/* Grid de métricas */
.grid-metricas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metrica-card {
  background: var(--fundo-card);
  border: 1px solid var(--borda);
  border-radius: var(--raio-lg);
  padding: 20px;
  box-shadow: var(--sombra);
}

.metrica-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--texto-suave);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.metrica-valor {
  font-size: 28px;
  font-weight: 700;
  color: var(--texto);
  line-height: 1;
}

.metrica-sub {
  font-size: 12px;
  color: var(--texto-suave);
  margin-top: 6px;
}

.metrica-icone {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  margin-bottom: 12px;
}

.icone-roxo  { background: #ede9fe; color: #7c3aed; }
.icone-verde { background: #ecfdf5; color: #059669; }
.icone-azul  { background: #eff6ff; color: #2563eb; }
.icone-laranja { background: #fff7ed; color: #ea580c; }

/* ===== BOTÕES ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}

.btn:active { transform: scale(.98); }

.btn-primario {
  background: var(--cor-primaria);
  color: white;
}
.btn-primario:hover { background: var(--cor-primaria-hover); color: white; }

.btn-secundario {
  background: var(--fundo);
  color: var(--texto);
  border: 1px solid var(--borda);
}
.btn-secundario:hover { background: #f1f5f9; }

.btn-perigo {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}
.btn-perigo:hover { background: #fee2e2; }

.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ===== FORMULÁRIOS ===== */
.form-grupo {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--texto);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--borda);
  border-radius: 6px;
  font-size: 14px;
  color: var(--texto);
  background: var(--fundo-card);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-input:focus {
  border-color: var(--cor-primaria);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .1);
}

.form-input::placeholder { color: #94a3b8; }

.form-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--texto-suave);
  cursor: pointer;
}

.form-checkbox input { width: 15px; height: 15px; cursor: pointer; }

/* ===== TELA DE LOGIN ===== */
.pagina-login {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 50px rgba(0,0,0,.4);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-icone {
  width: 52px; height: 52px;
  margin: 0 auto 12px;
  font-size: 22px;
  border-radius: 12px;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: #0f172a;
}

.login-logo h1 span { color: var(--cor-primaria); }

.login-logo p {
  font-size: 13.5px;
  color: var(--texto-suave);
  margin-top: 4px;
}

.login-divisor {
  text-align: center;
  margin: 20px 0 8px;
  font-size: 12px;
  color: var(--texto-suave);
}

.link-configurar {
  display: block;
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--cor-primaria);
  text-decoration: none;
}

.link-configurar:hover { text-decoration: underline; }

/* ===== TABELA ===== */
.tabela {
  width: 100%;
  border-collapse: collapse;
}

.tabela thead tr {
  background: #f8fafc;
  border-bottom: 2px solid var(--borda);
}

.tabela th {
  padding: 11px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--texto-suave);
  white-space: nowrap;
}

.tabela td {
  padding: 13px 16px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--borda);
  vertical-align: middle;
}

.tabela tbody tr:last-child td { border-bottom: none; }

.tabela tbody tr:hover { background: #f8fafc; }

/* ===== ESTADO VAZIO ===== */
.estado-vazio {
  text-align: center;
  padding: 60px 20px;
  background: var(--fundo-card);
  border: 1px solid var(--borda);
  border-radius: var(--raio-lg);
}

.estado-vazio-icone { font-size: 48px; margin-bottom: 16px; }
.estado-vazio-titulo { font-size: 17px; font-weight: 600; color: var(--texto); margin-bottom: 8px; }
.estado-vazio-texto { font-size: 14px; color: var(--texto-suave); max-width: 380px; margin: 0 auto; }

/* ===== BADGE DE STATUS ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-verde   { background: #dcfce7; color: #166534; }
.badge-amarelo { background: #fef9c3; color: #854d0e; }
.badge-vermelho{ background: #fee2e2; color: #991b1b; }
.badge-azul    { background: #dbeafe; color: #1e40af; }
.badge-cinza   { background: #f1f5f9; color: #475569; }
.badge-roxo    { background: #ede9fe; color: #5b21b6; }

/* ===== UTILITÁRIOS ===== */
.texto-suave { color: var(--texto-suave); }
.texto-centro { text-align: center; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.w-full { width: 100%; }

/* ===== ELEMENTOS MOBILE (ocultos no desktop) ===== */
.btn-hamburger { display: none; }
.sidebar-overlay { display: none; }
.mobile-bottom-nav { display: none; }
.tf-cards-mobile { display: none; }
.cli-cards-mobile { display: none; }

/* ===== RESPONSIVO MOBILE ===== */
/* pointer:coarse = dedo (touch screen), funciona mesmo em "modo desktop" */
@media (max-width: 768px), (pointer: coarse) {

  /* --- Sidebar vira gaveta deslizante --- */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 400;
    width: 260px;
  }
  .sidebar.aberta {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.35);
  }

  /* --- Overlay escuro atrás da sidebar --- */
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
  }
  .sidebar-overlay.visivel {
    opacity: 1;
    pointer-events: all;
  }

  /* --- Conteúdo ocupa tela toda --- */
  .conteudo-principal {
    margin-left: 0;
  }

  /* --- Topo com hambúrguer --- */
  .topo {
    padding: 10px 14px;
    gap: 10px;
  }
  .btn-hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--texto);
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    flex-shrink: 0;
  }
  .btn-hamburger:hover { background: var(--fundo); }
  .topo-titulo { font-size: 15px; }
  .topo-acoes { gap: 6px; }
  .topo-acoes .btn span { display: none; }
  .topo-acoes .btn { padding: 8px 10px; }

  /* --- Área de conteúdo --- */
  .pagina {
    padding: 14px;
    padding-bottom: 80px;
  }

  /* --- Tabelas com scroll horizontal --- */
  table.tabela {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* --- Grid de métricas: 2 colunas --- */
  .grid-metricas {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .metrica-valor { font-size: 22px; }

  /* --- Cards com padding menor --- */
  .card { padding: 14px; }

  /* --- Botões menores no mobile --- */
  .btn-lg { padding: 10px 16px; font-size: 14px; }

  /* --- Modais full-screen embaixo --- */
  .modal {
    align-items: flex-end;
    padding: 0;
  }
  .modal-conteudo {
    width: 100%;
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    overflow-y: auto;
  }

  /* --- Chat IA flutuante — sobe acima da nav bar --- */
  #ia-float-btn { bottom: 76px; right: 16px; }
  #ia-float-panel {
    right: 8px;
    left: 8px;
    width: auto;
    bottom: 136px;
    max-height: 60vh;
  }

  /* --- Barra de navegação inferior (estilo app) --- */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 62px;
    background: #0f172a;
    border-top: 1px solid #1e293b;
    z-index: 200;
    align-items: stretch;
  }
  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: #64748b;
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    background: none;
    border: none;
    padding: 6px 4px;
    transition: color .15s;
    position: relative;
  }
  .mobile-nav-item i { font-size: 20px; }
  .mobile-nav-item.ativo { color: #6366f1; }
  .mobile-nav-item:hover { color: #94a3b8; }
  .mobile-nav-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 16px);
    background: #ef4444;
    color: white;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 999px;
    min-width: 16px;
    text-align: center;
  }

  /* ===== DASHBOARD: 2 colunas ===== */
  .dash-row-5, .dash-row-4 {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }
  .dcard {
    padding: 12px 10px 10px;
    min-height: 0;
    border-radius: 14px;
  }
  /* Desativa o word-break que quebra moeda letra por letra */
  .dcard-valor {
    font-size: 22px !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.15;
    margin-bottom: 5px;
  }
  /* Valores monetários longos: fonte menor para caber */
  .dcard-valor.medio   { font-size: 16px !important; }
  .dcard-valor.pequeno { font-size: 13px !important; }
  .dcard-label {
    font-size: 9px;
    letter-spacing: .2px;
    margin-bottom: 6px;
    margin-top: 3px;
    gap: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .dcard-label i { font-size: 10px; }
  .dcard-sub {
    font-size: 10px;
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .dcard-bg-icon { font-size: 42px; }
  .dcard-top { height: 3px; border-radius: 14px 14px 0 0; }
  .dash-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    margin-bottom: 14px;
    scrollbar-width: none;
  }
  .dash-bar::-webkit-scrollbar { display: none; }
  .dash-btn { flex-shrink: 0; font-size: 12px; padding: 6px 12px; }
  .dash-custom { display: none; }
  .dash-periodo-label { display: none; }

  /* ===== TAREFAS: oculta tabela, mostra cards ===== */
  .tf-table-wrap { display: none !important; }
  .tf-cards-mobile { display: flex !important; flex-direction: column; gap: 8px; }
  .tf-toolbar { flex-wrap: wrap; gap: 6px; }
  .tf-busca { width: 100%; box-sizing: border-box; max-width: 100%; }
  .tf-filtro { flex: 1; min-width: calc(50% - 3px); font-size: 12px; padding: 6px 8px; }
  .tf-view-bar .tf-vtab { flex: 1; justify-content: center; font-size: 12px; padding: 7px 8px; }

  /* ===== CLIENTES: oculta tabela, mostra cards ===== */
  .cli-wrap { display: none !important; }
  .cli-cards-mobile { display: flex !important; flex-direction: column; gap: 8px; }
  .cli-toolbar .cli-busca { min-width: 0; max-width: 100%; flex: 1; }
  .cli-toolbar .cli-date { display: none; }
  .cli-total { margin-left: 0; width: 100%; margin-top: 4px; }

  /* ===== CARDS MOBILE (clientes e tarefas) ===== */
  .mob-card {
    background: white;
    border: 1px solid #e8ecf0;
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
    transition: box-shadow .15s;
  }
  .mob-card:active { box-shadow: 0 2px 8px rgba(0,0,0,.1); }
  .mob-card-topo {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
  }
  .mob-card-titulo {
    flex: 1;
    font-weight: 700;
    color: #1e293b;
    font-size: 14px;
    line-height: 1.4;
  }
  .mob-card-sub {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
  }
  .mob-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
    margin-top: 6px;
  }
  .mob-card-linha {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
  }
  .mob-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
  }
}
