/* ============================================================================
   FERREIRA ADVOCACIA — PAINEL FINANCEIRO
   CSS puro — tema escuro estilo SaaS premium (Stripe / Linear / Vercel)
============================================================================ */

:root {
  --bg: #020617;
  --bg-elevated: #0b1120;
  --card-bg: rgba(15, 23, 42, 0.72);
  --card-bg-solid: #0f172a;
  --border: #1e293b;
  --border-light: #334155;
  --text: #e2e8f0;
  --text-strong: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --accent: #6366f1;
  --emerald: #34d399;
  --emerald-bg: rgba(16, 185, 129, 0.12);
  --rose: #f87171;
  --rose-bg: rgba(244, 63, 94, 0.12);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.12);
  --sky: #38bdf8;
  --indigo-bg: rgba(99, 102, 241, 0.12);
  --slate-bg: rgba(100, 116, 139, 0.18);
  --radius-lg: 1rem;
  --radius-md: 0.75rem;
  --radius-sm: 0.5rem;
  --shadow-card: 0 8px 30px rgba(0, 0, 0, 0.28);
  --shadow-pop: 0 20px 60px rgba(0, 0, 0, 0.45);
  --sidebar-w: 264px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0; font-family: inherit; font-weight: 800; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ---------- Scrollbars ---------- */
.scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.scroll::-webkit-scrollbar-track { background: transparent; }
.scroll::-webkit-scrollbar-thumb { background: #2a2f3a; border-radius: 10px; }
.scroll::-webkit-scrollbar-thumb:hover { background: #3a4150; }
.scroll { scrollbar-width: thin; scrollbar-color: #2a2f3a transparent; }

/* ---------- Animações ---------- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.anim-fade { animation: fadeIn 0.35s ease both; }
.anim-scale { animation: scaleIn 0.2s cubic-bezier(0.16,1,0.3,1) both; }
.anim-slide { animation: slideIn 0.3s cubic-bezier(0.16,1,0.3,1) both; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
.spin { animation: spin 0.8s linear infinite; display: inline-flex; }
.transition { transition: all 0.18s cubic-bezier(0.4,0,0.2,1); }

/* ============================================================================
   LAYOUT GERAL
============================================================================ */
.app-shell { min-height: 100vh; display: flex; background: var(--bg); }

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.main-content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}
@media (min-width: 1024px) { .main-content { padding: 2rem 2.5rem; } }

/* ============================================================================
   SIDEBAR
============================================================================ */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: var(--sidebar-w);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
}
@media (min-width: 1024px) {
  .sidebar { position: static; transform: none; }
}
.sidebar.open { transform: translateX(0); }

.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(2,6,23,0.7);
  z-index: 30;
}
@media (min-width: 1024px) { .sidebar-overlay { display: none !important; } }

