/* Experiência móvel final: navegação, toque, modais e conteúdo responsivo. */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 860px) {
  html {
    scroll-padding-top: 14px;
    scroll-padding-bottom: calc(102px + env(safe-area-inset-bottom));
  }

  body {
    min-width: 0;
    -webkit-tap-highlight-color: transparent;
  }

  button,
  a,
  input,
  select,
  textarea {
    touch-action: manipulation;
  }

  button,
  .nav-item,
  .module-tab,
  .primary-button,
  .secondary-button,
  .danger-button,
  .edit-button {
    min-height: 44px;
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
  select,
  textarea {
    max-width: 100%;
    min-height: 46px;
    font-size: 16px !important;
  }

  .app-shell {
    width: 100%;
    min-width: 0;
  }

  .main-content {
    width: 100%;
    min-width: 0;
    padding:
      max(12px, env(safe-area-inset-top))
      12px
      calc(102px + env(safe-area-inset-bottom));
  }

  .mobile-account {
    top: max(15px, env(safe-area-inset-top));
    right: 16px;
  }

  .mobile-account-button {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  }

  .mobile-account .account-menu {
    top: calc(100% + 9px);
    width: min(320px, calc(100vw - 24px));
    max-height: calc(100dvh - 90px);
    overflow-y: auto;
  }

  .hero-header {
    min-height: 112px;
    margin-bottom: 12px;
    padding: 18px 76px 18px 18px;
    border-radius: 19px;
  }

  .hero-badge {
    padding: 6px 9px;
    font-size: 0.73rem;
  }

  .brand-title {
    margin: 9px 0 4px;
    font-size: clamp(2rem, 9vw, 2.75rem);
    line-height: 1;
  }

  .hero-description {
    font-size: 0.84rem;
    line-height: 1.45;
  }

  .hero-logo-wrap {
    display: none;
  }

  .module-switcher-panel {
    min-height: 0;
    margin-bottom: 12px;
    padding: 14px 16px;
    border-radius: 17px;
  }

  .module-switcher-panel h2 {
    margin: 2px 0 0;
    font-size: 1.22rem;
  }

  .module-switcher-panel .panel-eyebrow,
  .module-switcher-description,
  .module-switcher-actions {
    display: none;
  }

  .module-section {
    min-width: 0;
  }

  .panel,
  .stat-card,
  .toolbar-panel,
  .goals-panel,
  .chart-panel,
  .table-panel {
    max-width: 100%;
    border-radius: 17px;
  }

  .panel,
  .chart-panel,
  .table-panel,
  .settings-panel {
    padding: 17px;
  }

  .toolbar-panel,
  .cards-grid,
  .summary-grid,
  .panel,
  .chart-panel,
  .table-panel {
    margin-bottom: 12px;
  }

  .panel-header {
    margin-bottom: 14px;
  }

  .panel-header h2 {
    font-size: 1.25rem;
    line-height: 1.2;
  }

  .panel-description,
  .goals-helper {
    line-height: 1.5;
  }

  .toolbar-panel {
    gap: 12px;
    padding: 14px;
  }

  .filters-inline {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .filter-group,
  .filter-group select,
  .filters-inline > button {
    width: 100%;
    min-width: 0;
  }

  #applyFilterButton {
    grid-column: 1 / -1;
  }

  .toolbar-panel-right .primary-button {
    min-height: 48px;
  }

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

  .panel-header-split > button,
  .panel-header-split > .primary-button,
  .panel-header-split > .secondary-button {
    width: 100%;
  }

  .cards-grid,
  .cards-grid-main,
  .summary-grid {
    gap: 10px;
  }

  .stat-card {
    min-height: 132px;
    padding: 17px;
  }

  .stat-card-featured {
    min-height: 142px;
  }

  .stat-value,
  .stat-value.small {
    font-size: clamp(1.45rem, 8vw, 2.15rem);
  }

  .form-actions,
  .settings-actions,
  .monthly-closing-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .form-actions > button,
  .settings-actions > button,
  .monthly-closing-actions > button {
    width: 100%;
    margin: 0;
  }

  .table-wrapper {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
  }

  .table-filters,
  .table-filters-extended {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    padding: 10px;
  }

  .table-filters input,
  .table-filters select,
  .table-filters button {
    width: 100%;
    min-width: 0;
  }

  .table-filters input:first-child,
  .table-filters .bulk-delete-button {
    grid-column: 1 / -1;
  }

  #transactions-section .table-wrapper {
    overflow: visible;
    border-radius: 0;
  }

  #transactions-section table,
  #transactions-section thead,
  #transactions-section tbody,
  #transactions-section tr {
    display: block;
    width: 100%;
  }

  #transactions-section thead tr {
    margin-bottom: 8px;
  }

  #transactions-section thead th {
    display: none;
  }

  #transactions-section thead th.checkbox-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    position: static;
    padding: 10px 2px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.82rem;
  }

  #transactions-section thead th.checkbox-cell::after {
    content: "Selecionar esta página";
  }

  #transactions-section tbody {
    display: grid;
    gap: 10px;
  }

  #transactions-section tbody tr {
    position: relative;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: var(--user-surface-top);
  }

  #transactions-section tbody tr.selected-row {
    border-color: var(--line-strong);
    background: var(--blue-soft);
  }

  #transactions-section tbody td {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 12px;
    align-items: baseline;
    padding: 8px 0;
    border-color: rgba(var(--user-accent-rgb), 0.07);
    text-align: right;
    overflow-wrap: anywhere;
  }

  #transactions-section tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-align: left;
  }

  #transactions-section tbody td.checkbox-cell {
    position: absolute;
    top: 11px;
    right: 11px;
    display: block;
    width: auto;
    padding: 0;
    border: 0;
  }

  #transactions-section tbody td.checkbox-cell::before {
    display: none;
  }

  #transactions-section tbody td:nth-child(2) {
    padding-right: 38px;
  }

  #transactions-section tbody td.action-cell {
    display: grid;
    grid-template-columns: 92px repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding-top: 12px;
    border-bottom: 0;
  }

  #transactions-section .action-cell .edit-button,
  #transactions-section .action-cell .danger-button {
    width: 100%;
    margin: 0;
  }

  .pagination-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .pagination-info {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 100%;
  }

  .pagination-button {
    width: 100%;
  }

  .chart-wrapper,
  .temporal-chart-wrapper {
    min-height: 330px;
  }

  .category-chart-wrapper {
    min-height: 300px;
  }

  canvas {
    max-width: 100%;
  }

  .modal {
    align-items: flex-end;
    padding:
      14px
      0
      env(safe-area-inset-bottom);
  }

  .modal-content,
  .modal .modal-content,
  .modal .modal-content.modal-confirm {
    width: 100% !important;
    max-width: none !important;
    max-height: min(92dvh, 860px);
    margin: 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 22px 22px 0 0 !important;
    animation: mobileSheetEnter 0.26s ease;
  }

  .modal-header {
    position: sticky;
    z-index: 5;
    top: -20px;
    margin: -20px -16px 16px;
    padding: 18px 16px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--user-surface-bottom);
    background: color-mix(
      in srgb,
      var(--user-surface-bottom) 94%,
      transparent
    );
    backdrop-filter: blur(14px);
  }

  .modal-header h2 {
    font-size: 1.3rem;
  }

  .modal .icon-button {
    width: 44px;
    height: 44px;
  }

  .transaction-form,
  .form-grid {
    gap: 13px;
  }

  .quick-add-button {
    right: 16px;
    bottom: calc(82px + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    border-radius: 18px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.38);
  }

  .mobile-bottom-nav {
    position: fixed;
    z-index: 110;
    right: 8px;
    bottom: 8px;
    left: 8px;
    display: flex;
    align-items: stretch;
    min-height: 66px;
    padding: 6px 5px calc(6px + env(safe-area-inset-bottom));
    overflow: hidden;
    border: 1px solid rgba(var(--user-accent-rgb), 0.2);
    border-radius: 19px;
    background: rgba(var(--user-menu-bg-rgb), 0.96);
    box-shadow: 0 16px 46px rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(18px);
  }

  .mobile-bottom-nav button {
    min-width: 0;
    min-height: 54px;
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 3px;
    padding: 5px 2px;
    border: 0;
    border-radius: 13px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 0.64rem;
    font-weight: 700;
    cursor: pointer;
  }

  .mobile-bottom-nav button.active {
    background: rgba(var(--user-accent-rgb), 0.16);
    color: color-mix(in srgb, var(--user-accent) 68%, white);
  }

  .mobile-nav-icon {
    min-height: 22px;
    display: grid;
    place-items: center;
    color: currentColor;
    font-size: 1rem;
    line-height: 1;
  }

  .mobile-nav-icon-text {
    font-size: 0.7rem;
    font-weight: 800;
  }

  body.auth-open .mobile-bottom-nav,
  body.modal-open .mobile-bottom-nav {
    display: none;
  }

  .toast-container {
    top: max(14px, env(safe-area-inset-top));
    right: 12px;
    left: 12px;
    z-index: 6200;
  }

  .toast {
    width: 100%;
  }

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

