
:root {
  --background: #0f1117;
  --foreground: #e8eaf0;
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 64px;
  --topbar-height: 4rem;
  --main-padding-x: clamp(0.75rem, 3vw, 1.5rem);
  --main-padding-y: clamp(1rem, 2.5vw, 1.5rem);
  --touch-target-min: 44px;
  --primary: #0d9488;
  --primary-foreground: #ffffff;
  --secondary: #1a1f2e;
  --secondary-foreground: #a0a8bc;
  --accent: #14b8a6;
  --accent-foreground: #ffffff;
  --muted: #252b3b;
  --muted-foreground: #6b7280;
  --card: #1a1f2e;
  --card-foreground: #e8eaf0;
  --border: #252b3b;
  --input: #1e2332;
  --ring: #0d9488;
  --radius: 0.75rem;
  --font-sans: 'Plus Jakarta Sans', sans-serif;

  --positive: #10b981;
  --positive-bg: #10b98115;
  --negative: #f43f5e;
  --negative-bg: #f43f5e15;
  --warning: #f59e0b;
  --warning-bg: #f59e0b15;
  --info: #3b82f6;
  --info-bg: #3b82f615;
}

* {
    box-sizing: border-box;
    border-color: var(--border);
  }

  body {
    background-color: var(--background);
    color: var(--foreground);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
  }

  [data-lucide],
  svg.lucide {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
  }

  html:not(.icons-ready) [data-lucide] {
    opacity: 0;
  }

  html.icons-ready [data-lucide],
  html.icons-ready svg.lucide {
    opacity: 1;
  }

  svg.lucide {
    display: block;
  }

  html {
    scroll-behavior: smooth;
  }

h1, h2, h3, h4, h5, h6, p {
  margin: 0;
}

.text-hero-xl {
    font-size: clamp(2rem, 4vw, 3.5rem);
    line-height: 1.1;
  }

  .tabular-nums {
    font-variant-numeric: tabular-nums;
  }

  .scrollbar-thin {
    scrollbar-width: thin;
    scrollbar-color: var(--muted) transparent;
  }

  .scrollbar-thin::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }

  .scrollbar-thin::-webkit-scrollbar-track {
    background: transparent;
  }

  .scrollbar-thin::-webkit-scrollbar-thumb {
    background-color: var(--muted);
    border-radius: 2px;
  }

  .fade-in {
    animation: fadeIn 0.2s ease forwards;
  }

  .slide-up {
    animation: slideUp 0.25s ease forwards;
  }

  .bg-positive-tint {
    background-color: var(--positive-bg);
  }

  .bg-negative-tint {
    background-color: var(--negative-bg);
  }

  .bg-warning-tint {
    background-color: var(--warning-bg);
  }

  .bg-info-tint {
    background-color: var(--info-bg);
  }

  .text-positive {
    color: var(--positive);
  }

  .text-negative {
    color: var(--negative);
  }

  .text-warning {
    color: var(--warning);
  }

  .text-info {
    color: var(--info);
  }

  .border-positive {
    border-color: var(--positive);
  }

  .border-negative {
    border-color: var(--negative);
  }

.border-warning {
  border-color: var(--warning);
}

.card {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }

  .btn-primary {
    background-color: var(--primary);
    color: var(--primary-foreground);
    border-radius: calc(var(--radius) - 2px);
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.625rem 1.25rem;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
  }

  .btn-primary:hover {
    background-color: var(--accent);
  }

  .btn-primary:active {
    opacity: 0.9;
  }

  .btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .btn-ghost {
    background-color: transparent;
    color: var(--secondary-foreground);
    border-radius: calc(var(--radius) - 2px);
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.625rem 1.25rem;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
  }

  .btn-ghost:hover {
    background-color: var(--muted);
    color: var(--foreground);
  }

  .input-field {
    background-color: var(--input);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    color: var(--foreground);
    font-size: 0.875rem;
    padding: 0.625rem 0.875rem;
    width: 100%;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
  }

  .input-field:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
  }

  .input-field::placeholder {
    color: var(--muted-foreground);
  }

  .input-field.error {
    border-color: var(--negative);
  }

  .input-field.error:focus {
    box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.15);
  }

  .status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--secondary-foreground);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
  }

  .nav-item:hover {
    background-color: var(--muted);
    color: var(--foreground);
  }

.nav-item.active {
  background-color: rgba(13, 148, 136, 0.15);
  color: var(--accent);
}

.nav-group-toggle {
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.nav-group.is-active > .nav-group-toggle {
  color: var(--accent);
}

.nav-group .nav-subitems {
  display: none;
  margin-top: 0.25rem;
  margin-left: 0.5rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--border);
}

.nav-group.is-open .nav-subitems {
  display: block;
}

.nav-subitem {
  font-size: 0.8125rem;
  padding: 0.4rem 0.65rem;
}

.nav-group-chevron {
  transition: transform 0.15s ease;
}

.nav-group.is-open .nav-group-chevron {
  transform: rotate(180deg);
}

.sidebar.collapsed .nav-subitems,
.sidebar.collapsed .nav-group-chevron {
  display: none;
}

.categories-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.25rem;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  width: fit-content;
}

