/* =====================================================
 *  FinControl — Design System v2 (inspirado no Apple HIG)
 *  ===================================================== */

:root {
  --radius: 18px;
  --radius-sm: 12px;
  --ease: cubic-bezier(.32, .72, 0, 1);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Inter', sans-serif;
}

[data-theme="dark"] {
  --bg: #000000;
  --bg-card: #1C1C1E;
  --bg-elevated: #2C2C2E;
  --fill: rgba(120,120,128,.24);
  --text: #FFFFFF;
  --text-secondary: #AEAEB2;
  --text-muted: #8E8E93;
  --border: rgba(84,84,88,.55);
  --accent: #30D158;
  --accent-soft: rgba(48,209,88,.16);
  --on-accent: #062B14;
  --danger: #FF453A;
  --warning: #FF9F0A;
  --info: #0A84FF;
  --nav-bg: rgba(22,22,24,.78);
  --shadow-card: none;
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
}

[data-theme="light"] {
  --bg: #F2F2F7;
  --bg-card: #FFFFFF;
  --bg-elevated: #E5E5EA;
  --fill: rgba(120,120,128,.14);
  --text: #1C1C1E;
  --text-secondary: #3A3A3C;
  --text-muted: #8E8E93;
  --border: rgba(60,60,67,.12);
  --accent: #059669;
  --accent-soft: rgba(5,150,105,.12);
  --on-accent: #FFFFFF;
  --danger: #FF3B30;
  --warning: #FF9500;
  --info: #007AFF;
  --nav-bg: rgba(249,249,249,.78);
  --shadow-card: 0 1px 2px rgba(60,60,67,.06), 0 8px 24px rgba(60,60,67,.07);
  --shadow-lg: 0 16px 48px rgba(60,60,67,.18);
}

/* ============ BASE ============ */
* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html { -webkit-text-size-adjust:100%; }
body {
  font-family: var(--font);
  background: var(--bg); color: var(--text);
  font-size:16px; line-height:1.47;
  letter-spacing:-0.01em;
  transition: background .35s var(--ease), color .35s var(--ease);
  overscroll-behavior-y: contain;
  overflow-x:hidden;
}
button { font-family:inherit; cursor:pointer; border:none; background:none; color:inherit; }
input, select, textarea { font-family:inherit; font-size:16px; }
::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width:8px; height:8px; }
::-webkit-scrollbar-thumb { background:var(--fill); border-radius:4px; }
:focus-visible { outline:none; box-shadow:0 0 0 3px var(--accent-soft); border-radius:8px; }

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

.sidebar {
  width:260px; position:fixed; inset:0 auto 0 0; z-index:50;
  display:flex; flex-direction:column; padding:20px 14px;
  background:var(--nav-bg);
  -webkit-backdrop-filter:saturate(180%) blur(20px); backdrop-filter:saturate(180%) blur(20px);
  border-right:1px solid var(--border);
}
.logo { display:flex; align-items:center; gap:10px; padding:6px 12px 22px; }
.logo-icon { font-size:1.5rem; }
.logo-text { font-weight:700; font-size:1.15rem; letter-spacing:-0.02em; }
.nav-menu { flex:1; display:flex; flex-direction:column; gap:2px; }
.nav-item {
  display:flex; align-items:center; gap:12px; width:100%; text-align:left;
  padding:10px 12px; border-radius:10px; font-size:15px; font-weight:500;
  color:var(--text-secondary); transition:all .2s var(--ease);
}
.nav-item:hover { background:var(--fill); color:var(--text); }
.nav-item:active { transform:scale(.98); }
.nav-item.active { background:var(--accent-soft); color:var(--accent); font-weight:600; }
.nav-item .nav-icon { font-size:1.15rem; width:24px; text-align:center; }
.sidebar-footer { padding-top:14px; border-top:1px solid var(--border); }
.theme-toggle {
  width:100%; padding:9px; border-radius:10px; background:var(--fill);
  font-size:1.05rem; transition:all .2s var(--ease);
}
.theme-toggle:active { transform:scale(.96); }

.main { flex:1; margin-left:260px; display:flex; flex-direction:column; min-height:100vh; }

