@media (max-width: 1023px) {
  .contacts-page {
    gap: 16px;
    height: calc(100vh - 80px);
  }

  .contacts-sidebar {
    min-height: calc(100vh - 100px);
  }

  .contacts-sidebar {
    flex: 0 1 clamp(401px, 34vw, 456px);
    width: auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: auto;
    align-self: stretch;
    min-height: 0;
    background-color: #ffffff;
    border-right: 1px solid #e0e0e009;
    box-shadow: 4px 0 8px rgba(0, 0, 0, 0.08);
    padding: 32px clamp(16px, 2.5vw, 52px);
  }

  .contacts-main {
    padding: 32px 24px;
  }

  .contacts-header h1 {
    font-size: 40px;
  }

  .header-line {
    height: 40px;
  }

  .avatar.big {
    width: 104px;
    height: 104px;
    font-size: 42px;
  }

  .header {
    padding: 24px 40px !important;
    height: 96px;
  }

  .contact-toast {
    right: 32px;
    bottom: 120px;
    padding: 14px 20px;
    font-size: 18px;
  }
}

@media (max-width: 425px) {
  .header {
    height: 80px;
  }
}

@media (max-width: 768px) {
  .contacts-header h1 {
    font-size: 36px;
  }

  .contact-detail-header h2 {
    font-size: 28px;
  }
}