.categories-subnav-link {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.85rem;
  border-radius: calc(var(--radius) - 4px);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

.categories-subnav-link:hover {
  color: var(--foreground);
  background: var(--muted);
}

.categories-subnav-link.is-active {
  background: rgba(13, 148, 136, 0.15);
  color: var(--accent);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-highlight {
  0% { background-color: transparent; }
  30% { background-color: rgba(13, 148, 136, 0.12); }
  100% { background-color: transparent; }
}

.value-updated {
  animation: pulse-highlight 0.8s ease forwards;
}

/* Layout utilities (substitui Tailwind no PHP) */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.grid { display: grid; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.col-span-2 { grid-column: span 2; }
.h-full { height: 100%; }
.h-screen { height: 100vh; }
.h-9 { height: 2.25rem; }
.h-10 { height: 2.5rem; min-height: 2.5rem; }
.h-16 { height: 4rem; }
.min-h-screen { min-height: 100vh; }
.w-full { width: 100%; }
.w-64 { width: 16rem; }
.min-w-0 { min-width: 0; }
.shrink-0 { flex-shrink: 0; }
.overflow-hidden { overflow: hidden; }
.overflow-x-auto { overflow-x: auto; }
.overflow-y-auto { overflow-y: auto; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-5 { padding: 1.25rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }
.p-10 { padding: 2.5rem; }
.p-12 { padding: 3rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }
.py-10 { padding-top: 2.5rem; padding-bottom: 2.5rem; }
.py-12 { padding-top: 3rem; padding-bottom: 3rem; }
.py-16 { padding-top: 4rem; padding-bottom: 4rem; }
.text-center { text-align: center; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-5 { padding-left: 1.25rem; padding-right: 1.25rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.py-6 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.pl-9 { padding-left: 2.25rem; }
.mt-0\.5 { margin-top: 0.125rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-5 { margin-bottom: 1.25rem; }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-3 > * + * { margin-top: 0.75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-5 > * + * { margin-top: 1.25rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }
.divide-y > * + * { border-top: 1px solid var(--border); }
.border { border: 1px solid var(--border); }
.border-b { border-bottom: 1px solid var(--border); }
.border-t { border-top: 1px solid var(--border); }
.border-r { border-right: 1px solid var(--border); }
.rounded-lg { border-radius: 0.5rem; }
.rounded-full { border-radius: 9999px; }
.rounded-md { border-radius: 0.375rem; }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; line-height: 1.4; }
.text-xl { font-size: 1.25rem; line-height: 1.35; }
.text-2xl { font-size: 1.5rem; line-height: 1.25; }
.text-3xl { font-size: 1.875rem; line-height: 1.2; }
.text-4xl { font-size: 2.25rem; line-height: 1.1; }
.font-500 { font-weight: 500; }
.font-600 { font-weight: 600; }
.font-700 { font-weight: 700; }
.font-800 { font-weight: 800; }
.text-foreground { color: var(--foreground); }
.text-muted-foreground { color: var(--muted-foreground); }
.text-primary { color: var(--primary); }
.text-secondary-foreground { color: var(--secondary-foreground); }
.bg-background { background-color: var(--background); }
.bg-secondary { background-color: var(--secondary); }
.bg-muted { background-color: var(--muted); }
.bg-card { background-color: var(--card); }
.bg-primary-15 { background-color: rgba(13, 148, 136, 0.15); }
.bg-positive-15 { background-color: rgba(16, 185, 129, 0.15); }
.bg-warning-15 { background-color: rgba(245, 158, 11, 0.15); }
.bg-info-15 { background-color: rgba(59, 130, 246, 0.15); }
.bg-accent-15 { background-color: rgba(20, 184, 166, 0.15); }
.bg-muted-30 { background-color: rgba(37, 43, 59, 0.5); }
.bg-muted-40 { background-color: rgba(37, 43, 59, 0.6); }
.bg-primary-5 { background-color: rgba(13, 148, 136, 0.05); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whitespace-nowrap { white-space: nowrap; }
.hidden { display: none; }
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.inset-0 { inset: 0; }
.top-11 { top: 2.75rem; }
.right-0 { right: 0; }
.z-50 { z-index: 50; }
.mx-auto { margin-left: auto; margin-right: auto; }
.max-w-md { max-width: 28rem; }
.max-w-\[200px\] { max-width: 200px; }
.shadow-modal { box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); }
.shadow-elevated { box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35); }
.shadow-card { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.transition-all { transition: all 0.15s ease; }
.transition-colors { transition: color 0.15s, background 0.15s; }
.transition-opacity { transition: opacity 0.15s; }
.opacity-0 { opacity: 0; }
.opacity-100 { opacity: 1; }
.cursor-pointer { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; }
table { border-collapse: collapse; width: 100%; }
.group:hover .group-hover\:opacity-100 { opacity: 1; }
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overscroll-behavior: none;
}

html.modal-open,
html.modal-open body {
  overflow: hidden;
  height: 100%;
}

html.modal-open .app-main > main {
  overflow: hidden !important;
  overscroll-behavior: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 17, 23, 0.88);
  /* Sem backdrop-filter: blur — repinta a GPU em cada hover no modal */
}

.modal-panel {
  position: relative;
  z-index: 1;
  max-width: 32rem;
  width: 100%;
  max-height: calc(100vh - 2rem);
  contain: layout style paint;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.125rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
}

.modal-body {
  padding: 1.375rem 1.5rem 1.5rem;
}

.modal-body.space-y-4 > * + * {
  margin-top: 1rem;
}

.modal-intro {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--muted-foreground);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 1.5rem 1.375rem;
  border-top: 1px solid var(--border);
}

.modal-footer .btn-ghost,
.modal-footer .btn-primary {
  min-height: 2.5rem;
}

.modal-panel--sheet {
  max-height: min(90vh, 90dvh);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-panel--sheet .modal-body {
  padding-top: 1.5rem;
  padding-bottom: 1.625rem;
}

.modal-panel--sheet .modal-footer {
  padding-top: 1.125rem;
  padding-bottom: 1.5rem;
}

.modal-panel--sheet .modal-header {
  padding-top: 1.25rem;
  padding-bottom: 1.25rem;
}

.modal-sheet-handle {
  display: none;
}
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(22rem, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.875rem;
  animation: fadeIn 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

.toast-message {
  flex: 1;
  line-height: 1.4;
}

.toast-dismiss {
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  margin: -0.15rem -0.25rem 0 0;
}

.toast-dismiss:hover {
  color: var(--foreground);
}

.toast-success { border-color: var(--positive); }
.toast-error { border-color: var(--negative); }
.toast-info { border-color: var(--info); }
/* Cards de resumo (objetivos, fundo emergência, investimentos) — sempre lado a lado */
.summary-cards {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.summary-cards .card.p-5 {
  min-height: 5.75rem;
}

.summary-cards .text-2xl {
  min-height: 2rem;
  line-height: 2rem;
  font-variant-numeric: tabular-nums;
}

.summary-cards--4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1023px) {
  .summary-cards--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .summary-cards,
  .summary-cards--4 {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 640px) {
  .sm\:block { display: block; }
  .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sm\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 768px) {
  .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md\:flex-row { flex-direction: row; }
  .md\:items-center { align-items: center; }
  .md\:p-8 { padding: 2rem; }
  .md\:text-right { text-align: right; }
}
@media (min-width: 1024px) {
  .lg\:flex { display: flex; }
  .lg\:w-\[45\%\] { width: 45%; }
  .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lg\:col-span-2 { grid-column: span 2; }
  .lg\:px-8 { padding-left: 2rem; padding-right: 2rem; }
}
@media (min-width: 1280px) {
  .xl\:col-span-2 { grid-column: span 2; }
  .xl\:col-span-3 { grid-column: span 3; }
  .xl\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .xl\:grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .xl\:px-10 { padding-left: 2.5rem; padding-right: 2.5rem; }
}
@media (min-width: 1536px) {
  .max-w-screen-2xl { max-width: 1536px; }
}
.bento-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 768px) { .bento-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .bento-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1280px) { .bento-grid { grid-template-columns: repeat(4, 1fr); } }
.bento-hero { grid-column: span 1; }
@media (min-width: 768px) { .bento-hero { grid-column: span 2; } }

.period-filters {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0.5rem;
  align-items: center;
}

.period-filters .period-select {
  width: auto;
  min-width: 7.5rem;
  flex: 1 1 0;
  max-width: none;
}

@media (max-width: 639px) {
  .period-filters {
    width: 100%;
    flex-wrap: nowrap;
  }
  .period-filters .period-select {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
  }
}

.metric-card-editable {
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.metric-card-editable:hover {
  box-shadow: 0 4px 14px rgba(15, 17, 23, 0.08);
}

.push-banner {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  z-index: 60;
  max-width: 24rem;
  margin: 0 auto;
  padding: 1rem;
}

@media (min-width: 768px) {
  .push-banner {
    left: auto;
    right: 1.5rem;
    margin: 0;
  }
}

.charts-row { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
@media (min-width: 1280px) { .charts-row { grid-template-columns: 3fr 2fr; } }
.charts-section { display: flex; flex-direction: column; gap: 1.5rem; }
.chart-card-full { width: 100%; }
.chart-wrap--tall { height: 280px; }
.modal-overlay.is-hidden { display: none; }
.dashboard-bottom { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
.dashboard-bottom > * { min-width: 0; max-width: 100%; }
@media (min-width: 1280px) { .dashboard-bottom { grid-template-columns: 2fr 1fr; } }

.metric-card-link {
  display: block;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.metric-card-link:hover {
  border-color: rgba(13, 148, 136, 0.35);
  background: rgba(13, 148, 136, 0.04);
}

.dashboard-goals-card .dashboard-goal-action {
  width: 1.75rem;
  height: 1.75rem;
}

.dashboard-goals-link {
  font-weight: 600;
}
.sidebar {
  width: var(--sidebar-width);
  transition: width 0.3s ease, transform 0.3s ease;
  overflow: hidden;
  overscroll-behavior: none;
}

.sidebar > nav {
  overflow: hidden;
  overscroll-behavior: none;
}
.sidebar.collapsed { width: var(--sidebar-collapsed-width); }
.sidebar.collapsed .sidebar-label { display: none; }
.sidebar.collapsed .sidebar-group-title { display: none; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.sidebar-brand:hover .sidebar-label {
  color: var(--foreground);
}

.app-logo {
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  display: block;
  border-radius: 0.5rem;
  object-fit: contain;
}

.sidebar.collapsed .sidebar-brand {
  justify-content: center;
  width: 100%;
}
input[type="checkbox"] { accent-color: var(--primary); }
select.input-field { appearance: auto; }
textarea.input-field { resize: vertical; min-height: 4rem; }
.alert-error { color: var(--negative); font-size: 0.75rem; margin-top: 0.25rem; }
.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem; }
.icon-btn { width: 1.75rem; height: 1.75rem; display: inline-flex; align-items: center; justify-content: center; border-radius: 0.25rem; color: var(--muted-foreground); }
.icon-btn:hover { color: var(--foreground); background: var(--muted); }
.bulk-bar { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 50; }
.chart-wrap { height: 220px; position: relative; }

/* Botões segmentados (tipo, estado no modal) */
.segmented-control {
  display: flex;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  overflow: hidden;
  background: var(--input);
}

.segmented-control label {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted-foreground);
  cursor: pointer;
  user-select: none;
  border-right: 1px solid var(--border);
}

.segmented-control label:last-child {
  border-right: none;
}

.segmented-control label.is-selected,
.segmented-control label:has(input:checked) {
  background: var(--primary);
  color: var(--primary-foreground);
}

@media (hover: hover) {
  .segmented-control label:not(.is-selected):not(:has(input:checked)):hover {
    background: var(--muted);
    color: var(--foreground);
  }
}

.segmented-control input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
  pointer-events: none;
}

.segmented-control label span {
  pointer-events: none;
}

.segmented-control-icons label {
  min-height: 2.25rem;
  padding: 0.4rem 0.35rem;
  font-size: 0.75rem;
}

/* Objetivos — igual ao GoalsPanel original */
.goal-progress-track {
  width: 100%;
  height: 6px;
  background: var(--muted);
  border-radius: 9999px;
  overflow: hidden;
}

.goal-progress-fill {
  height: 100%;
  border-radius: 9999px;
  background: var(--primary);
  transition: none;
}

.goal-card,
.emergency-hero {
  contain: layout style;
}

.goal-row-actions {
  opacity: 0;
}

@media (hover: hover) {
  .goal-row:hover .goal-row-actions {
    opacity: 1;
  }
}

.tracking-tight {
  letter-spacing: -0.025em;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-foreground);
  margin-bottom: 6px;
}

.goals-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 768px) {
  .goals-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.goal-icon-box {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid transparent;
}

.goal-badge-primary {
  background: rgba(13, 148, 136, 0.15);
  color: var(--primary);
  border-color: rgba(13, 148, 136, 0.3);
}

.goal-badge-accent {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent);
  border-color: rgba(99, 102, 241, 0.3);
}

.goal-badge-info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--info);
  border-color: rgba(59, 130, 246, 0.3);
}

.goal-badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.3);
}

.goal-badge-positive {
  background: rgba(34, 197, 94, 0.15);
  color: var(--positive);
  border-color: rgba(34, 197, 94, 0.3);
}

.goal-progress-fill.bg-primary { background: var(--primary); }
.goal-progress-fill.bg-accent { background: var(--accent); }
.goal-progress-fill.bg-info { background: var(--info); }
.goal-progress-fill.bg-warning { background: var(--warning); }
.goal-progress-fill.bg-positive { background: var(--positive); }

.goal-form-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border);
  background: var(--muted);
}

