/* ============================================================
   MyFinance — Design System & Style Guide
   Foco: Alinhamento, Espaçamento (Respiro) e Consistência
   ============================================================ */

/* 1. VARIÁVEIS GLOBAIS (Tokens de Design)
   ============================================================ */
:root {
  /* Cores Principais (Dark Theme) */
  --bg-1: #0a0b0d;      /* Fundo Principal */
  --bg-2: #141619;      /* Cards, Sidebar */
  --bg-3: #1f2227;      /* Inputs, Hovers */

  /* Cores de Destaque */
  --gold: #d4af37;      /* Primária (Dourado Luxo) */
  --gold-dim: #aa8c2c;  /* Dourado Suave (Hovers) */
  --text-1: #ffffff;    /* Títulos e Texto Forte */
  --text-2: #b0b0b0;    /* Corpo de Texto (Clareado para leitura) */
  --text-3: #6c757d;    /* Placeholders, Desativados */

  /* Cores Semânticas */
  --emerald: #2ecc71;   /* Receitas, Sucesso */
  --emerald-dim: rgba(46, 204, 113, 0.1);
  --crimson: #e74c3c;   /* Despesas, Erro */
  --crimson-dim: rgba(231, 76, 60, 0.1);
  --border: #2a2d33;    /* Linhas Divisórias */

  /* Tipografia */
  --font-title: 'Playfair Display', serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;

  /* Espaçamento e Bordas (Aumentados para "Respiro") */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 20px;
  --spacing-xs: 0.5rem;  /* 8px */
  --spacing-sm: 1rem;    /* 16px */
  --spacing-md: 1.5rem;  /* 24px */
  --spacing-lg: 2rem;    /* 32px */
  --spacing-xl: 3rem;    /* 48px */

  /* Sombras e Transições */
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.6);
  --shadow-sm: 0 4px 12px rgba(0,0,0,0.4);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* Grid de Layout */
  --sidebar-width: 280px;
  --topbar-height: 80px;
}

/* 2. RESET E ESTILOS BASE
   ============================================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  outline: none;
  -webkit-font-smoothing: antialiased;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-1);
  color: var(--text-2);
  line-height: 1.6;
  overflow: hidden;
}

h1, h2, h3, h4 {
  font-family: var(--font-title);
  color: var(--text-1);
  font-weight: 600;
  line-height: 1.2;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font-body);
  transition: var(--transition);
}

/* 3. COMPONENTES REUTILIZÁVEIS (UI KIT)
   ============================================================ */