.sidebar-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 1.25rem; height: 64px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; flex-shrink: 0; overflow: hidden;
}
.sidebar-logo img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-title { font-family: inherit; font-size: 0.9rem; font-weight: 800; color: var(--text-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-subtitle { font-size: 0.68rem; color: var(--text-faint); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 1rem 0.75rem; display: flex; flex-direction: column; gap: 0.25rem; }
.nav-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 0.75rem; border-radius: var(--radius-md);
  font-size: 0.875rem; font-weight: 500; color: var(--text-muted);
  width: 100%; text-align: left;
}
.nav-item:hover { color: var(--text-strong); background: rgba(30,41,59,0.7); }
.nav-item.active { color: #fff; background: var(--accent); box-shadow: var(--shadow-card); }
.nav-item .icon { flex-shrink: 0; }

/* ============================================================================
   TOPBAR
============================================================================ */
.topbar {
  height: 64px; flex-shrink: 0; border-bottom: 1px solid var(--border);
  background: rgba(2,6,23,0.82); backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem; position: sticky; top: 0; z-index: 20;
}
@media (min-width: 1024px) { .topbar { padding: 0 2rem; } }
.topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar-title { font-size: 1rem; font-weight: 800; color: var(--text-strong); line-height: 1.2; }
@media (min-width: 1024px) { .topbar-title { font-size: 1.1rem; } }
.topbar-subtitle { font-size: 0.72rem; color: var(--text-faint); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.topbar-user { display: flex; align-items: center; gap: 0.6rem; padding-left: 0.75rem; border-left: 1px solid var(--border); }
.avatar-circle {
  width: 32px; height: 32px; border-radius: 50%; background: var(--indigo-bg);
  color: #a5b4fc; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.topbar-user-name { font-size: 0.85rem; font-weight: 600; color: var(--text-strong); line-height: 1.2; }
.topbar-user-role { font-size: 0.68rem; color: var(--text-faint); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.5rem; border-radius: var(--radius-sm); color: var(--text-muted);
}
.icon-btn:hover { color: var(--text-strong); background: rgba(30,41,59,0.7); }
.lg-hide { }
@media (min-width: 1024px) { .lg-hide { display: none !important; } }
.sm-hide { display: none; }
@media (min-width: 640px) { .sm-hide { display: block; } }

/* ============================================================================
   ICONS
============================================================================ */
.icon { display: inline-block; vertical-align: middle; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ============================================================================
   CARDS / GRID
============================================================================ */
.card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card-bg);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(6px);
}
.card.card-hover:hover { border-color: var(--border-light); }
.card-pad { padding: 1.25rem; }
.card-pad-lg { padding: 1.5rem; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(1, 1fr); }
.grid-3 { grid-template-columns: repeat(1, 1fr); }
.grid-4 { grid-template-columns: repeat(1, 1fr); }
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}
.gap-lg { gap: 1.5rem; }
.stack { display: flex; flex-direction: column; gap: 1.5rem; }
.stack-sm { display: flex; flex-direction: column; gap: 1rem; }

/* ---------- Stat Card ---------- */
.stat-card { padding: 1.25rem; }
.stat-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.stat-icon { width: 40px; height: 40px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; }
.stat-icon.tone-indigo { background: var(--indigo-bg); color: #a5b4fc; }
.stat-icon.tone-emerald { background: var(--emerald-bg); color: var(--emerald); }
.stat-icon.tone-rose { background: var(--rose-bg); color: var(--rose); }
.stat-icon.tone-amber { background: var(--amber-bg); color: var(--amber); }
.stat-delta { display: inline-flex; align-items: center; gap: 2px; font-size: 0.72rem; font-weight: 700; }
.stat-delta.positive { color: var(--emerald); }
.stat-delta.negative { color: var(--rose); }
.stat-label { font-size: 0.72rem; color: var(--text-faint); margin-bottom: 2px; }
.stat-value { font-size: 1.5rem; font-weight: 800; color: var(--text-strong); letter-spacing: -0.02em; }
.stat-foot { font-size: 0.68rem; color: var(--text-faint); margin-top: 0.5rem; }

/* ---------- Chart Card ---------- */
.chart-card-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.25rem; gap: 0.5rem; }
.chart-card-title { font-size: 0.85rem; font-weight: 800; color: var(--text-strong); }
.chart-card-subtitle { font-size: 0.72rem; color: var(--text-faint); margin-top: 2px; }

/* ============================================================================
   BADGES
============================================================================ */
.badge {
  display: inline-flex; align-items: center; border-radius: 999px; border: 1px solid;
  padding: 0.3rem 0.7rem; font-size: 0.7rem; font-weight: 600; white-space: nowrap;
}
.badge.tone-slate { background: var(--slate-bg); color: #cbd5e1; border-color: rgba(100,116,139,0.4); }
.badge.tone-emerald { background: var(--emerald-bg); color: var(--emerald); border-color: rgba(16,185,129,0.3); }
.badge.tone-amber { background: var(--amber-bg); color: var(--amber); border-color: rgba(245,158,11,0.3); }
.badge.tone-rose { background: var(--rose-bg); color: var(--rose); border-color: rgba(244,63,94,0.3); }
.badge.tone-indigo { background: var(--indigo-bg); color: #a5b4fc; border-color: rgba(99,102,241,0.3); }

/* ============================================================================
   BOTÕES
============================================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  font-weight: 600; border-radius: var(--radius-md); font-size: 0.85rem;
  padding: 0.62rem 1.05rem; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.75rem; gap: 0.35rem; }
.btn-primary { color: #fff; background: var(--accent); box-shadow: var(--shadow-card); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); }
.btn-secondary { background: #1e293b; color: #e2e8f0; }
.btn-secondary:hover:not(:disabled) { background: #334155; }
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text-strong); background: rgba(30,41,59,0.7); }
.btn-danger { background: var(--rose-bg); color: #fca5a5; border: 1px solid rgba(244,63,94,0.3); }
.btn-danger:hover:not(:disabled) { background: rgba(244,63,94,0.25); }
.btn-block { width: 100%; }

/* ============================================================================
   FORMULÁRIOS
============================================================================ */
.field { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.85rem; }
.field-label { color: #cbd5e1; font-weight: 600; }
.field-hint { font-size: 0.72rem; color: var(--text-faint); }
.input, .select, .textarea {
  width: 100%; border-radius: var(--radius-md); background: rgba(30,41,59,0.7);
  border: 1px solid var(--border-light); color: var(--text-strong);
  padding: 0.62rem 0.85rem; outline: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus { border-color: transparent; box-shadow: 0 0 0 2px var(--accent); }
.textarea { resize: none; }
.select-wrap { position: relative; }
.select { appearance: none; -webkit-appearance: none; padding-right: 2.25rem; cursor: pointer; }
.select-chevron { position: absolute; right: 0.85rem; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.input-icon-wrap { position: relative; }
.input-icon-wrap .icon-left { position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.input-icon-wrap .input { padding-left: 2.5rem; }
.field-row { display: grid; gap: 1rem; }
.field-row.cols-2 { grid-template-columns: 1fr 1fr; }
.field-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 560px) { .field-row.cols-2, .field-row.cols-3 { grid-template-columns: 1fr; } }

/* ============================================================================
   MODAL
============================================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(2,6,23,0.72); backdrop-filter: blur(3px); }
.modal-box {
  position: relative; width: 100%; max-width: 32rem; border-radius: var(--radius-lg);
  border: 1px solid var(--border); background: var(--card-bg-solid);
  box-shadow: var(--shadow-pop); max-height: 88vh; overflow-y: auto;
}
.modal-box.narrow { max-width: 26rem; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(15,23,42,0.97); backdrop-filter: blur(4px); z-index: 5;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 800; color: var(--text-strong); }
.modal-body { padding: 1.5rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; padding-top: 0.5rem; }

/* ---------- Confirm dialog ---------- */
.confirm-icon {
  width: 48px; height: 48px; border-radius: 50%; background: var(--rose-bg); color: var(--rose);
  display: flex; align-items: center; justify-content: center; margin-bottom: 1rem;
}
.confirm-title { font-size: 1rem; font-weight: 800; color: var(--text-strong); margin-bottom: 0.4rem; }
.confirm-message { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.5rem; line-height: 1.5; }

/* ============================================================================
   TOASTS
============================================================================ */
.toast-root {
  position: fixed; top: 1.25rem; right: 1.25rem; z-index: 100;
  display: flex; flex-direction: column; gap: 0.5rem; width: min(360px, 92vw);
}
.toast {
  display: flex; align-items: flex-start; gap: 0.75rem; border-radius: var(--radius-md);
  border: 1px solid; padding: 0.75rem 1rem; box-shadow: var(--shadow-pop); backdrop-filter: blur(8px);
  font-size: 0.85rem;
}
.toast.tone-success { background: var(--emerald-bg); border-color: rgba(16,185,129,0.3); color: #6ee7b7; }
.toast.tone-error { background: var(--rose-bg); border-color: rgba(244,63,94,0.3); color: #fca5a5; }
.toast.tone-info { background: rgba(56,189,248,0.12); border-color: rgba(56,189,248,0.3); color: #7dd3fc; }
.toast-msg { flex: 1; line-height: 1.4; }
.toast-close { color: var(--text-faint); flex-shrink: 0; }
.toast-close:hover { color: var(--text-muted); }

/* ============================================================================
   TABELAS
============================================================================ */
.table-toolbar { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.table-search { position: relative; flex: 1; max-width: 20rem; }
.table-search .icon { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.table-search input {
  width: 100%; border-radius: var(--radius-md); background: rgba(30,41,59,0.7);
  border: 1px solid var(--border-light); color: var(--text-strong); padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  font-size: 0.85rem; outline: none;
}
.table-search input:focus { border-color: var(--border-light); }
.table-count { font-size: 0.72rem; color: var(--text-faint); }
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table thead tr { border-bottom: 1px solid var(--border); background: rgba(30,41,59,0.4); }
.data-table th { text-align: left; padding: 0.75rem 1rem; font-weight: 700; color: var(--text-faint); white-space: nowrap; }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text-muted); }
.data-table th .sort-arrow { display: inline-block; margin-left: 2px; transition: transform 0.15s; }
.data-table th .sort-arrow.desc { transform: rotate(180deg); }
.data-table td { padding: 0.75rem 1rem; color: var(--text); border-bottom: 1px solid rgba(30,41,59,0.6); white-space: nowrap; }
.data-table tbody tr:hover { background: rgba(30,41,59,0.3); }
.data-table tbody tr:last-child td { border-bottom: none; }
.table-actions { display: flex; justify-content: flex-end; gap: 0.25rem; }
.table-empty { text-align: center; color: var(--text-faint); padding: 2.5rem 1rem; font-size: 0.85rem; }
.text-emerald { color: var(--emerald); }
.text-rose { color: var(--rose); }
.font-medium { font-weight: 600; }

/* ============================================================================
   CATEGORIAS (grid de cards)
============================================================================ */
.category-card {
  padding: 1rem; display: flex; align-items: center; justify-content: space-between;
}
.category-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.category-name { font-size: 0.85rem; font-weight: 600; color: var(--text-strong); }
.category-actions { display: flex; gap: 0.25rem; opacity: 0.6; }
.category-card:hover .category-actions { opacity: 1; }

/* ============================================================================
   METAS / PROGRESSO
============================================================================ */
.progress-track { height: 10px; border-radius: 999px; background: #1e293b; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.progress-track.thin { height: 8px; }
.ranking-item + .ranking-item { margin-top: 0.9rem; }
.ranking-row { display: flex; justify-content: space-between; font-size: 0.75rem; margin-bottom: 0.35rem; gap: 0.5rem; }
.ranking-desc { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ranking-value { color: var(--text-muted); font-weight: 600; flex-shrink: 0; }
.ranking-cat { font-size: 0.68rem; color: var(--text-faint); margin-top: 0.25rem; }

/* ============================================================================
   SKELETON
============================================================================ */
.skeleton { border-radius: var(--radius-md); background: rgba(30,41,59,0.9); }

/* ============================================================================
   GRÁFICOS SVG
============================================================================ */
.chart-svg { width: 100%; height: auto; overflow: visible; }
.chart-legend { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.4rem 0.6rem; margin-top: 0.75rem; max-height: 7rem; overflow-y: auto; }
.legend-item { display: flex; align-items: center; gap: 0.4rem; font-size: 0.68rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.chart-tooltip {
  position: fixed; z-index: 200; pointer-events: none; background: #0f1420; border: 1px solid #1f2530;
  border-radius: 0.6rem; color: #e2e8f0; font-size: 0.72rem; padding: 0.45rem 0.65rem; box-shadow: var(--shadow-pop);
  display: none; white-space: nowrap;
}
.chart-tooltip strong { color: #fff; }
.axis-label { fill: #64748b; font-size: 10px; font-family: inherit; }
.grid-line { stroke: #1e293b; stroke-dasharray: 3 3; }

/* ============================================================================
   MISC
============================================================================ */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-faint); }

/* ============================================================================
   IMPRESSÃO (usado na exportação de relatórios em PDF)
============================================================================ */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-content { padding: 0 !important; }
  body, .app-shell { background: #fff !important; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* ============================================================================
   RESPONSIVIDADE GERAL
============================================================================ */
@media (max-width: 640px) {
  .stat-value { font-size: 1.25rem; }
  .modal-body { padding: 1.1rem; }
}