.goal-category-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
}

@media (max-width: 520px) {
  .goal-category-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.goal-category-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 4.25rem;
  padding: 0.5rem 0.35rem;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--card);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.goal-category-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.goal-category-option-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-foreground);
}

.goal-category-emoji {
  font-size: 1.125rem;
  line-height: 1;
}

.goal-category-option-label {
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  color: var(--muted-foreground);
}

.goal-category-option:hover {
  border-color: var(--primary);
  background: var(--muted);
}

.goal-category-option.is-selected,
.goal-category-option:has(input:checked) {
  border-color: var(--primary);
  background: rgba(13, 148, 136, 0.08);
  box-shadow: 0 0 0 1px rgba(13, 148, 136, 0.25);
}

.goal-category-option.is-selected .goal-category-option-icon,
.goal-category-option:has(input:checked) .goal-category-option-icon,
.goal-category-option.is-selected .goal-category-option-label,
.goal-category-option:has(input:checked) .goal-category-option-label {
  color: var(--primary);
}

.goal-color-swatches {
  margin-top: 0.25rem;
}

.goal-emergency-interest {
  padding: 0.75rem 1rem;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid rgba(13, 148, 136, 0.25);
  background: rgba(13, 148, 136, 0.06);
}

.goal-emergency-interest.hidden {
  display: none;
}