.topbar {
  position:sticky; top:0; z-index:40;
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:12px 24px;
  padding-top:calc(12px + env(safe-area-inset-top));
  background:var(--nav-bg);
  -webkit-backdrop-filter:saturate(180%) blur(20px); backdrop-filter:saturate(180%) blur(20px);
  border-bottom:1px solid var(--border);
}
.topbar-left { display:flex; align-items:center; gap:10px; min-width:0; }
.mobile-logo { display:none; font-size:1.3rem; }
.topbar h1 { font-size:17px; font-weight:700; letter-spacing:-0.02em; }
.month-nav {
  display:flex; align-items:center; gap:2px;
  background:var(--fill); border-radius:999px; padding:3px;
}
.month-label { font-weight:600; font-size:13px; min-width:118px; text-align:center; letter-spacing:-0.01em; }
.btn-icon {
  width:30px; height:30px; border-radius:50%; font-size:1.1rem;
  display:flex; align-items:center; justify-content:center;
  color:var(--text-secondary); transition:all .2s var(--ease);
}
.btn-icon:hover { background:var(--bg-card); color:var(--text); }
.btn-icon:active { transform:scale(.9); }

.content { flex:1; width:100%; max-width:1080px; margin:0 auto; padding:24px; }
.screen { display:none; }
.screen.active { display:block; animation:screenIn .35s var(--ease); }
@keyframes screenIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

/* ============ CARDS & PAINÉIS ============ */
.cards-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:14px; margin-bottom:16px; }
.card, .panel {
  background:var(--bg-card); border-radius:var(--radius);
  padding:18px 20px; box-shadow:var(--shadow-card);
}
.panel { margin-bottom:16px; }
.card-label { font-size:13px; font-weight:500; color:var(--text-muted); margin-bottom:6px; display:flex; align-items:center; gap:6px; }
.card-value { font-size:26px; font-weight:700; letter-spacing:-0.03em; font-variant-numeric:tabular-nums; }
.card-value.income, .card-value.balance-positive { color:var(--accent); }
.card-value.expense, .card-value.balance-negative { color:var(--danger); }
.card-sub { font-size:12px; color:var(--text-muted); margin-top:4px; }
.panel-title { font-size:15px; font-weight:700; letter-spacing:-0.01em; margin-bottom:14px; display:flex; align-items:center; gap:8px; }
.panels-row { display:grid; grid-template-columns:1fr 1fr; gap:16px; }

