:root {
  --bg: #081615;
  --text: #e6f7f3;
  --muted: #8ab7af;
  --surface: rgba(7, 30, 27, 0.74);
  --surface-solid: #0e2522;
  --border: rgba(120, 185, 166, 0.24);
  --shadow: 0 18px 40px rgba(2, 12, 11, 0.42);
  --link: #e5e7eb;
  --table-head-bg: rgba(18, 55, 49, 0.92);
  --table-stripe-bg: rgba(39, 110, 96, 0.10);
  --finance-primary: #22c55e;
  --finance-accent: #14b8a6;
  --finance-primary-rgb: 34, 197, 94;
  --finance-accent-rgb: 20, 184, 166;
  --card-radius: 18px;
}

html[data-theme="light"] {
  --bg: #eef8f4;
  --text: #0f172a;
  --muted: #4b6a64;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --border: rgba(15, 95, 78, 0.18);
  --shadow: 0 14px 30px rgba(11, 42, 38, 0.12);
  --link: #0f172a;
  --table-head-bg: rgba(233, 248, 243, 0.96);
  --table-stripe-bg: rgba(20, 184, 166, 0.05);
}

/* Base layout */
.app-body {
  min-height: 100vh;
  overflow-x: hidden;
  background: radial-gradient(1200px 600px at 18% -10%, rgba(var(--finance-accent-rgb), 0.22), transparent 60%),
              radial-gradient(900px 500px at 85% 0%, rgba(var(--finance-primary-rgb), 0.18), transparent 58%),
              var(--bg);
  color: var(--text);
}

.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1rem;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: 240px;
  color: var(--text);
  --bs-offcanvas-bg: var(--surface-solid);
  --bs-offcanvas-color: var(--text);
  background: var(--surface-solid);
  border-right: 1px solid var(--border);
}

.app-sidebar .offcanvas-body {
  height: 100%;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: var(--surface);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.app-side-link {
  color: var(--text);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  display: flex;
  align-items: center;
  position: relative;
  overflow: hidden;
  transition: background .16s ease, transform .16s ease, box-shadow .16s ease;
}

.app-sidebar .nav-link:hover {
  color: var(--text);
  background: rgba(var(--finance-accent-rgb), 0.14);
  transform: translateX(4px);
  box-shadow: inset 0 0 0 1px rgba(var(--finance-accent-rgb), 0.25);
}

.app-sidebar .nav-link.active {
  color: var(--text);
  background: linear-gradient(
    90deg,
    rgba(var(--finance-primary-rgb), 0.26) 0%,
    rgba(var(--finance-accent-rgb), 0.12) 100%
  );
  border-radius: 10px;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(var(--finance-primary-rgb), 0.35);
}

.app-sidebar .nav-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--finance-primary), var(--finance-accent));
}

.app-main {
  flex: 1;
  min-width: 0;
}

@media (min-width: 768px) {
  .app-container { padding: 0 1.5rem; }

  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 240px;
    overflow-y: auto;
    background: rgba(0,0,0,0.15);
    backdrop-filter: blur(6px);
    box-shadow:
      8px 0 30px rgba(0,0,0,0.35),
      0 0 0 1px rgba(255,255,255,0.04);
    z-index: 1020;
  }

  .app-main {
    margin-left: 240px;
    width: calc(100% - 240px);
    padding-left: 28px;
    padding-right: 24px;
  }
}

@media (min-width: 1200px) {
  .app-container { padding: 0 2rem; }
}

@media (max-width: 767.98px) {
  .app-sidebar {
    width: min(85vw, 300px);
  }
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.app-header-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
}

.app-brand {
  display: inline-flex;
  gap: 0.75rem;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
}

.app-brand:hover {
  color: var(--text);
}

.app-logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, rgba(var(--finance-accent-rgb), 0.16), rgba(var(--finance-primary-rgb), 0.22));
  border: 1px solid rgba(var(--finance-accent-rgb), 0.18);
  box-shadow: 0 10px 24px rgba(2, 12, 11, 0.14);
  overflow: hidden;
}

.app-logo-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-brand-copy {
  min-width: 0;
}

.app-title { display: block; font-size: 0.95rem; font-weight: 700; line-height: 1.2; }
.app-subtitle { display: block; font-size: 0.75rem; color: var(--muted); }

.app-sidebar-brand {
  width: 100%;
}

.app-topbar-brand {
  flex: 1;
  justify-content: center;
  margin: 0 0.75rem;
}

.app-topbar-brand .app-logo {
  width: 34px;
  height: 34px;
  border-radius: 11px;
}