.icon-btn-primary:hover {
  color: var(--primary);
  background: rgba(13, 148, 136, 0.1);
}

.icon-btn-danger:hover {
  color: var(--negative);
  background: rgba(239, 68, 68, 0.1);
}

.emergency-hero {
  border: 1px solid rgba(13, 148, 136, 0.2);
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.06) 0%, transparent 60%);
}

.inv-type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
}

.inv-badge-etf { background: rgba(20, 184, 166, 0.15); color: #14b8a6; }
.inv-badge-acao { background: rgba(99, 102, 241, 0.15); color: #6366f1; }
.inv-badge-cripto { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.inv-badge-obrigacao { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.inv-badge-fundo { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.inv-badge-fundo-cash { background: rgba(14, 165, 233, 0.15); color: #0ea5e9; }
.inv-badge-outro { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }

/* Formulário investimentos — visibilidade por tipo (CSS :has, funciona sem JS) */
#investment-form .inv-type-panel {
  display: none !important;
}

#investment-form .inv-type-panel.is-active {
  display: block !important;
}

.inv-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 9999px;
  display: inline-block;
}

.inv-row:hover {
  background: rgba(255, 255, 255, 0.02);
}

.inv-live-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.inv-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45);
  animation: inv-live-pulse 1.8s infinite;
}

.inv-live-status.is-error .inv-live-dot {
  background: #ef4444;
  animation: none;
}

@keyframes inv-live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.inv-live-price {
  color: var(--primary);
}

.inv-row td {
  vertical-align: middle;
}

.inv-history-row td {
  vertical-align: top;
}

.inv-history-cell {
  padding: 0 1.25rem 0.85rem;
  background: rgba(15, 23, 42, 0.22);
}

.inv-history-details summary {
  cursor: pointer;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0;
}

.inv-history-details summary::-webkit-details-marker {
  display: none;
}

.inv-history-table-wrap {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  overflow: auto;
  max-height: 16rem;
  background: rgba(255, 255, 255, 0.02);
}

.inv-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.inv-history-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(15, 23, 42, 0.92);
  color: var(--muted-foreground);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.65rem;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
  text-align: center;
}

