/* =====================================================================
   app.css — design system "Faturas" (app-like, mobile-first)
   Camada sobre o Bootstrap 5. Tokens primeiro, componentes depois.
   ===================================================================== */

:root {
  --app-primary: #4f46e5;
  --app-primary-dark: #4338ca;
  --app-primary-2: #7c3aed;
  --app-grad: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --app-bg: #f1f3f9;
  --app-surface: #ffffff;
  --ink: #111827;
  --ink-2: #6b7280;
  --ink-3: #9ca3af;
  --line: #e7e9f0;
  --ok: #0ca30c;
  --warn: #fab219;
  --bad: #d03b3b;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --shadow-card: 0 1px 2px rgba(17, 24, 39, .04), 0 8px 24px rgba(17, 24, 39, .06);
  --shadow-float: 0 10px 30px rgba(79, 70, 229, .35);
  --tabbar-h: 64px;
}

/* ---------- Base ---------- */
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--app-bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  letter-spacing: -0.01em;
  -webkit-tap-highlight-color: transparent;
}
@media (max-width: 991.98px) {
  body { padding-bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); }
}

h1, h2, h3, h4, h5, h6, .fw-bold { letter-spacing: -0.02em; }
a { color: var(--app-primary); }

/* ---------- Barra superior (desktop) ---------- */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.5rem;
}
.app-topbar-inner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-height: 64px;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}
.app-brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
}
.app-brand-icon {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--app-grad);
  color: #fff;
  font-size: .9rem;
  box-shadow: 0 4px 12px rgba(79, 70, 229, .35);
}
.app-nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  list-style: none;
  margin: 0 auto 0 0;
  padding: 0;
}
.app-nav-link {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .5rem .85rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: .875rem;
  color: var(--ink-2);
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.app-nav-link i { font-size: .8rem; }
.app-nav-link:hover { background: #eef0fb; color: var(--app-primary); }
.app-nav-link.active { background: var(--app-grad); color: #fff; box-shadow: 0 4px 12px rgba(79, 70, 229, .3); }
.app-user { display: flex; align-items: center; gap: .6rem; }
.app-user-name { font-weight: 600; font-size: .875rem; }
.app-logout { color: var(--ink-3); font-size: 1rem; padding: .35rem; }
.app-logout:hover { color: var(--bad); }

.app-avatar {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--app-grad);
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  border: none;
  flex: 0 0 auto;
}
.app-avatar-lg { width: 48px; height: 48px; font-size: 1.15rem; }

/* ---------- Barra superior (mobile) ---------- */
.app-mobilebar {
  position: sticky;
  top: 0;
  z-index: 1030;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: .4rem 1rem;
  padding-top: calc(.4rem + env(safe-area-inset-top));
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
}

/* ---------- Barra de abas inferior (mobile) ---------- */
.app-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1040;
  display: flex;
  align-items: stretch;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 .25rem env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.app-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--ink-3);
  text-decoration: none;
  font-size: .65rem;
  font-weight: 600;
  padding: 6px 2px;
  transition: color .15s ease, transform .1s ease;
}
.app-tab i { font-size: 1.2rem; }
.app-tab:active { transform: scale(.94); }
.app-tab.active { color: var(--app-primary); }
.app-tab-main { position: relative; color: var(--ink-2); }
.app-tab-fab {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-top: -26px;
  border-radius: 50%;
  background: var(--app-grad);
  color: #fff;
  font-size: 1.25rem;
  box-shadow: var(--shadow-float);
  border: 4px solid var(--app-bg);
}
.app-tab-main.active .app-tab-fab { filter: brightness(1.08); }
.app-tab-main span:last-child { margin-top: 2px; }

/* ---------- Bottom sheet (menu Mais) ---------- */
.app-sheet {
  border-radius: 22px 22px 0 0;
  border: none;
  height: auto !important;
  max-height: 80vh;
  padding-bottom: env(safe-area-inset-bottom);
}
.app-sheet-grab {
  width: 42px;
  height: 5px;
  border-radius: 999px;
  background: var(--line);
  margin: 10px auto 2px;
}
.app-sheet-user {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .5rem .25rem 1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: .5rem;
}
.app-sheet-link {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .85rem .5rem;
  border-radius: var(--r-md);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}