.btn-primary {
  background-color: var(--gold);
  color: #000;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.btn-primary:hover { background-color: var(--gold-dim); transform: translateY(-1px); }

.btn-secondary {
  background-color: var(--bg-3);
  color: var(--text-1);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.btn-secondary:hover { border-color: var(--gold); color: var(--gold); }

.btn-icon { width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); color: var(--text-2); background-color: var(--bg-3); }
.btn-icon:hover { background-color: var(--border); color: var(--text-1); }
.btn-icon.success:hover { background-color: var(--emerald); color: #000; }
.btn-icon.danger:hover { background-color: var(--crimson); color: #fff; }

/* Inputs e Forms */
input[type="text"], input[type="date"], select, textarea {
  width: 100%; padding: 0.75rem 1rem; background-color: var(--bg-3); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-1); font-family: var(--font-body); transition: var(--transition);
}
input:focus, select:focus { border-color: var(--gold); }

/* Badges e Status Polidos */
.badge-status { padding: 0.3rem 0.8rem; font-size: 0.65rem; font-weight: 700; border-radius: 30px; text-transform: uppercase; letter-spacing: 0.5px; }
.status-CONFIRMED { background-color: var(--emerald-dim); color: var(--emerald); border: 1px solid rgba(46, 204, 113, 0.2); }
.status-PENDING { background-color: rgba(212, 175, 55, 0.1); color: var(--gold); border: 1px solid rgba(212, 175, 55, 0.2); }
.status-CANCELLED { background-color: var(--crimson-dim); color: var(--crimson); border: 1px solid rgba(231, 76, 60, 0.2); }
.badge-cat { background-color: var(--bg-3); padding: 0.2rem 0.6rem; border-radius: var(--radius-sm); font-size: 0.75rem; border: 1px solid var(--border); }

/* 4. LANDING PAGE (Home)
   ============================================================ */
#page-home { display: none; min-height: 100vh; position: relative; background-color: var(--bg-1); overflow: hidden; }
#page-home.active { display: flex; align-items: center; justify-content: center; }
.home-container { max-width: 900px; width: 90%; text-align: center; z-index: 10; }
.home-brand { margin-bottom: var(--spacing-xl); }
.home-brand .brand-icon { font-size: 3rem; color: var(--gold); margin-bottom: var(--spacing-xs); }
.home-brand h1 { font-size: 3.5rem; margin-bottom: var(--spacing-xs); }
.home-brand .brand-tagline { font-size: 1rem; color: var(--text-2); }
.home-card { background-color: var(--bg-2); padding: var(--spacing-lg); border-radius: var(--radius-lg); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.home-card h2 { font-size: 2rem; margin-bottom: var(--spacing-sm); }
.home-description { color: var(--text-2); margin-bottom: var(--spacing-lg); max-width: 600px; margin-left: auto; margin-right: auto; }
.btn-keycloak { background-color: var(--gold); color: #000; font-size: 1rem; padding: 1rem 2rem; border-radius: var(--radius-sm); font-weight: 600; display: inline-flex; gap: 1rem; align-items: center; }
.btn-keycloak:hover { background-color: var(--gold-dim); }
.home-features { display: flex; justify-content: center; gap: var(--spacing-lg); margin-top: var(--spacing-lg); color: var(--text-3); font-size: 0.9rem; }
.home-features .feat { display: flex; align-items: center; gap: 0.5rem; }
.home-bg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; }
.home-orb { position: absolute; border-radius: 50%; filter: blur(100px); opacity: 0.1; }
.orb-1 { width: 300px; height: 300px; background-color: var(--emerald); top: 10%; left: 10%; }
.orb-2 { width: 400px; height: 400px; background-color: var(--gold); bottom: 10%; right: 10%; }
.orb-3 { width: 250px; height: 250px; background-color: var(--crimson); top: 50%; left: 50%; }

/* 5. APP LAYOUT - SIDEBAR & USER CARD (PERFIL PREMIUM)
   ============================================================ */
#page-app { display: none; min-height: 100vh; }
#page-app.active { display: flex; }

/* AQUI FOI ADICIONADA A TRANSIÇÃO NA SIDEBAR */
.sidebar { width: var(--sidebar-width); background-color: var(--bg-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: var(--spacing-sm); height: 100vh; position: sticky; top: 0; transition: left 0.3s ease; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding-bottom: var(--spacing-sm); margin-bottom: var(--spacing-sm); border-bottom: 1px solid var(--border); }
.sidebar-brand { font-family: var(--font-title); color: var(--text-1); font-size: 1.25rem; font-weight: 600; }
.sidebar-close { display: none; }

.sidebar-user {
  background: linear-gradient(145deg, var(--bg-3) 0%, var(--bg-2) 100%);
  padding: var(--spacing-sm);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: var(--spacing-md);
  border: 1px solid var(--border);
  transition: var(--transition);
  cursor: pointer;
}

.sidebar-user:hover {
  border-color: var(--gold-dim);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.user-avatar {
  width: 46px; height: 46px;
  background-color: rgba(212, 175, 55, 0.1);
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-weight: 700; font-size: 1.3rem;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.user-info .user-name { display: block; color: var(--text-1); font-size: 1rem; font-weight: 600; }
.user-info .user-role { font-size: 0.7rem; color: var(--gold-dim); text-transform: uppercase; letter-spacing: 1px; font-weight: 500; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.5rem; flex-grow: 1; }
.nav-item { width: 100%; padding: 0.8rem 1rem; display: flex; align-items: center; gap: 1rem; border-radius: var(--radius-sm); color: var(--text-2); font-size: 0.95rem; margin-bottom: 0.3rem; }
.nav-item i { width: 20px; font-size: 1.1rem; opacity: 0.7; }
.nav-item:hover { background-color: var(--bg-3); color: var(--text-1); }
.nav-item.active { background-color: rgba(212, 175, 55, 0.08); color: var(--gold); font-weight: 600; }
.nav-item.active i { color: var(--gold); opacity: 1; }

.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding-top: var(--spacing-sm); }
.btn-logout { width: 100%; color: var(--crimson); display: flex; align-items: center; gap: 1rem; padding: 0.7rem 1rem; border-radius: var(--radius-sm); }
.btn-logout:hover { background-color: var(--crimson-dim); }

.main-wrapper { flex-grow: 1; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.topbar { height: var(--topbar-height); background-color: var(--bg-1); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 var(--spacing-lg); }
.menu-toggle { display: none; }

.content { flex-grow: 1; padding: var(--spacing-lg); overflow-y: auto; background-color: var(--bg-1); }
.content-section { display: none; }
.content-section.active { display: block; }

/* 6. ESTILOS ESPECÍFICOS DAS SEÇÕES E CARDS
   ============================================================ */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--spacing-lg); padding-bottom: var(--spacing-sm); border-bottom: 1px solid var(--border); }
.header-actions { display: flex; gap: var(--spacing-sm); align-items: center; }
.section-title { font-size: 1.75rem; }
.section-sub { color: var(--text-3); font-size: 0.9rem; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--spacing-sm); margin-bottom: var(--spacing-lg); }
.kpi-card { background-color: var(--bg-2); border-radius: var(--radius-md); padding: var(--spacing-md); display: flex; align-items: center; gap: var(--spacing-sm); border: 1px solid var(--border); transition: var(--transition); }
.kpi-card:hover { border-color: var(--border); transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.kpi-icon { width: 50px; height: 50px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; }
.kpi-label { display: block; font-size: 0.8rem; color: var(--text-3); margin-bottom: 0.2rem; }
.kpi-value { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 500; color: var(--text-1); }
.kpi-card.income .kpi-icon { background-color: var(--emerald-dim); color: var(--emerald); }
.kpi-card.expense .kpi-icon { background-color: var(--crimson-dim); color: var(--crimson); }
.kpi-card.balance .kpi-icon { background-color: var(--bg-3); color: var(--text-1); }

.card { background-color: var(--bg-2); border-radius: var(--radius-md); padding: var(--spacing-md); border: 1px solid var(--border); box-shadow: var(--shadow-sm); margin-bottom: var(--spacing-sm);}

/* ============================================================
   NOVO: Gráfico Donut (Dashboard)
   ============================================================ */
.donut-container { display: flex; align-items: center; gap: 2rem; padding: 1rem; justify-content: center; flex-wrap: wrap; }
.donut-chart {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  -webkit-mask: radial-gradient(circle, transparent 55%, black 56%);
  mask: radial-gradient(circle, transparent 55%, black 56%);
  transition: transform 0.3s ease;
}
.donut-chart:hover { transform: scale(1.02); }
.donut-legend-container { display: flex; flex-direction: column; gap: 0.8rem; max-width: 250px; }
.donut-legend-item { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: var(--text-2); }
.donut-legend-color { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.donut-legend-text { display: flex; flex-direction: column; }
.donut-legend-name { font-weight: 500; }
.donut-legend-pct { font-size: 0.8rem; opacity: 0.8; }

/* Progressão de Metas */
.goal-progress-container { margin: 1rem 0; }
.goal-progress-label { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-2); margin-bottom: 0.4rem; }
.goal-track { height: 8px; background-color: var(--bg-3); border-radius: 10px; overflow: hidden; margin-bottom: 0.4rem; }
.goal-fill { height: 100%; background-color: var(--gold); border-radius: 10px; transition: width 0.4s ease; }
.goal-target-label { font-size: 0.75rem; color: var(--text-3); text-align: right; }

.cards-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--spacing-sm); }
.item-card { background-color: var(--bg-2); border-radius: var(--radius-md); padding: var(--spacing-sm); border: 1px solid var(--border); transition: var(--transition); }
.item-card:hover { border-color: var(--gold-dim); transform: translateY(-2px); }
.item-card-header { display: flex; justify-content: space-between; margin-bottom: var(--spacing-xs); }
.item-card-title { color: var(--text-1); font-weight: 500; }
.item-card-meta { font-size: 0.8rem; color: var(--text-3); margin-bottom: var(--spacing-xs); }
.item-card-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: var(--spacing-xs); }

/* Tabelas */
/* AQUI O OVERFLOW FOI TROCADO PARA OVERFLOW-X: AUTO */
.table-wrapper { background-color: var(--bg-2); border-radius: var(--radius-md); border: 1px solid var(--border); overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th { background-color: var(--bg-3); text-align: left; color: var(--text-1); font-weight: 600; padding: 1.2rem var(--spacing-sm); font-size: 0.85rem; border-bottom: 2px solid var(--border); }
.data-table tbody td { padding: 1rem var(--spacing-sm); border-bottom: 1px solid var(--border); color: var(--text-1); vertical-align: middle; }
.data-table tbody tr:hover { background-color: rgba(255,255,255,0.02); }

/* 7. UTILITÁRIOS (JS INJECTS)
   ============================================================ */
.is-inactive { opacity: 0.5; filter: grayscale(100%); }
.text-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }
.text-muted { color: var(--text-3) !important; }
.fw-bold { font-weight: 600 !important; }
.text-success { color: var(--emerald) !important; }
.text-danger { color: var(--crimson) !important; }
.val-positive { color: var(--emerald); }
.val-negative { color: var(--crimson); }
.item-card-value { font-size: 1.5rem; font-family: var(--font-mono); margin: 0.5rem 0; font-weight: 600; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-3); }
.empty-state i { font-size: 3rem; margin-bottom: 1rem; opacity: 0.3; }
.spinner-container { display: flex; justify-content: center; align-items: center; padding: 3rem; }
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--text-3); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
button .spinner { width: 14px; height: 14px; margin-right: 8px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.pagination { display: flex; justify-content: center; gap: 0.5rem; margin-top: 1.5rem; }
.pagination button { padding: 0.4rem 0.8rem; background-color: var(--bg-3); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-2); font-size: 0.85rem; }
.pagination button:hover:not(:disabled) { background-color: var(--gold); color: #000; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* 8. MODAIS E TOASTS
   ============================================================ */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.85); backdrop-filter: blur(8px); z-index: 1000; display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: var(--transition); }