.app-topbar-brand .app-title {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.app-nav-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.55rem 0.8rem;
  border-radius: 12px;
}

.app-nav-link:hover {
  background: rgba(148, 163, 184, 0.12);
}

.app-theme-toggle {
  margin-left: 0;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-icon { font-size: 1.05rem; }
/* Icones: claro => lua; escuro => sol */
html[data-theme="light"] .theme-icon-moon { display: inline-block; }
html[data-theme="light"] .theme-icon-sun { display: none; }
html[data-theme="dark"] .theme-icon-moon { display: none; }
html[data-theme="dark"] .theme-icon-sun { display: inline-block; }

/* Harmonizar Bootstrap components com o tema */
.card,
.modal-content {
  background: var(--surface-solid) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
  box-shadow: var(--shadow);
  border-radius: var(--card-radius);
}

.card .table-responsive {
  border-radius: inherit;
  overflow-x: auto;
  overflow-y: hidden;
}
.card {
  overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.card:hover {
  transform: translateY(-1px);
  box-shadow: 0 20px 40px rgba(3, 24, 21, 0.18);
  border-color: rgba(var(--finance-accent-rgb), 0.35) !important;
}

.table {
  --bs-table-color: var(--text);
  --bs-table-bg: var(--surface-solid);
  --bs-table-border-color: rgba(148, 163, 184, 0.22);
  --bs-table-striped-bg: var(--table-stripe-bg);
  --bs-table-striped-color: var(--text);
  --bs-table-hover-bg: rgba(148, 163, 184, 0.12);
  --bs-table-hover-color: var(--text);
  color: var(--text) !important;
}

.table thead th {
  background: var(--table-head-bg) !important;
  border-color: var(--border) !important;
}

.table td, .table th {
  background: var(--surface-solid) !important;
  color: var(--text) !important;
  border-color: rgba(148, 163, 184, 0.22) !important;
}

.table tbody tr {
  transition: background-color .14s ease;
}

.table tbody tr:hover > * {
  background-color: rgba(var(--finance-accent-rgb), 0.09) !important;
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
  background-color: var(--table-stripe-bg) !important;
  color: var(--text) !important;
}

.card .table {
  margin-bottom: 0;
}

.card .table thead th {
  border-top: none;
}

.form-control,
.form-select {
  background: var(--surface-solid) !important;
  color: var(--text) !important;
  border-color: rgba(148, 163, 184, 0.28) !important;
}

.form-control::placeholder { color: rgba(156, 163, 175, 0.85); }

.form-control:focus,
.form-select:focus {
  border-color: rgba(var(--finance-primary-rgb), 0.65) !important;
  box-shadow: 0 0 0 0.2rem rgba(var(--finance-primary-rgb), 0.18) !important;
}

.btn-primary {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--finance-primary);
  --bs-btn-border-color: var(--finance-primary);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #1fb455;
  --bs-btn-hover-border-color: #1fb455;
  --bs-btn-active-bg: #199447;
  --bs-btn-active-border-color: #199447;
}

.btn-outline-primary {
  --bs-btn-color: color-mix(in srgb, var(--finance-accent) 70%, var(--text));
  --bs-btn-border-color: rgba(var(--finance-accent-rgb), 0.55);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--finance-accent);
  --bs-btn-hover-border-color: var(--finance-accent);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #0f9e90;
  --bs-btn-active-border-color: #0f9e90;
}

.btn-outline-secondary {
  border-color: rgba(148, 163, 184, 0.35) !important;
  color: var(--text) !important;
}

.btn-outline-secondary:hover {
  background: rgba(148, 163, 184, 0.12) !important;
}

.flash-toast-host {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: min(420px, calc(100vw - 2rem));
  display: grid;
  gap: 0.75rem;
  z-index: 1080;
  pointer-events: none;
}

.flash-toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: start;
  padding: 0.85rem 0.9rem;
  border-radius: var(--card-radius);
  border: 1px solid transparent;
  background: var(--surface-solid);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.flash-toast.flash-toast-enter {
  opacity: 1;
  transform: translateY(0);
}

.flash-toast.flash-toast-exit {
  opacity: 0;
  transform: translateY(-8px);
}

.flash-toast-icon {
  font-size: 1.2rem;
  line-height: 1;
  margin-top: 0.1rem;
}