@media (min-width: 520px) and (max-width: 860px) {
  .cards-grid,
  .cards-grid-main,
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cards-grid-main .stat-card:first-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 519px) {
  .form-actions,
  .settings-actions,
  .monthly-closing-actions {
    grid-template-columns: 1fr;
  }

  .filters-inline > button {
    grid-column: 1 / -1;
  }

  .table-filters,
  .table-filters-extended {
    grid-template-columns: 1fr;
  }

  .table-filters input,
  .table-filters select,
  .table-filters button {
    grid-column: auto !important;
  }

  #transactions-section tbody td.action-cell {
    grid-template-columns: 1fr 1fr;
  }

  #transactions-section tbody td.action-cell::before {
    grid-column: 1 / -1;
  }

  .chart-wrapper,
  .temporal-chart-wrapper {
    min-height: 290px;
  }

  .mobile-bottom-nav {
    right: 5px;
    bottom: 5px;
    left: 5px;
    border-radius: 17px;
  }

  .mobile-bottom-nav button {
    font-size: 0.59rem;
  }
}

@media (max-width: 620px) {
  .auth-screen {
    min-height: 100dvh;
  }

  .auth-layout {
    min-height: 100dvh;
    grid-template-rows: auto 1fr;
  }

  .auth-intro {
    min-height: 0;
    padding:
      max(18px, env(safe-area-inset-top))
      20px
      18px;
  }

  .auth-brand-logo {
    width: 42px;
    height: 42px;
  }

  .auth-brand span {
    font-size: 1.12rem;
  }

  .auth-intro-copy {
    margin: 24px 0 0;
    padding: 0;
  }

  .auth-intro-copy h1 {
    margin: 10px 0 0;
    font-size: clamp(2rem, 11vw, 2.8rem);
  }

  .auth-card {
    min-height: 0;
    justify-content: flex-start;
    padding: 28px 20px calc(24px + env(safe-area-inset-bottom));
  }

  .auth-view-heading {
    margin-bottom: 22px;
  }

  .auth-view-heading h2 {
    font-size: 1.8rem;
  }

  .auth-form {
    gap: 15px;
  }

  .auth-footer-note {
    margin-top: 26px;
    line-height: 1.5;
  }
}

@media (max-width: 390px) {
  .main-content {
    padding-right: 9px;
    padding-left: 9px;
  }

  .panel,
  .chart-panel,
  .table-panel,
  .settings-panel {
    padding: 14px;
  }

  .hero-header {
    padding-left: 15px;
  }

  .mobile-bottom-nav button {
    letter-spacing: -0.02em;
  }
}

@media (max-width: 860px) and (hover: none) {
  .primary-button:hover,
  .secondary-button:hover,
  .danger-button:hover,
  .edit-button:hover,
  .nav-item:hover,
  .theme-preset:hover {
    transform: none;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .hero-header {
    min-height: 88px;
  }

  .brand-title {
    font-size: 1.8rem;
  }

  .hero-description {
    display: none;
  }

  .modal-content,
  .modal .modal-content {
    max-height: 96dvh;
  }
}