@media (max-width: 680px) {
  .contacts-page {
    display: block;
    min-height: calc(100vh - 100px);
    background: #f6f7f8;
    height: calc(100vh - 100px);
  }

  .contacts-sidebar {
    max-width: none !important;
    width: 100% !important;
    min-width: 0;
    height: calc(100vh - 100px);
    padding: 16px 16px 0px;
    background: #fff;
    box-shadow: none;
    border: 0;
    flex: none;
    margin: 0 !important;
    box-sizing: border-box;
  }

  .contacts-scroll-wrap {
    flex: 1;
    min-height: 0;
    min-width: 0;
    left: 15px;
  }

  .contacts-scroll {
    max-height: calc(100vh - 220px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.25) transparent;
  }

  .contacts-scroll::-webkit-scrollbar {
    width: 6px;
  }

  .contacts-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
  }

  .contacts-scroll::-webkit-scrollbar-track {
    background: transparent;
  }

  .contacts-list {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    position: static;
  }

  .letter-group {
    width: 100%;
    margin: 0;
    padding: 10px 12px 8px;
    font-size: 16px;
    color: #2a3647;
    background: transparent;
    position: relative;
    left: 10px;
    border-bottom: 0;
  }

  .letter-group::after {
    content: "";
    position: absolute;
    left: -12px;
    right: 50px;
    bottom: 0;
    height: 1px;
    background: #d1d1d1;
  }

  .contact-item {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 12px 12px;
    border-radius: 8px;
    gap: 12px;
  }

  .contact-item:hover {
    background: #f5f5f5;
  }

  .avatar {
    width: 42px;
    height: 42px;
    font-size: 16px;
    position: relative;
    right: 5px;
  }

  .contact-name,
  .contact-mail {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    font-size: 16px;
    position: relative;
    left: 20px;
  }

  .contacts-main {
    display: none;
    width: 100%;
    max-width: 100%;
    min-height: calc(100vh - 100px);
    height: auto;
    padding: 16px 16px 0px;
    background: #f6f7f8;
    box-sizing: border-box;
  }

  body.show-contact-details .contacts-sidebar {
    display: none;
  }

  body.show-contact-details .contacts-main {
    display: block;
  }

  .contacts-header {
    margin: 6px 0 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    column-gap: 10px;
    row-gap: 6px;
    align-items: start;
    max-width: 100%;
    padding: 0;
    position: relative;
    left: 5px;
  }

  .contacts-header h1 {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    margin: 0;
    font-size: 44px;
    font-weight: 700;
    letter-spacing: 0.2px;
    max-width: 100%;
    white-space: normal;
  }

  .header-line {
    display: none;
  }

  .contacts-header span {
    grid-column: 1 / 2;
    grid-row: 2 / 3;
    margin: 0;
    font-size: 16px;
    color: #777;
    line-height: 1.2;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    position: relative;
    display: inline-block;
    padding-bottom: 10px;
  }

  .contacts-header span::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 90px;
    height: 3px;
    background: #29ABE2;
    border-radius: 2px;
  }

  #mobileBackBtn,
  #contactsBackBtn,
  .contacts-back-btn {
    grid-column: 2 / 3;
    grid-row: 1 / 3;
    align-self: start;
    justify-self: end;
    display: inline-flex;
    padding: 8px;
    border-radius: 10px;
    background: transparent;
    border: 0;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: none;
    outline: none;
  }

  .contact-item {
    width: calc(100% - 30px);
    margin-right: 16px;
  }

  #mobileBackBtn img,
  #contactsBackBtn img,
  .contacts-back-btn img {
    display: block;
    width: 24px;
    height: 24px;
    box-shadow: none;
    filter: none;
  }

  .contact-details {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-top: 14px;
    padding: 18px 0 0;
  }

  .contact-detail-header {
    gap: 16px;
    align-items: center;
    margin-bottom: 18px;
    min-width: 0;
  }

  .avatar.big {
    width: 92px;
    height: 92px;
    font-size: 34px;
    border: 3px solid #fff;
  }

  .contact-detail-header h2 {
    font-size: 30px;
    line-height: 1.1;
    margin: 0;
    max-width: 100%;
    white-space: normal;
    min-width: 0;
  }

  .contact-actions {
    display: none;
  }

  .contact-info h3 {
    font-size: 18px;
    margin: 0 0 14px;
  }

  .contact-info p {
    font-size: 16px;
    margin: 0 0 14px;
    overflow-wrap: anywhere;
  }

  .contacts-sidebar .contacts-add-btn {
    position: fixed;
    right: 20px;
    bottom: 90px;
    width: 56px;
    height: 56px;
    padding: 0;
    border-radius: 50%;
    margin: 0;
    gap: 0;
    font-size: 0;
    line-height: 0;
    z-index: 9998;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    background: #2a3647;
    border-color: #2a3647;
  }

  .contacts-sidebar .contacts-add-btn:hover {
    background: #29ABE2;
    border-color: #29ABE2;
  }

  #mobileMenuBtn {
    position: fixed;
    right: 20px;
    bottom: 98px !important;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #2a3647;
    color: #ffffff;
    border: none;
    font-size: 22px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    z-index: 99999;
    pointer-events: auto;
  }


  #mobileMenuBtn:hover {
    background: #29ABE2;
  }

  body:not(.show-contact-details) #mobileMenuBtn {
    display: none;
  }

  body.show-contact-details #mobileMenuBtn {
    display: flex;
  }

  #mobileActionsMenu {
    display: none;
    flex-direction: column;
    position: fixed;
    right: 18px;
    bottom: 155px;
    background: #fff;
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.16);
    z-index: 100000;
    min-width: 160px;
    max-width: calc(100vw - 36px);
    pointer-events: auto;
  }

  body.show-contact-details #mobileActionsMenu.is-open {
    display: flex;
  }

  .contacts-more-item {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 0;
    background: transparent;
    padding: 12px 12px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    color: #2a3647;
  }

  .contacts-more-item img {
    width: 18px;
    height: 18px;
  }

  .contacts-more-item:hover {
    background: #f6f7f8;
    color: #29abe2;
  }

  body.show-contact-details .contacts-sidebar .contacts-add-btn {
    display: none;
  }

  #addContactModal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 66px 24px;
    box-sizing: border-box;
  }

  .modal {
    width: 100%;
    max-width: 396px;
    height: auto;
    margin: 0;
    display: flex;
    flex-direction: column;
    border-radius: 30px;
    background: transparent;
  }

  .modal-left {
    width: 100%;
    padding: 28px 20px 72px;
    border-radius: 30px 30px 0 0;
    box-sizing: border-box;
    min-height: 260px;
  }

  .modal-logo {
    display: none;
  }

  .modal-left h2 {
    font-size: 34px;
    font-weight: 700;
    line-height: 1.05;
    margin: 40px 0 0;
  }

  .modal-left .modal-subtitle,
  .modal-left p {
    margin: 10px 0 0;
    font-size: 16px;
    line-height: 1.2;
    opacity: 0.9;
  }

  .modal-close {
    color: #ffffff;
  }

  .modal-line {
    width: 90px;
    height: 3px;
    margin-top: 14px;
    border-radius: 2px;
  }

  .modal-right {
    width: 100%;
    padding: 72px 20px 20px;
    border-radius: 0 0 30px 30px;
    background: #f6f7f8;
    box-sizing: border-box;
  }

  .modal-person {
    position: absolute;
    left: 50%;
    top: -46px;
    transform: translateX(-50%);
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: #d1d1d1;
    border: 0px solid #ffffff;
    box-shadow: 0 0 0 3px #f6f7f8, 0 6px 12px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .modal-person img {
    width: 44px;
    opacity: 1;
  }

  #mobileMenuBtn,
  .contact-more-btn,
  .contacts-more-btn,
  #contactsMoreBtn {
    position: fixed;
    right: 10px;
    bottom: 112px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    z-index: 10;
    pointer-events: auto;
  }

  #mobileActionsMenu,
  #contactsMoreMenu {
    position: fixed;
    right: 10px;
    bottom: 155px;
    z-index: 100000;
    pointer-events: auto;
  }

  #addContactModal[data-mode="edit"] button[data-action="delete"] {
    display: inline-flex;
  }

  #addContactForm {
    max-width: 100%;
    margin: 10px 0 0;
    gap: 10px;
  }

  .input-wrapper input {
    width: 100%;
    height: 41px;
    border: 1px solid #d1d1d1;
    border-radius: 10px;
    padding: 13px 21px;
    font-size: 16px;
    background: white;
  }

  .input-icon {
    position: absolute;
    right: 14px;
    top: 21px;
    transform: translateY(-50%);
    width: 18px;
    opacity: 0.6;
    
  }

  .modal-actions {
    margin-top: 30px;
    display: flex;
    justify-content: center;
    gap: 12px;
  }

  .btn-cancel {
    display: none;
  }

  .btn-create {
    width: auto;
    max-width: none;
    height: 40px;
    padding: 0 24px;
    border-radius: 6px;
    justify-content: center;
  }

  #mobileMenuBtn,
  .contact-more-btn,
  .contacts-more-btn,
  #contactsMoreBtn {
    position: fixed;
    right: 20px;
    bottom: 120px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    z-index: 10;
    pointer-events: auto;
  }

  #mobileActionsMenu,
  #contactsMoreMenu {
    position: fixed;
    right: 18px;
    bottom: 155px;
    z-index: 1000000;
    pointer-events: auto;
  }

  .contacts-main,
  .contacts-page,
  .contacts-sidebar,
  .contacts-scroll,
  .contacts-scroll-wrap,
  .contact-details {
    pointer-events: auto;
  }

  .d-none {
    display: none;
    pointer-events: none;
  }

  .contact-toast {
    left: 50%;
    right: auto;
    bottom: 120px;
    transform: translateX(-50%);
    padding: 12px 18px;
    font-size: 16px;
    border-radius: 10px;
    max-width: 280px;
    text-align: center;
  }
}

@media (max-width: 460px) {
  .contacts-header h1 {
    font-size: 32px;
  }

  .contact-action {
    font-size: 16px;
  }

  .contacts-scroll {
    max-height: calc(100vh - 210px);
  }

  .letter-group {
    width: 100%;
    margin: 0;
    padding: 10px 12px 8px;
    font-size: 16px;
    color: #2a3647;
    background: transparent;
    position: relative;
    left: 10px;
    border-bottom: 0;
  }

  .input-wrapper input {
    width: 100%;
    height: 30px;
    border: 1px solid #d1d1d1;
    border-radius: 6px;
  }

  .contact-more-btn,
  .contacts-more-btn,
  #contactsMoreBtn {
    position: fixed;
    right: 5px;
    bottom: 112px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    z-index: 0;
    pointer-events: auto;
  }

  .input-icon {
    position: absolute;
    right: 14px;
    top: 15px;
    transform: translateY(-50%);
    width: 18px;
    opacity: 0.6;
    
  }

}

@media (max-width: 320px) {
  .contacts-header h1 {
    font-size: 28px;
  }

  .contacts-scroll {
    max-height: calc(100vh - 200px);
  }
}