/* Mobile finance-app feel: bottom nav, sticky actions, touch-friendly spacing. */

@media (max-width: 991.98px) {
  #topbar {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  #topbar #page-title {
    font-size: 0.95rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #topbar .btn {
    padding: 0.35rem 0.45rem;
    font-size: 0.85rem;
  }

  #topbar .btn-outline-secondary {
    min-width: auto;
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #topbar .dropdown-toggle::after {
    display: none;
  }

  #topbar #current-user-name {
    display: none;
  }

  #topbar .dropdown-menu {
    min-width: auto;
  }

  #app-content {
    padding: 0.85rem 0.85rem 5.5rem;
  }

  #topbar .mt-search {
    display: none;
  }

  #bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 64px;
    background-color: var(--bg-elevated);
    border-top: 1px solid var(--border);
    z-index: 1030;
    padding-bottom: env(safe-area-inset-bottom);
  }

  #bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.68rem;
  }

  #bottom-nav a i {
    font-size: 1.25rem;
  }

  #bottom-nav a.active {
    color: var(--brand);
  }

  .mt-stat-card {
    padding: 0.9rem 1rem;
  }

  .mt-stat-card .mt-stat-value {
    font-size: 1.35rem;
  }

  .btn,
  .form-control,
  .form-select {
    min-height: 44px;
  }

  .table-responsive {
    -webkit-overflow-scrolling: touch;
  }

  .modal-dialog {
    margin: 0.5rem;
  }

  /* Mobile dashboard improvements */
  .mt-dashboard-scroll-card {
    min-width: 180px;
  }

  .mt-stat-card-modern {
    padding: 1rem !important;
  }

  .mt-stat-card-modern .mt-stat-value {
    font-size: 1.5rem;
  }

  #period-selector {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  #period-selector button {
    flex: 1;
    min-width: 70px;
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
  }

  .mt-card {
    border-radius: 0.65rem;
  }

  /* Mobile: Convert Grid to List View */
  /* Stack all grid columns to full width */
  .row [class*="col-"] {
    width: 100% !important;
    flex: 0 0 100% !important;
  }

  /* Override Bootstrap grid for mobile */
  .col-6,
  .col-md-1,
  .col-md-2,
  .col-md-3,
  .col-md-4,
  .col-md-5,
  .col-md-6 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }

  /* Ensure filters/forms stack properly */
  .row.g-2 > [class*="col"],
  .row.g-3 > [class*="col"] {
    margin-bottom: 0.5rem;
  }

  /* Hide desktop-only grid layouts */
  .d-grid {
    display: grid !important;
    gap: 0.5rem;
  }

  /* Mobile list item styling */
  .mt-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    gap: 0.75rem;
  }

  .mt-list-item-content {
    flex: 1;
    min-width: 0;
  }

  .mt-list-item-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin: 0 0 0.25rem 0;
  }

  .mt-list-item-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
  }

  .mt-list-item-value {
    font-weight: 600;
    font-size: 1.1rem;
    text-align: right;
    white-space: nowrap;
  }

  .mt-list-item-actions {
    display: flex;
    gap: 0.25rem;
  }

  .mt-list-item-actions button {
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
  }

  /* Table to list card conversion */
  table.table {
    display: block;
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
  }

  table.table thead {
    display: none;
  }

  table.table tbody {
    display: block;
  }

  table.table tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 1rem;
    background-color: var(--bg-card);
    page-break-inside: avoid;
  }

  table.table td {
    display: block;
    padding: 0.5rem 0;
    border: none;
    text-align: left;
    word-break: break-word;
  }

  /* Show label for each cell from data-label attribute */
  table.table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
  }

  /* Highlight monetary values */
  table.table td.text-end {
    text-align: right;
    font-weight: 600;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
  }

  /* Action buttons in last cell */
  table.table td:last-child {
    display: flex;
    justify-content: flex-end;
    gap: 0.25rem;
    padding-top: 0.75rem;
    margin-top: auto;
  }

  table.table td:last-child[data-label]::before {
    display: none;
  }

  /* Responsive action buttons in lists */
  .btn-group-sm {
    gap: 0.25rem;
  }

  .btn-sm {
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
  }

  /* Dual table/list containers: hide the desktop table, show the app-style list. */
  .mt-list-dual .table-responsive {
    display: none;
  }

  .mt-list-dual .mt-desktop-cards {
    display: none;
  }

  .mt-list-dual .mt-mlist {
    display: flex;
  }
}

/* App-style mobile list (crypto/messaging app look): colored avatar, title/subtitle, right amount + badge.
   Hidden by default (desktop shows the <table> instead); shown on mobile via .mt-list-dual above. */
.mt-mlist {
  display: none;
  flex-direction: column;
  background-color: var(--bg-card);
  border-radius: 0.65rem;
  overflow: hidden;
  border: 1px solid var(--border);
}

.mt-mlist-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.mt-mlist-item:last-child {
  border-bottom: none;
}

.mt-mlist-item:active {
  background-color: var(--bg-hover);
}

.mt-mlist-icon {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.mt-mlist-body {
  flex: 1 1 auto;
  min-width: 0;
}

.mt-mlist-title {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.mt-mlist-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mt-mlist-end {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
  text-align: right;
}

.mt-mlist-amount {
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
}

.mt-mlist-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.05rem 0.4rem;
  border-radius: 1rem;
  white-space: nowrap;
  background-color: var(--bg-hover);
  color: var(--text-muted);
}

.mt-mlist-badge.positive {
  background-color: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.mt-mlist-badge.negative {
  background-color: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.mt-mlist-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 0.1rem;
  margin-left: 0.15rem;
}

.mt-mlist-actions .btn {
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  min-height: auto;
}

/* Mobile filter bar: compact search + a toggle button that reveals From/To/Category in a collapsible
   panel (instead of always showing the full desktop filter row). Add-new is handled by the FAB. */
.mt-filter-toggle {
  position: relative;
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: auto;
}

.mt-filter-toggle.has-filters::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--brand);
  border: 1.5px solid var(--bg-card);
}

/* Stacked mobile list items (e.g. subscriptions): title/amount row wraps, then a full-width action row */
.mt-mlist-item-stacked {
  flex-wrap: wrap;
}

.mt-mlist-item-stacked .mt-mlist-actions-row {
  flex: 1 1 100%;
  display: flex;
  gap: 0.4rem;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}

.mt-mlist-item-stacked .mt-mlist-actions-row .btn {
  flex: 0 0 auto;
  min-height: auto;
  padding: 0.3rem 0.5rem;
  font-size: 0.78rem;
}

.mt-mlist-item-stacked .mt-mlist-actions-row .btn.flex-grow-1 {
  flex: 1 1 auto;
}