/* ============ LISTAS AGRUPADAS (estilo iOS) ============ */
.list {
  display:flex; flex-direction:column;
  background:var(--bg-card); border-radius:var(--radius);
  overflow:hidden; box-shadow:var(--shadow-card);
}
.list-item {
  display:flex; align-items:center; gap:12px;
  padding:12px 16px; border-bottom:1px solid var(--border);
  transition:background .15s var(--ease);
}
.list-item:last-child { border-bottom:none; }
.list-item:hover { background:var(--fill); }
.list > .panel {
  background:transparent; box-shadow:none; border-radius:0;
  border-bottom:1px solid var(--border); margin:0;
}
.list > .panel:last-child { border-bottom:none; }
.item-icon {
  width:38px; height:38px; border-radius:10px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center; font-size:1.15rem;
}
.item-info { flex:1; min-width:0; }
.item-title { font-weight:600; font-size:15px; letter-spacing:-0.01em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.item-sub { font-size:12.5px; color:var(--text-muted); margin-top:1px; }
.item-value { font-weight:600; font-size:15px; white-space:nowrap; font-variant-numeric:tabular-nums; }
.item-value.income { color:var(--accent); }
.item-value.expense { color:var(--danger); }
.item-actions { display:flex; gap:6px; }
.btn-sm { padding:6px 10px; border-radius:8px; font-size:.8rem; background:var(--fill); color:var(--text-secondary); transition:all .15s var(--ease); }
.btn-sm:active { transform:scale(.92); }
.btn-sm.danger { color:var(--danger); }
.empty-state { text-align:center; padding:48px 20px; color:var(--text-muted); font-size:15px; }
.empty-state .empty-icon { font-size:2.6rem; margin-bottom:10px; }

/* ============ FILTROS & FORMULÁRIOS ============ */
.filters { display:flex; gap:10px; margin-bottom:16px; flex-wrap:wrap; }
.search-input, .filter-select, .form-input, .form-select {
  width:100%; padding:11px 14px; border:none; border-radius:var(--radius-sm);
  background:var(--fill); color:var(--text); outline:none;
  transition:box-shadow .2s var(--ease), background .2s var(--ease);
}
.search-input { flex:1; min-width:180px; }
.search-input:focus, .form-input:focus, .form-select:focus, .filter-select:focus {
  box-shadow:0 0 0 3px var(--accent-soft);
}
.search-input::placeholder, .form-input::placeholder { color:var(--text-muted); }
.form-select, .filter-select {
  appearance:none; -webkit-appearance:none; padding-right:36px;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%238E8E93' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-position:right 14px center;
}
.form-input[type="color"] { padding:6px; height:48px; }
.form-group { margin-bottom:16px; }
.form-label { display:block; font-size:13px; font-weight:600; color:var(--text-muted); margin-bottom:6px; letter-spacing:-0.01em; }
.form-row { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.checkbox-row { display:flex; align-items:center; gap:10px; font-size:15px; }
.checkbox-row input { width:20px; height:20px; accent-color:var(--accent); }
textarea.form-input { resize:vertical; min-height:120px; }

/* Segmented control (Despesa/Receita) */
.type-switch { display:flex; gap:2px; padding:2px; background:var(--fill); border-radius:10px; margin-bottom:16px; }
.type-btn {
  flex:1; padding:10px; border-radius:8px; font-weight:600; font-size:15px;
  color:var(--text-muted); transition:all .25s var(--ease);
}
.type-btn:active { transform:scale(.97); }
.type-btn.active-expense { background:var(--bg-card); color:var(--danger); box-shadow:0 1px 5px rgba(0,0,0,.15); }
.type-btn.active-income { background:var(--bg-card); color:var(--accent); box-shadow:0 1px 5px rgba(0,0,0,.15); }

/* ============ BOTÕES ============ */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  padding:12px 18px; border-radius:var(--radius-sm);
  font-weight:600; font-size:15px; letter-spacing:-0.01em;
  transition:transform .15s var(--ease), background .2s var(--ease), opacity .2s;
}
.btn:active { transform:scale(.97); }
.btn-primary { background:var(--accent); color:var(--on-accent); }
.btn-primary:hover { opacity:.88; }
.btn-secondary { background:var(--fill); color:var(--text); }
.btn-secondary:hover { background:var(--bg-elevated); }
.btn-danger { background:rgba(255,59,48,.14); color:var(--danger); }
.btn-block { width:100%; }
.btn-group { display:flex; gap:10px; flex-wrap:wrap; }

.fab {
  position:fixed; right:20px; z-index:45;
  bottom:calc(84px + env(safe-area-inset-bottom));
  width:56px; height:56px; border-radius:50%;
  background:var(--accent); color:var(--on-accent); font-size:1.7rem;
  display:flex; align-items:center; justify-content:center;
  box-shadow:0 6px 20px var(--accent-soft), 0 4px 12px rgba(0,0,0,.2);
  transition:transform .2s var(--ease);
}
.fab:hover { transform:scale(1.06); }
.fab:active { transform:scale(.9); }

/* ============ BARRA INFERIOR (tab bar iOS) ============ */
.bottom-nav {
  position:fixed; left:0; right:0; bottom:0; z-index:50; display:none;
  background:var(--nav-bg);
  -webkit-backdrop-filter:saturate(180%) blur(20px); backdrop-filter:saturate(180%) blur(20px);
  border-top:1px solid var(--border);
  padding-bottom:env(safe-area-inset-bottom);
}
.bottom-nav-inner { display:flex; overflow-x:auto; scrollbar-width:none; }
.bottom-nav-inner::-webkit-scrollbar { display:none; }
.bnav-item {
  flex:0 0 auto; min-width:62px; display:flex; flex-direction:column; align-items:center; gap:2px;
  padding:9px 4px 7px; font-size:10px; font-weight:500;
  color:var(--text-muted); transition:color .2s var(--ease);
}
.bnav-item:active { transform:scale(.92); }
.bnav-item.active { color:var(--accent); }
.bnav-item .bnav-icon { font-size:1.35rem; }

/* ============ MODAL (sheet iOS) ============ */
.modal-overlay {
  position:fixed; inset:0; z-index:100; display:none;
  align-items:flex-end; justify-content:center;
  background:rgba(0,0,0,.4);
  -webkit-backdrop-filter:blur(6px); backdrop-filter:blur(6px);
}
.modal-overlay.open { display:flex; }
.modal {
  width:100%; max-width:560px; max-height:92vh; overflow-y:auto;
  background:var(--bg-card); padding:12px 22px calc(24px + env(safe-area-inset-bottom));
  border-radius:24px 24px 0 0; animation:sheetUp .4s var(--ease);
}
.modal::before {
  content:''; display:block; width:36px; height:5px; border-radius:3px;
  background:var(--fill); margin:4px auto 14px;
}
@keyframes sheetUp { from { transform:translateY(60px); opacity:.4; } to { transform:none; opacity:1; } }
.modal-title { font-size:17px; font-weight:700; letter-spacing:-0.02em; margin-bottom:18px; display:flex; justify-content:space-between; align-items:center; }
.modal-close { width:30px; height:30px; border-radius:50%; background:var(--fill); color:var(--text-muted); font-size:1rem; display:flex; align-items:center; justify-content:center; }

/* ============ PROGRESSO & GRÁFICOS ============ */
.progress-wrap { margin-bottom:14px; }
.progress-header { display:flex; justify-content:space-between; margin-bottom:6px; font-size:13px; font-variant-numeric:tabular-nums; }
.progress-header .cat-name { display:flex; align-items:center; gap:8px; font-weight:600; }
.progress-bar { height:6px; background:var(--fill); border-radius:3px; overflow:hidden; }
.progress-fill { height:100%; border-radius:3px; transition:width .6s var(--ease); }
.progress-fill.ok { background:var(--accent); }
.progress-fill.warn { background:var(--warning); }
.progress-fill.over { background:var(--danger); }

.chart-container { display:flex; justify-content:center; padding:8px 0; }
.donut-legend { display:flex; flex-wrap:wrap; gap:8px 16px; margin-top:14px; justify-content:center; }
.legend-item { display:flex; align-items:center; gap:6px; font-size:12.5px; color:var(--text-secondary); }
.legend-dot { width:8px; height:8px; border-radius:50%; }
.bar-chart { display:flex; align-items:flex-end; gap:8px; height:180px; padding-top:10px; }
.bar-col { flex:1; display:flex; flex-direction:column; align-items:center; gap:6px; height:100%; justify-content:flex-end; }
.bar-fill { width:100%; max-width:44px; border-radius:6px 6px 2px 2px; background:var(--accent); min-height:2px; transition:height .6s var(--ease); }
.bar-fill.expense { background:var(--danger); opacity:.9; }
.bar-label { font-size:11px; color:var(--text-muted); }
.bar-value { font-size:10px; font-weight:600; font-variant-numeric:tabular-nums; }

/* ============ TOAST (HUD) ============ */
.toast {
  position:fixed; left:50%; z-index:200;
  bottom:calc(96px + env(safe-area-inset-bottom));
  transform:translateX(-50%) translateY(16px);
  background:rgba(28,28,30,.88); color:#fff;
  -webkit-backdrop-filter:blur(12px); backdrop-filter:blur(12px);
  padding:10px 20px; border-radius:999px;
  font-weight:600; font-size:14px; box-shadow:var(--shadow-lg);
  opacity:0; pointer-events:none; transition:all .35s var(--ease);
}
.toast.show { opacity:1; transform:translateX(-50%) translateY(0); }

/* ============ BADGES & UTIL ============ */
.badge { padding:2px 8px; border-radius:6px; font-size:11px; font-weight:600; }
.badge-reembolso { background:rgba(0,122,255,.14); color:var(--info); }
.badge-parcela { background:rgba(255,149,0,.14); color:var(--warning); }
.text-muted { color:var(--text-muted); }
.mt { margin-top:16px; }
.mb { margin-bottom:16px; }
.settings-item { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:14px 0; border-bottom:1px solid var(--border); }
.settings-item:last-child { border-bottom:none; }
.settings-label { font-weight:600; font-size:15px; }
.settings-desc { font-size:13px; color:var(--text-muted); }

/* ============ TABELA DE RELATÓRIO ============ */
.report-table { width:100%; border-collapse:collapse; font-size:14px; font-variant-numeric:tabular-nums; }
.report-table th, .report-table td { padding:10px 8px; text-align:right; border-bottom:1px solid var(--border); }
.report-table th:first-child, .report-table td:first-child { text-align:left; }
.report-table thead { color:var(--text-muted); font-size:11px; text-transform:uppercase; letter-spacing:.05em; }
.report-table tfoot { font-weight:700; background:var(--fill); }
.report-table .pos { color:var(--accent); }
.report-table .neg { color:var(--danger); }

/* ============ SELETOR DE ÍCONES ============ */
.icon-grid { display:flex; flex-wrap:wrap; gap:10px; }
.icon-opt {
  width:46px; height:46px; font-size:1.35rem; border-radius:12px;
  background:var(--fill); display:flex; align-items:center; justify-content:center;
  transition:transform .15s var(--ease), background .2s, box-shadow .2s;
}
.icon-opt:hover { transform:scale(1.07); }
.icon-opt:active { transform:scale(.92); }
.icon-opt.selected { background:var(--accent-soft); box-shadow:0 0 0 2px var(--accent); }

/* ============ BLOQUEIO / ONBOARDING ============ */
.gate-overlay {
  position:fixed; inset:0; z-index:300; display:flex;
  align-items:center; justify-content:center; padding:20px; overflow-y:auto;
  background:radial-gradient(1000px 500px at 50% -10%, var(--accent-soft), transparent), var(--bg);
}
.gate-card {
  width:100%; max-width:420px; text-align:center;
  background:var(--bg-card); border-radius:28px; padding:36px 28px;
  box-shadow:var(--shadow-lg);
}
.gate-logo { font-size:3rem; margin-bottom:8px; }
.gate-card h2 { font-size:22px; font-weight:700; letter-spacing:-0.02em; margin-bottom:8px; }
.gate-error { color:var(--danger); font-size:13px; min-height:1.2em; margin-top:8px; }
.gate-hint { font-size:12.5px; color:var(--text-muted); margin-top:16px; }
.onb-progress { font-size:11px; font-weight:700; letter-spacing:.08em; text-transform:uppercase; color:var(--accent); margin-bottom:12px; }
.radio-cards { display:flex; flex-direction:column; gap:10px; margin-top:16px; text-align:left; }
.radio-card {
  position:relative; display:flex; flex-direction:column; gap:4px;
  padding:14px 16px; border:1.5px solid var(--border); border-radius:16px;
  cursor:pointer; transition:all .2s var(--ease);
}
.radio-card input { position:absolute; opacity:0; }
.radio-card.selected { border-color:var(--accent); background:var(--accent-soft); }
.radio-card strong { font-size:15px; letter-spacing:-0.01em; }
.radio-card span { font-size:13px; color:var(--text-muted); }
.demo-badge {
  position:fixed; top:calc(10px + env(safe-area-inset-top)); left:50%; transform:translateX(-50%);
  z-index:250; background:var(--warning); color:#1C1C1E;
  font-weight:700; font-size:12px; padding:6px 16px; border-radius:999px;
  box-shadow:var(--shadow-lg);
}

/* ============ RESPONSIVO ============ */
@media (max-width: 860px) {
  .sidebar { display:none; }
  .main { margin-left:0; }
  .mobile-logo { display:block; }
  .bottom-nav { display:block; }
  .topbar { padding:10px 16px; padding-top:calc(10px + env(safe-area-inset-top)); }
  .topbar h1 { font-size:16px; }
  .month-label { min-width:104px; font-size:12px; }
  .content { padding:16px; padding-bottom:calc(100px + env(safe-area-inset-bottom)); }
  .cards-grid { grid-template-columns:repeat(2,1fr); gap:10px; }
  .card, .panel { padding:16px; border-radius:16px; }
  .card-value { font-size:21px; }
  .panels-row { grid-template-columns:1fr; }
  .fab { right:16px; bottom:calc(76px + env(safe-area-inset-bottom)); }
}
@media (max-width: 480px) {
  .form-row { grid-template-columns:1fr; }
  .report-table { font-size:12px; }
}
@media (min-width: 600px) {
  .modal-overlay { align-items:center; }
  .modal { border-radius:24px; padding-top:22px; animation:popIn .3s var(--ease); }
  .modal::before { display:none; }
  @keyframes popIn { from { transform:scale(.94); opacity:0; } to { transform:none; opacity:1; } }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation:none !important; transition:none !important; }
}