.inv-history-table thead th:first-child {
  text-align: left;
}

.inv-history-table tbody td {
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  vertical-align: middle;
  text-align: center;
}

.inv-history-table tbody td:first-child {
  text-align: left;
}

.inv-history-table tbody tr:last-child td {
  border-bottom: none;
}

.inv-history-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.inv-history-table__date {
  white-space: nowrap;
  color: var(--muted-foreground);
}

.inv-history-actions {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
}

@media (max-width: 899px) {
  .inv-history-cell {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .inv-history-table thead th,
  .inv-history-table tbody td {
    padding-left: 0.45rem;
    padding-right: 0.45rem;
  }
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Categorias — cor e emoji */
.category-pickers {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-start;
}

.category-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.color-swatch {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  cursor: pointer;
  position: relative;
  border: 2px solid transparent;
  background: var(--swatch-color);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.color-swatch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.color-swatch:hover {
  transform: scale(1.08);
}

.color-swatch.is-selected {
  border-color: var(--foreground);
  box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--swatch-color);
}

.emoji-picker {
  position: relative;
}

.emoji-picker-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.emoji-picker-trigger {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.emoji-picker-trigger:hover {
  border-color: var(--primary);
  background: rgba(13, 148, 136, 0.1);
}

.emoji-picker-manual {
  max-width: 7rem;
}

.emoji-picker-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  flex-wrap: wrap;
  gap: 0.25rem;
  max-width: 16rem;
  padding: 0.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

.emoji-picker-panel.is-open {
  display: flex;
}

.emoji-picker-panel[hidden] {
  display: none !important;
}

.emoji-option {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.375rem;
  font-size: 1.125rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  background: transparent;
}

.emoji-option:hover {
  background: var(--muted);
}

.emoji-option.is-selected {
  background: rgba(13, 148, 136, 0.14);
  color: var(--primary);
}

.emoji-option--clear {
  width: auto;
  padding: 0 0.5rem;
  font-size: 0.7rem;
  color: var(--muted-foreground);
}

.emoji-picker--goal .emoji-picker-trigger {
  background: transparent;
  border-color: rgba(232, 234, 240, 0.45);
  color: var(--foreground);
}

.emoji-picker--goal .emoji-picker-trigger:hover {
  background: transparent;
  border-color: var(--foreground);
  color: var(--foreground);
}

.emoji-picker--goal .emoji-picker-panel.is-open {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
  width: min(100vw - 2rem, 16rem);
}

.emoji-picker--goal .emoji-option {
  width: 2.35rem;
  height: 2.35rem;
  border: 1px solid rgba(232, 234, 240, 0.35);
  border-radius: calc(var(--radius) - 4px);
  background: transparent;
  color: var(--foreground);
}

.emoji-picker--goal .emoji-option svg {
  stroke: currentColor;
}

.emoji-picker--goal .emoji-option:hover {
  border-color: var(--foreground);
  background: transparent;
  color: var(--foreground);
}

.emoji-picker--goal .emoji-option.is-selected {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(13, 148, 136, 0.06);
}

.emoji-picker--goal .emoji-option--clear {
  grid-column: span 5;
  width: 100%;
  border-style: dashed;
  font-size: 0.75rem;
}

.emoji-picker--goal .emoji-picker-preview--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--foreground);
}

.emoji-picker--goal .emoji-picker-preview--icon svg {
  stroke: currentColor;
}

.category-row-form {
  padding: 1rem 1.25rem;
}

.category-row-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: start;
}

@media (min-width: 768px) {
  .category-row-grid {
    grid-template-columns: minmax(160px, 1fr) minmax(280px, 2fr) auto;
    align-items: center;
  }
}

.category-row-name {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.category-row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-shrink: 0;
}

.category-save-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.25rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid rgba(13, 148, 136, 0.35);
  border-radius: calc(var(--radius) - 4px);
  background: rgba(13, 148, 136, 0.08);
  color: var(--primary);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.category-save-btn:hover {
  background: rgba(13, 148, 136, 0.15);
  border-color: var(--primary);
}

.category-preview-badge {
  align-self: flex-start;
}

.category-form-new .category-pickers {
  margin-top: 0.25rem;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.35rem 0.5rem 0.35rem 0.35rem;
  margin-left: 0.25rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
  min-width: 0;
  max-width: 14rem;
  border-left: 1px solid var(--border);
  padding-left: 0.75rem;
}

.user-menu-trigger:hover,
.user-menu-trigger[aria-expanded="true"] {
  background: var(--muted);
  border-color: var(--border);
}

.user-menu-trigger--static {
  cursor: default;
}

.user-menu-trigger--static:hover {
  background: transparent;
  border-color: transparent;
}

.user-menu-trigger-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.user-profile-name {
  max-width: 9rem;
  line-height: 1.25;
}

.user-profile-scope {
  max-width: 9rem;
  line-height: 1.2;
}

.user-menu-chevron {
  transition: transform 0.15s ease;
}

.user-menu-trigger[aria-expanded="true"] .user-menu-chevron {
  transform: rotate(180deg);
}

.profile-menu-panel {
  width: 15.5rem;
  z-index: 50;
}

.profile-menu-form {
  margin: 0;
}

.profile-menu-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: none;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--foreground);
  cursor: pointer;
  text-align: left;
}

.profile-menu-item:hover {
  background: var(--muted);
}

.profile-menu-item.is-active {
  background: rgba(13, 148, 136, 0.1);
}

.profile-menu-item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.375rem;
  background: var(--muted);
  color: var(--muted-foreground);
  flex-shrink: 0;
}