.flash-toast-title {
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.flash-toast-text {
  color: var(--text);
  word-break: break-word;
}

.flash-toast-close {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0.1rem 0.25rem;
  border-radius: 8px;
}

.flash-toast-close:hover {
  background: rgba(148, 163, 184, 0.15);
}

.flash-toast-timer {
  margin-top: 0.45rem;
  display: grid;
  gap: 0.35rem;
}

.flash-toast-count {
  font-size: 0.82rem;
  font-weight: 600;
  opacity: 0.9;
}

.flash-toast-progress {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.flash-toast-progress-bar {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transition: width 1000ms linear;
}

.flash-toast-success {
  background: #0f2f1f;
  border-color: #22c55e;
}

.flash-toast-danger {
  background: #351414;
  border-color: #ef4444;
}

.flash-toast-warning {
  background: #3a2a0c;
  border-color: #f59e0b;
}

.flash-toast-info {
  background: #0b2a33;
  border-color: #0ea5e9;
}

.flash-toast-success .flash-toast-icon,
.flash-toast-success .flash-toast-title {
  color: #16a34a;
}

.flash-toast-success .flash-toast-progress-bar {
  background: linear-gradient(90deg, #16a34a, #10b981);
}


.flash-toast-danger .flash-toast-icon,
.flash-toast-danger .flash-toast-title {
  color: #dc2626;
}


.flash-toast-warning .flash-toast-icon,
.flash-toast-warning .flash-toast-title {
  color: #d97706;
}


.flash-toast-info .flash-toast-icon,
.flash-toast-info .flash-toast-title {
  color: #0284c7;
}

@media (prefers-reduced-motion: reduce) {
  .flash-toast,
  .flash-toast-progress-bar {
    transition: none;
  }
}

.summary-value {
  font-size: clamp(1.35rem, 2vw, 2rem);
}

.monthly-table {
  font-size: 0.95rem;
}

.monthly-table th,
.monthly-table td {
  white-space: nowrap;
}

.monthly-table .col-description {
  min-width: 220px;
  max-width: 320px;
  white-space: normal;
  word-break: break-word;
}

.monthly-table .col-actions {
  min-width: 150px;
}

.monthly-table .actions-cell {
  display: flex;
  justify-content: flex-end;
  gap: 0.35rem;
  flex-wrap: nowrap;
}

.monthly-table .actions-cell .btn {
  white-space: nowrap;
}

.tl-card {
  height: 100%;
}

.tl-head{
  display:grid;
  gap:12px;
  padding:12px 16px;
  border-bottom:1px solid var(--border);
  font-weight:600;
  opacity:.85;
  min-width: 0;
}

.tl-list {
  width: 100%;
}

.tl-row{
  display:grid;
  gap:12px;
  padding:12px 16px;
  border-bottom:1px solid rgba(148, 163, 184, 0.16);
  min-width: 0;
}

.tl-row:hover{
  background: rgba(var(--finance-accent-rgb), 0.10);
}

.tl-label{
  font-size:.8rem;
  opacity:.7;
}

.tl-cell{
  min-width:0;
}

.tl-truncate{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.grid-transactions {
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 0.9fr) minmax(0, 2fr) minmax(0, 1.2fr) minmax(0, 0.9fr) minmax(0, 1.3fr);
}

.grid-topcats {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.8fr) minmax(0, 0.5fr);
}

.grid-topcats .tl-cell:first-child {
  min-width: 0;
}

.grid-credit {
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.1fr) minmax(0, 1.8fr) minmax(0, 0.9fr);
}

.grid-annual-summary {
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.85fr) minmax(0, 0.85fr) minmax(0, 0.85fr);
}

.grid-project-items {
  grid-template-columns: minmax(0, 1.8fr) minmax(0, 0.9fr) minmax(0, 0.8fr);
}

.tl-actions {
  display: inline-flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  max-width: 100%;
}

.tl-actions .btn {
  white-space: nowrap;
}

.floating-new-transaction {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1050;
  border-radius: 999px;
  box-shadow: 0 0.5rem 1.25rem rgba(15, 23, 42, 0.25);
}

.floating-fab{
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1030;
  border-radius: 9999px;
  padding: 14px 16px;
  box-shadow: 0 14px 32px rgba(2, 22, 19, .28);
  transition: transform .16s ease, box-shadow .16s ease;
}

.floating-fab:hover{
  transform: translateY(-2px);
  box-shadow: 0 20px 36px rgba(2, 22, 19, .34);
}

.project-card-link{
  display:block;
  height: 100%;
  border-radius: 16px;
  text-decoration: none;
  color: inherit;
}

.project-card-link .project-card{
  position: relative;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
  border: 1px solid rgba(255,255,255,.10);
  box-shadow: 0 10px 30px rgba(0,0,0,.22);
}

