@media (max-width: 768px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .topbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-rows: auto !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 10px 12px !important;
  }

  .topbar-left {
    grid-column: 1 !important;
    grid-row: 1 !important;
    min-width: 0;
  }

  .logo {
    max-width: 142px;
    line-height: 1.12;
    white-space: normal;
  }

  .topbar-nav {
    display: none !important;
  }

  .topbar-right {
    grid-column: 2 !important;
    grid-row: 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 5px !important;
    flex-wrap: nowrap !important;
    min-width: 0;
  }

  .hamburger-btn {
    display: inline-flex !important;
    order: 99;
  }

  .topbar-right .btn,
  .hamburger-btn,
  #theme-toggle,
  .topbar-right button[title="Lock"] {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    border-radius: 10px !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
    white-space: nowrap !important;
  }

  .topbar-right .btn {
    gap: 0 !important;
    font-size: 0 !important;
  }

  .topbar-right .btn svg {
    width: 16px !important;
    height: 16px !important;
    flex: 0 0 auto;
  }

  #theme-toggle,
  .topbar-right button[title="Lock"] {
    display: none !important;
  }

  .topbar-right .btn svg {
    display: none !important;
  }

  .topbar-right .btn-ghost:not(#sync-btn) {
    order: 10;
  }

  .topbar-right .btn-map {
    order: 20;
  }

  .topbar-right .btn[onclick="openDepositedChecks()"],
  .topbar-right .btn[onclick="openPaidHistory()"] {
    order: 20;
  }

  .topbar-right #sync-btn {
    order: 30;
  }

  .topbar-right .btn-primary {
    order: 40;
  }

  .topbar-right .btn-map::before {
    content: "🗺";
    font-size: 19px;
    line-height: 1;
  }

  .topbar-right .btn[onclick="openDepositedChecks()"]::before {
    content: "✓";
    font-size: 21px;
    font-weight: 700;
    line-height: 1;
  }

  .topbar-right .btn[onclick="openPaidHistory()"]::before {
    content: "✓";
    font-size: 21px;
    font-weight: 700;
    line-height: 1;
  }

  .topbar-right #sync-btn::before {
    content: "↻";
    font-size: 21px;
    line-height: 1;
  }

  .topbar-right .btn-primary::before {
    content: "+";
    font-size: 25px;
    font-weight: 700;
    line-height: 1;
  }

  .main {
    max-width: 100%;
    padding: 12px !important;
    overflow-x: hidden;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .stat {
    min-width: 0;
  }

  .controls {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px !important;
    align-items: stretch !important;
  }

  .search-wrap {
    grid-column: 1 / -1;
    min-width: 0 !important;
  }

  .controls select,
  .controls .btn {
    width: 100% !important;
    min-width: 0 !important;
  }

  .card-list,
  .balance-cards {
    display: flex !important;
    flex-direction: column;
    gap: 8px;
  }

  .table-wrap {
    max-width: 100%;
    overflow-x: auto;
  }

  .modal-overlay {
    align-items: flex-start !important;
    padding: 12px !important;
  }

  .modal {
    max-width: 100% !important;
  }

  .side-menu {
    width: min(82vw, 300px) !important;
  }

  #global-search-modal > div {
    max-width: calc(100vw - 24px) !important;
  }
}

@media (max-width: 380px) {
  .logo {
    max-width: 104px;
    font-size: 13px !important;
  }

  .topbar-right {
    gap: 3px !important;
  }

  .topbar-right .btn,
  .hamburger-btn,
  #theme-toggle,
  .topbar-right button[title="Lock"] {
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
  }
}