.profile-menu-item.is-active .profile-menu-item-icon {
  color: var(--primary);
  background: rgba(13, 148, 136, 0.15);
}

.profile-menu-item-body {
  flex: 1;
  min-width: 0;
}

.profile-menu-item-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25;
}

.profile-menu-item-hint {
  display: block;
  font-size: 0.6875rem;
  color: var(--muted-foreground);
  line-height: 1.2;
}

.profile-menu-item-check {
  flex-shrink: 0;
}

@media (max-width: 639px) {
  .user-menu-trigger {
    max-width: 10rem;
  }

  .user-profile-name,
  .user-profile-scope {
    max-width: 6.5rem;
    font-size: 0.8125rem;
  }
}

/* Definições */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 1024px) {
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-card--wide {
    grid-column: 1 / -1;
  }
}

.settings-card-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.settings-card-head--flush {
  margin-bottom: 1rem;
}

.settings-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  background: rgba(13, 148, 136, 0.12);
  color: var(--primary);
  flex-shrink: 0;
}

.settings-fields {
  display: grid;
  gap: 1rem;
}

@media (min-width: 640px) {
  .settings-fields--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.settings-field-span-2 {
  grid-column: 1 / -1;
}

.settings-toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  margin-bottom: 1rem;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border);
  background: rgba(37, 43, 59, 0.35);
  cursor: pointer;
}

.settings-toggle input[type="checkbox"] {
  margin-top: 0.15rem;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.settings-form-footer {
  margin-top: 0.5rem;
}

.settings-accounts-list {
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  overflow: hidden;
}

.settings-accounts-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
}

.settings-accounts-item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.375rem;
  background: var(--muted);
  color: var(--muted-foreground);
  flex-shrink: 0;
}

/* ─── Layout responsivo (telemóvel → desktop) ─── */

html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  touch-action: manipulation;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
}