/* ============ FIX: dropdowns e controles nativos no dark mode ============ */
[data-theme="dark"]  { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }

.form-select,
.filter-select {
  background: var(--bg-elevated);
}

.form-select option,
.filter-select option {
  background: var(--bg-card);
  color: var(--text);
}


/* ============ REEMBOLSOS ============ */
.badge-reimbursed { background: rgba(48,209,88,.16); color: var(--accent); }
.list-item.reimb-pending { box-shadow: inset 3px 0 0 var(--info); }
.list-item.reimb-done { opacity: .72; }


/* ============ FAIXA DE DESTAQUE (reembolsos a receber) ============ */
.strip {
  display:flex; align-items:center; gap:14px; flex-wrap:wrap;
  background:var(--bg-card); border-radius:var(--radius);
  border-left:4px solid var(--info);
  padding:14px 18px; margin-bottom:16px; box-shadow:var(--shadow-card);
}
.strip-icon { font-size:1.5rem; }
.strip-info { flex:1; min-width:160px; }
.strip-title { font-size:13px; font-weight:600; color:var(--text-muted); }
.strip-value { font-size:20px; font-weight:700; letter-spacing:-.02em; color:var(--info); font-variant-numeric:tabular-nums; }
.strip-sub { font-size:12px; color:var(--text-muted); }


/* ============ ÍCONES DO SELETOR DESPESA/RECEITA ============ */
.type-ico { width: 18px; height: 18px; vertical-align: middle; margin-right: 6px; }
#typeExpense { color: var(--danger); }
#typeIncome  { color: var(--accent); }