.modal-overlay:not(.hidden) { opacity: 1; visibility: visible; }
.modal { background-color: var(--bg-2); border-radius: var(--radius-lg); width: 90%; max-width: 550px; border: 1px solid var(--border); box-shadow: var(--shadow-lg); transform: scale(0.9); transition: var(--transition); max-height: 90vh; overflow-y: auto; }
.modal-overlay:not(.hidden) .modal { transform: scale(1); }
.modal-header { padding: var(--spacing-sm) var(--spacing-md); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--bg-2); z-index: 2; }
.modal-body { padding: var(--spacing-md); }
.modal-footer { padding: var(--spacing-sm) var(--spacing-md); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 0.5rem; position: sticky; bottom: 0; background: var(--bg-2); z-index: 2; }

/* Toast */
#toast-container { position: fixed; bottom: var(--spacing-lg); right: var(--spacing-lg); z-index: 1100; display: flex; flex-direction: column; gap: 10px; }
.toast { background-color: var(--bg-2); color: var(--text-1); padding: 1rem 1.5rem; border-radius: var(--radius-sm); border-left: 4px solid var(--gold); box-shadow: var(--shadow-sm); animation: slideInRight 0.3s ease forwards; }
.toast.success { border-left-color: var(--emerald); }
.toast.error { border-left-color: var(--crimson); }
.toast.warning { border-left-color: #f39c12; }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* 9. RESPONSIVO
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-width: 100%; }
  .sidebar { position: fixed; left: -100%; z-index: 1100; width: 280px; }
  .sidebar.mobile-open { left: 0; }
  .sidebar-close { display: block; font-size: 1.5rem; color: var(--text-2); }
  .menu-toggle { display: block; font-size: 1.5rem; color: var(--text-1); background: none; border: none; cursor: pointer; }
  .section-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
  .header-actions { width: 100%; justify-content: stretch; }
  .header-actions button { flex: 1; }
  .filter-input { width: 100%; margin-bottom: 0.5rem; }
  .date-filter-row { flex-direction: column; width: 100%; align-items: stretch; }
}