.app-sheet-link i { width: 22px; text-align: center; color: var(--app-primary); font-size: 1.05rem; }
.app-sheet-link:hover, .app-sheet-link:active { background: #eef0fb; color: var(--ink); }
.app-sheet-link.active { background: #eef0fb; }
.app-sheet-link-danger, .app-sheet-link-danger i { color: var(--bad); }
.app-sheet-link-danger:hover { background: #fdf1f1; color: var(--bad); }

/* ---------- Cards ---------- */
.card {
  border: none;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  background: var(--app-surface);
}
.card-body { padding: 1.15rem 1.15rem; }
@media (min-width: 992px) { .card-body { padding: 1.35rem 1.35rem; } }

.form-section-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: .09em;
  margin-bottom: .75rem;
}

/* ---------- Formulários (alvos de toque grandes) ---------- */
.form-control, .form-select {
  border-radius: var(--r-sm);
  border-color: var(--line);
  min-height: 46px;
  font-size: 16px; /* evita zoom automático no iOS */
  padding: .55rem .85rem;
}
.form-control-sm, .form-select-sm { min-height: 36px; font-size: 14px; }
.form-control:focus, .form-select:focus {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .12);
}
.form-label { font-weight: 600; font-size: .84rem; color: var(--ink-2); margin-bottom: .35rem; }
.form-text { font-size: .78rem; }

/* ---------- Botões ---------- */
.btn { border-radius: var(--r-sm); font-weight: 600; padding: .55rem 1rem; transition: transform .1s ease, box-shadow .15s ease; }
.btn:active { transform: scale(.97); }
.btn-sm { padding: .35rem .7rem; border-radius: 8px; }
.btn-primary {
  background: var(--app-grad);
  border: none;
  box-shadow: 0 4px 14px rgba(79, 70, 229, .3);
}
.btn-primary:hover, .btn-primary:focus { background: linear-gradient(135deg, #4338ca 0%, #6d28d9 100%); }
.btn-outline-primary { color: var(--app-primary); border-color: #c7cbf5; }
.btn-outline-primary:hover { background: var(--app-primary); border-color: var(--app-primary); }
.btn-outline-secondary { border-color: var(--line); color: var(--ink-2); }
.btn-outline-secondary:hover { background: #eef0fb; border-color: #c7cbf5; color: var(--app-primary); }
.btn-icon { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; }

/* ---------- Tabelas (desktop) ---------- */
.table { --bs-table-hover-bg: #f5f6fd; }
.table thead th {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-2);
  border-bottom-width: 1px;
}
.table td { border-color: #f0f1f7; }
.sticky-th th { position: sticky; top: 0; background: #fff; z-index: 2; }
.table-responsive { border-radius: var(--r-sm); }

/* Badges */
.badge { font-weight: 600; border-radius: 999px; padding: .38em .7em; }

/* Alerts */
.alert { border: none; border-radius: var(--r-md); box-shadow: var(--shadow-card); }

/* Modais e list-group */
.modal-content { border: none; border-radius: var(--r-lg); box-shadow: 0 24px 60px rgba(17, 24, 39, .22); }
.modal-header { border-bottom-color: var(--line); }
.modal-footer { border-top-color: var(--line); }
.list-group-item { border-color: #f0f1f7; padding: .85rem 1rem; }
.list-group { border-radius: var(--r-md); }

@media (max-width: 991.98px) {
  .modal-dialog { margin: .75rem; }
}

/* ---------- Navegação de mês (‹ mês ›) ---------- */
.month-nav .btn { padding: .45rem .7rem; }
.month-nav .form-control { text-align: center; font-weight: 600; }

/* ---------- Barra de limite ---------- */
.limit-bar {
  height: 7px;
  border-radius: 999px;
  background: #edeef6;
  overflow: hidden;
  margin-top: 6px;
}
.limit-bar > span { display: block; height: 100%; border-radius: 999px; }

/* ---------- Linhas clicáveis ---------- */
tr.row-clickable { cursor: pointer; }
tr.row-clickable:hover { background: #eef0fb !important; }

/* ---------- Filtros por coluna ---------- */
.col-filter-row th { padding: 4px 6px; background: #f8f9fd; }
.col-filter-row input, .col-filter-row select { font-size: 12px; height: 32px; min-height: 32px; padding: 2px 8px; }

/* ---------- Select2 alinhado ao design ---------- */
.select2-container--default .select2-selection--single {
  height: 46px;
  border-radius: var(--r-sm);
  border-color: var(--line);
}
.select2-selection__rendered { line-height: 44px !important; padding-left: .85rem !important; }
.select2-selection__arrow { height: 44px !important; }
.select2-dropdown { border-radius: var(--r-md); border-color: var(--line); box-shadow: var(--shadow-card); overflow: hidden; }
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable { background: var(--app-primary); }

/* ---------- Formulário retrátil no mobile ---------- */
.mobile-form-toggle { display: none; }
@media (max-width: 991.98px) {
  .mobile-form-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    border: none;
    background: none;
    padding: 0;
    color: var(--ink);
    font-weight: 700;
  }
  .mobile-form-toggle .chev { transition: transform .2s ease; color: var(--ink-3); }
  .mobile-form-toggle.open .chev { transform: rotate(180deg); }
  .mobile-collapsible { display: none; padding-top: 1rem; }
  .mobile-collapsible.open { display: block; }
}

/* =====================================================================
   Tabelas → cards no mobile (padrão de app de banco)
   Aplica-se a tabelas com a classe .table-cards, cujas células levam
   classes td-*. No desktop nada muda.
   ===================================================================== */
@media (max-width: 767.98px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody { display: block; width: 100%; }
  .table-cards tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px 12px;
    padding: .8rem .3rem;
    border-bottom: 1px solid #f0f1f7;
  }
  .table-cards tbody tr:last-child { border-bottom: none; }
  .table-cards td { display: block; border: none; padding: 0; background: none !important; box-shadow: none !important; }

  /* posições no card (extrato de banco):
     linha 1: descrição ......... valor
     linha 2: meta (data) ....... meta2 (cartão)
     linha 3: sub (conta) ....... ações
     linha 4: sub2 (subconta) ... ações  */
  .table-cards .td-desc { grid-column: 1; grid-row: 1; font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
  .table-cards .td-value {
    grid-column: 2; grid-row: 1;
    text-align: right !important;
    font-weight: 700;
    font-size: .95rem;
    white-space: nowrap;
  }
  .table-cards .td-meta { grid-column: 1; grid-row: 2; font-size: .74rem; color: var(--ink-2); }
  .table-cards .td-meta2 { grid-column: 2; grid-row: 2; text-align: right !important; font-size: .74rem; color: var(--ink-2); white-space: nowrap; }
  .table-cards .td-sub { grid-column: 1; grid-row: 3; font-size: .74rem; color: var(--ink-3); }
  .table-cards .td-sub2 { grid-column: 1; grid-row: 4; font-size: .74rem; color: var(--ink-3); }
  .table-cards .td-actions { grid-column: 2; grid-row: 3 / span 2; align-self: end; text-align: right !important; white-space: nowrap; }
  .table-cards .td-hide-mobile { display: none; }

  /* rótulo inline nos campos que precisam de contexto (ex.: "Fecha dia: 29") */
  .table-cards td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--ink-3);
    font-weight: 500;
  }

  /* linhas de estado (vazio / sem correspondência) */
  .table-cards tr.row-simple { display: block; text-align: center; padding: 1rem; }
  .table-cards tr.row-simple td { display: block; }
}

/* Esconde filtros de coluna no mobile (o filtro de mês continua) */
@media (max-width: 767.98px) {
  .col-filter-row { display: none !important; }
}

/* ---------- Tiles de estatística (dashboard) ---------- */
.stat-tile {
  background: var(--app-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: 1.05rem 1.15rem;
  height: 100%;
}
.stat-tile .stat-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: .45rem;
}
.stat-tile .stat-label i { color: var(--app-primary); }
.stat-tile .stat-value { font-size: 1.45rem; font-weight: 800; margin-top: .3rem; }
.stat-tile .stat-foot { font-size: .74rem; color: var(--ink-3); margin-top: .15rem; }
.stat-tile-hero {
  background: var(--app-grad);
  color: #fff;
}
.stat-tile-hero .stat-label, .stat-tile-hero .stat-foot { color: rgba(255, 255, 255, .8); }
.stat-tile-hero .stat-label i { color: #fff; }

/* ---------- Página de login ---------- */
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(60% 50% at 15% 0%, rgba(124, 58, 237, .18), transparent 60%),
    radial-gradient(50% 40% at 100% 100%, rgba(79, 70, 229, .16), transparent 60%),
    var(--app-bg);
  padding: 1.25rem;
}
.login-card { width: 100%; max-width: 400px; }
.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: var(--app-grad);
  color: #fff;
  font-size: 1.6rem;
  margin: 0 auto 1rem;
  box-shadow: var(--shadow-float);
}
