/* ================= RESPONSIVE ================= */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--ink);
  color: #EFE9D8;
  padding: 14px 18px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.mobile-menu-btn {
  all: unset;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.mobile-topbar-title {
  font-weight: 800;
  font-size: 15px;
  margin-left: auto;
}

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 28, 0.45);
  z-index: 45;
}

.mobile-overlay.show {
  display: block;
}

/* Flagged assets: give the unit more room and keep quantity compact. */
#page-flagged .holdings-table th:nth-child(2),
#page-flagged .holdings-table td:nth-child(2) {
  width: 18%;
  min-width: 165px;
}

#page-flagged .holdings-table td:nth-child(2) select {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

#page-flagged .holdings-table th:nth-child(3),
#page-flagged .holdings-table td:nth-child(3) {
  width: 7%;
  min-width: 74px;
}

#page-flagged .holdings-table td:nth-child(3) input[type=number] {
  width: 72px;
  min-width: 64px;
  box-sizing: border-box;
}

@media (max-width: 920px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .mobile-topbar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 50;
    width: 260px;
    height: 100vh;
    transform: translateX(0);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.3);
  }

  .sidebar.collapsed {
    transform: translateX(100%);
    width: 260px;
    flex-basis: 260px;
    padding: 28px 20px;
  }

  .sidebar.collapsed .brand {
    justify-content: flex-start;
  }

  .sidebar.collapsed .brand-text {
    display: block;
  }

  .sidebar.collapsed nav .nav-item {
    justify-content: flex-start;
    padding: 12px 14px;
  }

  .sidebar.collapsed .nav-item .label {
    display: inline;
  }

  .sidebar.collapsed .sidebar-footer {
    display: block;
  }

  .content {
    padding: 18px 14px;
    max-width: 100%;
  }

  .page-header {
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 18px;
  }

  .page-header h2 {
    font-size: 19px;
  }

  .card {
    padding: 16px 14px;
  }

  .hero-total {
    padding: 20px 18px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .hero-total .value {
    font-size: 26px;
  }

  .btn-row {
    gap: 8px;
  }

  button.btn {
    padding: 10px 14px;
  }

  input[type=text],
  input[type=number],
  input[type=password] {
    padding: 9px 10px;
    font-size: 14px;
  }

  .chart-box {
    height: 230px;
  }

  /* ================= FLAGGED ASSETS MOBILE ================= */
  #page-flagged {
    overflow-x: hidden;
  }

  #page-flagged .page-relative,
  #page-flagged .card {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  #page-flagged .card {
    padding: 14px 12px;
  }

  #page-flagged .card h3 {
    font-size: 16px;
    line-height: 1.7;
  }

  #page-flagged .card h3 small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.6;
  }

  /* Main groups table: fixed, compact horizontal layout instead of table-to-grid conversion. */
  #page-flagged > .page-relative > .card:first-of-type > .table-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
  }

  #page-flagged > .page-relative > .card:first-of-type > .table-scroll > table {
    width: 100%;
    min-width: 640px;
    table-layout: fixed;
  }

  #page-flagged > .page-relative > .card:first-of-type > .table-scroll > table th,
  #page-flagged > .page-relative > .card:first-of-type > .table-scroll > table td {
    padding: 9px 7px;
    font-size: 12px;
    white-space: normal;
    vertical-align: middle;
  }

  #page-flagged > .page-relative > .card:first-of-type > .table-scroll > table th:nth-child(1),
  #page-flagged > .page-relative > .card:first-of-type > .table-scroll > table td:nth-child(1) {
    width: 42px;
  }

  #page-flagged > .page-relative > .card:first-of-type > .table-scroll > table th:nth-child(2),
  #page-flagged > .page-relative > .card:first-of-type > .table-scroll > table td:nth-child(2) {
    width: 150px;
  }

  #page-flagged > .page-relative > .card:first-of-type > .table-scroll > table th:nth-child(7),
  #page-flagged > .page-relative > .card:first-of-type > .table-scroll > table td:nth-child(7) {
    width: 72px;
  }

  #flaggedGroupsTableBody input[type=text] {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  #flaggedGroupsTableBody .asset-toggle {
    width: 30px;
    height: 30px;
    min-width: 30px;
  }

  #flaggedGroupsTableBody .btn-danger {
    padding: 7px 9px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* Nested details keep real table semantics for reliable mobile rendering. */
  #page-flagged .holdings-row > td {
    padding: 8px 0 14px !important;
  }

  #page-flagged .holdings-row .table-scroll,
  #page-flagged .holdings-row .holdings-scroll {
    width: 100%;
    max-width: calc(100vw - 56px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #page-flagged .holdings-table {
    min-width: 900px !important;
    width: 900px;
    table-layout: fixed;
  }

  #page-flagged .holdings-table th,
  #page-flagged .holdings-table td {
    padding: 8px 6px;
    font-size: 12px;
    vertical-align: middle;
  }

  #page-flagged .holdings-table th:nth-child(1),
  #page-flagged .holdings-table td:nth-child(1) {
    width: 130px;
    min-width: 130px;
  }

  #page-flagged .holdings-table th:nth-child(2),
  #page-flagged .holdings-table td:nth-child(2) {
    width: 150px;
    min-width: 150px;
  }

  #page-flagged .holdings-table th:nth-child(3),
  #page-flagged .holdings-table td:nth-child(3) {
    width: 72px;
    min-width: 72px;
  }

  #page-flagged .holdings-table th:nth-child(4),
  #page-flagged .holdings-table td:nth-child(4),
  #page-flagged .holdings-table th:nth-child(5),
  #page-flagged .holdings-table td:nth-child(5) {
    width: 135px;
    min-width: 135px;
  }

  #page-flagged .holdings-table th:nth-child(6),
  #page-flagged .holdings-table td:nth-child(6) {
    width: 120px;
    min-width: 120px;
  }

  #page-flagged .holdings-table th:nth-child(7),
  #page-flagged .holdings-table td:nth-child(7) {
    width: 85px;
    min-width: 85px;
  }

  #page-flagged .holdings-table th:nth-child(8),
  #page-flagged .holdings-table td:nth-child(8) {
    width: 110px;
    min-width: 110px;
  }

  #page-flagged .holdings-table th:nth-child(9),
  #page-flagged .holdings-table td:nth-child(9) {
    width: 65px;
    min-width: 65px;
  }

  #page-flagged .holdings-table input,
  #page-flagged .holdings-table select {
    width: 100% !important;
    max-width: 100%;
    min-width: 0 !important;
    box-sizing: border-box;
  }

  #page-flagged .holdings-table td:nth-child(3) input[type=number] {
    width: 100% !important;
    min-width: 0 !important;
  }

  #page-flagged .holdings-table .readonly-amount {
    display: block;
    width: 100%;
    box-sizing: border-box;
    white-space: nowrap;
  }

  #page-flagged .holdings-total-line {
    margin-top: 8px;
    font-size: 12px;
    line-height: 1.8;
    white-space: normal;
  }

  #page-flagged .btn-row {
    flex-wrap: wrap;
  }

  #page-flagged .btn-row .btn {
    flex: 1 1 150px;
  }
}

@media (max-width: 480px) {
  #page-flagged .card {
    padding: 12px 10px;
  }

  #page-flagged > .page-relative > .card:first-of-type > .table-scroll > table {
    min-width: 610px;
  }

  #page-flagged .holdings-row .table-scroll,
  #page-flagged .holdings-row .holdings-scroll {
    max-width: calc(100vw - 48px);
  }

  #page-flagged .btn-row .btn {
    flex: 1 1 100%;
  }
}