.app-main-inner {
  padding: var(--main-padding-y) var(--main-padding-x);
  padding-bottom: max(var(--main-padding-y), env(safe-area-inset-bottom, 0px));
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 17, 23, 0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.sidebar-backdrop--visible {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-mobile-close {
  display: none;
  margin-left: auto;
  width: var(--touch-target-min);
  height: var(--touch-target-min);
}

.topbar {
  padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  min-height: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
  height: auto;
  flex-wrap: nowrap;
  box-sizing: border-box;
}

.topbar-menu-btn {
  display: none;
  width: var(--touch-target-min);
  height: var(--touch-target-min);
  flex-shrink: 0;
}

.topbar-search {
  max-width: 20rem;
  min-width: 0;
}

.investments-charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 1024px) {
  .investments-charts {
    grid-template-columns: 2fr 1fr;
  }
}

.page-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.page-header-actions .btn-primary,
.page-header-actions .btn-ghost,
.page-header-actions form {
  flex-shrink: 0;
}

/* Telemóvel pequeno (iPhone SE, etc.) */
@media (max-width: 374px) {
  :root {
    --main-padding-x: 0.625rem;
    --main-padding-y: 0.75rem;
  }

  .text-2xl { font-size: 1.25rem; }
  .text-3xl { font-size: 1.5rem; }
  .text-4xl { font-size: 1.75rem; }

  .card.p-5 {
    padding: 1rem;
  }

  .summary-cards .card.p-5 {
    padding: 0.875rem 1rem;
  }
}

/* Telemóvel */
@media (max-width: 767px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    width: min(var(--sidebar-width), 88vw);
    max-width: 300px;
    transform: translateX(-100%);
    box-shadow: none;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
  }

  .sidebar.sidebar--open {
    transform: translateX(0);
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.45);
  }

  .sidebar-backdrop {
    display: block;
  }

  .sidebar-desktop-toggle {
    display: none !important;
  }

  .sidebar-mobile-close {
    display: inline-flex;
  }

  .sidebar-head {
    padding-right: 0.25rem;
  }

  .topbar-menu-btn {
    display: inline-flex;
  }

  .topbar-search {
    display: none;
  }

  .topbar {
    padding-left: max(0.5rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
    gap: 0.5rem;
  }

  body.sidebar-open {
    overflow: hidden;
  }

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

  .page-header > div:first-child {
    min-width: 0;
  }

  .page-header-actions,
  .page-header > .flex {
    width: 100%;
  }

  .page-header-actions .btn-primary,
  .page-header-actions .btn-ghost {
    flex: 1 1 auto;
    justify-content: center;
    min-height: var(--touch-target-min);
  }

  .page-header form.flex {
    width: 100%;
  }

  .page-header form.flex select {
    flex: 1;
    min-width: 0;
  }

  .modal-overlay {
    padding: 0;
    align-items: flex-end;
    touch-action: none;
  }

  .modal-backdrop {
    touch-action: none;
  }

  .modal-panel {
    max-width: 100%;
    max-height: min(92dvh, 92vh);
    border-radius: 1rem 1rem 0 0;
    margin: 0;
    will-change: transform;
    touch-action: pan-y;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    contain: none;
    overflow: hidden !important;
  }

  .modal-sheet-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: scroll;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scroll-padding-top: 0.5rem;
    scroll-padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
  }

  .modal-sheet-body::before {
    content: '';
    display: block;
    height: 0.5rem;
    flex-shrink: 0;
  }

  .modal-sheet-body::after {
    content: '';
    display: block;
    height: max(1.5rem, env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
  }

  .modal-sheet-body > form,
  .modal-sheet-body > :only-child {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
  }

  .modal-sheet-body > form:only-of-type,
  .modal-sheet-body > form:first-child:last-child {
    min-height: calc(100% + 1px);
  }

  .modal-sheet-body > form:not(:only-of-type):first-of-type {
    min-height: calc(100% + 1px);
  }

  .modal-sheet-body form > .modal-body,
  .modal-sheet-body form > div.modal-body {
    padding-top: 1.25rem;
    padding-bottom: 1.25rem;
    flex: 1 1 auto;
  }

  .modal-sheet-body form > .modal-footer,
  .modal-sheet-body form > div.modal-footer {
    flex-shrink: 0;
    padding-top: 1rem;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
  }

  .modal-sheet-body form > .px-6.py-5,
  .modal-sheet-body form > div.px-6.py-5 {
    padding-top: 1.25rem;
    padding-bottom: 1.25rem;
    flex: 1 1 auto;
  }

  .modal-sheet-body form > .flex.border-t,
  .modal-sheet-body form > div.border-t,
  .modal-sheet-body form > div[class*='border-t'],
  .modal-sheet-body form > div.flex[class*='border-t'] {
    flex-shrink: 0;
    padding-top: 1rem;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
  }

  .modal-sheet-body > form + form {
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
  }

  .modal-sheet-body [style*='overflow-y: auto'],
  .modal-sheet-body [style*='overflow-y:auto'] {
    max-height: none !important;
    overflow: visible !important;
  }

  .modal-panel input[type='date'],
  .modal-panel input[type='number'],
  .modal-sheet-body input[type='date'],
  .modal-sheet-body input[type='number'] {
    width: 100%;
    max-width: 100%;
    display: block;
    box-sizing: border-box;
  }

  .modal-panel .grid-cols-2 > div,
  .modal-panel .grid > div {
    min-width: 0;
  }

  .modal-panel input[type='date'],
  .modal-sheet-body input[type='date'] {
    min-height: var(--touch-target-min);
    -webkit-appearance: none;
    appearance: none;
  }

  .modal-sheet-drag-zone {
    flex-shrink: 0;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .modal-sheet-drag-zone > .border-b,
  .modal-sheet-drag-zone > [class*="border-b"] {
    border-top: none;
  }

  .modal-sheet-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    padding: 0.75rem 1rem 0.375rem;
    cursor: inherit;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .modal-sheet-handle-bar {
    display: block;
    width: 2.75rem;
    height: 0.3125rem;
    border-radius: 999px;
    background: var(--muted-foreground);
    opacity: 0.42;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
  }

  .modal-panel.is-sheet-dragging .modal-sheet-drag-zone {
    cursor: grabbing;
  }

  .modal-panel.is-sheet-dragging .modal-sheet-handle {
    cursor: grabbing;
  }

  .modal-panel.is-sheet-dragging .modal-sheet-handle-bar {
    opacity: 0.55;
  }

  .bulk-bar {
    left: var(--main-padding-x);
    right: var(--main-padding-x);
    transform: none;
    width: auto;
    max-width: none;
  }

  .toast-container {
    left: var(--main-padding-x);
    right: var(--main-padding-x);
    bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  }

  .chart-wrap {
    height: min(220px, 45vw);
    min-height: 160px;
  }

  .data-table {
    font-size: 0.8125rem;
  }

  .data-table th,
  .data-table td {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .modal-panel .grid-cols-2 {
    grid-template-columns: 1fr;
  }

  .modal-panel .col-span-2 {
    grid-column: auto;
  }

  .grid-cols-2.gap-4,
  .grid-cols-2.gap-3 {
    grid-template-columns: 1fr;
  }

  .nav-item {
    min-height: var(--touch-target-min);
    padding-top: 0.625rem;
    padding-bottom: 0.625rem;
  }

  #notif-panel,
  .profile-menu-panel {
    position: fixed !important;
    left: var(--main-padding-x) !important;
    right: var(--main-padding-x) !important;
    top: calc(var(--topbar-height) + 0.5rem) !important;
    width: auto !important;
    max-width: none;
  }
}

/* Telemóvel médio / grande */
@media (min-width: 375px) and (max-width: 767px) {
  .topbar-search--compact {
    display: flex;
    max-width: 12rem;
  }
}

/* Tablet retrato e paisagem estreito */
@media (min-width: 768px) and (max-width: 1023px) {
  .sidebar {
    width: var(--sidebar-collapsed-width);
  }

  .sidebar .sidebar-label,
  .sidebar .sidebar-group-title {
    display: none;
  }

  .sidebar .sidebar-brand {
    justify-content: center;
    width: 100%;
  }

  .sidebar-desktop-toggle {
    display: none !important;
  }

  .app-main-inner {
    --main-padding-x: 1.25rem;
  }

  .charts-row {
    grid-template-columns: 1fr;
  }

  .bento-hero {
    grid-column: span 1;
  }
}

/* Tablet paisagem / laptop pequeno */
@media (min-width: 1024px) and (max-width: 1279px) {
  .charts-row {
    grid-template-columns: 1fr 1fr;
  }

  .dashboard-bottom {
    grid-template-columns: 1fr;
  }
}

/* Desktop grande */
@media (min-width: 1536px) {
  .app-main-inner {
    --main-padding-x: 2rem;
    --main-padding-y: 1.75rem;
  }
}

/* Telemóvel / tablet em horizontal (altura reduzida) */
@media (max-height: 500px) and (orientation: landscape) {
  .modal-panel {
    max-height: 96dvh;
    overflow-y: auto;
  }

  .chart-wrap {
    height: 140px;
    min-height: 120px;
  }

  .sidebar {
    overflow-y: auto;
  }
}

/* ─── Transações (sem scroll horizontal) ─── */

.transactions-page {
  min-width: 0;
  max-width: 100%;
}

.transactions-filters {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0.5rem;
}

.transactions-filters-search {
  flex: 2 1 0;
  min-width: 0;
}

.transactions-filters-search .input-field {
  width: 100%;
}

.transactions-filters-select {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
  max-width: none;
}

.transactions-filters .btn-ghost {
  flex: 0 0 auto;
  white-space: nowrap;
}

.transactions-filters-submit {
  flex: 0 0 auto;
  white-space: nowrap;
  min-width: 5.5rem;
  padding-left: 1rem;
  padding-right: 1rem;
  font-weight: 600;
}

.transactions-header-select {
  min-width: 0;
  max-width: 100%;
  flex: 1 1 auto;
}

@media (max-width: 639px) {
  .transactions-page .page-header-actions .btn-primary,
  .transactions-page .page-header-actions .btn-ghost {
    flex: 1 1 calc(50% - 0.25rem);
    justify-content: center;
  }
}

@media (max-width: 639px) {
  .transactions-filters {
    gap: 0.375rem;
  }

  .transactions-filters-select {
    flex: 1 1 0;
    min-width: 0;
  }
}

@media (max-width: 767px) {
  .transactions-card-head {
    flex-direction: column;
    align-items: stretch;
  }

  .transactions-card-head-actions {
    width: 100%;
  }

  .transactions-card-head-actions .btn-primary,
  .transactions-card-head-actions .btn-ghost {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
  }

  .transactions-card .transactions-filters {
    flex-wrap: wrap;
  }

  .transactions-card .transactions-filters-search {
    flex: 1 1 100%;
    width: 100%;
  }

  .transactions-card .transactions-filters-select {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: 0;
  }

  .transactions-card .transactions-filters-submit {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }

  .transactions-card-period.period-filters .period-select {
    flex: 1 1 calc(50% - 0.25rem);
    max-width: none;
  }

  .transactions-card [data-tx-footer] {
    flex-direction: column;
    align-items: stretch;
  }

  .transactions-card [data-tx-footer] > .flex {
    width: 100%;
    justify-content: space-between;
  }
}

.dashboard-transactions-host {
  min-width: 0;
  max-width: 100%;
}

.transactions-card {
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}

.transactions-card-period.period-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.transactions-card-period.period-filters .period-select {
  flex: 1 1 8rem;
  min-width: 0;
  max-width: 12rem;
}

.transactions-card-head-summary {
  margin-top: 0.25rem;
}

.dashboard-transactions-host.is-loading .transactions-card {
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.dashboard-transactions-host.is-loading .transactions-table-wrap {
  min-height: 8rem;
}

.transactions-table-wrap {
  overflow: hidden;
  max-width: 100%;
}

.transactions-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

.transactions-table th:not(.col-date),
.transactions-table td:not(.col-date) {
  padding: 0.625rem 0.5rem;
  vertical-align: middle;
  overflow: hidden;
}

.transactions-table .col-date {
  padding: 0.625rem 0.5rem;
  padding-left: 0.75rem;
  padding-right: 0.25rem;
  vertical-align: middle;
  width: 7rem;
  min-width: 7rem;
  overflow: visible;
  white-space: nowrap;
}

.transactions-table thead .col-date {
  overflow: visible;
  white-space: nowrap;
}

.transactions-table thead th {
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

.transactions-table .col-desc {
  width: auto;
  min-width: 0;
}

.transactions-table .col-cat {
  width: 28%;
}

.transactions-table .col-valor {
  width: 5.75rem;
  text-align: right;
  white-space: nowrap;
}

.transactions-table .col-actions {
  width: 4.25rem;
  padding-right: 0.75rem;
}

.transactions-cat-badge {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.transactions-row-actions {
  justify-content: flex-end;
}

.transactions-row-goal {
  background: rgba(13, 148, 136, 0.04);
}

.transactions-row-goal .col-desc p:first-child {
  color: var(--muted-foreground);
}

@media (max-width: 899px) {
  .transactions-table .col-cat {
    width: 32%;
  }

  .transactions-table .col-date {
    width: 7rem;
    min-width: 7rem;
    font-size: 0.75rem;
  }
}

@media (max-width: 639px) {
  .transactions-table thead {
    display: none;
  }

  .transactions-table tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto auto;
    gap: 0.125rem 0.5rem;
    padding: 0.75rem;
    align-items: center;
    border-bottom: 1px solid var(--border);
  }

  .transactions-table tbody tr:hover {
    background: rgba(37, 43, 59, 0.35);
  }

  .transactions-table tbody td {
    display: block;
    padding: 0;
    border: none;
  }

  .transactions-table .col-desc {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }

  .transactions-table .col-valor {
    grid-column: 2;
    grid-row: 1;
    text-align: right;
    align-self: start;
    font-size: 0.875rem;
    width: auto;
  }

  .transactions-table .col-date {
    grid-column: 1;
    grid-row: 2;
    width: auto;
    min-width: unset;
    font-size: 0.75rem;
    color: var(--muted-foreground);
    overflow: visible;
    white-space: nowrap;
  }

  .transactions-table .col-cat {
    grid-column: 1;
    grid-row: 3;
    width: auto;
  }

  .transactions-table .col-actions {
    grid-column: 2;
    grid-row: 3;
    width: auto;
    align-self: end;
  }

  .transactions-table .transactions-empty {
    display: block;
    grid-column: 1 / -1;
  }
}

@media (min-width: 640px) {
  .transactions-table .col-desc .truncate {
    max-width: 100%;
  }
}
