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

body {
  overflow-x: hidden;
}

*,
*::before,
*::after {
  min-width: 0;
  box-sizing: border-box;
}

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

#app {
  width: 100%;
  overflow-x: hidden;
}

main,
main.with-sidebar {
  width: 100%;
  box-sizing: border-box;
}

input,
select,
textarea,
button {
  max-width: 100%;
}

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

@media (max-width: 1180px) {
  .topbar {
    height: auto;
    min-height: 72px;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
  }

  .topbar-brand {
    flex: 1 1 220px;
  }

  nav {
    flex: 1 1 100%;
    order: 3;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 5px;
    -webkit-overflow-scrolling: touch;
  }

  nav .nav-btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .topbar-right {
    margin-right: 0;
  }

  .topbar-rates,
  .logo-sidebar {
    display: none;
  }

  main.with-sidebar {
    padding-right: 18px;
  }
}

@media (max-width: 1024px) {
  main,
  main.with-sidebar {
    padding: 18px 14px 80px;
  }

  .summary-grid,
  .cards,
  .clients-grid,
  .companies-grid,
  .users-grid,
  .opening-grid,
  .rates-board-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .quick-add-row,
  .dex-dual-rates,
  .ex-dual-rates,
  .live-rates-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .section-header,
  .filter-bar,
  .action-bar {
    align-items: stretch;
    flex-wrap: wrap;
    gap: 10px;
  }

  .section-header > *,
  .filter-bar > *,
  .action-bar > * {
    max-width: 100%;
  }

  .modal {
    max-width: min(94vw, 620px);
  }
}

@media (max-width: 768px) {
  body {
    min-width: 0;
  }

  .topbar {
    position: sticky;
    top: 0;
    min-height: 64px;
    padding: 8px 10px;
    align-items: stretch;
    gap: 8px;
  }

  .topbar-brand {
    order: 1;
    width: 100%;
    flex: 1 1 100%;
    justify-content: center;
    text-align: center;
  }

  .topbar-brand h2 {
    font-size: 0.95rem;
    line-height: 1.25;
  }

  .brand-sub,
  .nav-divider {
    display: none !important;
  }

  nav {
    order: 2;
    flex: 1 1 100%;
    width: 100%;
    scroll-snap-type: x proximity;
    border-radius: 14px;
  }

  nav .nav-btn {
    min-height: 38px;
    padding: 8px 11px;
    font-size: 0.78rem;
    scroll-snap-align: start;
  }

  .topbar-right {
    order: 3;
    width: 100%;
    flex: 1 1 100%;
    justify-content: space-between;
    gap: 6px;
  }

  .topbar-right .btn {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 0.78rem;
  }

  .user-chip {
    flex: 1 1 auto;
    max-width: 100%;
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  main,
  main.with-sidebar {
    padding: 12px 10px 84px;
  }

  .summary-grid,
  .cards,
  .stat-row,
  .users-grid,
  .clients-grid,
  .companies-grid,
  .opening-grid,
  .rates-board-grid,
  .quick-add-row,
  .dex-dual-rates,
  .ex-dual-rates,
  .live-rates-row,
  .grid-2 {
    grid-template-columns: 1fr !important;
  }

  .section-header,
  .filter-bar,
  .action-bar,
  .modal-footer {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .section-header .btn,
  .filter-bar .btn,
  .action-bar .btn,
  .modal-footer .btn,
  .toolbar .btn {
    width: 100%;
    justify-content: center;
  }

  .table-wrap {
    overflow-x: auto;
    border-radius: 12px;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 720px;
  }

  th,
  td {
    padding: 10px 9px;
    font-size: 0.82rem;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .btn {
    min-height: 40px;
  }

  .currency-card,
  .card,
  .panel,
  .quick-add-wrap {
    border-radius: 12px;
    padding: 14px;
  }

  .card-amount,
  .currency-card .amount {
    font-size: 1.45rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  .login-split {
    width: 100%;
    min-height: auto;
    flex-direction: column;
    border-radius: 16px;
  }

  #login-screen {
    align-items: flex-start;
    min-height: 100dvh;
    padding: 10px;
    overflow-y: auto;
  }

  .login-split-visual {
    min-height: 210px;
    padding: 28px 18px;
  }

  .login-split-form {
    padding: 24px 18px;
  }

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

  .modal {
    width: 100%;
    max-width: 100vw;
    max-height: 92dvh;
    margin: 0;
    overflow-y: auto;
    border-radius: 18px 18px 0 0;
    padding: 18px;
  }

  .theme-panel {
    display: flex !important;
    left: 10px;
    top: auto;
    bottom: 86px;
    transform: translateX(-100%);
    border: 1px solid var(--border);
    border-left: 1px solid var(--border);
    border-radius: 14px;
    overflow: visible;
    z-index: 700;
  }

  .theme-panel.open {
    transform: translateX(0);
  }

  .theme-toggle-btn {
    right: -34px;
    width: 34px;
    height: 48px;
    border-radius: 0 12px 12px 0;
  }

  .theme-panel-title {
    padding: 9px 12px 6px;
    font-size: 0.7rem;
  }

  .theme-swatch-row {
    padding: 8px;
    gap: 7px;
  }

  .theme-swatch {
    width: 34px;
    height: 34px;
    border-radius: 9px;
  }

  .theme-swatch .swatch-tip {
    display: none;
  }

  .toast {
    left: 10px;
    right: 10px;
    width: auto;
    max-width: none;
  }
}

@media (max-width: 420px) {
  .topbar {
    padding: 7px 8px;
  }

  nav .nav-btn {
    padding: 8px 9px;
    font-size: 0.74rem;
  }

  .topbar-right {
    flex-wrap: wrap;
  }

  .topbar-right .btn {
    flex: 1 1 calc(50% - 4px);
  }

  .user-chip {
    flex-basis: 100%;
  }

  main,
  main.with-sidebar {
    padding-inline: 8px;
  }

  table {
    min-width: 660px;
  }

  .modal {
    padding: 14px;
  }
}