.project-card-link .project-card .card-body {
  position: relative;
}

.project-card-chevron{
  position:absolute;
  right: 14px;
  top: 14px;
  opacity: .6;
  transform: translateX(0);
  transition: opacity .12s ease, transform .12s ease;
}

.project-card-link:hover .project-card{
  transform: translateY(-3px);
  box-shadow: 0 16px 40px rgba(0,0,0,.30);
  border-color: rgba(255,255,255,.18);
}

.project-card-link:hover .project-card-chevron{
  opacity: .95;
  transform: translateX(2px);
}

.project-card-link:focus-visible{
  outline: 2px solid rgba(var(--finance-accent-rgb), 0.55);
  outline-offset: 3px;
}

.card-accent {
  position: relative;
}

.card-accent::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 4px;
  border-radius: var(--card-radius) var(--card-radius) 0 0;
  background: linear-gradient(90deg, var(--finance-primary), var(--finance-accent));
}

/* Shared analytics section spacing across index, credit-card and annual pages */
.page-analytics-row {
  margin-bottom: 1.5rem;
}

.simulation-panel-card {
  height: auto;
  position: relative;
  isolation: isolate;
}

.simulation-panel-card:hover {
  transform: none;
  box-shadow: var(--shadow);
  border-color: var(--border) !important;
}

.finance-progress {
  height: 0.62rem;
  border-radius: 999px;
  background: rgba(var(--finance-accent-rgb), 0.14);
}

.finance-progress .progress-bar {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--finance-primary), var(--finance-accent));
}

.finance-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.45rem;
}

.badge {
  border-radius: 999px;
  letter-spacing: .01em;
}

/* =========================
   RESPONSIVO GLOBAL (site todo)
   ========================= */

/* 1) Evitar qualquer overflow horizontal */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Container deve ocupar a tela inteira */
.app-container {
  width: 100%;
  max-width: none; /* remove centralizacao/limite */
  margin: 0;
  padding-left: 16px;
  padding-right: 16px;
}

@media (min-width: 992px) {
  .app-container {
    padding-left: 24px;
    padding-right: 24px;
  }
}

@media (min-width: 1400px) {
  .app-container {
    padding-left: 32px;
    padding-right: 32px;
  }
}

img, svg, video, canvas {
  max-width: 100%;
  height: auto;
}

/* 2) Containers: nao deixar padding exagerado no mobile */
.app-container {
  width: 100%;
}

/* 3) Tabelas: sempre scroll horizontal quando precisar */
.table-responsive,
.table-responsive-sm,
.table-responsive-md,
.table-responsive-lg,
.table-responsive-xl,
.table-responsive-xxl {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* 4) Ajustes gerais do Bootstrap no mobile */
@media (max-width: 576px) {
  .btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
  }

  .floating-fab{ right: 16px; bottom: 16px; }

  .h1, .h2, .h3, h1, h2, h3 {
    line-height: 1.15;
  }
}

@media (max-width: 992px) {
  .monthly-table {
    font-size: 0.88rem;
  }
}

@media (max-width: 768px) {
  /* Header / nav (se voce estiver usando os app-* do base.html) */
  .app-header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .app-brand {
    justify-content: flex-start;
  }

  .app-subtitle {
    display: none;
  }

  .app-nav {
    justify-content: space-between;
    gap: 0.25rem;
  }

  .app-nav-link {
    padding: 0.5rem 0.6rem;
    font-size: 0.9rem;
    border-radius: 10px;
  }

  .app-theme-toggle {
    width: 40px;
    height: 40px;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch !important;
  }

  .page-header .btn {
    width: 100%;
  }

  .month-filter .btn,
  .year-filter .btn {
    width: 100%;
  }

  .floating-new-transaction {
    right: 1rem;
    bottom: 1rem;
  }

  .summary-card .card-body {
    padding: 0.9rem;
  }

  .monthly-table {
    font-size: 0.84rem;
  }

  /* Tabela mensal: diminuir risco de estourar */
  .monthly-table .col-actions {
    min-width: 120px;
  }

  .monthly-table .actions-cell {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .tl-row{
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
    padding: 14px 16px;
  }
}

/* 5) Mobile: modais quase full-screen para ficar usavel */
@media (max-width: 576px) {
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    width: 100%;
    height: 100%;
  }

  .modal-content {
    height: 100%;
    border-radius: 0;
  }

  .modal-header, .modal-footer {
    position: sticky;
    background: inherit;
    z-index: 1;
  }

  .modal-header { top: 0; }
  .modal-footer { bottom: 0; }
}
